*/ class LSsession { var $confDir = NULL; var $ldapServer = NULL; var $ldapServerId = NULL; var $topDn = NULL; var $LSuserObject = NULL; var $dn = NULL; var $rdn = NULL; var $JSscripts = array(); var $CssFiles = array(); var $template = NULL; var $LSrights = array ( 'topDn_admin' => array () ); var $LSaccess = array(); /** * Constructeur * * @author Benjamin Renard * * @retval void */ function LSsession ($configDir=LS_DEFAULT_CONF_DIR) { $this -> confDir = $configDir; if ($this -> loadConfig()) { $this -> startLSerror(); } else { return; } } /* * Chargement de la configuration * * Chargement des fichiers de configuration et création de l'objet Smarty. * * @author Benjamin Renard * * @retval true si tout c'est bien passé, false sinon */ function loadConfig() { if (loadDir($this -> confDir, '^config\..*\.php$')) { if ( @include_once $GLOBALS['LSconfig']['Smarty'] ) { $GLOBALS['Smarty'] = new Smarty(); return true; } else { $GLOBALS['LSerror'] -> addErrorCode(1008); return; } return true; } else { return; } } /* * Initialisation de la gestion des erreurs * * Création de l'objet LSerror * * @author Benjamin Renard loadLSclass('LSerror')) return; $GLOBALS['LSerror'] = new LSerror(); return true; } /* * Chargement d'une classe d'LdapSaisie * * @param[in] $class Nom de la classe à charger (Exemple : LSeepeople) * @param[in] $type (Optionnel) Type de classe à charger (Exemple : LSobjects) * * @author Benjamin Renard loadLSclass($object,'LSobjects')) return; if (!require_once( LS_OBJECTS_DIR . 'config.LSobjects.'.$object.'.php' )) return; return true; } /* * Chargement des objects LdapSaisie * * Chargement des LSobjects contenue dans la variable * $GLOBALS['LSobjects_loads'] * * @retval boolean true si le chargement a réussi, false sinon. */ function loadLSobjects() { $this -> loadLSclass('LSldapObject'); if(!is_array($GLOBALS['LSobjects_loads'])) { $GLOBALS['LSerror'] -> addErrorCode(1001,"LSobjects['loads']"); return; } foreach ($GLOBALS['LSobjects_loads'] as $object) { if ( !$this -> loadLSobject($object) ) return; } return true; } /* * Chargement d'un addons d'LdapSaisie * * @param[in] $addon Nom de l'addon à charger (Exemple : samba) * * @author Benjamin Renard addErrorCode(1001,"LSaddons['loads']"); return; } foreach ($GLOBALS['LSaddons']['loads'] as $addon) { $this -> loadLSaddon($addon); if (!call_user_func('LSaddon_'. $addon .'_support')) { $GLOBALS['LSerror'] -> addErrorCode(1002,$addon); } } return true; } /* * Initialisation de la session LdapSaisie * * Initialisation d'une LSsession : * - Authentification et activation du mécanisme de session de LdapSaisie * - ou Chargement des paramètres de la session à partir de la variable * $_SESSION['LSsession']. * - ou Destruction de la session en cas de $_GET['LSsession_logout']. * * @retval boolean True si l'initialisation à réussi (utilisateur authentifié), false sinon. */ function startLSsession() { $this -> loadLSobjects(); $this -> loadLSaddons(); session_start(); // Déconnexion if (isset($_GET['LSsession_logout'])) { session_destroy(); unset($_SESSION['LSsession']); } if(isset($_SESSION['LSsession'])) { // Session existante $this -> confDir = $_SESSION['LSsession'] -> confDir; $this -> topDn = $_SESSION['LSsession'] -> topDn; //$this -> LSuserObject = $_SESSION['LSsession'] -> LSuserObject; $this -> dn = $_SESSION['LSsession'] -> dn; $this -> rdn = $_SESSION['LSsession'] -> rdn; $this -> ldapServerId = $_SESSION['LSsession'] -> ldapServerId; if ( ($GLOBALS['LSconfig']['cacheLSrights']) || ($this -> ldapServer['cacheLSrights']) ) { $this -> ldapServer = $_SESSION['LSsession'] -> ldapServer; $this -> LSrights = $_SESSION['LSsession'] -> LSrights; $this -> LSaccess = $_SESSION['LSsession'] -> LSaccess; if (!$this -> LSldapConnect()) return; } else { $this -> setLdapServer($this -> ldapServerId); if (!$this -> LSldapConnect()) return; $this -> loadLSrights(); } $this -> LSuserObject = new $this -> ldapServer['authobject'](); $this -> LSuserObject -> loadData($this -> dn); $this -> loadLSaccess(); $GLOBALS['Smarty'] -> assign('LSsession_username',$this -> LSuserObject -> getDisplayValue()); return true; } else { // Session inexistante if (isset($_POST['LSsession_user'])) { if (isset($_POST['LSsession_ldapserver'])) { $this -> setLdapServer($_POST['LSsession_ldapserver']); } else { $this -> setLdapServer(0); } // Connexion au serveur LDAP if ($this -> LSldapConnect()) { // topDn if ( $_POST['LSsession_topDn'] != '' ){ $this -> topDn = $_POST['LSsession_topDn']; } else { $this -> topDn = $this -> ldapServer['ldap_config']['basedn']; } if ( $this -> loadLSobject($this -> ldapServer['authobject']) ) { $authobject = new $this -> ldapServer['authobject'](); $result = $authobject -> searchObject($_POST['LSsession_user'],$this -> topDn); $nbresult=count($result); if ($nbresult==0) { // identifiant incorrect debug('identifiant incorrect'); $GLOBALS['LSerror'] -> addErrorCode(1006); } else if ($nbresult>1) { // duplication d'authentité $GLOBALS['LSerror'] -> addErrorCode(1007); } else { if ( $this -> checkUserPwd($result[0],$_POST['LSsession_pwd']) ) { // Authentification réussi $this -> LSuserObject = $result[0]; $this -> dn = $result[0]->getValue('dn'); $this -> rdn = $_POST['LSsession_user']; $this -> loadLSrights(); $this -> loadLSaccess(); $GLOBALS['Smarty'] -> assign('LSsession_username',$this -> LSuserObject -> getDisplayValue()); $_SESSION['LSsession']=$this; return true; } else { $GLOBALS['LSerror'] -> addErrorCode(1006); debug('mdp incorrect'); } } } else { $GLOBALS['LSerror'] -> addErrorCode(1010); } } else { $GLOBALS['LSerror'] -> addErrorCode(1009); } } $this -> displayLoginForm(); return; } } /* * Définition du serveur Ldap de la session * * Définition du serveur Ldap de la session à partir de son ID dans * le tableau $GLOBALS['LSconfig']['ldap_servers']. * * @param[in] integer Index du serveur Ldap * * @retval boolean True sinon false. */ function setLdapServer($id) { if ( isset($GLOBALS['LSconfig']['ldap_servers'][$id]) ) { $this -> ldapServerId = $id; $this -> ldapServer=$GLOBALS['LSconfig']['ldap_servers'][$id]; return true; } else { return; } } /* * Connexion au serveur Ldap * * @retval boolean True sinon false. */ function LSldapConnect() { if ($this -> ldapServer) { include_once($GLOBALS['LSconfig']['NetLDAP']); if (!$this -> loadLSclass('LSldap')) return; $GLOBALS['LSldap'] = new LSldap($this -> ldapServer['ldap_config']); if ($GLOBALS['LSldap'] -> isConnected()) return true; else return; return $GLOBALS['LSldap'] = new LSldap($this -> ldapServer['ldap_config']); } else { $GLOBALS['LSerror'] -> addErrorCode(1003); return; } } function getSubDnLdapServer() { if ( isset($this ->ldapServer['subdnobject']) ) { if( $this -> loadLSobject($this ->ldapServer['subdnobject']) ) { if ($subdnobject = new $this ->ldapServer['subdnobject']()) { return $subdnobject -> getSelectArray(); } else { return; } } else { $GLOBALS['LSerror'] -> addErrorCode(1004,$this ->ldapServer['subdnobject']); return; } } else { return; } } /* * Retourne les options d'une liste déroulante pour le choix du topDn * de connexion au serveur Ldap * * Liste les subdnobject ($this ->ldapServer['subdnobject']) * * @retval string Les options (