diff --git a/.phpcs-ruleset.xml b/.phpcs-ruleset.xml new file mode 100644 index 00000000..13faff04 --- /dev/null +++ b/.phpcs-ruleset.xml @@ -0,0 +1,11 @@ + + + PSR12, with max line length = 100 characters + + + + + + + + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e0d3579d..d3ebd023 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ repos: entry: phpcbf language: system files: \.php$ - args: [--standard=PSR12, --colors] + args: [--standard=./.phpcs-ruleset.xml, --colors] # linters (work required) ######################################################################## # - repo: https://github.com/pre-commit/pre-commit-hooks @@ -41,7 +41,7 @@ repos: entry: phpcs language: system files: \.php$ - args: [--standard=PSR12, --colors] + args: [--standard=./.phpcs-ruleset.xml, --colors] - id: php-l name: php -l entry: php diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 60870776..17378d77 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,6 +4,7 @@ This code base is currently using PHP version 8.3. All files are required to be linted with PSR-12 standard. +The maximum line length for any PHP file is 100 characters, instead of PSR-12's 120 characters. This repository will automatically check PRs for linting compliance. ## Development Environment diff --git a/resources/init.php b/resources/init.php index fe4eea8d..660f0bc0 100644 --- a/resources/init.php +++ b/resources/init.php @@ -107,7 +107,10 @@ $errorid = uniqid("sso-"); $eppn = $_SERVER["REMOTE_USER"]; UnitySite::errorLog("SSO Failure", "{$e} ($errorid)"); - UnitySite::die("Invalid eppn: '$eppn'. Please contact {$CONFIG["mail"]["support"]} (id: $errorid)", true); + UnitySite::die( + "Invalid eppn: '$eppn'. Please contact {$CONFIG["mail"]["support"]} (id: $errorid)", + true + ); } $_SESSION["SSO"] = $SSO; diff --git a/resources/lib/UnityGroup.php b/resources/lib/UnityGroup.php index 27b201e1..abf7d7b1 100644 --- a/resources/lib/UnityGroup.php +++ b/resources/lib/UnityGroup.php @@ -44,7 +44,9 @@ public function __construct($gid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK) public function equals($other_group) { if (!is_a($other_group, self::class)) { - throw new Exception("Unable to check equality because the parameter is not a " . self::class . " object"); + throw new Exception( + "Unable to check equality because the parameter is not a " . self::class . " object" + ); } return $this->gid == $other_group->gid; @@ -69,8 +71,14 @@ public function exists() // Portal-facing methods, these are the methods called by scripts in webroot // - public function requestGroup($firstname, $lastname, $email, $org, $send_mail_to_admins, $send_mail = true) - { + public function requestGroup( + $firstname, + $lastname, + $email, + $org, + $send_mail_to_admins, + $send_mail = true + ) { // check for edge cases... if ($this->exists()) { return; @@ -150,7 +158,8 @@ public function approveGroup($operator = null, $send_mail = true) ); } - // initialize ldap objects, if this fails the script will crash, but nothing will persistently break + // initialize ldap objects, if this fails the script will crash, + // but nothing will persistently break $this->init(); // remove the request from the sql table @@ -279,7 +288,8 @@ public function cancelGroupJoinRequest($user, $send_mail = true) // } /** - * This method is executed when a user is approved to join the group (either by admin or the group owner) + * This method is executed when a user is approved to join the group + * (either by admin or the group owner) */ public function approveUser($new_user, $send_mail = true) { @@ -388,8 +398,14 @@ public function removeUser($new_user, $send_mail = true) } } - public function newUserRequest($new_user, $firstname, $lastname, $email, $org, $send_mail = true) - { + public function newUserRequest( + $new_user, + $firstname, + $lastname, + $email, + $org, + $send_mail = true + ) { if ($this->userExists($new_user)) { UnitySite::errorLog("warning", "user '$new_user' already in group"); return; @@ -532,7 +548,8 @@ private function init() $this->REDIS->appendCacheArray("sorted_groups", "", $this->gid); - // TODO if we ever make this project based, we need to update the cache here with the memberuid + // TODO if we ever make this project based, + // we need to update the cache here with the memberuid } private function addUserToGroup($new_user) diff --git a/resources/lib/UnityLDAP.php b/resources/lib/UnityLDAP.php index 69a67c3e..18637ca4 100644 --- a/resources/lib/UnityLDAP.php +++ b/resources/lib/UnityLDAP.php @@ -234,15 +234,30 @@ public function getAllUsersUIDs() // // Functions that return user/group objects // - public function getAllUsers($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false) - { + public function getAllUsers( + $UnitySQL, + $UnityMailer, + $UnityRedis, + $UnityWebhook, + $ignorecache = false + ) { $out = array(); if (!$ignorecache) { $users = $UnityRedis->getCache("sorted_users", ""); if (!is_null($users)) { foreach ($users as $user) { - array_push($out, new UnityUser($user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook)); + array_push( + $out, + new UnityUser( + $user, + $this, + $UnitySQL, + $UnityMailer, + $UnityRedis, + $UnityWebhook + ) + ); } return $out; } @@ -273,15 +288,22 @@ public function getAllUsersAttributes($attributes) return $user_attributes; } - public function getAllPIGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false) - { + public function getAllPIGroups( + $UnitySQL, + $UnityMailer, + $UnityRedis, + $UnityWebhook, + $ignorecache = false + ) { $out = array(); if (!$ignorecache) { $groups = $UnityRedis->getCache("sorted_groups", ""); if (!is_null($groups)) { foreach ($groups as $group) { - $params = array($group, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook); + $params = array( + $group, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook + ); array_push($out, new UnityGroup(...$params)); } @@ -362,17 +384,31 @@ public function getAllUID2PIGIDs() return $uid2pigids; } - public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false) - { + public function getAllOrgGroups( + $UnitySQL, + $UnityMailer, + $UnityRedis, + $UnityWebhook, + $ignorecache = false + ) { $out = array(); if (!$ignorecache) { $orgs = $UnityRedis->getCache("sorted_orgs", ""); if (!is_null($orgs)) { foreach ($orgs as $org) { - array_push($out, new UnityOrg($org, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook)); + array_push( + $out, + new UnityOrg( + $org, + $this, + $UnitySQL, + $UnityMailer, + $UnityRedis, + $UnityWebhook + ) + ); } - return $out; } } diff --git a/resources/lib/UnityMailer.php b/resources/lib/UnityMailer.php index 903493b5..d4676330 100644 --- a/resources/lib/UnityMailer.php +++ b/resources/lib/UnityMailer.php @@ -57,7 +57,9 @@ public function __construct( $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'"); + throw new Exception( + "SMTP security is not set correctly, leave empty, use 'tls', or 'ssl'" + ); } $this->SMTPSecure = $security; diff --git a/resources/lib/UnityPerms.php b/resources/lib/UnityPerms.php index e16a66de..fe5d4981 100644 --- a/resources/lib/UnityPerms.php +++ b/resources/lib/UnityPerms.php @@ -21,7 +21,10 @@ public function checkApproveUser($uid, $operated_on, $group) $role = $this->SQL->getRole($uid, $group); - if ($this->SQL->hasPerm($role, 'unity.admin') || $this->SQL->hasPerm($role, 'unity.admin_no_grant')) { + if ( + $this->SQL->hasPerm($role, 'unity.admin') + || $this->SQL->hasPerm($role, 'unity.admin_no_grant') + ) { return true; } @@ -46,7 +49,10 @@ public function checkDenyUser($uid, $operated_on, $group) $role = $this->SQL->getRole($uid, $group); - if ($this->SQL->hasPerm($role, 'unity.admin') || $this->SQL->hasPerm($role, 'unity.admin_no_grant')) { + if ( + $this->SQL->hasPerm($role, 'unity.admin') + || $this->SQL->hasPerm($role, 'unity.admin_no_grant') + ) { return true; } @@ -79,7 +85,10 @@ public function checkGrantRole($uid, $group, $role) return false; } - if ($this->SQL->hasPerm($user_role, 'unity.admin') || $this->SQL->hasPerm($user_role, 'unity.admin_no_grant')) { + if ( + $this->SQL->hasPerm($user_role, 'unity.admin') + || $this->SQL->hasPerm($user_role, 'unity.admin_no_grant') + ) { return true; } @@ -112,7 +121,10 @@ public function checkRevokeRole($uid, $group, $role) return false; } - if ($this->SQL->hasPerm($user_role, 'unity.admin') || $this->SQL->hasPerm($user_role, 'unity.admin_no_grant')) { + if ( + $this->SQL->hasPerm($user_role, 'unity.admin') + || $this->SQL->hasPerm($user_role, 'unity.admin_no_grant') + ) { return true; } diff --git a/resources/lib/UnitySQL.php b/resources/lib/UnitySQL.php index db004c50..ef544a59 100644 --- a/resources/lib/UnitySQL.php +++ b/resources/lib/UnitySQL.php @@ -19,7 +19,7 @@ class UnitySQL private const TABLE_GROUP_JOIN_REQUESTS = "groupJoinRequests"; - // FIXME this string should be changed to something more intuitive, requires production sql change + // FIXME this string should be changed to something more intuitive, requires production change public const REQUEST_BECOME_PI = "admin"; private $conn; @@ -38,8 +38,14 @@ public function getConn() // // requests table methods // - public function addRequest($requestor, $firstname, $lastname, $email, $org, $dest = self::REQUEST_BECOME_PI) - { + public function addRequest( + $requestor, + $firstname, + $lastname, + $email, + $org, + $dest = self::REQUEST_BECOME_PI + ) { if ($this->requestExists($requestor, $dest)) { return; } @@ -156,8 +162,9 @@ public function deleteRequestsByUser($user) public function addNotice($title, $date, $content, $operator) { + $table = self::TABLE_NOTICES; $stmt = $this->conn->prepare( - "INSERT INTO " . self::TABLE_NOTICES . " (date, title, message) VALUES (:date, :title, :message)" + "INSERT INTO $table (date, title, message) VALUES (:date, :title, :message)" ); $stmt->bindParam(":date", $date); $stmt->bindParam(":title", $title); @@ -175,8 +182,9 @@ public function addNotice($title, $date, $content, $operator) public function editNotice($id, $title, $date, $content) { + $table = self::TABLE_NOTICES; $stmt = $this->conn->prepare( - "UPDATE " . self::TABLE_NOTICES . " SET date=:date, title=:title, message=:message WHERE id=:id" + "UPDATE $table SET date=:date, title=:title, message=:message WHERE id=:id" ); $stmt->bindParam(":date", $date); $stmt->bindParam(":title", $title); @@ -261,8 +269,9 @@ public function editPage($id, $content, $operator) // audit log table methods public function addLog($operator, $operator_ip, $action_type, $recipient) { + $table = self::TABLE_AUDIT_LOG; $stmt = $this->conn->prepare( - "INSERT INTO " . self::TABLE_AUDIT_LOG . " (operator, operator_ip, action_type, recipient) + "INSERT INTO $table (operator, operator_ip, action_type, recipient) VALUE (:operator, :operator_ip, :action_type, :recipient)" ); $stmt->bindParam(":operator", $operator); @@ -332,9 +341,8 @@ public function updateSiteVar($name, $value) public function getRole($uid, $group) { - $stmt = $this->conn->prepare( - "SELECT * FROM " . self::TABLE_GROUP_ROLE_ASSIGNMENTS . " WHERE user=:uid AND `group`=:group" - ); + $table = self::TABLE_GROUP_ROLE_ASSIGNMENTS; + $stmt = $this->conn->prepare("SELECT * FROM $table WHERE user=:uid AND `group`=:group"); $stmt->bindParam(":uid", $uid); $stmt->bindParam(":group", $group); @@ -372,9 +380,8 @@ public function getPriority($role) public function roleAvailableInGroup($uid, $group, $role) { - $stmt = $this->conn->prepare( - "SELECT * FROM " . self::TABLE_GROUP_ROLE_ASSIGNMENTS . " WHERE user=:uid AND `group`=:group" - ); + $table = self::TABLE_GROUP_ROLE_ASSIGNMENTS; + $stmt = $this->conn->prepare("SELECT * FROM $table WHERE user=:uid AND `group`=:group"); $stmt->bindParam(":uid", $uid); $stmt->bindParam(":group", $group); diff --git a/resources/lib/UnityUser.php b/resources/lib/UnityUser.php index f500374f..7791ad7a 100644 --- a/resources/lib/UnityUser.php +++ b/resources/lib/UnityUser.php @@ -35,7 +35,9 @@ public function __construct($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK) public function equals($other_user) { if (!is_a($other_user, self::class)) { - throw new Exception("Unable to check equality because the parameter is not a " . self::class . " object"); + throw new Exception( + "Unable to check equality because the parameter is not a " . self::class . " object" + ); } return $this->uid == $other_user->uid; @@ -594,7 +596,8 @@ public function getPIGroupGIDs($ignorecache = false) } /** - * Sends an email to admins about account deletion request and also adds it to a table in the database + * Sends an email to admins about account deletion request + * and also adds it to a table in the database */ public function requestAccountDeletion() { diff --git a/resources/mail/footer.php b/resources/mail/footer.php index 83ff615e..9e6a712b 100644 --- a/resources/mail/footer.php +++ b/resources/mail/footer.php @@ -1,6 +1,10 @@ - diff --git a/resources/templates/header.php b/resources/templates/header.php index fbb4e312..adb42b3a 100644 --- a/resources/templates/header.php +++ b/resources/templates/header.php @@ -20,7 +20,10 @@ } if (isset($SSO)) { - if (!$_SESSION["user_exists"] && !str_ends_with($_SERVER['PHP_SELF'], "/panel/new_account.php")) { + if ( + !$_SESSION["user_exists"] + && !str_ends_with($_SERVER['PHP_SELF'], "/panel/new_account.php") + ) { UnitySite::redirect($CONFIG["site"]["prefix"] . "/panel/new_account.php"); } } @@ -45,11 +48,16 @@ ?> - /css/global.css"> - /css/navbar.css"> - /css/modal.css"> - /css/tables.css"> - /css/filters.css"> + + + + + + "; + ?> "> @@ -63,14 +71,19 @@ /assets/"> @@ -120,7 +135,9 @@
- +