[ Index ]
 

Code source de SPIP Agora 1.4

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/Agora1-4/ecrire/ -> inc_auth_ldap.php (source)

   1  <?php
   2  /*****************************************************
   3  * This file is part of Agora, web based content management system.
   4  *
   5  * Agora is free software; you can redistribute it and/or modify
   6  * it under the terms of the GNU General Public License as published by
   7  * the Free Software Foundation; version 2 of the License.
   8  *
   9  * Agora is distributed in the hope that it will be useful,
  10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  * GNU General Public License for more details (file "COPYING").
  13  *
  14  * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière.
  15  * List of authors detailed in "copyright_fr.html" file.
  16  * E-mail : agora@sig.premier-ministre.gouv.fr
  17  * Web site : http://www.agora.gouv.fr
  18  *****************************************************/
  19  // Ce fichier ne sera execute qu'une fois
  20  if (defined("_ECRIRE_INC_AUTH_LDAP"))
  21      return;
  22  
  23  define("_ECRIRE_INC_AUTH_LDAP", "1");
  24  
  25  class Auth_ldap {
  26      var $user_dn;
  27      var $auteurId, $nom, $login, $email, $pass, $statut, $bio;
  28  
  29  	function init () {
  30          if (!$GLOBALS['ldap_present'])
  31              return false;
  32          else {
  33              $auteurLDAP = &recuperer_instance_auteur(true);
  34              return true;
  35          }
  36      }
  37  
  38  	function verifier_challenge_md5 ($login, $mdpass_actuel, $mdpass_futur) {
  39          return false;
  40      }
  41  
  42  	function verifier ($login, $pass) {
  43          global $ldap_link, $ldap_base;
  44  
  45          // Securite, au cas ou le serveur LDAP est tres laxiste
  46          if (!$login || !$pass)
  47              return false;
  48  
  49          // Attributs testes pour egalite avec le login
  50          $atts = array('uid', 'login', 'userid', 'cn', 'sn');
  51          $login_search = ereg_replace("[^-._[:space:][:alnum:]]", "", $login); // securite
  52  
  53          $auteurLDAP = &recuperer_instance_auteur(true);
  54  
  55          if ($auteurLDAP->verifyPassword($login, $pass)) {
  56              $this->user_dn = $auteurLDAP->getAuteurDN();
  57              $this->login = $login;
  58              return true;
  59          }
  60          else {
  61              return false;
  62          }
  63      }
  64  
  65  	function lire () {
  66          global $ldap_link, $ldap_base, $flag_utf8_decode;
  67          $this->nom = $this->email = $this->pass = $this->statut = 'NULL';
  68  
  69          if (!$this->login)
  70              return false;
  71  
  72          // Si l'auteur existe dans la base, y recuperer les infos
  73          $auteurMetier = &recuperer_instance_auteur();
  74          $allAuteurs = $auteurMetier->getAllForLoginAndSource($this->login, 'ldap');
  75  
  76          if (PEAR::isError($allAuteurs)) {
  77              die ($allAuteurs->getMessage());
  78          }
  79  
  80          while (list(, $auteurMetier) = each($allAuteurs)) {
  81              $this -> auteurId = $auteurMetier->getAuteurId();
  82              $this -> nom    = $auteurMetier->getNom();
  83              $this -> bio    = $auteurMetier->getBio();
  84              $this -> email    = $auteurMetier->getEmail();
  85              $this -> statut    = $auteurMetier->getStatut();
  86              return true;
  87          }
  88  
  89          // Lire les infos sur l'auteur depuis LDAP
  90          $auteurLDAP = &recuperer_instance_auteur(true);
  91          $auteurLDAP -> getAuteurInfos($this->login);
  92          $this -> nom    = $auteurLDAP->getNom();
  93          $this -> email    = $auteurLDAP->getEmail();
  94          $this -> login    = $auteurLDAP->getLogin();
  95          $this -> bio    = $auteurLDAP->getBio();
  96  
  97          // Convertir depuis UTF-8 (jeu de caracteres par defaut)
  98          if ($flag_utf8_decode) {
  99              $this -> nom    = utf8_decode($this->nom);
 100              $this -> email    = utf8_decode($this->email);
 101              $this -> login    = utf8_decode($this->login);
 102              $this -> bio    = utf8_decode($this->bio);
 103          }
 104  
 105          return true;
 106      }
 107  
 108  	function activer () {
 109          $nom            = addslashes($this->nom);
 110          $login            = addslashes($this->login);
 111          $email            = addslashes($this->email);
 112          $bio            = addslashes($this->bio);
 113          $statut            = lire_meta("ldap_profil_import");
 114          $profilMetier    = &recuperer_instance_profil();
 115          $monProfil        = $profilMetier->getProfilForIntitule($statut);
 116  
 117          $profil = $monProfil->getPoids();
 118  
 119          if (!$profil)
 120              return false;
 121  
 122          // Si l'auteur n'existe pas, l'inserer avec le statut par defaut (defini a l'install)
 123          $auteurMetier = &recuperer_instance_auteur();
 124          $size = $auteurMetier->getAllForLogin($login);
 125  
 126          if (PEAR::isError($size)) {
 127              die ($size->getMessage());
 128          }
 129  
 130          $auteurMetier->setSource('ldap');
 131          $auteurMetier->setNom($nom);
 132          $auteurMetier->setLogin($login);
 133          $auteurMetier->setEmail($email);
 134          $auteurMetier->setProfil($profil);
 135          $auteurMetier->setBio($bio);
 136          $auteurMetier->setPass('');
 137  
 138          if (sizeOf($size) == 0) {
 139              $createOK = $auteurMetier->create();
 140  
 141              if (PEAR::isError($createOK)) {
 142                  die ($createOK->getMessage());
 143              }
 144              $this->auteurId = $auteurMetier->_auteurId;
 145          }
 146      }
 147  }
 148  ?>


Généré le : Sat Feb 24 14:40:03 2007 par Balluche grâce à PHPXref 0.7