first commit
This commit is contained in:
57
ldap_local.php
Executable file
57
ldap_local.php
Executable file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
|
||||
// Base DN bezeichnet die oberste OU unter der die User zu finden sind.
|
||||
$basedn = "ou=OUHochschulnetzwerk,dc=hsnet,dc=hs-ludwigsburg,dc=de";
|
||||
$server = "localhost";
|
||||
|
||||
// da der Zugriff auch ohne Anmeldung möglich sein soll, hab ich einen extra User im AD angelegt, um mich mit dem Server zu verbinden.
|
||||
|
||||
$username = "cn=LDAPqueryUser,dc=hsnet,dc=hs-ludwigsburg,dc=de";
|
||||
$password = "ldHS332";
|
||||
|
||||
$name_user = "schwaral";
|
||||
$password_user = "15879";
|
||||
|
||||
$ldap_port = "389";
|
||||
|
||||
$ds = @ldap_connect($server, $ldap_port);
|
||||
#ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
|
||||
if ($ds) {
|
||||
# bind wird benötigt, sonst werden die Umlaute bei Namen nicht richtig angezeigt ?!!?
|
||||
$r = ldap_bind($ds, $username, $password);
|
||||
if($r){
|
||||
echo "bind erfolgreich<br>";
|
||||
}else{
|
||||
echo "bind fehlgeschlagen<br>";
|
||||
}
|
||||
$_ldap_dn = "dc=hsnet,dc=hs-ludwigsburg,dc=de";
|
||||
$sr = ldap_search($ds, $_ldap_dn, "sAMAccountName=$name_user");
|
||||
$info = ldap_get_entries($ds, $sr);
|
||||
$anzahl = ldap_count_entries($ds, $sr);
|
||||
echo "Anzahl: $anzahl<br>";
|
||||
$vorname = $info[0]['givenname'][0];
|
||||
$nachname = $info[0]['sn'][0];
|
||||
$mail = $info[0]['mail'][0];
|
||||
$first = @ldap_first_entry($ds, $sr);
|
||||
$distinguishedName = @ldap_get_dn($ds, $first);
|
||||
echo $distinguishedName."<br>";
|
||||
################################
|
||||
|
||||
# Bind geht im hsnet nur über den DN "CN=Schwarz\, Alexander, OU=Externe Benutzer, ou=OUHochschulnetzwerk,dc=hsnet,dc=hs-ludwigsburg,dc=de"
|
||||
##!!!!! IM STUDNET MIT DEM USERNAMEN BINDEN, IM HSNET MIT DEM DISTINGUISHEDNAME !!!!!!#################
|
||||
if ($bind = @ldap_bind($ds, $distinguishedName, $password_user) AND $anzahl > 0) {
|
||||
#echo "hsnet: Bind funktioniert: $anzahl |$distinguishedName|<br>";
|
||||
$login = "0";
|
||||
$login_ad = "hsnet";
|
||||
} else {
|
||||
# Bind funktioniert nicht
|
||||
$login = "1";
|
||||
ldap_close($ds);
|
||||
#echo "hsnet: Bind funktioniert nicht: $anzahl <br>";
|
||||
}
|
||||
}else{
|
||||
echo "kein connect";
|
||||
}
|
||||
echo $login;
|
||||
?>
|
Reference in New Issue
Block a user