From 1aeabc6c5ae3bf572d05eb9e169042fae071d006 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 10 Nov 2025 08:47:58 -0500 Subject: [PATCH 1/3] fix .prettierrc --- prettierrc.yml => .prettierrc.yml | 2 ++ 1 file changed, 2 insertions(+) rename prettierrc.yml => .prettierrc.yml (65%) diff --git a/prettierrc.yml b/.prettierrc.yml similarity index 65% rename from prettierrc.yml rename to .prettierrc.yml index db7ce182..a356d87e 100644 --- a/prettierrc.yml +++ b/.prettierrc.yml @@ -2,3 +2,5 @@ overrides: - files: ["*.php"] options: printWidth: 100 +plugins: + - "@prettier/plugin-php" From ea89d12b988c3c2d660689d74d316e17a40f9204 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 10 Nov 2025 09:08:51 -0500 Subject: [PATCH 2/3] fix pre commit, prettier --- .pre-commit-config.yaml | 32 +++++--------------------------- .prettierrc.yml | 1 + 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bc28907b..a5929f4f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,16 +14,6 @@ repos: # https://github.com/prettier/plugin-php/issues/2430 exclude: workers/.* - - repo: https://github.com/rbubley/mirrors-prettier - rev: v3.4.2 - hooks: - - id: prettier - exclude: | - (?x)^( - composer\.json| - composer\.lock| - )$ - - repo: local hooks: - id: phpcbf @@ -43,27 +33,15 @@ repos: resources/lib/.*| )$ - - repo: local + - repo: https://github.com/rbubley/mirrors-prettier + rev: v3.4.2 hooks: - - id: prettier (php) - name: prettier (php) - entry: npx - args: - [ - -p, - prettier, - -p, - "@prettier/plugin-php", - prettier, - --plugin=@prettier/plugin-php, - --php-version=8.3, - --write, - ] - language: system - files: \.php$ + - id: prettier # exclude impure PHP files exclude: | (?x)^( + composer\.json| + composer\.lock| node_modules/.*| resources/lib/phpopenldaper/.*| vendor/.*| diff --git a/.prettierrc.yml b/.prettierrc.yml index a356d87e..1ee19294 100644 --- a/.prettierrc.yml +++ b/.prettierrc.yml @@ -4,3 +4,4 @@ overrides: printWidth: 100 plugins: - "@prettier/plugin-php" +phpVersion: "8.3" From f95a5e8ccfc0fa3d9431145dd3f7aeb1f7cfe37a Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 10 Nov 2025 09:09:09 -0500 Subject: [PATCH 3/3] set prettier line length to 100 --- coverage.php | 4 +- resources/config.php | 8 +- resources/init.php | 30 +--- resources/lib/UnityConfig.php | 18 +- resources/lib/UnityGroup.php | 167 ++++++------------ resources/lib/UnityHTTPD.php | 45 +---- resources/lib/UnityLDAP.php | 101 ++--------- resources/lib/UnityMailer.php | 35 +--- resources/lib/UnityRedis.php | 7 +- resources/lib/UnitySQL.php | 106 +++-------- resources/lib/UnitySSO.php | 19 +- resources/lib/UnityUser.php | 94 ++-------- resources/lib/UnityWebhook.php | 20 +-- resources/lib/utils.php | 12 +- resources/mail/group_disband.php | 4 +- .../mail/group_join_request_cancelled.php | 7 +- resources/mail/group_request_cancelled.php | 4 +- resources/mail/group_user_denied.php | 4 +- resources/mail/group_user_denied_owner.php | 4 +- resources/mail/user_loginshell.php | 4 +- .../functional/AccountDeletionRequestTest.php | 4 +- test/functional/LoginShellSetTest.php | 4 +- test/functional/NewUserTest.php | 82 ++------- test/functional/PIMemberRequestTest.php | 8 +- test/functional/PageLoadTest.php | 5 +- test/functional/PiBecomeRequestTest.php | 8 +- test/functional/PiMemberApproveTest.php | 4 +- test/functional/PiMemberDenyTest.php | 20 +-- test/functional/PiRemoveUserTest.php | 9 +- test/functional/SSHKeyAddTest.php | 12 +- test/phpunit-bootstrap.php | 22 +-- workers/update-ldap-cache.php | 39 +--- 32 files changed, 208 insertions(+), 702 deletions(-) diff --git a/coverage.php b/coverage.php index 44119cb9..95dfa86a 100644 --- a/coverage.php +++ b/coverage.php @@ -2,6 +2,4 @@ use RobinIngelbrecht\PHPUnitCoverageTools\MinCoverage\MinCoverageRule; -return [ - new MinCoverageRule(pattern: "*", minCoverage: 62, exitOnLowCoverage: true), -]; +return [new MinCoverageRule(pattern: "*", minCoverage: 62, exitOnLowCoverage: true)]; diff --git a/resources/config.php b/resources/config.php index 92014ab1..ac43e9ed 100644 --- a/resources/config.php +++ b/resources/config.php @@ -2,10 +2,4 @@ use UnityWebPortal\lib\UnityConfig; -define( - "CONFIG", - UnityConfig::getConfig( - __DIR__ . "/../defaults", - __DIR__ . "/../deployment", - ), -); +define("CONFIG", UnityConfig::getConfig(__DIR__ . "/../defaults", __DIR__ . "/../deployment")); diff --git a/resources/init.php b/resources/init.php index d1e08d3d..b9c63d80 100644 --- a/resources/init.php +++ b/resources/init.php @@ -15,10 +15,7 @@ use UnityWebPortal\lib\UnityHTTPD; if (CONFIG["site"]["enable_exception_handler"]) { - set_exception_handler([ - "UnityWebPortal\lib\UnityHTTPD", - "exceptionHandler", - ]); + set_exception_handler(["UnityWebPortal\lib\UnityHTTPD", "exceptionHandler"]); } session_start(); @@ -40,25 +37,11 @@ $SSO = UnitySSO::getSSO(); $_SESSION["SSO"] = $SSO; - $OPERATOR = new UnityUser( - $SSO["user"], - $LDAP, - $SQL, - $MAILER, - $REDIS, - $WEBHOOK, - ); + $OPERATOR = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); $_SESSION["is_admin"] = $OPERATOR->isAdmin(); if (isset($_SESSION["viewUser"]) && $_SESSION["is_admin"]) { - $USER = new UnityUser( - $_SESSION["viewUser"], - $LDAP, - $SQL, - $MAILER, - $REDIS, - $WEBHOOK, - ); + $USER = new UnityUser($_SESSION["viewUser"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); } else { $USER = $OPERATOR; } @@ -67,12 +50,7 @@ $_SESSION["is_pi"] = $USER->isPI(); $SEND_PIMESG_TO_ADMINS = CONFIG["mail"]["send_pimesg_to_admins"]; - $SQL->addLog( - $OPERATOR->uid, - $_SERVER["REMOTE_ADDR"], - "user_login", - $OPERATOR->uid, - ); + $SQL->addLog($OPERATOR->uid, $_SERVER["REMOTE_ADDR"], "user_login", $OPERATOR->uid); if (!$_SESSION["user_exists"]) { // populate cache diff --git a/resources/lib/UnityConfig.php b/resources/lib/UnityConfig.php index e844400d..21e4f810 100644 --- a/resources/lib/UnityConfig.php +++ b/resources/lib/UnityConfig.php @@ -4,15 +4,9 @@ class UnityConfig { - public static function getConfig( - string $def_config_loc, - string $deploy_loc, - ): array { - $CONFIG = parse_ini_file( - $def_config_loc . "/config.ini.default", - true, - INI_SCANNER_TYPED, - ); + public static function getConfig(string $def_config_loc, string $deploy_loc): array + { + $CONFIG = parse_ini_file($def_config_loc . "/config.ini.default", true, INI_SCANNER_TYPED); $CONFIG = self::pullConfig($CONFIG, $deploy_loc); if (array_key_exists("HTTP_HOST", $_SERVER)) { $cur_url = $_SERVER["HTTP_HOST"]; @@ -28,11 +22,7 @@ private static function pullConfig(array $CONFIG, string $loc): array { $file_loc = $loc . "/config/config.ini"; if (file_exists($file_loc)) { - $CONFIG_override = parse_ini_file( - $file_loc, - true, - INI_SCANNER_TYPED, - ); + $CONFIG_override = parse_ini_file($file_loc, true, INI_SCANNER_TYPED); return array_replace_recursive($CONFIG, $CONFIG_override); } else { return $CONFIG; diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index 52dc3d1d..e6e9c609 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -79,13 +79,7 @@ public function requestGroup( if ($this->SQL->accDeletionRequestExists($this->getOwner()->uid)) { return; } - $this->SQL->addRequest( - $this->getOwner()->uid, - $firstname, - $lastname, - $email, - $org, - ); + $this->SQL->addRequest($this->getOwner()->uid, $firstname, $lastname, $email, $org); if ($send_mail) { $this->MAILER->sendMail($email, "group_request"); $this->WEBHOOK->sendWebhook("group_request_admin", [ @@ -114,10 +108,8 @@ public function requestGroup( /** * This method will create the group (this is what is executed when an admin approved the group) */ - public function approveGroup( - ?UnityUser $operator = null, - bool $send_mail = true, - ): void { + public function approveGroup(?UnityUser $operator = null, bool $send_mail = true): void + { $uid = $this->getOwner()->uid; $request = $this->SQL->getRequest($uid, UnitySQL::REQUEST_BECOME_PI); if ($this->exists()) { @@ -134,9 +126,7 @@ public function approveGroup( } $this->init(); $this->SQL->removeRequest($this->getOwner()->uid); - $operator = is_null($operator) - ? $this->getOwner()->uid - : $operator->uid; + $operator = is_null($operator) ? $this->getOwner()->uid : $operator->uid; $this->SQL->addLog( $operator, $_SERVER["REMOTE_ADDR"], @@ -151,21 +141,14 @@ public function approveGroup( /** * This method is executed when an admin denys the PI group request */ - public function denyGroup( - ?UnityUser $operator = null, - bool $send_mail = true, - ): void { - $request = $this->SQL->getRequest( - $this->getOwner()->uid, - UnitySQL::REQUEST_BECOME_PI, - ); + public function denyGroup(?UnityUser $operator = null, bool $send_mail = true): void + { + $request = $this->SQL->getRequest($this->getOwner()->uid, UnitySQL::REQUEST_BECOME_PI); $this->SQL->removeRequest($this->getOwner()->uid); if ($this->exists()) { return; } - $operator = is_null($operator) - ? $this->getOwner()->uid - : $operator->uid; + $operator = is_null($operator) ? $this->getOwner()->uid : $operator->uid; $this->SQL->addLog( $operator, $_SERVER["REMOTE_ADDR"], @@ -190,20 +173,16 @@ public function cancelGroupRequest(bool $send_mail = true): void } } - public function cancelGroupJoinRequest( - UnityUser $user, - bool $send_mail = true, - ): void { + public function cancelGroupJoinRequest(UnityUser $user, bool $send_mail = true): void + { if (!$this->requestExists($user)) { return; } $this->SQL->removeRequest($user->uid, $this->gid); if ($send_mail) { - $this->MAILER->sendMail( - $this->getOwner()->getMail(), - "group_join_request_cancelled", - ["uid" => $user->uid], - ); + $this->MAILER->sendMail($this->getOwner()->getMail(), "group_join_request_cancelled", [ + "uid" => $user->uid, + ]); } } @@ -248,10 +227,8 @@ public function cancelGroupJoinRequest( * This method is executed when a user is approved to join the group * (either by admin or the group owner) */ - public function approveUser( - UnityUser $new_user, - bool $send_mail = true, - ): void { + public function approveUser(UnityUser $new_user, bool $send_mail = true): void + { $request = $this->SQL->getRequest($new_user->uid, $this->gid); if (!$new_user->exists()) { $new_user->init( @@ -267,18 +244,13 @@ public function approveUser( $this->MAILER->sendMail($new_user->getMail(), "group_user_added", [ "group" => $this->gid, ]); - $this->MAILER->sendMail( - $this->getOwner()->getMail(), - "group_user_added_owner", - [ - "group" => $this->gid, - "user" => $new_user->uid, - "name" => - $request["firstname"] . " " . $request["lastname"], - "email" => $request["email"], - "org" => $request["org"], - ], - ); + $this->MAILER->sendMail($this->getOwner()->getMail(), "group_user_added_owner", [ + "group" => $this->gid, + "user" => $new_user->uid, + "name" => $request["firstname"] . " " . $request["lastname"], + "email" => $request["email"], + "org" => $request["org"], + ]); } } @@ -291,51 +263,37 @@ public function denyUser(UnityUser $new_user, bool $send_mail = true): void $this->MAILER->sendMail($request["email"], "group_user_denied", [ "group" => $this->gid, ]); - $this->MAILER->sendMail( - $this->getOwner()->getMail(), - "group_user_denied_owner", - [ - "group" => $this->gid, - "user" => $new_user->uid, - "name" => $new_user->getFullName(), - "email" => $new_user->getMail(), - "org" => $new_user->getOrg(), - ], - ); + $this->MAILER->sendMail($this->getOwner()->getMail(), "group_user_denied_owner", [ + "group" => $this->gid, + "user" => $new_user->uid, + "name" => $new_user->getFullName(), + "email" => $new_user->getMail(), + "org" => $new_user->getOrg(), + ]); } } - public function removeUser( - UnityUser $new_user, - bool $send_mail = true, - ): void { + public function removeUser(UnityUser $new_user, bool $send_mail = true): void + { if (!$this->memberExists($new_user)) { return; } if ($new_user->uid == $this->getOwner()->uid) { - throw new Exception( - "Cannot delete group owner from group. Disband group instead", - ); + throw new Exception("Cannot delete group owner from group. Disband group instead"); } // remove request, this will fail silently if the request doesn't exist $this->removeUserFromGroup($new_user); if ($send_mail) { - $this->MAILER->sendMail( - $new_user->getMail(), - "group_user_removed", - ["group" => $this->gid], - ); - $this->MAILER->sendMail( - $this->getOwner()->getMail(), - "group_user_removed_owner", - [ - "group" => $this->gid, - "user" => $new_user->uid, - "name" => $new_user->getFullName(), - "email" => $new_user->getMail(), - "org" => $new_user->getOrg(), - ], - ); + $this->MAILER->sendMail($new_user->getMail(), "group_user_removed", [ + "group" => $this->gid, + ]); + $this->MAILER->sendMail($this->getOwner()->getMail(), "group_user_removed_owner", [ + "group" => $this->gid, + "user" => $new_user->uid, + "name" => $new_user->getFullName(), + "email" => $new_user->getMail(), + "org" => $new_user->getOrg(), + ]); } } @@ -348,17 +306,11 @@ public function newUserRequest( bool $send_mail = true, ): void { if ($this->memberExists($new_user)) { - UnityHTTPD::errorLog( - "warning", - "user '$new_user' already in group", - ); + UnityHTTPD::errorLog("warning", "user '$new_user' already in group"); return; } if ($this->requestExists($new_user)) { - UnityHTTPD::errorLog( - "warning", - "user '$new_user' already requested group membership", - ); + UnityHTTPD::errorLog("warning", "user '$new_user' already requested group membership"); return; } if ($this->SQL->accDeletionRequestExists($new_user->uid)) { @@ -370,17 +322,13 @@ public function newUserRequest( $this->MAILER->sendMail($email, "group_user_request", [ "group" => $this->gid, ]); - $this->MAILER->sendMail( - $this->getOwner()->getMail(), - "group_user_request_owner", - [ - "group" => $this->gid, - "user" => $new_user->uid, - "name" => "$firstname $lastname", - "email" => $email, - "org" => $org, - ], - ); + $this->MAILER->sendMail($this->getOwner()->getMail(), "group_user_request_owner", [ + "group" => $this->gid, + "user" => $new_user->uid, + "name" => "$firstname $lastname", + "email" => $email, + "org" => $org, + ]); } } @@ -502,14 +450,7 @@ private function addRequest( string $email, string $org, ): void { - $this->SQL->addRequest( - $uid, - $firstname, - $lastname, - $email, - $org, - $this->gid, - ); + $this->SQL->addRequest($uid, $firstname, $lastname, $email, $org, $this->gid); } public function getOwner(): UnityUser @@ -532,9 +473,7 @@ public static function ownerUID2GID(string $uid): string public static function GID2OwnerUID(string $gid): string { if (substr($gid, 0, strlen(self::PI_PREFIX)) != self::PI_PREFIX) { - throw new Exception( - "PI group GID doesn't have the correct prefix.", - ); + throw new Exception("PI group GID doesn't have the correct prefix."); } return substr($gid, strlen(self::PI_PREFIX)); } diff --git a/resources/lib/UnityHTTPD.php b/resources/lib/UnityHTTPD.php index 6504f0cb..bf5abbf3 100644 --- a/resources/lib/UnityHTTPD.php +++ b/resources/lib/UnityHTTPD.php @@ -27,10 +27,7 @@ public static function die(mixed $x = null, bool $show_user = false): never public static function redirect($dest): never { header("Location: $dest"); - self::errorToUser( - "Redirect failed, click here to continue.", - 302, - ); + self::errorToUser("Redirect failed, click here to continue.", 302); self::die(); } @@ -52,8 +49,7 @@ public static function errorLog( \jsonEncode($data); $output["data"] = $data; } catch (\JsonException $e) { - $output["data"] = - "data could not be JSON encoded: " . $e->getMessage(); + $output["data"] = "data could not be JSON encoded: " . $e->getMessage(); } } $output["REMOTE_USER"] = $_SERVER["REMOTE_USER"] ?? null; @@ -65,10 +61,7 @@ public static function errorLog( $output["error"] = self::throwableToArray($error); } else { // newlines are bad for error log, but getTrace() is too verbose - $output["trace"] = explode( - "\n", - (new \Exception())->getTraceAsString(), - ); + $output["trace"] = explode("\n", (new \Exception())->getTraceAsString()); } error_log("$title: " . \jsonEncode($output)); } @@ -97,8 +90,7 @@ private static function errorToUser( if (!CONFIG["site"]["enable_error_to_user"]) { return; } - $notes = - "Please notify a Unity admin at " . CONFIG["mail"]["support"] . "."; + $notes = "Please notify a Unity admin at " . CONFIG["mail"]["support"] . "."; if (!is_null($errorid)) { $notes = $notes . " Error ID: $errorid."; } @@ -116,11 +108,7 @@ public static function badRequest( ?array $data = null, ): never { $errorid = uniqid(); - self::errorToUser( - "Invalid requested action or submitted data.", - 400, - $errorid, - ); + self::errorToUser("Invalid requested action or submitted data.", 400, $errorid); self::errorLog("bad request", $message, $errorid, $error, $data); self::die($message); } @@ -142,18 +130,8 @@ public static function internalServerError( ?array $data = null, ): never { $errorid = uniqid(); - self::errorToUser( - "An internal server error has occurred.", - 500, - $errorid, - ); - self::errorLog( - "internal server error", - $message, - $errorid, - $error, - $data, - ); + self::errorToUser("An internal server error has occurred.", 500, $errorid); + self::errorLog("internal server error", $message, $errorid, $error, $data); self::die($message); } @@ -161,10 +139,7 @@ public static function internalServerError( public static function exceptionHandler(\Throwable $e): void { ini_set("log_errors", true); // in case something goes wrong and error is not logged - self::internalServerError( - "An internal server error has occurred.", - error: $e, - ); + self::internalServerError("An internal server error has occurred.", error: $e); ini_set("log_errors", false); // error logged successfully } @@ -207,8 +182,6 @@ public static function getUploadedFileContents( public static function alert(string $message): void { // jsonEncode escapes quotes - echo ""; + echo ""; } } diff --git a/resources/lib/UnityLDAP.php b/resources/lib/UnityLDAP.php index cd4a471b..db8ba3f2 100644 --- a/resources/lib/UnityLDAP.php +++ b/resources/lib/UnityLDAP.php @@ -39,11 +39,7 @@ class UnityLDAP extends ldapConn public function __construct() { - parent::__construct( - CONFIG["ldap"]["uri"], - CONFIG["ldap"]["user"], - CONFIG["ldap"]["pass"], - ); + parent::__construct(CONFIG["ldap"]["uri"], CONFIG["ldap"]["user"], CONFIG["ldap"]["pass"]); $this->baseOU = $this->getEntry(CONFIG["ldap"]["basedn"]); $this->userOU = $this->getEntry(CONFIG["ldap"]["user_ou"]); $this->groupOU = $this->getEntry(CONFIG["ldap"]["group_ou"]); @@ -90,22 +86,13 @@ public function getDefUserShell(): string public function getNextUIDGIDNumber(string $uid): int { - $IDNumsInUse = array_merge( - $this->getAllUIDNumbersInUse(), - $this->getAllGIDNumbersInUse(), - ); + $IDNumsInUse = array_merge($this->getAllUIDNumbersInUse(), $this->getAllGIDNumbersInUse()); $customIDMappings = $this->getCustomIDMappings(); $customMappedID = $customIDMappings[$uid] ?? null; - if ( - !is_null($customMappedID) && - !in_array($customMappedID, $IDNumsInUse) - ) { + if (!is_null($customMappedID) && !in_array($customMappedID, $IDNumsInUse)) { return $customMappedID; } - if ( - !is_null($customMappedID) && - in_array($customMappedID, $IDNumsInUse) - ) { + if (!is_null($customMappedID) && in_array($customMappedID, $IDNumsInUse)) { UnityHTTPD::errorLog( "warning", "user '$uid' has a custom mapped IDNumber $customMappedID but it's already in use!", @@ -113,10 +100,7 @@ public function getNextUIDGIDNumber(string $uid): int } return $this->getNextIDNumber( $this->offset_UIDGID, - array_merge( - $IDNumsInUse, - array_values($this->getCustomIDMappings()), - ), + array_merge($IDNumsInUse, array_values($this->getCustomIDMappings())), ); } @@ -124,10 +108,7 @@ public function getNextPIGIDNumber(): int { return $this->getNextIDNumber( $this->offset_PIGID, - array_merge( - $this->getAllGIDNumbersInUse(), - array_values($this->getCustomIDMappings()), - ), + array_merge($this->getAllGIDNumbersInUse(), array_values($this->getCustomIDMappings())), ); } @@ -135,10 +116,7 @@ public function getNextOrgGIDNumber(): int { return $this->getNextIDNumber( $this->offset_ORGGID, - array_merge( - $this->getAllGIDNumbersInUse(), - array_values($this->getCustomIDMappings()), - ), + array_merge($this->getAllGIDNumbersInUse(), array_values($this->getCustomIDMappings())), ); } @@ -152,10 +130,7 @@ private function isIDNumberForbidden($id): bool private function getNextIDNumber($start, $IDsToSkip): int { $new_id = $start; - while ( - $this->isIDNumberForbidden($new_id) || - in_array($new_id, $IDsToSkip) - ) { + while ($this->isIDNumberForbidden($new_id) || in_array($new_id, $IDsToSkip)) { $new_id++; } return $new_id; @@ -194,11 +169,7 @@ private function getAllUIDNumbersInUse(): array // use baseOU for awareness of externally managed entries return array_map( fn($x) => $x["uidnumber"][0], - $this->baseOU->getChildrenArray( - ["uidNumber"], - true, - "(objectClass=posixAccount)", - ), + $this->baseOU->getChildrenArray(["uidNumber"], true, "(objectClass=posixAccount)"), ); } @@ -207,11 +178,7 @@ private function getAllGIDNumbersInUse(): array // use baseOU for awareness of externally managed entries return array_map( fn($x) => $x["gidnumber"][0], - $this->baseOU->getChildrenArray( - ["gidNumber"], - true, - "(objectClass=posixGroup)", - ), + $this->baseOU->getChildrenArray(["gidNumber"], true, "(objectClass=posixGroup)"), ); } @@ -254,14 +221,7 @@ public function getAllUsers( $users = $this->getAllUsersUIDs(); sort($users); foreach ($users as $user) { - $params = [ - $user, - $this, - $UnitySQL, - $UnityMailer, - $UnityRedis, - $UnityWebhook, - ]; + $params = [$user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook]; array_push($out, new UnityUser(...$params)); } return $out; @@ -296,14 +256,7 @@ public function getAllPIGroups( $groups = $UnityRedis->getCache("sorted_groups", ""); if (!is_null($groups)) { foreach ($groups as $group) { - $params = [ - $group, - $this, - $UnitySQL, - $UnityMailer, - $UnityRedis, - $UnityWebhook, - ]; + $params = [$group, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook]; array_push($out, new UnityGroup(...$params)); } @@ -352,10 +305,7 @@ public function getAllPIGroupOwnerAttributes(array $attributes): array // get the PI groups, filter for just the GIDs, then map the GIDs to owner UIDs $owner_uids = array_map( fn($x) => UnityGroup::GID2OwnerUID($x), - array_map( - fn($x) => $x["cn"][0], - $this->pi_groupOU->getChildrenArray(["cn"]), - ), + array_map(fn($x) => $x["cn"][0], $this->pi_groupOU->getChildrenArray(["cn"])), ); $owner_attributes = $this->getAllUsersAttributes($attributes); foreach ($owner_attributes as $i => $attributes) { @@ -371,9 +321,7 @@ public function getAllPIGroupOwnerAttributes(array $attributes): array if (count($owners_not_found) > 0) { UnityHTTPD::errorLog( "warning", - "PI group owners not found: " . - \jsonEncode($owners_not_found) . - "\n", + "PI group owners not found: " . \jsonEncode($owners_not_found) . "\n", ); } return $owner_attributes; @@ -388,10 +336,7 @@ public function getAllUID2PIGIDs(): array $uids = $this->getAllUsersUIDs(); $uid2pigids = array_combine($uids, array_fill(0, count($uids), [])); // for each PI group, append that GID to the member list for each of its member UIDs - foreach ( - $this->getAllPIGroupsAttributes(["cn", "memberuid"]) - as $array - ) { + foreach ($this->getAllPIGroupsAttributes(["cn", "memberuid"]) as $array) { $gid = $array["cn"][0]; foreach ($array["memberuid"] as $uid) { if (array_key_exists($uid, $uid2pigids)) { @@ -463,32 +408,24 @@ public function getAllOrgGroupsAttributes(array $attributes): array public function getUserEntry(string $uid): LDAPEntry { $uid = ldap_escape($uid, "", LDAP_ESCAPE_DN); - return $this->getEntry( - UnityLDAP::RDN . "=$uid," . CONFIG["ldap"]["user_ou"], - ); + return $this->getEntry(UnityLDAP::RDN . "=$uid," . CONFIG["ldap"]["user_ou"]); } public function getGroupEntry(string $gid): LDAPEntry { $gid = ldap_escape($gid, "", LDAP_ESCAPE_DN); - return $this->getEntry( - UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["group_ou"], - ); + return $this->getEntry(UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["group_ou"]); } public function getPIGroupEntry(string $gid): LDAPEntry { $gid = ldap_escape($gid, "", LDAP_ESCAPE_DN); - return $this->getEntry( - UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["pigroup_ou"], - ); + return $this->getEntry(UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["pigroup_ou"]); } public function getOrgGroupEntry(string $gid): LDAPEntry { $gid = ldap_escape($gid, "", LDAP_ESCAPE_DN); - return $this->getEntry( - UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["orggroup_ou"], - ); + return $this->getEntry(UnityLDAP::RDN . "=$gid," . CONFIG["ldap"]["orggroup_ou"]); } } diff --git a/resources/lib/UnityMailer.php b/resources/lib/UnityMailer.php index a8e1d7b0..51a1aeba 100644 --- a/resources/lib/UnityMailer.php +++ b/resources/lib/UnityMailer.php @@ -11,8 +11,7 @@ class UnityMailer extends PHPMailer { private string $template_dir = __DIR__ . "/../mail"; // location of all email templates - private string $override_template_dir = - __DIR__ . "/../../deployment/mail_overrides"; + private string $override_template_dir = __DIR__ . "/../../deployment/mail_overrides"; private string $MSG_LINKREF; private string $MSG_SENDER_EMAIL; @@ -49,8 +48,7 @@ public function __construct() $this->Port = CONFIG["smtp"]["port"]; $security = CONFIG["smtp"]["security"]; - $security_conf_valid = - empty($security) || $security == "tls" || $security == "ssl"; + $security_conf_valid = empty($security) || $security == "tls" || $security == "ssl"; if (!$security_conf_valid) { throw new Exception( "SMTP security is not set correctly, leave empty, use 'tls', or 'ssl'", @@ -80,33 +78,21 @@ public function __construct() } } - public function sendMail( - string $recipients, - ?string $template = null, - mixed $data = null, - ) { + public function sendMail(string $recipients, ?string $template = null, mixed $data = null) + { if (isset($template)) { $this->setFrom($this->MSG_SENDER_EMAIL, $this->MSG_SENDER_NAME); - $this->addReplyTo( - $this->MSG_SUPPORT_EMAIL, - $this->MSG_SUPPORT_NAME, - ); + $this->addReplyTo($this->MSG_SUPPORT_EMAIL, $this->MSG_SUPPORT_NAME); $template_filename = $template . ".php"; - if ( - file_exists( - $this->override_template_dir . "/" . $template_filename, - ) - ) { - $template_path = - $this->override_template_dir . "/" . $template_filename; + if (file_exists($this->override_template_dir . "/" . $template_filename)) { + $template_path = $this->override_template_dir . "/" . $template_filename; } else { $template_path = $this->template_dir . "/" . $template_filename; } if (file_exists($this->override_template_dir . "/footer.php")) { - $footer_template_path = - $this->override_template_dir . "/footer.php"; + $footer_template_path = $this->override_template_dir . "/footer.php"; } else { $footer_template_path = $this->template_dir . "/footer.php"; } @@ -120,10 +106,7 @@ public function sendMail( if ($recipients == "admin") { $this->addBCC($this->MSG_ADMIN_EMAIL, $this->MSG_ADMIN_NAME); } elseif ($recipients == "pi_approve") { - $this->addBCC( - $this->MSG_PI_APPROVAL_EMAIL, - $this->MSG_PI_APPROVAL_NAME, - ); + $this->addBCC($this->MSG_PI_APPROVAL_EMAIL, $this->MSG_PI_APPROVAL_NAME); } else { if (is_array($recipients)) { foreach ($recipients as $addr) { diff --git a/resources/lib/UnityRedis.php b/resources/lib/UnityRedis.php index 47909052..644f1c39 100644 --- a/resources/lib/UnityRedis.php +++ b/resources/lib/UnityRedis.php @@ -61,11 +61,8 @@ public function getCache(string $object, string $key): mixed return null; } - public function appendCacheArray( - string $object, - string $key, - mixed $value, - ): void { + public function appendCacheArray(string $object, string $key, mixed $value): void + { if (!$this->enabled) { return; } diff --git a/resources/lib/UnitySQL.php b/resources/lib/UnitySQL.php index b6a09cf4..2c086ebe 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -19,10 +19,7 @@ class UnitySQL public function __construct() { $this->conn = new PDO( - "mysql:host=" . - CONFIG["sql"]["host"] . - ";dbname=" . - CONFIG["sql"]["dbname"], + "mysql:host=" . CONFIG["sql"]["host"] . ";dbname=" . CONFIG["sql"]["dbname"], CONFIG["sql"]["user"], CONFIG["sql"]["pass"], ); @@ -66,18 +63,14 @@ public function addRequest( $stmt->execute(); } - public function removeRequest( - $requestor, - string $dest = self::REQUEST_BECOME_PI, - ): void { + public function removeRequest($requestor, string $dest = self::REQUEST_BECOME_PI): void + { if (!$this->requestExists($requestor, $dest)) { return; } $stmt = $this->conn->prepare( - "DELETE FROM " . - self::TABLE_REQS . - " WHERE uid=:uid and request_for=:request_for", + "DELETE FROM " . self::TABLE_REQS . " WHERE uid=:uid and request_for=:request_for", ); $stmt->bindParam(":uid", $requestor); $stmt->bindParam(":request_for", $dest); @@ -88,9 +81,7 @@ public function removeRequest( public function removeRequests(string $dest = self::REQUEST_BECOME_PI): void { $stmt = $this->conn->prepare( - "DELETE FROM " . - self::TABLE_REQS . - " WHERE request_for=:request_for", + "DELETE FROM " . self::TABLE_REQS . " WHERE request_for=:request_for", ); $stmt->bindParam(":request_for", $dest); @@ -100,31 +91,23 @@ public function removeRequests(string $dest = self::REQUEST_BECOME_PI): void public function getRequest(string $user, string $dest): array { $stmt = $this->conn->prepare( - "SELECT * FROM " . - self::TABLE_REQS . - " WHERE uid=:uid and request_for=:request_for", + "SELECT * FROM " . self::TABLE_REQS . " WHERE uid=:uid and request_for=:request_for", ); $stmt->bindParam(":uid", $user); $stmt->bindParam(":request_for", $dest); $stmt->execute(); $result = $stmt->fetchAll(); if (count($result) == 0) { - throw new \Exception( - "no such request: uid='$user' request_for='$dest'", - ); + throw new \Exception("no such request: uid='$user' request_for='$dest'"); } if (count($result) > 1) { - throw new \Exception( - "multiple requests for uid='$user' request_for='$dest'", - ); + throw new \Exception("multiple requests for uid='$user' request_for='$dest'"); } return $result[0]; } - public function requestExists( - string $requestor, - string $dest = self::REQUEST_BECOME_PI, - ): bool { + public function requestExists(string $requestor, string $dest = self::REQUEST_BECOME_PI): bool + { try { $this->getRequest($requestor, $dest); return true; @@ -144,9 +127,7 @@ public function getAllRequests(): array public function getRequests(string $dest = self::REQUEST_BECOME_PI): array { $stmt = $this->conn->prepare( - "SELECT * FROM " . - self::TABLE_REQS . - " WHERE request_for=:request_for", + "SELECT * FROM " . self::TABLE_REQS . " WHERE request_for=:request_for", ); $stmt->bindParam(":request_for", $dest); @@ -157,9 +138,7 @@ public function getRequests(string $dest = self::REQUEST_BECOME_PI): array public function getRequestsByUser(string $user): array { - $stmt = $this->conn->prepare( - "SELECT * FROM " . self::TABLE_REQS . " WHERE uid=:uid", - ); + $stmt = $this->conn->prepare("SELECT * FROM " . self::TABLE_REQS . " WHERE uid=:uid"); $stmt->bindParam(":uid", $user); $stmt->execute(); @@ -169,9 +148,7 @@ public function getRequestsByUser(string $user): array public function deleteRequestsByUser(string $user): void { - $stmt = $this->conn->prepare( - "DELETE FROM " . self::TABLE_REQS . " WHERE uid=:uid", - ); + $stmt = $this->conn->prepare("DELETE FROM " . self::TABLE_REQS . " WHERE uid=:uid"); $stmt->bindParam(":uid", $user); $stmt->execute(); @@ -193,20 +170,11 @@ public function addNotice( $stmt->execute(); - $this->addLog( - $operator->uid, - $_SERVER["REMOTE_ADDR"], - "added_cluster_notice", - $operator, - ); + $this->addLog($operator->uid, $_SERVER["REMOTE_ADDR"], "added_cluster_notice", $operator); } - public function editNotice( - string $id, - string $title, - string $date, - string $content, - ): void { + public function editNotice(string $id, string $title, string $date, string $content): void + { $table = self::TABLE_NOTICES; $stmt = $this->conn->prepare( "UPDATE $table SET date=:date, title=:title, message=:message WHERE id=:id", @@ -221,9 +189,7 @@ public function editNotice( public function deleteNotice(string $id): void { - $stmt = $this->conn->prepare( - "DELETE FROM " . self::TABLE_NOTICES . " WHERE id=:id", - ); + $stmt = $this->conn->prepare("DELETE FROM " . self::TABLE_NOTICES . " WHERE id=:id"); $stmt->bindParam(":id", $id); $stmt->execute(); @@ -231,9 +197,7 @@ public function deleteNotice(string $id): void public function getNotice(string $id): array { - $stmt = $this->conn->prepare( - "SELECT * FROM " . self::TABLE_NOTICES . " WHERE id=:id", - ); + $stmt = $this->conn->prepare("SELECT * FROM " . self::TABLE_NOTICES . " WHERE id=:id"); $stmt->bindParam(":id", $id); $stmt->execute(); @@ -261,9 +225,7 @@ public function getPages(): array public function getPage(string $id): array { - $stmt = $this->conn->prepare( - "SELECT * FROM " . self::TABLE_PAGES . " WHERE page=:id", - ); + $stmt = $this->conn->prepare("SELECT * FROM " . self::TABLE_PAGES . " WHERE page=:id"); $stmt->bindParam(":id", $id); $stmt->execute(); @@ -271,27 +233,17 @@ public function getPage(string $id): array return $stmt->fetchAll()[0]; } - public function editPage( - string $id, - string $content, - UnityUser $operator, - ): void { + public function editPage(string $id, string $content, UnityUser $operator): void + { $stmt = $this->conn->prepare( - "UPDATE " . - self::TABLE_PAGES . - " SET content=:content WHERE page=:id", + "UPDATE " . self::TABLE_PAGES . " SET content=:content WHERE page=:id", ); $stmt->bindParam(":id", $id); $stmt->bindParam(":content", $content); $stmt->execute(); - $this->addLog( - $operator->uid, - $_SERVER["REMOTE_ADDR"], - "edited_page", - $operator, - ); + $this->addLog($operator->uid, $_SERVER["REMOTE_ADDR"], "edited_page", $operator); } public function addLog( @@ -316,9 +268,7 @@ public function addLog( public function addAccountDeletionRequest(string $uid): void { $stmt = $this->conn->prepare( - "INSERT INTO " . - self::TABLE_ACCOUNT_DELETION_REQUESTS . - " (uid) VALUE (:uid)", + "INSERT INTO " . self::TABLE_ACCOUNT_DELETION_REQUESTS . " (uid) VALUE (:uid)", ); $stmt->bindParam(":uid", $uid); @@ -328,9 +278,7 @@ public function addAccountDeletionRequest(string $uid): void public function accDeletionRequestExists(string $uid): bool { $stmt = $this->conn->prepare( - "SELECT * FROM " . - self::TABLE_ACCOUNT_DELETION_REQUESTS . - " WHERE uid=:uid", + "SELECT * FROM " . self::TABLE_ACCOUNT_DELETION_REQUESTS . " WHERE uid=:uid", ); $stmt->bindParam(":uid", $uid); @@ -345,9 +293,7 @@ public function deleteAccountDeletionRequest(string $uid): void return; } $stmt = $this->conn->prepare( - "DELETE FROM " . - self::TABLE_ACCOUNT_DELETION_REQUESTS . - " WHERE uid=:uid", + "DELETE FROM " . self::TABLE_ACCOUNT_DELETION_REQUESTS . " WHERE uid=:uid", ); $stmt->bindParam(":uid", $uid); $stmt->execute(); diff --git a/resources/lib/UnitySSO.php b/resources/lib/UnitySSO.php index cddb5cce..2b01f2c2 100644 --- a/resources/lib/UnitySSO.php +++ b/resources/lib/UnitySSO.php @@ -38,14 +38,9 @@ private static function getAttributeRaw( return $_SERVER[$attributeName]; } if (is_null($fallbackAttributeName)) { - throw new SSOException( - "\$_SERVER[\"$attributeName\"] is unset or empty!", - ); + throw new SSOException("\$_SERVER[\"$attributeName\"] is unset or empty!"); } - if ( - isset($_SERVER[$fallbackAttributeName]) && - $_SERVER[$fallbackAttributeName] != "" - ) { + if (isset($_SERVER[$fallbackAttributeName]) && $_SERVER[$fallbackAttributeName] != "") { return $_SERVER[$fallbackAttributeName]; } throw new SSOException( @@ -58,10 +53,7 @@ private static function getAttribute( string $attributeName, ?string $fallbackAttributeName = null, ): string { - $attribute_raw = self::getAttributeRaw( - $attributeName, - $fallbackAttributeName, - ); + $attribute_raw = self::getAttributeRaw($attributeName, $fallbackAttributeName); // attributes may have multiple values, by default they are split by ';' // see SPConfig setting attributeValueDelimiter return explode(";", $attribute_raw)[0]; @@ -74,10 +66,7 @@ public static function getSSO(): array "org" => self::eppnToOrg(self::getAttribute("REMOTE_USER")), "firstname" => self::getAttribute("givenName"), "lastname" => self::getAttribute("sn"), - "name" => - self::getAttribute("givenName") . - " " . - self::getAttribute("sn"), + "name" => self::getAttribute("givenName") . " " . self::getAttribute("sn"), "mail" => self::getAttribute("mail", "eppn"), ]; } diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index 01ddd071..30e2305b 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -67,38 +67,23 @@ public function init( $ldapGroupEntry = $this->getGroupEntry(); $id = $this->LDAP->getNextUIDGIDNumber($this->uid); \ensure(!$ldapGroupEntry->exists()); - $ldapGroupEntry->setAttribute( - "objectclass", - UnityLDAP::POSIX_GROUP_CLASS, - ); + $ldapGroupEntry->setAttribute("objectclass", UnityLDAP::POSIX_GROUP_CLASS); $ldapGroupEntry->setAttribute("gidnumber", strval($id)); $ldapGroupEntry->write(); \ensure(!$this->entry->exists()); - $this->entry->setAttribute( - "objectclass", - UnityLDAP::POSIX_ACCOUNT_CLASS, - ); + $this->entry->setAttribute("objectclass", UnityLDAP::POSIX_ACCOUNT_CLASS); $this->entry->setAttribute("uid", $this->uid); $this->entry->setAttribute("givenname", $firstname); $this->entry->setAttribute("sn", $lastname); $this->entry->setAttribute( "gecos", - \transliterator_transliterate( - "Latin-ASCII", - "$firstname $lastname", - ), + \transliterator_transliterate("Latin-ASCII", "$firstname $lastname"), ); $this->entry->setAttribute("mail", $email); $this->entry->setAttribute("o", $org); - $this->entry->setAttribute( - "homedirectory", - self::HOME_DIR . $this->uid, - ); - $this->entry->setAttribute( - "loginshell", - $this->LDAP->getDefUserShell(), - ); + $this->entry->setAttribute("homedirectory", self::HOME_DIR . $this->uid); + $this->entry->setAttribute("loginshell", $this->LDAP->getDefUserShell()); $this->entry->setAttribute("uidnumber", strval($id)); $this->entry->setAttribute("gidnumber", strval($id)); $this->entry->write(); @@ -107,16 +92,8 @@ public function init( $this->REDIS->setCache($this->uid, "lastname", $lastname); $this->REDIS->setCache($this->uid, "mail", $email); $this->REDIS->setCache($this->uid, "org", $org); - $this->REDIS->setCache( - $this->uid, - "homedir", - self::HOME_DIR . $this->uid, - ); - $this->REDIS->setCache( - $this->uid, - "loginshell", - $this->LDAP->getDefUserShell(), - ); + $this->REDIS->setCache($this->uid, "homedir", self::HOME_DIR . $this->uid); + $this->REDIS->setCache($this->uid, "loginshell", $this->LDAP->getDefUserShell()); $this->REDIS->setCache($this->uid, "sshkeys", []); $org = $this->getOrgGroup(); @@ -133,12 +110,7 @@ public function init( $this->REDIS->appendCacheArray("sorted_users", "", $this->uid); - $this->SQL->addLog( - $this->uid, - $_SERVER["REMOTE_ADDR"], - "user_added", - $this->uid, - ); + $this->SQL->addLog($this->uid, $_SERVER["REMOTE_ADDR"], "user_added", $this->uid); if ($send_mail) { $this->MAILER->sendMail($this->getMail(), "user_created", [ @@ -203,12 +175,7 @@ public function setFirstname(string $firstname, ?UnityUser $operator = null) $this->entry->setAttribute("givenname", $firstname); $operator = is_null($operator) ? $this->uid : $operator->uid; - $this->SQL->addLog( - $operator, - $_SERVER["REMOTE_ADDR"], - "firstname_changed", - $this->uid, - ); + $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "firstname_changed", $this->uid); $this->entry->write(); $this->REDIS->setCache($this->uid, "firstname", $firstname); @@ -252,12 +219,7 @@ public function setLastname(string $lastname, $operator = null) $this->entry->setAttribute("sn", $lastname); $operator = is_null($operator) ? $this->uid : $operator->uid; - $this->SQL->addLog( - $operator, - $_SERVER["REMOTE_ADDR"], - "lastname_changed", - $this->uid, - ); + $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "lastname_changed", $this->uid); $this->entry->write(); $this->REDIS->setCache($this->uid, "lastname", $lastname); @@ -307,12 +269,7 @@ public function setMail(string $email, ?UnityUser $operator = null) $this->entry->setAttribute("mail", $email); $operator = is_null($operator) ? $this->uid : $operator->uid; - $this->SQL->addLog( - $operator, - $_SERVER["REMOTE_ADDR"], - "email_changed", - $this->uid, - ); + $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "email_changed", $this->uid); $this->entry->write(); $this->REDIS->setCache($this->uid, "mail", $email); @@ -361,12 +318,7 @@ public function setSSHKeys($keys, $operator = null, bool $send_mail = true) $this->REDIS->setCache($this->uid, "sshkeys", $keys_filt); - $this->SQL->addLog( - $operator, - $_SERVER["REMOTE_ADDR"], - "sshkey_modify", - $this->uid, - ); + $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "sshkey_modify", $this->uid); if ($send_mail) { $this->MAILER->sendMail($this->getMail(), "user_sshkey", [ @@ -420,14 +372,10 @@ public function setLoginShell( ) { // ldap schema syntax is "IA5 String (1.3.6.1.4.1.1466.115.121.1.26)" if (!mb_check_encoding($shell, "ASCII")) { - throw new Exception( - "non ascii characters are not allowed in a login shell!", - ); + throw new Exception("non ascii characters are not allowed in a login shell!"); } if ($shell != trim($shell)) { - throw new Exception( - "leading/trailing whitespace is not allowed in a login shell!", - ); + throw new Exception("leading/trailing whitespace is not allowed in a login shell!"); } if (empty($shell)) { throw new Exception("login shell must not be empty!"); @@ -438,12 +386,7 @@ public function setLoginShell( $operator = is_null($operator) ? $this->uid : $operator->uid; - $this->SQL->addLog( - $operator, - $_SERVER["REMOTE_ADDR"], - "loginshell_changed", - $this->uid, - ); + $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "loginshell_changed", $this->uid); $this->REDIS->setCache($this->uid, "loginshell", $shell); @@ -489,12 +432,7 @@ public function setHomeDir(string $home, ?UnityUser $operator = null) $this->entry->write(); $operator = is_null($operator) ? $this->uid : $operator->uid; - $this->SQL->addLog( - $operator, - $_SERVER["REMOTE_ADDR"], - "homedir_changed", - $this->uid, - ); + $this->SQL->addLog($operator, $_SERVER["REMOTE_ADDR"], "homedir_changed", $this->uid); $this->REDIS->setCache($this->uid, "homedir", $home); } diff --git a/resources/lib/UnityWebhook.php b/resources/lib/UnityWebhook.php index 8c1b387e..80203762 100644 --- a/resources/lib/UnityWebhook.php +++ b/resources/lib/UnityWebhook.php @@ -5,8 +5,7 @@ class UnityWebhook { private string $template_dir = __DIR__ . "/../mail"; - private string $override_template_dir = - __DIR__ . "/../../deployment/mail_overrides"; + private string $override_template_dir = __DIR__ . "/../../deployment/mail_overrides"; private string $url = CONFIG["webhook"]["url"]; private string $MSG_LINKREF; private string $Subject; // set by template @@ -35,16 +34,11 @@ public function htmlToMarkdown(string $html): string return $md; } - public function sendWebhook( - ?string $template = null, - mixed $data = null, - ): bool { + public function sendWebhook(?string $template = null, mixed $data = null): bool + { $template_filename = $template . ".php"; - if ( - file_exists($this->override_template_dir . "/" . $template_filename) - ) { - $template_path = - $this->override_template_dir . "/" . $template_filename; + if (file_exists($this->override_template_dir . "/" . $template_filename)) { + $template_path = $this->override_template_dir . "/" . $template_filename; } else { $template_path = $this->template_dir . "/" . $template_filename; } @@ -58,9 +52,7 @@ public function sendWebhook( $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->url); curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_HTTPHEADER, [ - "Content-Type: application/json", - ]); + curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, \jsonEncode(["text" => $message])); $result = curl_exec($ch); diff --git a/resources/lib/utils.php b/resources/lib/utils.php index d8760b0b..f9f23c8b 100644 --- a/resources/lib/utils.php +++ b/resources/lib/utils.php @@ -16,10 +16,7 @@ function arrayGet(array $array, mixed ...$keys): mixed throw new ArrayKeyException( "key not found: \$array" . // [1, 2, "foo"] => [1][2]["foo"] - implode( - "", - array_map(fn($x) => jsonEncode([$x]), $keysTraversed), - ), + implode("", array_map(fn($x) => jsonEncode([$x]), $keysTraversed)), ); } $cursor = $cursor[$key]; @@ -83,11 +80,8 @@ function mbConvertEncoding( return $output; } -function mbDetectEncoding( - string $string, - ?array $encodings = null, - mixed $_ = null, -): string { +function mbDetectEncoding(string $string, ?array $encodings = null, mixed $_ = null): string +{ $output = mb_detect_encoding($string, $encodings, strict: true); if ($output === false) { throw new EncodingUnknownException(base64_encode($string)); diff --git a/resources/mail/group_disband.php b/resources/mail/group_disband.php index c26b3eb1..ab5ce3aa 100644 --- a/resources/mail/group_disband.php +++ b/resources/mail/group_disband.php @@ -5,9 +5,7 @@

