|
13 | 13 | use UnityWebPortal\lib\UnityWebhook;
|
14 | 14 | use PHPOpenLDAPer\LDAPEntry;
|
15 | 15 |
|
| 16 | +// in PHP LDAP all attributes are arrays, we need these as strings instead |
| 17 | +// it's possible but probably difficult to find this out using LDAP schema information |
| 18 | +$user_string_attributes = [ |
| 19 | + "gidnumber", |
| 20 | + "givenname", |
| 21 | + "homedirectory", |
| 22 | + "loginshell", |
| 23 | + "mail", |
| 24 | + "o", |
| 25 | + "sn", |
| 26 | + "uid", |
| 27 | + "uidnumber", |
| 28 | + "gecos", |
| 29 | +]; |
| 30 | + |
| 31 | +$pi_group_string_attributes = [ |
| 32 | + "gidnumber", |
| 33 | +]; |
| 34 | + |
16 | 35 | $options = getopt("fu");
|
17 | 36 | if (array_key_exists("f", $options)) {
|
18 | 37 | echo "flushing cache...\n";
|
|
21 | 40 |
|
22 | 41 | if ((!is_null($REDIS->getCache("initialized", "")) and (!array_key_exists("u", $options)))) {
|
23 | 42 | echo "cache is already initialized, nothing doing.";
|
24 |
| - echo " use -f argument to flush cache, or -u argument to update without flush."; |
| 43 | + echo " use -f argument to flush cache, or -u argument to update without flush.\n"; |
25 | 44 | } else {
|
26 | 45 | echo "updating cache...\n";
|
27 |
| - $user_ou = new LDAPEntry($LDAP->getConn(), $CONFIG["ldap"]["user_ou"]); |
28 | 46 | echo "waiting for LDAP response (users)...\n";
|
29 |
| - $users = $user_ou->getChildrenArray(true); |
| 47 | + $users = $LDAP->search("objectClass=posixAccount", $CONFIG["ldap"]["basedn"]); |
30 | 48 | echo "response received.\n";
|
31 | 49 | // phpcs:disable
|
32 |
| - $user_CNs = array_map(function ($x){return $x["cn"][0];}, $users); |
| 50 | + $user_CNs = array_map(function ($x){return $x->getAttribute("cn")[0];}, $users); |
33 | 51 | // phpcs:enable
|
34 | 52 | sort($user_CNs);
|
35 | 53 | $REDIS->setCache("sorted_users", "", $user_CNs);
|
36 | 54 | foreach ($users as $user) {
|
37 |
| - $attribute_array = UnityLDAP::parseUserChildrenArray($user); |
38 |
| - foreach ($attribute_array as $key => $val) { |
39 |
| - $REDIS->setCache($user["cn"][0], $key, $val); |
| 55 | + $cn = $user->getAttribute("cn")[0]; |
| 56 | + foreach ($user->getAttributes() as $key => $val) { |
| 57 | + if (in_array($key, $user_string_attributes)) { |
| 58 | + $REDIS->setCache($cn, $key, $val[0]); |
| 59 | + } else { |
| 60 | + $REDIS->setCache($cn, $key, $val); |
| 61 | + } |
40 | 62 | }
|
41 | 63 | }
|
42 | 64 |
|
43 | 65 | $org_group_ou = new LDAPEntry($LDAP->getConn(), $CONFIG["ldap"]["orggroup_ou"]);
|
44 | 66 | echo "waiting for LDAP response (org_groups)...\n";
|
45 |
| - $org_groups = $org_group_ou->getChildrenArray(true); |
| 67 | + $org_groups = $LDAP->search("objectClass=posixGroup", $CONFIG["ldap"]["basedn"]); |
46 | 68 | echo "response received.\n";
|
47 | 69 | // phpcs:disable
|
48 |
| - $org_group_CNs = array_map(function($x){return $x["cn"][0];}, $org_groups); |
| 70 | + $org_group_CNs = array_map(function($x){return $x->getAttribute("cn")[0];}, $org_groups); |
49 | 71 | // phpcs:enable
|
50 | 72 | sort($org_group_CNs);
|
51 | 73 | $REDIS->setCache("sorted_orgs", "", $org_group_CNs);
|
52 | 74 | foreach ($org_groups as $org_group) {
|
53 |
| - $REDIS->setCache($org_group["cn"][0], "members", $org_group["memberuid"]); |
| 75 | + $REDIS->setCache($org_group->getAttribute("cn")[0], "members", $org_group->getAttribute("memberuid")); |
54 | 76 | }
|
55 | 77 |
|
56 | 78 | $pi_group_ou = new LDAPEntry($LDAP->getConn(), $CONFIG["ldap"]["pigroup_ou"]);
|
|
0 commit comments