braveo:classeldap
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
braveo:classeldap [2012/01/04 11:33] – modification externe 127.0.0.1 | braveo:classeldap [2024/04/16 22:20] (Version actuelle) – modification externe 127.0.0.1 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ==== LDAP.classe.php ==== | ||
+ | Cette classe PHP nous servira pour le différente opération à effectuer sur le serveur LDAP. | ||
+ | |||
+ | <code PHP> | ||
+ | |||
+ | <?php | ||
+ | / | ||
+ | /* */ | ||
+ | /* | ||
+ | /* |\/| |__| | [__ | | |\ | | \ | | | | |__] |__/ |___ */ | ||
+ | /* | ||
+ | /* */ | ||
+ | / | ||
+ | /* */ | ||
+ | /* Titre : Classe LDAP */ | ||
+ | /* */ | ||
+ | /* URL : http:// | ||
+ | /* Auteur : : Arnaud | ||
+ | /* Date édition | ||
+ | /* */ | ||
+ | /* Licence | ||
+ | / | ||
+ | |||
+ | class LDAP | ||
+ | { | ||
+ | // Adresse du serveur LDAP | ||
+ | private $serveur; | ||
+ | |||
+ | // Port du serveur | ||
+ | private $port; | ||
+ | |||
+ | // Base Dn pour l' | ||
+ | private $basedndn; | ||
+ | |||
+ | // Base Dn de connexion pour les modifications au niveau du ldap | ||
+ | private $rootdn; | ||
+ | |||
+ | // Mot de passe du LDAP | ||
+ | private | ||
+ | |||
+ | // Attribut de connexion | ||
+ | private $connexion; | ||
+ | |||
+ | // Attribut d' | ||
+ | private $identification; | ||
+ | |||
+ | // Attribut profil utilisateur | ||
+ | private $info_user; | ||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | // Définition du constructeur | ||
+ | public function __construct($serveur, | ||
+ | { | ||
+ | | ||
+ | // Vérification des variables | ||
+ | if (empty ($serveur) || empty ($port) || empty ($basedn) | ||
+ | exit; | ||
+ | } | ||
+ | else { | ||
+ | // Initialisation des attributs | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | | ||
+ | } | ||
+ | } // fin de la méthode | ||
+ | |||
+ | |||
+ | // Méthode de connexion | ||
+ | public function Connexion() | ||
+ | { | ||
+ | // Connexion au LDAP | ||
+ | $this-> | ||
+ | |||
+ | ldap_set_option($this-> | ||
+ | |||
+ | // Vérification de la connexion | ||
+ | if (!$this-> | ||
+ | { | ||
+ | // si erreur | ||
+ | return false; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | return true; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Méthode Identification() | ||
+ | public function Identification () | ||
+ | { | ||
+ | // Identification sur le serveur | ||
+ | $ident = @ldap_bind($this-> | ||
+ | |||
+ | // | ||
+ | if ($ident) | ||
+ | { | ||
+ | $this-> | ||
+ | return true; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | return false; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | /* Méthode qui retourne true si un utilisateur est enregistré dans le ldap | ||
+ | | ||
+ | |||
+ | public function Verif_utilisateur($utilisateur) | ||
+ | { | ||
+ | $champ_recherche = " | ||
+ | |||
+ | $search = ldap_search($this-> | ||
+ | if ($search != false ) | ||
+ | { | ||
+ | $info = ldap_get_entries($this-> | ||
+ | |||
+ | if ( $info[" | ||
+ | |||
+ | { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | else { | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | } // fin de la Méthode | ||
+ | |||
+ | |||
+ | /* Méthode qui récupère les informations | ||
+ | | ||
+ | |||
+ | public function Informations_utilisateur($utilisateur) | ||
+ | { | ||
+ | // si l' | ||
+ | |||
+ | if ($this-> | ||
+ | { | ||
+ | $profil = array ( | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | | ||
+ | return $profil; | ||
+ | } | ||
+ | else { | ||
+ | |||
+ | | ||
+ | } | ||
+ | |||
+ | } // fin de la Méthode | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | /* Méthode qui renvoie le nombre d' | ||
+ | |||
+ | public function Nombre_utilisateurs() | ||
+ | { | ||
+ | | ||
+ | |||
+ | | ||
+ | if ($search != false ) | ||
+ | { | ||
+ | $nombre = ldap_count_entries($this-> | ||
+ | | ||
+ | if ($nombre != false ) | ||
+ | { return $nombre; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | return false; | ||
+ | } // fin de la Méthode | ||
+ | |||
+ | |||
+ | // Méthode qui vérifie le mot de passe d'un utilisateur | ||
+ | |||
+ | | ||
+ | { | ||
+ | |||
+ | // on vérifie si le mot de passe est bon | ||
+ | if (@ldap_bind($this-> | ||
+ | |||
+ | | ||
+ | // @ldap_bind($this-> | ||
+ | | ||
+ | } | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | |||
+ | // Méthode qui permet de changer son mot de passe | ||
+ | | ||
+ | public function Modifier_mot_de_passe($utilisateur, | ||
+ | | ||
+ | |||
+ | if ( $this-> | ||
+ | { | ||
+ | // si le mot de passe actuel est valide, on peut le changer | ||
+ | | ||
+ | | ||
+ | |||
+ | // on ajoute le nouveau mot de passe dans le ldap | ||
+ | if (@ldap_modify($this-> | ||
+ | |||
+ | |||
+ | | ||
+ | } | ||
+ | | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | // on modifie l' | ||
+ | if (ldap_modify($this-> | ||
+ | { | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | return false; | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | // Ajout d'un utilisateur dans le ldap avec uid = cn | ||
+ | |||
+ | | ||
+ | { | ||
+ | $espace = " "; | ||
+ | $nom_prenom = $prenom . $espace . $nom; // concaténation | ||
+ | $les_initials = $prenom[0].$nom[0]; | ||
+ | $mdl29 = " | ||
+ | $adr_mail = $identifiant.$mdl29; | ||
+ | |||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | $entry[' | ||
+ | |||
+ | // on ajoute le compte dans le ldap | ||
+ | $res=@ldap_add($this-> | ||
+ | return $res; | ||
+ | } | ||
+ | |||
+ | // on passe en paramètre $attribut qui est un tableau | ||
+ | | ||
+ | |||
+ | |||
+ | |||
+ | // on modifie le prénom | ||
+ | if (array_key_exists(' | ||
+ | { | ||
+ | $entry[' | ||
+ | } | ||
+ | |||
+ | |||
+ | // on modifie le nom | ||
+ | if (array_key_exists(' | ||
+ | { | ||
+ | |||
+ | $entry[' | ||
+ | } | ||
+ | |||
+ | // on modifie le displayname | ||
+ | if (array_key_exists(' | ||
+ | | ||
+ | $entry[' | ||
+ | } | ||
+ | |||
+ | |||
+ | // on modifie les initials | ||
+ | if (array_key_exists(' | ||
+ | | ||
+ | $entry[' | ||
+ | } | ||
+ | |||
+ | |||
+ | // on modifie l' | ||
+ | |||
+ | if (array_key_exists(' | ||
+ | { | ||
+ | $entry[' | ||
+ | } | ||
+ | |||
+ | // url du blog et chimere | ||
+ | if (array_key_exists(' | ||
+ | { | ||
+ | $entry[' | ||
+ | (array_key_exists(' | ||
+ | ); | ||
+ | } | ||
+ | |||
+ | if (@ldap_modify($this-> | ||
+ | { | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | | ||
+ | |||
+ | } // fin méthode | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | // Méthode Deconnexion() | ||
+ | |||
+ | public function Deconnexion(){ | ||
+ | |||
+ | // Déconnexion du serveur | ||
+ | $deconnexion = @ldap_unbind($this-> | ||
+ | if(!$deconnexion) | ||
+ | @ldap_close($this-> | ||
+ | } //fin de déconnexion | ||
+ | |||
+ | } //fin de la classe | ||
+ | ?> | ||
+ | |||
+ | </ |