===== ldap_view.inc =====
EOB;
}
function foot() {
echo <<
EOB;
}
function toolbar($login) {
echo <<
login : {$login} (disconnect)
My profile
La liste des utilisateurs
EOB;
}
function view_auth() {
echo <<
Authentification sur l'annuaire LDAP
Login
Password
EOB;
}
?>
===== ldap_model.inc =====
===== ldap_lib.inc =====
$v) {
if(is_array($v)) {
foreach($v as $k1=>$v1) {
if(is_array($v1)) {
foreach($v1 as $k2=>$v2) {
echo $k1."=".$v2."
";
}
}
}
}
}
//affiche une partie des données
for ($i=0;$i<$info["count"];$i++) {
$res[$i]["uid"]=$info[$i]["uid"][0];
$res[$i]["cn"]=$info[$i]["cn"][0];
}
return $res ;
}
else {
return "Erreur de connexion" ;
}
}
function ldapAddUser($login, $clearpass, $loginshell, $gidnumber, $uidnumber, $homedirectory) {
$host="localhost";
$rootdn="cn=admin,dc=univ-lehavre,dc=fr";
$rootpasswd="azerty";
$ds = ldap_connect($host);
if($ds) {
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$r=ldap_bind($ds,$rootdn,$rootpasswd);
$info["uid"] = $login ;
$info["cn"] = $login ;
$info["objectclass"][0] = "account" ;
$info["objectclass"][1] = "posixAccount" ;
$info["userpassword"] = "{crypt}".constructPass($clearpass);
$info["uidnumber"] = $uidnumber ;
$info["gidnumber"] = $gidnumber ;
$info["homedirectory"] = $homedirectory ;
$dn = "uid=".$login.",ou=users,dc=univ-lehavre,dc=fr";
$res = ldap_add($ds, $dn, $info);
$res = ldap_err2str( ldap_errno($ds) );
ldap_close($ds);
return $res ;
}
}
/**
* Genere un salt aléatoire de 8 caracteres
*/
function generateSalt($length) {
return substr(str_shuffle("abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
}
function constructPass($text) {
return crypt($text,'$1$'.generateSalt('8'));
}
//Delete
function ldapDelUser($dn) {
$host="localhost";
$rootdn="cn=admin,dc=univ-lehavre,dc=fr";
$rootpasswd="azerty";
$ds = ldap_connect($host);
if($ds) {
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$r=ldap_bind($ds,$rootdn,$rootpasswd);
$res=ldap_delete($ds,$dn);
ldap_close($ds);
}
return $res ;
}
function ldapModPassUser($login, $newpass) {
$host="localhost";
$rootdn="cn=admin,dc=univ-lehavre,dc=fr";
$rootpasswd="azerty";
$ds = ldap_connect($host);
$dn = "uid=".$login.",ou=users,dc=univ-lehavre,dc=fr";
$info["userpassword"]="{crypt}".constructPass($newpass);
if($ds) {
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$r=ldap_bind($ds,$rootdn,$rootpasswd);
$res=ldap_modify($ds,$dn,$info);
ldap_close($ds);
}
return $res;
}
?>