Hello,

-

Your PI group, , has been disbanded on the Unity +

Your PI group, , has been disbanded on the Unity cluster. Any jobs associated with this PI account have been killed.

If you believe this to be a mistake, please reply to this email

diff --git a/resources/mail/group_join_request_cancelled.php b/resources/mail/group_join_request_cancelled.php index 331350ca..90119b80 100644 --- a/resources/mail/group_join_request_cancelled.php +++ b/resources/mail/group_join_request_cancelled.php @@ -1,7 +1,4 @@ Subject = - "Unity PI Membership Request Cancelled: '" . $data["uid"] . "'"; ?> +$this->Subject = "Unity PI Membership Request Cancelled: '" . $data["uid"] . "'"; ?>

Hello,

-

The user '' has cancelled their request to join your PI group.

+

The user '' has cancelled their request to join your PI group.

diff --git a/resources/mail/group_request_cancelled.php b/resources/mail/group_request_cancelled.php index 31012c59..1af2e8bb 100644 --- a/resources/mail/group_request_cancelled.php +++ b/resources/mail/group_request_cancelled.php @@ -1,6 +1,4 @@ Subject = "PI Request Cancelled: '" . $data["uid"] . "'"; ?>

Hello,

-

The user '' has cancelled their request to become a PI.

+

