diff --git a/defaults/config.ini.default b/defaults/config.ini.default index 5ab81435..8ba96480 100644 --- a/defaults/config.ini.default +++ b/defaults/config.ini.default @@ -2,7 +2,7 @@ ; DO NOT EDIT THIS FILE. Instead make a config.ini file in the config folder. ; [upstream] -version = "1.1.2" ; Current upstream version of the web portal +version = "1.2.0" ; Current upstream version of the web portal repo = "https://github.com/UnityHPC/unity-web-portal" ; Upstream URL for the web portal [site] diff --git a/resources/lib/UnityLDAP.php b/resources/lib/UnityLDAP.php index 88a957f2..61371638 100644 --- a/resources/lib/UnityLDAP.php +++ b/resources/lib/UnityLDAP.php @@ -332,35 +332,4 @@ public function getOrgGroupEntry($gid) $gid = ldap_escape($gid, LDAP_ESCAPE_DN); return $this->getEntry(unityLDAP::RDN . "=$gid," . $this->STR_ORGGROUPOU); } - - public static function parseUserChildrenArray(array $userChildrenArray): array - { - // input comes from LdapEntry::getChildrenArray on a UnityUser - $output = []; - $required_string_attributes = [ - "gidnumber", - "givenname", - "homedirectory", - "loginshell", - "mail", - "o", - "sn", - "uid", - "uidnumber", - "gecos", - ]; - foreach ($required_string_attributes as $key) { - $output[$key] = $userChildrenArray[$key][0]; - } - $output["firstname"] = $output["givenname"]; - $output["lastname"] = $output["sn"]; - $output["org"] = $output["o"]; - $output["objectclass"] = $userChildrenArray["objectclass"]; - if (array_key_exists("sspublickey", $userChildrenArray)) { - $output["sshpublickey"] = $userChildrenArray["sshpublickey"]; - } else { - $output["sshpublickey"] = []; - } - return $output; - } } diff --git a/resources/templates/header.php b/resources/templates/header.php index 269a6541..b4066e6e 100644 --- a/resources/templates/header.php +++ b/resources/templates/header.php @@ -4,7 +4,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { if ((@$_SESSION["is_admin"] ?? false) == true - && (@$_POST["form_name"] ?? null) == "clearView" + && (@$_POST["form_type"] ?? null) == "clearView" ) { unset($_SESSION["viewUser"]); UnitySite::redirect($CONFIG["site"]["prefix"] . "/admin/user-mgmt.php"); @@ -141,7 +141,7 @@
You are accessing the web portal as the user $viewUser
- +
diff --git a/test/functional/PiRemoveUserTest.php b/test/functional/PiRemoveUserTest.php index c02a8908..2acd46fd 100644 --- a/test/functional/PiRemoveUserTest.php +++ b/test/functional/PiRemoveUserTest.php @@ -9,7 +9,7 @@ private function removeUser(string $uid) { http_post( __DIR__ . "/../../webroot/panel/pi.php", - ["form_name" => "remUser", "uid" => $uid] + ["form_type" => "remUser", "uid" => $uid] ); } diff --git a/test/functional/ViewAsUserTest.php b/test/functional/ViewAsUserTest.php index 4601c430..8d5be3c4 100644 --- a/test/functional/ViewAsUserTest.php +++ b/test/functional/ViewAsUserTest.php @@ -18,7 +18,7 @@ public function _testViewAsUser(array $beforeUser, array $afterUser) http_post( __DIR__ . "/../../webroot/admin/user-mgmt.php", [ - "form_name" => "viewAsUser", + "form_type" => "viewAsUser", "uid" => $afterUid, ], ); @@ -32,7 +32,7 @@ public function _testViewAsUser(array $beforeUser, array $afterUser) // $this->assertTrue($_SESSION["user_exists"]); http_post( __DIR__ . "/../../resources/templates/header.php", - ["form_name" => "clearView"], + ["form_type" => "clearView"], ); $this->assertArrayNotHasKey("viewUser", $_SESSION); // redirect means that php process dies and user's browser will initiate a new one @@ -68,7 +68,7 @@ public function testNonAdminViewAsAdmin() http_post( __DIR__ . "/../../webroot/admin/user-mgmt.php", [ - "form_name" => "viewAsUser", + "form_type" => "viewAsUser", "uid" => $adminUid, ], ); diff --git a/webroot/admin/ajax/get_group_members.php b/webroot/admin/ajax/get_group_members.php index 6946ff11..ba126ce2 100644 --- a/webroot/admin/ajax/get_group_members.php +++ b/webroot/admin/ajax/get_group_members.php @@ -37,7 +37,7 @@ echo "
- + @@ -63,7 +63,7 @@ echo " - + diff --git a/webroot/admin/pi-mgmt.php b/webroot/admin/pi-mgmt.php index f5a2eb77..24e09d61 100644 --- a/webroot/admin/pi-mgmt.php +++ b/webroot/admin/pi-mgmt.php @@ -15,7 +15,7 @@ $form_user = new UnityUser($_POST["uid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); } - switch ($_POST["form_name"]) { + switch ($_POST["form_type"]) { case "req": if ($_POST["action"] == "Approve") { // approve group @@ -84,7 +84,7 @@ echo ""; echo " - + diff --git a/webroot/admin/user-mgmt.php b/webroot/admin/user-mgmt.php index 1568aa64..e27725c2 100644 --- a/webroot/admin/user-mgmt.php +++ b/webroot/admin/user-mgmt.php @@ -9,7 +9,7 @@ } if ($_SERVER["REQUEST_METHOD"] == "POST") { - switch ($_POST["form_name"]) { + switch ($_POST["form_type"]) { case "viewAsUser": $_SESSION["viewUser"] = $_POST["uid"]; UnitySite::redirect($CONFIG["site"]["prefix"] . "/panel/account.php"); @@ -65,7 +65,7 @@ echo ""; echo " - +
"; diff --git a/webroot/panel/groups.php b/webroot/panel/groups.php index c22d218d..916acb9e 100644 --- a/webroot/panel/groups.php +++ b/webroot/panel/groups.php @@ -9,7 +9,7 @@ $modalErrors = array(); $errors = array(); - if (isset($_POST["form_name"])) { + if (isset($_POST["form_type"])) { if (isset($_POST["pi"])) { $pi_account = new UnityGroup(trim($_POST["pi"]), $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); if (!$pi_account->exists()) { @@ -18,7 +18,7 @@ } } - switch ($_POST["form_name"]) { + switch ($_POST["form_type"]) { case "addPIform": // The new PI modal was submitted // existing PI request @@ -116,7 +116,7 @@ "
- +
diff --git a/webroot/panel/modal/new_pi.php b/webroot/panel/modal/new_pi.php index a007e43b..ebdd7dc1 100644 --- a/webroot/panel/modal/new_pi.php +++ b/webroot/panel/modal/new_pi.php @@ -4,7 +4,7 @@ ?>
/panel/groups.php"> - +
diff --git a/webroot/panel/pi.php b/webroot/panel/pi.php index 386a8ceb..8cafa812 100644 --- a/webroot/panel/pi.php +++ b/webroot/panel/pi.php @@ -16,7 +16,7 @@ $form_user = new UnityUser($_POST["uid"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); } - switch ($_POST["form_name"]) { + switch ($_POST["form_type"]) { case "userReq": if ($_POST["action"] == "Approve") { $group->approveUser($form_user); @@ -62,7 +62,7 @@ echo ""; echo " - + @@ -92,7 +92,7 @@ echo ""; echo " - + diff --git a/workers/update-ldap-cache.php b/workers/update-ldap-cache.php old mode 100644 new mode 100755 index 6fb07c78..a62b19f5 --- a/workers/update-ldap-cache.php +++ b/workers/update-ldap-cache.php @@ -1,3 +1,4 @@ +#!/bin/php flushAll(); @@ -21,36 +48,39 @@ if ((!is_null($REDIS->getCache("initialized", "")) and (!array_key_exists("u", $options)))) { echo "cache is already initialized, nothing doing."; - echo " use -f argument to flush cache, or -u argument to update without flush."; + echo " use -f argument to flush cache, or -u argument to update without flush.\n"; } else { echo "updating cache...\n"; - $user_ou = new LDAPEntry($LDAP->getConn(), $CONFIG["ldap"]["user_ou"]); echo "waiting for LDAP response (users)...\n"; - $users = $user_ou->getChildrenArray(true); + $users = $LDAP->search("objectClass=posixAccount", $CONFIG["ldap"]["basedn"]); echo "response received.\n"; // phpcs:disable - $user_CNs = array_map(function ($x){return $x["cn"][0];}, $users); + $user_CNs = array_map(function ($x){return $x->getAttribute("cn")[0];}, $users); // phpcs:enable sort($user_CNs); $REDIS->setCache("sorted_users", "", $user_CNs); foreach ($users as $user) { - $attribute_array = UnityLDAP::parseUserChildrenArray($user); - foreach ($attribute_array as $key => $val) { - $REDIS->setCache($user["cn"][0], $key, $val); + $cn = $user->getAttribute("cn")[0]; + foreach ($user->getAttributes() as $key => $val) { + if (in_array($key, $user_string_attributes)) { + $REDIS->setCache($cn, $key, $val[0]); + } else { + $REDIS->setCache($cn, $key, $val); + } } } $org_group_ou = new LDAPEntry($LDAP->getConn(), $CONFIG["ldap"]["orggroup_ou"]); echo "waiting for LDAP response (org_groups)...\n"; - $org_groups = $org_group_ou->getChildrenArray(true); + $org_groups = $LDAP->search("objectClass=posixGroup", $CONFIG["ldap"]["basedn"]); echo "response received.\n"; // phpcs:disable - $org_group_CNs = array_map(function($x){return $x["cn"][0];}, $org_groups); + $org_group_CNs = array_map(function($x){return $x->getAttribute("cn")[0];}, $org_groups); // phpcs:enable sort($org_group_CNs); $REDIS->setCache("sorted_orgs", "", $org_group_CNs); foreach ($org_groups as $org_group) { - $REDIS->setCache($org_group["cn"][0], "members", $org_group["memberuid"]); + $REDIS->setCache($org_group->getAttribute("cn")[0], "members", $org_group->getAttribute("memberuid")); } $pi_group_ou = new LDAPEntry($LDAP->getConn(), $CONFIG["ldap"]["pigroup_ou"]);