40
|
1 |
<?php
|
|
2 |
|
|
3 |
/**
|
|
4 |
* @author Bettina Schwarzer - Fritz-Haber-Institut
|
|
5 |
* @copyright 08/2013
|
|
6 |
*
|
|
7 |
* LDAP Test
|
|
8 |
*/
|
|
9 |
|
|
10 |
error_reporting(E_ALL ^ E_NOTICE);
|
|
11 |
|
|
12 |
$ldaphost = "ldap.rz-berlin.mpg.de"; // Ihr ldap servers
|
|
13 |
$ldapport = 389; // Die Portnummer ihres ldap servers
|
|
14 |
|
|
15 |
echo "<p>Test Verbindung zu LDAP</p>";
|
|
16 |
// Verbindung zu LDAP
|
|
17 |
$ldapconn = ldap_connect( $ldaphost, $ldapport )
|
|
18 |
or die( "Keine Verbindung zu {$ldaphost} möglich" );
|
|
19 |
|
|
20 |
if ($ldapconn)
|
|
21 |
{
|
|
22 |
echo "Verbindung zu LDAP erfolgreich -> $ldapconn<br />";
|
|
23 |
$login = $_POST["login"];
|
|
24 |
$log = $_POST["log"];
|
|
25 |
?>
|
|
26 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
27 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
28 |
|
|
29 |
<head>
|
|
30 |
<!-- <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> -->
|
|
31 |
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
|
32 |
<link href="/fhiiqm/css/db.css" rel="STYLESHEET" type="TEXT/CSS" />
|
|
33 |
|
|
34 |
<title>LDAP + fhiiqm</title>
|
|
35 |
</head>
|
|
36 |
|
|
37 |
<body onload="document.flogin.user.focus();">
|
|
38 |
<?php
|
|
39 |
|
|
40 |
if (!$log)
|
|
41 |
{
|
|
42 |
include ($_SERVER['DOCUMENT_ROOT'] ."/fhiiqm/form/login_form.inc.php");
|
|
43 |
}
|
|
44 |
else
|
|
45 |
{
|
|
46 |
|
|
47 |
// $ldaprdn = "cn=admin,dc=rz-berlin,dc=mpg,dc=de";
|
|
48 |
// $ldappwd = 'ooboot';
|
|
49 |
$ldaprdn = "uid=" . $log["user"].",ou=people,dc=ppb,dc=rz-berlin,dc=mpg,dc=de";
|
|
50 |
$ldappwd = $log["pass"];
|
|
51 |
echo "rdn = $ldaprdn<br />";
|
|
52 |
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
|
|
53 |
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
|
|
54 |
$ldapbind = @ldap_bind($ldapconn, $ldaprdn, $ldappwd);
|
|
55 |
// $ldapbind = @ldap_bind($ldapconn);
|
|
56 |
|
|
57 |
$base="ou=people,dc=ppb,dc=rz-berlin,dc=mpg,dc=de";
|
|
58 |
if ($ldapbind)
|
|
59 |
{
|
|
60 |
echo "<p>Authentifizierung erfolgreich!</p>";
|
|
61 |
// Enable to show everything
|
|
62 |
$filter = "(sn=*)";
|
|
63 |
$afields = array ("uid","cn","givenName","sn","title","userPassword","mail");
|
|
64 |
$afieldsort = array ("uid","givenName","sn");
|
|
65 |
// search active directory
|
|
66 |
if (!($search=@ldap_search($ldapconn,$base,$filter,$afields))) {
|
|
67 |
die("Unable to search ldap server");
|
|
68 |
}
|
|
69 |
foreach ($afieldsort as $esort)
|
|
70 |
{
|
|
71 |
if (in_array($esort, $afields)) { // making sure we don't accidentally try to sort against an inexisting field
|
|
72 |
ldap_sort($ldapconn, $search, $esort);
|
|
73 |
}
|
|
74 |
}
|
|
75 |
// Find out what we can see
|
|
76 |
$number_returned = ldap_count_entries($ldapconn,$search);
|
|
77 |
$info = ldap_get_entries($ldapconn, $search);
|
|
78 |
|
|
79 |
//Number of hits
|
|
80 |
echo "<p>number of entries " . $number_returned . $newline ."</p>";
|
|
81 |
$bg1 = "#F8F8F8";
|
|
82 |
$bg2 = "#DEDFE1";
|
|
83 |
$bg = "#FFFFFF";
|
|
84 |
|
|
85 |
echo "<div align='center'>\n";
|
|
86 |
echo "<table border='0' cellspacing='2' cellpadding='2'>\n
|
|
87 |
<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";
|
|
88 |
for ($i=0; $i<$info["count"]; $i++)
|
|
89 |
{
|
|
90 |
// if ($info[$i]["uid"][0] == $log["user"])
|
|
91 |
{
|
|
92 |
if ($bg == $bg1) $bg = $bg2; else $bg = $bg1;
|
|
93 |
echo "<tr bgcolor='" . $bg . "'>";
|
|
94 |
echo "<td>". $i. " ".$info[$i]["sn"][0]."</td>";
|
|
95 |
echo "<td>". $info[$i]["givenname"][0]."</td>";
|
|
96 |
echo "<td>". $info[$i]["cn"][0]."</td>";
|
|
97 |
echo "<td>". $info[$i]["title"][0]."</td>";
|
|
98 |
echo "<td>". $info[$i]["uid"][0]."</td>";
|
|
99 |
echo "<td>". $info[$i]["userpassword"][0]."</td>";
|
|
100 |
echo "<td>". $info[$i]["mail"][0]."</td>";
|
|
101 |
echo "</tr>\n";
|
|
102 |
}
|
|
103 |
}
|
|
104 |
echo "</table>";
|
|
105 |
echo "</div>\n<br /><br />";
|
|
106 |
// ldap_close($ldapconn);
|
|
107 |
/*
|
|
108 |
//LDAP-Einträge - Test
|
|
109 |
include_once($_SERVER["DOCUMENT_ROOT"]."/fhiiqm/inc/func_lib.inc.php");
|
|
110 |
$sn = "Kändler";
|
|
111 |
$gn = "Jörn";
|
|
112 |
$title = "Dr.";
|
|
113 |
$roomnr = "A 2.06";
|
|
114 |
$tel = array("3150", "3153 FAX");
|
|
115 |
$mail = null;
|
|
116 |
$dep = "VW";
|
|
117 |
$ag = array("Verwaltung VL/AdGf");
|
|
118 |
$success = ldap_replace($sn,$gn,$title,$roomnr,$tel,$mail,$dep,$ag);
|
|
119 |
$gn = utf8_encode($gn);
|
|
120 |
$sn = utf8_encode($sn);
|
|
121 |
if ($success) echo "<p>Hurra, Daten fuer user '$gn $sn' wurden in LDAP eingetragen!</p>";
|
|
122 |
else echo "<p>LDAP-Aktualisierung fuer user '$gn $sn' ist leider fehlgeschlagen. :-(</p>";
|
|
123 |
*/
|
|
124 |
}
|
|
125 |
}
|
|
126 |
}
|
|
127 |
else echo "Verbindung zu LDAP failed -> $ldapconn";
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
?>
|
|
132 |
</body>
|
|
133 |
</html> |