Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,13 @@ public static function ownerMail2GID(string $email): string
$ownerUid = $entry->getAttribute("cn")[0];
return self::PI_PREFIX . $ownerUid;
}

public function getGroupMembersAttributes(array $attributes, array $default_values = []): array
{
return $this->LDAP->getUsersAttributes(
$this->getGroupMemberUIDs(),
$attributes,
$default_values,
);
}
}
47 changes: 47 additions & 0 deletions resources/lib/UnityLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace UnityWebPortal\lib;

use UnityWebPortal\lib\exceptions\EntryNotFoundException;
use PHPOpenLDAPer\LDAPConn;
use PHPOpenLDAPer\LDAPEntry;

Expand Down Expand Up @@ -487,4 +488,50 @@ public function getSortedGroupsForRedis(): array
sort($groups);
return $groups;
}

/**
* returns an array with each UID as an array key
* @throws \UnityWebPortal\lib\exceptions\EntryNotFoundException
*/
public function getUsersAttributes(
array $uids,
array $attributes,
array $default_values = [],
): array {
if (count($uids) === 0) {
return [];
}
$attributes = array_map("strtolower", $attributes);
if (in_array("uid", $attributes)) {
$asked_for_uid_attribute = true;
} else {
$asked_for_uid_attribute = false;
array_push($attributes, "uid");
}
$uids_escaped = array_map(fn($x) => ldap_escape($x, "", LDAP_ESCAPE_FILTER), $uids);
$filter =
"(&(objectClass=posixAccount)(|" .
implode("", array_map(fn($x) => "(uid=$x)", $uids_escaped)) .
"))";
$entries = $this->baseOU->getChildrenArrayStrict(
$attributes,
true,
$filter,
$default_values,
);
$output = [];
foreach ($entries as $entry) {
$uid = $entry["uid"][0];
if (!$asked_for_uid_attribute) {
unset($entry["uid"]);
}
$output[$uid] = $entry;
}
$uids_not_found = array_diff($uids, array_keys($output));
if (count($uids_not_found) > 0) {
throw new EntryNotFoundException(jsonEncode($uids_not_found));
}
ksort($output);
return $output;
}
}
24 changes: 11 additions & 13 deletions webroot/admin/ajax/get_group_members.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,42 @@
}

$group = new UnityGroup($_GET["gid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
$members = $group->getGroupMembers();
$members = $group->getGroupMembersAttributes(["gecos", "mail"]);
$requests = $group->getRequests();

$i = 0;
$count = count($members) + count($requests);
foreach ($members as $member) {
if ($member->uid == $group->getOwner()->uid) {
foreach ($members as $uid => $attributes) {
if ($uid == $group->getOwner()->uid) {
continue;
}

if ($i >= $count - 1) {
echo "<tr class='expanded $i last'>";
} else {
echo "<tr class='expanded $i'>";
}

echo "<td>" . $member->getFullname() . "</td>";
echo "<td>" . $member->uid . "</td>";
echo "<td><a href='mailto:" . $member->getMail() . "'>" . $member->getMail() . "</a></td>";
$fullname = $attributes["gecos"][0];
$mail = $attributes["mail"][0];
echo "<td>$fullname</td>";
echo "<td>$uid</td>";
echo "<td><a href='mailto:$mail'>$mail</a></td>";
echo "<td>";
echo "
<form
action=''
method='POST'
onsubmit='
return confirm(\"Are you sure you want to remove $member->uid from this group?\");
return confirm(\"Are you sure you want to remove $uid from this group?\");
'
>
<input type='hidden' name='form_type' value='remUserChild'>
<input type='hidden' name='uid' value='" . $member->uid . "'>
<input type='hidden' name='pi' value='" . $group->gid . "'>
<input type='hidden' name='uid' value='$uid'>
<input type='hidden' name='pi' value='$group->gid'>
<input type='submit' value='Remove'>
</form>
";
echo "</td>";
echo "</tr>";

$i++;
}

Expand All @@ -76,6 +75,5 @@
<input type='submit' name='action' value='Deny'></form>";
echo "</td>";
echo "</tr>";

$i++;
}
26 changes: 14 additions & 12 deletions webroot/panel/ajax/get_group_members.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@
if (!$group->memberExists($USER)) {
UnityHTTPD::forbidden("not a group member");
}
$members = $group->getGroupMembers();
$members = $group->getGroupMembersAttributes(["gecos", "mail"]);
$count = count($members);
foreach ($members as $key => $member) {
if ($member->uid == $group->getOwner()->uid) {
$i = 0;
foreach ($members as $uid => $attributes) {
if ($uid == $group->getOwner()->uid) {
continue;
}

if ($key >= $count - 1) {
echo "<tr class='expanded $key last'>";
if ($i >= $count - 1) {
echo "<tr class='expanded $i last'>";
} else {
echo "<tr class='expanded $key'>";
echo "<tr class='expanded $i'>";
}

echo "<td>" . $member->getFullname() . "</td>";
echo "<td>" . $member->uid . "</td>";
echo "<td><a href='mailto:" . $member->getMail() . "'>" . $member->getMail() . "</a></td>";
echo "<td><input type='hidden' name='uid' value='" . $member->uid . "'></td>";
$fullname = $attributes["gecos"][0];
$mail = $attributes["mail"][0];
echo "<td>$fullname</td>";
echo "<td>$uid</td>";
echo "<td><a href='mailto:$mail'>$mail</a></td>";
echo "<td><input type='hidden' name='uid' value='$uid'></td>";
echo "</tr>";
$i++;
}