[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-base-objects/www/includes/ -> ldap-class.inc.php (source)

   1  <?php
   2  
   3  require_once("config.inc.php");
   4  
   5  class Se3Ldap {
   6    public $res;
   7    public $dn;
   8  
   9    function __construct($anonymous=true) {
  10      // Paramètres défini dans la BD, lus par config
  11      global $ldap_server,$ldap_port,$ldap_base_dn,$adminRdn,$adminPw;
  12      global $peopleRdn,$groupsRdn,$rightsRdn,$trashRdn;
  13      global $parcsRdn,$computersRdn,$printersRdn;
  14        
  15      // Connexion au LDAP
  16      if ((!isset ($ldap_port) || ($ldap_port==''))) $ldap_port=389;
  17      $this->res = ldap_connect($ldap_server,$ldap_port);
  18      if (! $this->res) {
  19        return -1;
  20      }
  21  
  22      if (! ldap_set_option($this->res,LDAP_OPT_PROTOCOL_VERSION,3)) 
  23        syslog(LOG_WARNING,'se3-ldap : cannot fix ldap protocol version to 3');
  24        
  25      if ($anonymous) {
  26        ldap_bind($this->res);
  27      } else {
  28        ldap_bind($this->res,$adminRdn.",".$ldap_base_dn,$adminPw);
  29      }
  30  
  31      $this->dn=array();
  32      $this->dn['base']= $ldap_base_dn;
  33      $this->dn['people']= $peopleRdn.",".$ldap_base_dn;
  34      $this->dn['groups']= $groupsRdn.",".$ldap_base_dn;
  35      $this->dn['rights']= $rightsRdn.",".$ldap_base_dn;
  36      $this->dn['parcs']= $parcsRdn.",".$ldap_base_dn;
  37      $this->dn['computers']= $computersRdn.",".$ldap_base_dn;
  38      $this->dn['printers']= $printersRdn.",".$ldap_base_dn;
  39      $this->dn['trash']= $trashRdn.",".$ldap_base_dn;
  40  
  41    }
  42    
  43    function __destruct() {
  44      if ($this->res) {
  45        ldap_unbind($this->res);
  46      }
  47    }
  48  
  49    function get_groups($filter='') {
  50      $groups=array();
  51  
  52      $search_dn=$this->dn['groups'];
  53      $filter="(cn=".$filter."*)";
  54      $ldap_search_result=ldap_search($this->res,$search_dn,$filter);
  55      $info=ldap_get_entries($this->res,$ldap_search_result);
  56      $number_groups=$info['count'];
  57      for ($i=0;$i<$number_groups;$i++) {
  58        $groups[$info[$i]['cn']['0']]=$info[$i]['description']['0'];
  59      }
  60      return $groups;
  61    }
  62  
  63    function get_equipes() {
  64      return $this->get_groups('Equipe_');
  65    }
  66  
  67    function get_matieres() {
  68      return $this->get_groups('Matiere_');
  69    }
  70  
  71  }
  72  
  73  ?>


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1