<?php
/**
* @author Bettina Schwarzer - Fritz-Haber-Institut
* @copyright 08/2013
*
* LDAP Test
*/
error_reporting(E_ALL ^ E_NOTICE);
$ldaphost = "ldap.rz-berlin.mpg.de"; // Ihr ldap servers
$ldapport = 389; // Die Portnummer ihres ldap servers
echo "<p>Test Verbindung zu LDAP</p>";
// Verbindung zu LDAP
$ldapconn = ldap_connect( $ldaphost, $ldapport )
or die( "Keine Verbindung zu {$ldaphost} möglich" );
if ($ldapconn)
{
echo "Verbindung zu LDAP erfolgreich -> $ldapconn<br />";
$login = $_POST["login"];
$log = $_POST["log"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<!-- <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> -->
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link href="/fhiiqm/css/db.css" rel="STYLESHEET" type="TEXT/CSS" />
<title>LDAP + fhiiqm</title>
</head>
<body onload="document.flogin.user.focus();">
<?php
if (!$log)
{
include ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/form/login_form.inc.php");
}
else
{
// $ldaprdn = "cn=admin,dc=rz-berlin,dc=mpg,dc=de";
// $ldappwd = 'ooboot';
$ldaprdn = "uid=" . $log["user"].",ou=people,dc=ppb,dc=rz-berlin,dc=mpg,dc=de";
$ldappwd = $log["pass"];
echo "rdn = $ldaprdn<br />";
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
$ldapbind = @ldap_bind($ldapconn, $ldaprdn, $ldappwd);
// $ldapbind = @ldap_bind($ldapconn);
$base="ou=people,dc=ppb,dc=rz-berlin,dc=mpg,dc=de";
if ($ldapbind)
{
echo "<p>Authentifizierung erfolgreich!</p>";
// Enable to show everything
$filter = "(sn=*)";
$afields = array ("uid","cn","givenName","sn","title","userPassword","mail");
$afieldsort = array ("uid","givenName","sn");
// search active directory
if (!($search=@ldap_search($ldapconn,$base,$filter,$afields))) {
die("Unable to search ldap server");
}
foreach ($afieldsort as $esort)
{
if (in_array($esort, $afields)) { // making sure we don't accidentally try to sort against an inexisting field
ldap_sort($ldapconn, $search, $esort);
}
}
// Find out what we can see
$number_returned = ldap_count_entries($ldapconn,$search);
$info = ldap_get_entries($ldapconn, $search);
//Number of hits
echo "<p>number of entries " . $number_returned . $newline ."</p>";
$bg1 = "#F8F8F8";
$bg2 = "#DEDFE1";
$bg = "#FFFFFF";
echo "<div align='center'>\n";
echo "<table border='0' cellspacing='2' cellpadding='2'>\n
<tr bgcolor='#68ACBF'><th>sn</th><th>givenName</th><th>cn</th><th>title</th><th>uid</th><th>userPassword</th><th>mail</th></tr>\n";
for ($i=0; $i<$info["count"]; $i++)
{
// if ($info[$i]["uid"][0] == $log["user"])
{
if ($bg == $bg1) $bg = $bg2; else $bg = $bg1;
echo "<tr bgcolor='" . $bg . "'>";
echo "<td>". $i. " ".$info[$i]["sn"][0]."</td>";
echo "<td>". $info[$i]["givenname"][0]."</td>";
echo "<td>". $info[$i]["cn"][0]."</td>";
echo "<td>". $info[$i]["title"][0]."</td>";
echo "<td>". $info[$i]["uid"][0]."</td>";
echo "<td>". $info[$i]["userpassword"][0]."</td>";
echo "<td>". $info[$i]["mail"][0]."</td>";
echo "</tr>\n";
}
}
echo "</table>";
echo "</div>\n<br /><br />";
// ldap_close($ldapconn);
/*
//LDAP-Einträge - Test
include_once($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/inc/func_lib.inc.php");
$sn = "Kändler";
$gn = "Jörn";
$title = "Dr.";
$roomnr = "A 2.06";
$tel = array("3150", "3153 FAX");
$mail = null;
$dep = "VW";
$ag = array("Verwaltung VL/AdGf");
$success = ldap_replace($sn,$gn,$title,$roomnr,$tel,$mail,$dep,$ag);
$gn = utf8_encode($gn);
$sn = utf8_encode($sn);
if ($success) echo "<p>Hurra, Daten fuer user '$gn $sn' wurden in LDAP eingetragen!</p>";
else echo "<p>LDAP-Aktualisierung fuer user '$gn $sn' ist leider fehlgeschlagen. :-(</p>";
*/
}
}
}
else echo "Verbindung zu LDAP failed -> $ldapconn";
?>
</body>
</html>