-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldap_mods.php
111 lines (96 loc) · 3.41 KB
/
ldap_mods.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
include 'config.php';
$action=$_REQUEST['action'];
switch($action) {
case "addItem":
$detail_name=$_REQUEST['familyName'];
$detail_fistname=$_REQUEST['givenName'];
$ds=ldap_connect($ldapHost, $ldapPort); // must be a valid LDAP server!
if ($ds) {
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$r=ldap_bind($ds, $ldapWriteDN, $ldapWritePasswort);
// prepare data
$info["sn"] = $detail_name; //family name
$info["givenName"] = $detail_fistname;
$info["cn"] = $info["givenName"] . " " . $info["sn"]; //display name
foreach ($_REQUEST as $key=>$value) {
if( ( strcmp($key, "givenName")) && ( strcmp($key, "familyName")) && ( strcmp($key, "action")) ) {
$info[$key] = $value;
}
}
$info["objectclass"][0] = "inetOrgPerson";
$info["objectclass"][1] = "mozillaAbPersonAlpha";
$dn = "cn=" . $info["cn"] . "," . $ldapWriteOU;
ldap_add($ds, $dn, $info);
ldap_unbind($ds);
echo "Sucess: " . $dn;
} else {
echo "Unable to connect to LDAP server";
}
break;
case "delItem":
$del_distName = $_REQUEST['del_distName'];
$ds=ldap_connect($ldapHost, $ldapPort); // must be a valid LDAP server!
if ($ds) {
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$r=ldap_bind($ds, $ldapWriteDN, $ldapWritePasswort);
ldap_delete ($ds , $del_distName);
ldap_unbind($ds);
echo "Sucess: ";
} else {
echo "Unable to connect to LDAP server";
}
break;
case "getEntryDetails":
$details_distName = $_REQUEST['details_distName'];
$ds=ldap_connect($ldapHost, $ldapPort); // must be a valid LDAP server!
if ($ds) {
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$r=ldap_bind($ds, $ldapWriteDN, $ldapWritePasswort);
$cnTmp = ldap_explode_dn($details_distName,1);
$cn = explode(" + ", $cnTmp[0]);
$sr=ldap_search($ds, $ldapDomain, "cn=" . $cn[0]);
$info = ldap_get_entries($ds, $sr);
for ($i=0; $i<$info["count"]; $i++) {
echo json_encode($info[$i]);
}
ldap_unbind($ds);
} else {
echo "Unable to connect to LDAP server";
}
break;
case "modifyItem":
$mod_distName = $_REQUEST['mod_distName'];
// error_log($mod_distName);
$detail_name=$_REQUEST['familyName'];
$detail_fistname=$_REQUEST['givenName'];
$ds=ldap_connect($ldapHost, $ldapPort); // must be a valid LDAP server!
if ($ds) {
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$r=ldap_bind($ds, $ldapWriteDN, $ldapWritePasswort);
// prepare data
$info["sn"] = $detail_name; //family name
$info["givenName"] = $detail_fistname;
$info["cn"] = $info["givenName"] . " " . $info["sn"]; //display name
foreach ($_REQUEST as $key=>$value) {
if( ( strcmp($key, "givenName")) && ( strcmp($key, "familyName")) && ( strcmp($key, "action")) && ( strcmp($key, "mod_distName")) ) {
if ($value) {
$info[$key] = $value;
} else {
$info[$key] = array();
}
}
}
$info["objectclass"][0] = "inetOrgPerson";
$info["objectclass"][1] = "mozillaAbPersonAlpha";
$dn = $mod_distName;
//$dn = "cn=" . $info["cn"] . "," . $ldapWriteOU;
ldap_modify($ds, $dn, $info);
ldap_unbind($ds);
echo "Sucess: ";
} else {
echo "Unable to connect to LDAP server";
}
break;
}
?>