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
11 changes: 11 additions & 0 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -477,4 +477,15 @@ public static function GID2OwnerUID(string $gid): string
}
return substr($gid, strlen(self::PI_PREFIX));
}

public static function ownerMail2GID($email)
{
global $LDAP;
$entry = $LDAP->getUidFromEmail($email);
if ($entry !== null) {
$ownerUid = $entry->getAttribute("cn")[0];
return self::PI_PREFIX . $ownerUid;
}
return $email; // Leave untouched
}
}
13 changes: 11 additions & 2 deletions resources/lib/UnityLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use PHPOpenLDAPer\LDAPEntry;

/**
* An LDAP connection class which extends ldapConn tailored for the Unity Cluster
* An LDAP connection class which extends LDAPConn tailored for the Unity Cluster
*/
class UnityLDAP extends ldapConn
class UnityLDAP extends LDAPConn
{
private const string RDN = "cn"; // The defauls RDN for LDAP entries is set to "common name"

Expand Down Expand Up @@ -428,4 +428,13 @@ public function getOrgGroupEntry(string $gid): LDAPEntry
$gid = ldap_escape($gid, "", LDAP_ESCAPE_DN);
return $this->getEntry(UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["orggroup_ou"]);
}

public function getUidFromEmail($email)
{
$email = ldap_escape($email, "", LDAP_ESCAPE_FILTER);
$cn = $this->search("mail=$email", CONFIG["ldap"]["user_ou"], ["cn"]);
if ($cn && count($cn) == 1) {
return $cn[0];
}
}
}
30 changes: 21 additions & 9 deletions webroot/panel/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@

if (isset($_POST["form_type"])) {
if (isset($_POST["pi"])) {
$pi_account = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
$pi_groupname = $_POST["pi"];
if (substr($pi_groupname, 0, 3) !== "pi_" && str_contains($pi_groupname, "@")) {
$pi_groupname = UnityGroup::ownerMail2GID($pi_groupname);
}
$pi_account = new UnityGroup($pi_groupname, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
if (!$pi_account->exists()) {
// "\'" instead of "'", otherwise it will close a single quote from HTML
array_push($modalErrors, "This PI doesn\'t exist");
array_push($modalErrors, "This PI doesn't exist");
}
}

switch ($_POST["form_type"]) {
case "addPIform":
if ($pi_account->requestExists($USER)) {
array_push($modalErrors, "You\'ve already requested this");
}
if ($pi_account->memberExists($USER)) {
array_push($modalErrors, "You\'re already in this PI group");
if ($pi_account->exists()) {
if ($pi_account->requestExists($USER)) {
array_push($modalErrors, "You've already requested this");
}
if ($pi_account->memberExists($USER)) {
array_push($modalErrors, "You're already in this PI group");
}
}
if ($USER->uid != $SSO["user"]) {
$sso_user = $SSO["user"];
Expand All @@ -50,8 +55,15 @@
break;
}
}
$_SESSION['MODAL_ERRORS'] = $modalErrors;
} else {
if (isset($_SESSION['MODAL_ERRORS'])) {
$modalErrors = $_SESSION['MODAL_ERRORS'];
$_SESSION['MODAL_ERRORS'] = array(); // Forget after shown
}
}


require $LOC_HEADER;
?>

Expand Down Expand Up @@ -178,7 +190,7 @@
if (isset($modalErrors) && is_array($modalErrors) && count($modalErrors) > 0) {
$errorHTML = "";
foreach ($modalErrors as $error) {
$errorHTML .= "<span>$error</span>";
$errorHTML .= "<span>" . htmlentities($error) . "</span>";
}

echo "openModal('Add New PI', '" .
Expand Down
8 changes: 6 additions & 2 deletions webroot/panel/new_account.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
);
}
if ($_POST["new_user_sel"] == "not_pi") {
$form_group = new UnityGroup($_POST["pi"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
$pi_groupname = $_POST["pi"];
if (substr($pi_groupname, 0, 3) !== "pi_" && str_contains($pi_groupname, "@")) {
$pi_groupname = UnityGroup::ownerMail2GID($pi_groupname);
}
$form_group = new UnityGroup($pi_groupname, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
if (!$form_group->exists()) {
UnityHTTPD::badRequest("The selected PI '" . $_POST["pi"] . "'does not exist");
UnityHTTPD::badRequest("The selected PI '" . $pi_groupname . "'does not exist");
}
$form_group->newUserRequest(
$USER,
Expand Down