Skip to content
Snippets Groups Projects
Select Git revision
  • 891d819e660ea9182923f17f91794d09bef1920b
  • master default protected
  • Legacy_Php7
3 results

ldap.class.php

Blame
  • ldap.class.php 17.68 KiB
    <?php
    
    /**
     * IML LDAP CONNECTOR FOR USER AUTHENTICATION
     *
     * @author axel.hahn@iml.unibe.ch
     */
    class imlldap {
    
        private $_aLdap = array(
            'server'       => false,
            'port'         => false,
            'DnLdapUser' => false, // ldap rdn oder dn
            'PwLdapUser' => false,
            'DnUserNode'   => false,   // ou=People...
            'DnAppNode'    => false,   // cn=AppGroup...
            'protoVersion' => 3,
            'debugLevel'   => 0,
        );
        private $_ldapConn = false;
        private $_ldapBind = false;
        var $bDebug = false;
    
        /**
         * constructor
         * @param array  $aConfig  optional set ldap connection
         */
        public function __construct($aConfig = array()) {
            if (!function_exists("ldap_connect")){
                die(__CLASS__ . " ERROR: php-ldap module is not installed on this server.");
            }
            if (count($aConfig)) {
                $this->setConfig($aConfig);
            }
        }
    
        public function __destruct() {
            $this->close();
        }
    
    
        // ----------------------------------------------------------------------
        // write debug text
        // ----------------------------------------------------------------------
        
        /**
         * turn debug messages on;
         * if this detail level is not enough, set a value with key debugLevel in 
         * ldap config array
         * @see setConfig()
         */
        public function debugOn(){
            $this->bDebug=true;
            if($this->_aLdap['debugLevel']){
                $this->_w(__FUNCTION__ . ' setting debug level ' . $this->_aLdap['debugLevel']);
                ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, $this->_aLdap['debugLevel']);
            }
        }
        
        /**
         * turn debug messages off
         */
        public function debugOff(){
            $this->bDebug=false;
            ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 0);
        }
        
    
        private function _w($sText) {
            if (!$this->bDebug) {