load_config(); // Eléments d'authentification LDAP $ldaprdn = $obj->config['pref'].$user.$obj->config['basedn']; // DN ou RDN LDAP //$ldappass = 'password'; // Mot de passe associé // Connexion au serveur LDAP $ldapconn = ldap_connect($obj->config['host']) or die("Impossible de se connecter au serveur LDAP."); ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3); if ($ldapconn) { // Connexion au serveur LDAP $ldapbind = ldap_bind($ldapconn, $ldaprdn, $pass); // Vérification de l'authentification if ($ldapbind) { // echo "Connexion LDAP réussie..."; return true; } else { // echo "Connexion LDAP échouée..."; return false; } } } class Ldap { var $config; function load_config() { $x = @file_get_contents( dirname(__FILE__).'/data.dat' ); if ($x!==false) { $c = unserialize($x); // do some more tests here $this->config = $c; } if ( !isset($this->config) or empty($this->config['Test']) ) { $this->config['host'] = 'localhost'; $this->config['basedn'] = ',ou=utilisateurs,dc=22decembre,dc=eu'; $this->config['pref'] = 'uid='; $this->save_config(); } } function save_config() { $file = fopen( dirname(__FILE__).'/data.dat', 'w' ); fwrite($file, serialize($this->config) ); fclose( $file ); } function ldap_admin_menu($menu) { array_push($menu, array( 'NAME' => 'Ldap Login', 'URL' => get_admin_plugin_menu_link(dirname(__FILE__).'/admin/ldap_login_plugin_admin.php') ) ); return $menu; } } $ldap = new Ldap(); $ldap->load_config(); add_event_handler('get_admin_plugin_menu_links', array(&$ldap, 'ldap_admin_menu')); set_plugin_data($plugin['id'], $ldap); ?>