|
32 | 32 | echo " use -f argument to flush cache, or -u argument to update without flush.\n";
|
33 | 33 | } else {
|
34 | 34 | echo "updating cache...\n";
|
35 |
| - echo "waiting for LDAP response (users)...\n"; |
36 |
| - $users = $LDAP->search("objectClass=posixAccount", $CONFIG["ldap"]["basedn"]); |
37 |
| - echo "response received.\n"; |
38 |
| - // phpcs:disable |
39 |
| - $user_CNs = array_map(function ($x){return $x->getAttribute("cn")[0];}, $users); |
40 |
| - // phpcs:enable |
| 35 | + |
| 36 | + $user_CNs = $LDAP->getUserGroup()->getAttribute("memberuid"); |
41 | 37 | sort($user_CNs);
|
42 | 38 | $REDIS->setCache("sorted_users", "", $user_CNs);
|
| 39 | + |
| 40 | + // search entire tree, some users created for admin purposes might not be in the normal OU |
| 41 | + echo "waiting for LDAP search (users)...\n"; |
| 42 | + $users = $LDAP->search("objectClass=posixAccount", $CONFIG["ldap"]["basedn"]); |
| 43 | + echo "response received.\n"; |
43 | 44 | foreach ($users as $user) {
|
44 | 45 | $uid = $user->getAttribute("cn")[0];
|
| 46 | + if (!in_array($uid, $user_CNs)) { |
| 47 | + continue; |
| 48 | + } |
45 | 49 | $REDIS->setCache($uid, "firstname", $user->getAttribute("givenname")[0]);
|
46 | 50 | $REDIS->setCache($uid, "lastname", $user->getAttribute("sn")[0]);
|
47 | 51 | $REDIS->setCache($uid, "org", $user->getAttribute("o")[0]);
|
|
52 | 56 | }
|
53 | 57 |
|
54 | 58 | $org_group_ou = new LDAPEntry($LDAP->getConn(), $CONFIG["ldap"]["orggroup_ou"]);
|
55 |
| - echo "waiting for LDAP response (org_groups)...\n"; |
56 |
| - $org_groups = $LDAP->search("objectClass=posixGroup", $CONFIG["ldap"]["basedn"]); |
| 59 | + echo "waiting for LDAP search (org groups)...\n"; |
| 60 | + $org_groups = $org_group_ou->getChildrenArray(true); |
57 | 61 | echo "response received.\n";
|
58 | 62 | // phpcs:disable
|
59 |
| - $org_group_CNs = array_map(function($x){return $x->getAttribute("cn")[0];}, $org_groups); |
| 63 | + $org_group_CNs = array_map(function($x){return $x["cn"][0];}, $org_groups); |
60 | 64 | // phpcs:enable
|
61 | 65 | sort($org_group_CNs);
|
62 | 66 | $REDIS->setCache("sorted_orgs", "", $org_group_CNs);
|
63 | 67 | foreach ($org_groups as $org_group) {
|
64 |
| - $gid = $org_group->getAttribute("cn")[0]; |
65 |
| - $REDIS->setCache($gid, "members", $org_group->getAttribute("memberuid")); |
| 68 | + $gid = $org_group["cn"][0]; |
| 69 | + $REDIS->setCache($gid, "members", (@$org_group["memberuid"] ?? [])); |
66 | 70 | }
|
67 | 71 |
|
68 | 72 | $pi_group_ou = new LDAPEntry($LDAP->getConn(), $CONFIG["ldap"]["pigroup_ou"]);
|
69 |
| - echo "waiting for LDAP response (pi_groups)...\n"; |
| 73 | + echo "waiting for LDAP search (pi groups)...\n"; |
70 | 74 | $pi_groups = $pi_group_ou->getChildrenArray(true);
|
71 | 75 | echo "response received.\n";
|
72 | 76 | // phpcs:disable
|
|
75 | 79 | sort($pi_group_CNs);
|
76 | 80 | // FIXME should be sorted_pi_groups
|
77 | 81 | $REDIS->setCache("sorted_groups", "", $pi_group_CNs);
|
| 82 | + |
78 | 83 | $user_pi_group_member_of = [];
|
79 | 84 | foreach ($user_CNs as $uid) {
|
80 | 85 | $user_pi_group_member_of[$uid] = [];
|
81 | 86 | }
|
82 | 87 | foreach ($pi_groups as $pi_group) {
|
83 |
| - $gid = $pi_group->getAttribute("cn")[0]; |
84 |
| - $REDIS->setCache($gid, "members", $pi_group->getAttribute("memberuid")); |
| 88 | + $gid = $pi_group["cn"][0]; |
| 89 | + $REDIS->setCache($gid, "members", (@$pi_group["memberuid"] ?? [])); |
85 | 90 | }
|
86 | 91 | foreach ($user_pi_group_member_of as $uid => $pi_groups) {
|
87 | 92 | // FIXME should be pi_groups
|
|
0 commit comments