The user '' has cancelled their request to become a PI.

diff --git a/resources/mail/group_user_denied.php b/resources/mail/group_user_denied.php index 36dfc962..8e1f2ae0 100644 --- a/resources/mail/group_user_denied.php +++ b/resources/mail/group_user_denied.php @@ -5,8 +5,6 @@

Hello,

-

You have been denied from joining the PI group .

+

You have been denied from joining the PI group .

If you believe this to be a mistake, please reply to this email as soon as possible.

diff --git a/resources/mail/group_user_denied_owner.php b/resources/mail/group_user_denied_owner.php index 00c2560e..f98b161f 100644 --- a/resources/mail/group_user_denied_owner.php +++ b/resources/mail/group_user_denied_owner.php @@ -5,9 +5,7 @@

Hello,

-

A user has been denied from joining your PI group, . +

A user has been denied from joining your PI group, . The details of the denied user are below:

diff --git a/resources/mail/user_loginshell.php b/resources/mail/user_loginshell.php index f78bf54f..c21337dd 100644 --- a/resources/mail/user_loginshell.php +++ b/resources/mail/user_loginshell.php @@ -5,9 +5,7 @@

Hello,

-

You have updated your login shell on the Unity cluster to . +

You have updated your login shell on the Unity cluster to . You can view the login shell settings on the account settings page

diff --git a/test/functional/AccountDeletionRequestTest.php b/test/functional/AccountDeletionRequestTest.php index ad2fc8f3..756865ad 100644 --- a/test/functional/AccountDeletionRequestTest.php +++ b/test/functional/AccountDeletionRequestTest.php @@ -22,9 +22,7 @@ private function assertNumberAccountDeletionRequests(int $x) private function getNumberAccountDeletionRequests() { global $USER, $SQL; - $stmt = $SQL - ->getConn() - ->prepare("SELECT * FROM account_deletion_requests WHERE uid=:uid"); + $stmt = $SQL->getConn()->prepare("SELECT * FROM account_deletion_requests WHERE uid=:uid"); $uid = $USER->uid; $stmt->bindParam(":uid", $uid); $stmt->execute(); diff --git a/test/functional/LoginShellSetTest.php b/test/functional/LoginShellSetTest.php index a03cebfa..97e17c74 100644 --- a/test/functional/LoginShellSetTest.php +++ b/test/functional/LoginShellSetTest.php @@ -31,9 +31,7 @@ public static function getShells() private function isShellValid(string $shell) { - return mb_check_encoding($shell, "ASCII") && - $shell == trim($shell) && - !empty($shell); + return mb_check_encoding($shell, "ASCII") && $shell == trim($shell) && !empty($shell); } #[DataProvider("getShells")] diff --git a/test/functional/NewUserTest.php b/test/functional/NewUserTest.php index dc6d8f7b..9b38c32f 100644 --- a/test/functional/NewUserTest.php +++ b/test/functional/NewUserTest.php @@ -118,12 +118,7 @@ private function ensureUserDoesNotExist() array_values(array_diff($all_member_uids, [$USER->uid])), ); $all_users_group->write(); - ensure( - !in_array( - $USER->uid, - $all_users_group->getAttribute("memberuid"), - ), - ); + ensure(!in_array($USER->uid, $all_users_group->getAttribute("memberuid"))); } $REDIS->removeCacheArray("sorted_users", "", $USER->uid); } @@ -161,10 +156,8 @@ private function ensurePIGroupDoesNotExist() } #[DataProvider("provider")] - public function testCreateUserByJoinGoupByPI( - $user_to_create_args, - $expected_uid_gid, - ) { + public function testCreateUserByJoinGoupByPI($user_to_create_args, $expected_uid_gid) + { global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; $pi_user_args = getUserIsPIHasNoMembersNoMemberRequests(); switchUser(...$pi_user_args); @@ -172,14 +165,7 @@ public function testCreateUserByJoinGoupByPI( $gid = $pi_group->gid; switchUser(...$user_to_create_args); $this->assertTrue(!$USER->exists()); - $newOrg = new UnityOrg( - $SSO["org"], - $LDAP, - $SQL, - $MAILER, - $REDIS, - $WEBHOOK, - ); + $newOrg = new UnityOrg($SSO["org"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); $this->assertTrue(!$newOrg->exists()); $this->assertTrue($pi_group->exists()); $this->assertTrue(!$pi_group->memberExists($USER)); @@ -219,14 +205,8 @@ public function testCreateUserByJoinGoupByPI( $user_entry = $LDAP->getUserEntry($approve_uid); $user_group_entry = $LDAP->getGroupEntry($approve_uid); - $this->assertEquals( - $expected_uid_gid, - $user_entry->getAttribute("uidnumber")[0], - ); - $this->assertEquals( - $expected_uid_gid, - $user_group_entry->getAttribute("gidnumber")[0], - ); + $this->assertEquals($expected_uid_gid, $user_entry->getAttribute("uidnumber")[0]); + $this->assertEquals($expected_uid_gid, $user_group_entry->getAttribute("gidnumber")[0]); // $third_request_failed = false; // try { @@ -282,24 +262,15 @@ public function testCreateMultipleUsersByJoinGoupByPI() } #[DataProvider("provider")] - public function testCreateUserByJoinGoupByAdmin( - $user_to_create_args, - $expected_uid_gid, - ) { + public function testCreateUserByJoinGoupByAdmin($user_to_create_args, $expected_uid_gid) + { global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; switchUser(...getUserIsPIHasNoMembersNoMemberRequests()); $pi_group = $USER->getPIGroup(); $gid = $pi_group->gid; switchUser(...$user_to_create_args); $this->assertTrue(!$USER->exists()); - $newOrg = new UnityOrg( - $SSO["org"], - $LDAP, - $SQL, - $MAILER, - $REDIS, - $WEBHOOK, - ); + $newOrg = new UnityOrg($SSO["org"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); $this->assertTrue(!$newOrg->exists()); $this->assertTrue($pi_group->exists()); $this->assertTrue(!$pi_group->memberExists($USER)); @@ -339,14 +310,8 @@ public function testCreateUserByJoinGoupByAdmin( $user_entry = $LDAP->getUserEntry($approve_uid); $user_group_entry = $LDAP->getGroupEntry($approve_uid); - $this->assertEquals( - $expected_uid_gid, - $user_entry->getAttribute("uidnumber")[0], - ); - $this->assertEquals( - $expected_uid_gid, - $user_group_entry->getAttribute("gidnumber")[0], - ); + $this->assertEquals($expected_uid_gid, $user_entry->getAttribute("uidnumber")[0]); + $this->assertEquals($expected_uid_gid, $user_group_entry->getAttribute("gidnumber")[0]); // $third_request_failed = false; // try { @@ -366,23 +331,14 @@ public function testCreateUserByJoinGoupByAdmin( } #[DataProvider("provider")] - public function testCreateUserByCreateGroup( - $user_to_create_args, - $expected_uid_gid, - ) { + public function testCreateUserByCreateGroup($user_to_create_args, $expected_uid_gid) + { global $USER, $SSO, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK; switchuser(...$user_to_create_args); $pi_group = $USER->getPIGroup(); $this->assertTrue(!$USER->exists()); $this->assertTrue(!$pi_group->exists()); - $newOrg = new UnityOrg( - $SSO["org"], - $LDAP, - $SQL, - $MAILER, - $REDIS, - $WEBHOOK, - ); + $newOrg = new UnityOrg($SSO["org"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); $this->assertTrue(!$newOrg->exists()); try { $this->requestGroupCreation(); @@ -417,14 +373,8 @@ public function testCreateUserByCreateGroup( $user_entry = $LDAP->getUserEntry($approve_uid); $user_group_entry = $LDAP->getGroupEntry($approve_uid); - $this->assertEquals( - $expected_uid_gid, - $user_entry->getAttribute("uidnumber")[0], - ); - $this->assertEquals( - $expected_uid_gid, - $user_group_entry->getAttribute("gidnumber")[0], - ); + $this->assertEquals($expected_uid_gid, $user_entry->getAttribute("uidnumber")[0]); + $this->assertEquals($expected_uid_gid, $user_group_entry->getAttribute("gidnumber")[0]); // $third_request_failed = false; // try { diff --git a/test/functional/PIMemberRequestTest.php b/test/functional/PIMemberRequestTest.php index c1a7dec0..fac07b5a 100644 --- a/test/functional/PIMemberRequestTest.php +++ b/test/functional/PIMemberRequestTest.php @@ -30,16 +30,12 @@ public function testRequestMembership() $gid = $pi_group->gid; $this->assertTrue($USER->isPI()); $this->assertTrue($pi_group->exists()); - $this->assertTrue( - arraysAreEqualUnOrdered([$pi], $pi_group->getGroupMembers()), - ); + $this->assertTrue(arraysAreEqualUnOrdered([$pi], $pi_group->getGroupMembers())); $this->assertEquals([], $SQL->getRequests($gid)); switchUser(...getUserNotPiNotRequestedBecomePi()); $uid = $USER->uid; $this->assertFalse($USER->isPI()); - $this->assertFalse( - $SQL->requestExists($uid, UnitySQL::REQUEST_BECOME_PI), - ); + $this->assertFalse($SQL->requestExists($uid, UnitySQL::REQUEST_BECOME_PI)); $this->assertFalse($pi_group->memberExists($USER)); try { $this->requestMembership($gid); diff --git a/test/functional/PageLoadTest.php b/test/functional/PageLoadTest.php index 1d812b08..71d531dd 100644 --- a/test/functional/PageLoadTest.php +++ b/test/functional/PageLoadTest.php @@ -16,10 +16,7 @@ public static function provider() [$admin, __DIR__ . "/../../webroot/admin/user-mgmt.php"], [$admin, __DIR__ . "/../../webroot/admin/content.php"], [$admin, __DIR__ . "/../../webroot/admin/notices.php"], - [ - $nonexistent_user, - __DIR__ . "/../../webroot/panel/new_account.php", - ], + [$nonexistent_user, __DIR__ . "/../../webroot/panel/new_account.php"], [$normal_user, __DIR__ . "/../../webroot/panel/account.php"], [$normal_user, __DIR__ . "/../../webroot/panel/groups.php"], [$normal_user, __DIR__ . "/../../webroot/panel/support.php"], diff --git a/test/functional/PiBecomeRequestTest.php b/test/functional/PiBecomeRequestTest.php index 317a1bdd..d1306c46 100644 --- a/test/functional/PiBecomeRequestTest.php +++ b/test/functional/PiBecomeRequestTest.php @@ -25,9 +25,7 @@ private function getNumberPiBecomeRequests() // FIXME "admin" should be something else $stmt = $SQL ->getConn() - ->prepare( - "SELECT * FROM requests WHERE uid=:uid and request_for='admin'", - ); + ->prepare("SELECT * FROM requests WHERE uid=:uid and request_for='admin'"); $uid = $USER->uid; $stmt->bindParam(":uid", $uid); $stmt->execute(); @@ -67,9 +65,7 @@ public function testRequestBecomePi() public function testRequestBecomePiUserRequestedAccountDeletion() { global $USER, $SQL; - switchUser( - ...getUserNotPiNotRequestedBecomePiRequestedAccountDeletion(), - ); + switchUser(...getUserNotPiNotRequestedBecomePiRequestedAccountDeletion()); $this->assertFalse($USER->isPI()); $this->assertNumberPiBecomeRequests(0); $this->assertTrue($SQL->accDeletionRequestExists($USER->uid)); diff --git a/test/functional/PiMemberApproveTest.php b/test/functional/PiMemberApproveTest.php index f8b3d700..4d74c103 100644 --- a/test/functional/PiMemberApproveTest.php +++ b/test/functional/PiMemberApproveTest.php @@ -39,9 +39,7 @@ private function requestJoinPI(string $gid) private function assertGroupMembers(UnityGroup $group, array $members) { - $this->assertTrue( - arraysAreEqualUnOrdered($members, $group->getGroupMemberUIDs()), - ); + $this->assertTrue(arraysAreEqualUnOrdered($members, $group->getGroupMemberUIDs())); } public function testApproveRequest() diff --git a/test/functional/PiMemberDenyTest.php b/test/functional/PiMemberDenyTest.php index bb5ca84e..a39f5765 100644 --- a/test/functional/PiMemberDenyTest.php +++ b/test/functional/PiMemberDenyTest.php @@ -31,18 +31,9 @@ public function testDenyRequest() $pi = $USER; $piGroup = $USER->getPIGroup(); $this->assertTrue($piGroup->exists()); - $this->assertTrue( - arraysAreEqualUnOrdered([$pi->uid], $piGroup->getGroupMemberUIDs()), - ); + $this->assertTrue(arraysAreEqualUnOrdered([$pi->uid], $piGroup->getGroupMemberUIDs())); $this->assertEmpty($piGroup->getRequests()); - $requestedUser = new UnityUser( - self::$requestUid, - $LDAP, - $SQL, - $MAILER, - $REDIS, - $WEBHOOK, - ); + $requestedUser = new UnityUser(self::$requestUid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); try { $piGroup->newUserRequest( $requestedUser, @@ -55,12 +46,7 @@ public function testDenyRequest() $piGroup->denyUser($requestedUser); $this->assertEmpty($piGroup->getRequests()); - $this->assertTrue( - arraysAreEqualUnOrdered( - [$pi->uid], - $piGroup->getGroupMemberUIDs(), - ), - ); + $this->assertTrue(arraysAreEqualUnOrdered([$pi->uid], $piGroup->getGroupMemberUIDs())); $this->assertFalse($piGroup->memberExists($requestedUser)); } finally { $SQL->removeRequest(self::$requestUid, $piGroup->gid); diff --git a/test/functional/PiRemoveUserTest.php b/test/functional/PiRemoveUserTest.php index e6858bd5..6118ad6c 100644 --- a/test/functional/PiRemoveUserTest.php +++ b/test/functional/PiRemoveUserTest.php @@ -30,14 +30,7 @@ public function testRemoveUser() $memberToDelete = null; foreach ($memberUIDs as $uid) { if ($uid != $piUid) { - $memberToDelete = new UnityUser( - $uid, - $LDAP, - $SQL, - $MAILER, - $REDIS, - $WEBHOOK, - ); + $memberToDelete = new UnityUser($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); if ($memberToDelete->hasRequestedAccountDeletion()) { continue; } diff --git a/test/functional/SSHKeyAddTest.php b/test/functional/SSHKeyAddTest.php index c330ae58..1a8ea3a5 100644 --- a/test/functional/SSHKeyAddTest.php +++ b/test/functional/SSHKeyAddTest.php @@ -96,11 +96,8 @@ public function getKeyCount() } #[DataProvider("provider")] - public function testAddSshKeys( - string $methodName, - int $expectedKeysAdded, - array $keys, - ) { + public function testAddSshKeys(string $methodName, int $expectedKeysAdded, array $keys) + { global $USER; switchUser(...getUserHasNoSshKeys()); $numKeysBefore = $this->getKeyCount($USER); @@ -109,10 +106,7 @@ public function testAddSshKeys( call_user_func([SSHKeyAddTest::class, $methodName], $keys); // $method($keys); $numKeysAfter = $this->getKeyCount($USER); - $this->assertEquals( - $expectedKeysAdded, - $numKeysAfter - $numKeysBefore, - ); + $this->assertEquals($expectedKeysAdded, $numKeysAfter - $numKeysBefore); } finally { $USER->setSSHKeys([]); } diff --git a/test/phpunit-bootstrap.php b/test/phpunit-bootstrap.php index 34f81f53..4463c74c 100644 --- a/test/phpunit-bootstrap.php +++ b/test/phpunit-bootstrap.php @@ -1,9 +1,7 @@ flushAll(); } -if ( - !is_null($REDIS->getCache("initialized", "")) and - !array_key_exists("u", $options) -) { +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.\n"; } else { @@ -39,11 +36,7 @@ // search entire tree, some users created for admin purposes might not be in the normal OU echo "waiting for LDAP search (users)...\n"; - $users = $LDAP->search( - "objectClass=posixAccount", - CONFIG["ldap"]["basedn"], - [], - ); + $users = $LDAP->search("objectClass=posixAccount", CONFIG["ldap"]["basedn"], []); echo "response received.\n"; $user_CNs = $LDAP->getUserGroup()->getAttribute("memberuid"); sort($user_CNs); @@ -53,31 +46,16 @@ if (!in_array($uid, $user_CNs)) { continue; } - $REDIS->setCache( - $uid, - "firstname", - $user->getAttribute("givenname")[0], - ); + $REDIS->setCache($uid, "firstname", $user->getAttribute("givenname")[0]); $REDIS->setCache($uid, "lastname", $user->getAttribute("sn")[0]); $REDIS->setCache($uid, "org", $user->getAttribute("o")[0]); $REDIS->setCache($uid, "mail", $user->getAttribute("mail")[0]); $REDIS->setCache($uid, "sshkeys", $user->getAttribute("sshpublickey")); - $REDIS->setCache( - $uid, - "loginshell", - $user->getAttribute("loginshell")[0], - ); - $REDIS->setCache( - $uid, - "homedir", - $user->getAttribute("homedirectory")[0], - ); + $REDIS->setCache($uid, "loginshell", $user->getAttribute("loginshell")[0]); + $REDIS->setCache($uid, "homedir", $user->getAttribute("homedirectory")[0]); } - $org_group_ou = new LDAPEntry( - $LDAP->getConn(), - CONFIG["ldap"]["orggroup_ou"], - ); + $org_group_ou = new LDAPEntry($LDAP->getConn(), CONFIG["ldap"]["orggroup_ou"]); echo "waiting for LDAP search (org groups)...\n"; $org_groups = $org_group_ou->getChildrenArray(["cn", "memberuid"], true); echo "response received.\n"; @@ -93,10 +71,7 @@ $REDIS->setCache($gid, "members", $org_group["memberuid"] ?? []); } - $pi_group_ou = new LDAPEntry( - $LDAP->getConn(), - CONFIG["ldap"]["pigroup_ou"], - ); + $pi_group_ou = new LDAPEntry($LDAP->getConn(), CONFIG["ldap"]["pigroup_ou"]); echo "waiting for LDAP search (pi groups)...\n"; $pi_groups = $pi_group_ou->getChildrenArray(["cn", "memberuid"], true); echo "response received.\n";