diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml
index 84702a15..92fa84bb 100644
--- a/.github/workflows/phpunit.yml
+++ b/.github/workflows/phpunit.yml
@@ -9,19 +9,15 @@ jobs:
docker-compose-phpunit:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
- with:
- submodules: true
- - name: setup PHP
- uses: shivammathur/setup-php@v2
- with:
- php-version: "8.3"
- tools: composer
- - name: install composer dependencies
- run: composer update
- - name: Run docker compose
- uses: hoverkraft-tech/compose-action@v2.0.1
- with:
- compose-file: "./tools/docker-dev/docker-compose.yml"
- - name: Execute tests in the running services
- run: docker compose -f ./tools/docker-dev/docker-compose.yml exec -w '/var/www/unity-web-portal' web bash -c 'XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-clover="$(mktemp --suffix=.xml)" -d --min-coverage=./coverage.php'
+ - uses: actions/checkout@v3
+ with:
+ submodules: true
+ - uses: shivammathur/setup-php@v2
+ with:
+ php-version: "8.3"
+ tools: composer
+ - run: composer install --dev
+ - uses: hoverkraft-tech/compose-action@v2.0.1
+ with:
+ compose-file: "./tools/docker-dev/docker-compose.yml"
+ - run: docker compose -f ./tools/docker-dev/docker-compose.yml exec -w '/var/www/unity-web-portal' web bash -c 'XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-clover="$(mktemp --suffix=.xml)" -d --min-coverage=./coverage.php'
diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml
index 929a14b2..fca4d814 100644
--- a/.github/workflows/pre-commit.yml
+++ b/.github/workflows/pre-commit.yml
@@ -9,13 +9,15 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
- with:
- submodules: true
- - uses: actions/setup-python@v3
- - name: setup PHP
- uses: shivammathur/setup-php@v2
- with:
- php-version: "8.3"
- tools: composer, phpcs, phpcbf
- - uses: pre-commit/action@v3.0.1
+ - uses: actions/checkout@v3
+ with:
+ submodules: true
+ - uses: actions/setup-python@v3
+ - uses: shivammathur/setup-php@v2
+ with:
+ php-version: "8.3"
+ tools: composer
+ - run: composer install --dev
+ - uses: actions/setup-node@v6.0.0
+ - run: npm install --dev
+ - uses: pre-commit/action@v3.0.1
diff --git a/.gitignore b/.gitignore
index 94aa9f54..d08024d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,3 +20,5 @@ deployment/**/*
!deployment/**/README.md
.phpunit.result.cache
+
+node_modules
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 97d65767..bc28907b 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -11,19 +11,64 @@ repos:
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
+ # 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
name: PHP Code Beautifier and Fixer
- entry: phpcbf
+ entry: ./vendor/bin/phpcbf
+ args: [--standard=./.phpcs-ruleset.xml, --colors]
language: system
files: \.php$
- args: [--standard=./.phpcs-ruleset.xml, --colors]
+ # exclude pure PHP files
exclude: |
(?x)^(
test/.*|
workers/.*|
+ node_modules/.*|
+ resources/lib/phpopenldaper/.*|
+ vendor/.*|
+ resources/lib/.*|
+ )$
+
+ - repo: local
+ 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$
+ # exclude impure PHP files
+ exclude: |
+ (?x)^(
+ node_modules/.*|
+ resources/lib/phpopenldaper/.*|
+ vendor/.*|
+ resources/templates/.*|
+ webroot/.*|
)$
# linters (work required) ########################################################################
@@ -45,14 +90,19 @@ repos:
hooks:
- id: phpcs
name: PHP CodeSniffer
- entry: phpcs
+ entry: ./vendor/bin/phpcs
language: system
files: \.php$
args: [--standard=./.phpcs-ruleset.xml, --colors]
+ # exclude pure PHP files
exclude: |
(?x)^(
test/.*|
workers/.*|
+ node_modules/.*|
+ resources/lib/phpopenldaper/.*|
+ vendor/.*|
+ resources/lib/.*|
)$
- id: php-l
name: php -l
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 2dd73f67..d4c3e197 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -2,24 +2,25 @@
## Conventions
-* 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.
-* Comments should be used sparingly.
-* Empty lines should be used sparingly.
-* No code should fail quietly, instead exceptions should be thrown.
+- PHP version 8.3.
+- All pure PHP files are required to be formatted with Prettier.
+- All impure PHP files (mixed into HTML) are required to be linted with PSR-12 and formatted with `phpcbf`.
+- The maximum line length for any PHP file is 100 characters.
+- Comments should be used sparingly.
+- Empty lines should be used sparingly.
+- No code should fail quietly, instead exceptions should be thrown.
PHP builtin functions that fail quietly (ex: `json_encode`) should be replaced with a wrapper in `resources/utils.php`.
-* No code should call `die()` or `exit()`, instead `UnityHTTPD::die()`.
+- No code should call `die()` or `exit()`, instead `UnityHTTPD::die()`.
This will avoid the premature death of our automated testing processes.
-* No code should call `assert()`, instead `\ensure()`.
+- No code should call `assert()`, instead `\ensure()`.
This will enforce conditions even in production.
-* No code should call `json_encode()`, instead `\jsonEncode()`.
+- No code should call `json_encode()`, instead `\jsonEncode()`.
This will throw errors and escape slashes by default.
-* No code should call `mb_convert_encoding()`, instead `\mbConvertEncoding()`.
+- No code should call `mb_convert_encoding()`, instead `\mbConvertEncoding()`.
This will throw an exception rather than returning `false`.
-* No code should call `mb_detect_encoding()`, instead `\mbDetectEncoding()`.
+- No code should call `mb_detect_encoding()`, instead `\mbDetectEncoding()`.
This will enable strict mode and throw an exception rather than returning `false`.
-* `UnityHTTPD`'s user-facing error functionality (ex: `badRequest`) should only be called from `webroot/**/*.php`.
+- `UnityHTTPD`'s user-facing error functionality (ex: `badRequest`) should only be called from `webroot/**/*.php`.
`resources/**/*.php` should throw exceptions instead.
This repository will automatically check PRs for linting compliance.
@@ -29,6 +30,7 @@ This repository will automatically check PRs for linting compliance.
### Setting up your Environment
1. Clone this repo (including submodules): `git clone Hello, Hello, Hello, 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 Hello, The user '' has cancelled their request to join your PI group. The user '' has cancelled their request to join your PI group. Hello, Hello, Hello, The user '' has cancelled their request to become a PI. The user '' has cancelled their request to become a PI. Hello, Hello,
A new user has been added to your PI group,
-''.
+''.
The details of the new user are below:
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. 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/group_user_removed.php b/resources/mail/group_user_removed.php
index bfde1f18..83a1786e 100644
--- a/resources/mail/group_user_removed.php
+++ b/resources/mail/group_user_removed.php
@@ -1,8 +1,7 @@
Subject = "Removed from Group";
-?>
+$this->Subject = "Removed from Group"; ?>
Hello, Hello,
A user has been removed from your PI group,
-''.
+''.
The details of the removed user are below:
Hello, Hello,
A user has requested to join your PI group,
-''.
+''.
The details of the user are below:
Hello, 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 Hello,]*>(.*?)<\/del>/s';
+ $bold = "/<(b|strong)\b[^>]*>(.*?)<\/(b|strong)>/s";
+ $italic = "/]*>(.*?)<\/i>/s";
+ $strikethrough = "/]*>(.*?)<\/del>/s";
$link = '/]*href=["\']?([^"\'\s]*)[^>]*>(.*?)<\/a>/s';
// Replace each HTML tag with its corresponding markdown format
@@ -37,8 +38,11 @@ public function htmlToMarkdown($html)
public function sendWebhook($template = null, $data = null)
{
$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;
}
@@ -52,9 +56,11 @@ public function sendWebhook($template = null, $data = null)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('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(array('text' => $message)));
+ curl_setopt($ch, CURLOPT_POSTFIELDS, \jsonEncode(["text" => $message]));
$result = curl_exec($ch);
curl_close($ch);
return $result;
diff --git a/resources/lib/exceptions/ArrayKeyException.php b/resources/lib/exceptions/ArrayKeyException.php
index 7b591ac8..722878c2 100644
--- a/resources/lib/exceptions/ArrayKeyException.php
+++ b/resources/lib/exceptions/ArrayKeyException.php
@@ -2,6 +2,4 @@
namespace UnityWebPortal\lib\exceptions;
-class ArrayKeyException extends \Exception
-{
-}
+class ArrayKeyException extends \Exception {}
diff --git a/resources/lib/exceptions/EncodingConversionException.php b/resources/lib/exceptions/EncodingConversionException.php
index ac316d89..aeab6ef5 100644
--- a/resources/lib/exceptions/EncodingConversionException.php
+++ b/resources/lib/exceptions/EncodingConversionException.php
@@ -2,6 +2,4 @@
namespace UnityWebPortal\lib\exceptions;
-class EncodingConversionException extends \Exception
-{
-}
+class EncodingConversionException extends \Exception {}
diff --git a/resources/lib/exceptions/EncodingUnknownException.php b/resources/lib/exceptions/EncodingUnknownException.php
index 63725d01..d3520183 100644
--- a/resources/lib/exceptions/EncodingUnknownException.php
+++ b/resources/lib/exceptions/EncodingUnknownException.php
@@ -2,6 +2,4 @@
namespace UnityWebPortal\lib\exceptions;
-class EncodingUnknownException extends \Exception
-{
-}
+class EncodingUnknownException extends \Exception {}
diff --git a/resources/lib/exceptions/EnsureException.php b/resources/lib/exceptions/EnsureException.php
index f184f903..178142d9 100644
--- a/resources/lib/exceptions/EnsureException.php
+++ b/resources/lib/exceptions/EnsureException.php
@@ -2,6 +2,4 @@
namespace UnityWebPortal\lib\exceptions;
-class EnsureException extends \Exception
-{
-}
+class EnsureException extends \Exception {}
diff --git a/resources/lib/exceptions/NoDieException.php b/resources/lib/exceptions/NoDieException.php
index 49d8b2d8..9a069dca 100644
--- a/resources/lib/exceptions/NoDieException.php
+++ b/resources/lib/exceptions/NoDieException.php
@@ -2,6 +2,4 @@
namespace UnityWebPortal\lib\exceptions;
-class NoDieException extends \Exception
-{
-}
+class NoDieException extends \Exception {}
diff --git a/resources/lib/exceptions/SSOException.php b/resources/lib/exceptions/SSOException.php
index 2551180e..ce631639 100644
--- a/resources/lib/exceptions/SSOException.php
+++ b/resources/lib/exceptions/SSOException.php
@@ -2,6 +2,4 @@
namespace UnityWebPortal\lib\exceptions;
-class SSOException extends \Exception
-{
-}
+class SSOException extends \Exception {}
diff --git a/resources/lib/utils.php b/resources/lib/utils.php
index c0ae48ab..42acfed9 100644
--- a/resources/lib/utils.php
+++ b/resources/lib/utils.php
@@ -15,8 +15,11 @@ function arrayGet($array, ...$keys)
if (!isset($cursor[$key])) {
throw new ArrayKeyException(
"key not found: \$array" .
- // [1, 2, "foo"] => [1][2]["foo"]
- implode("", array_map(fn($x) => jsonEncode([$x]), $keysTraversed))
+ // [1, 2, "foo"] => [1][2]["foo"]
+ implode(
+ "",
+ array_map(fn($x) => jsonEncode([$x]), $keysTraversed),
+ ),
);
}
$cursor = $cursor[$key];
@@ -67,9 +70,11 @@ function mbConvertEncoding($string, $to_encoding, $from_encoding = null)
$output = mb_convert_encoding($string, $to_encoding, $from_encoding);
if ($output === false) {
throw new EncodingConversionException(
- jsonEncode(
- ["to" => $to_encoding, "from" => $from_encoding, "base64" => base64_encode($string)]
- )
+ jsonEncode([
+ "to" => $to_encoding,
+ "from" => $from_encoding,
+ "base64" => base64_encode($string),
+ ]),
);
}
return $output;
diff --git a/resources/mail/account_deletion_request_admin.php b/resources/mail/account_deletion_request_admin.php
index c9170d93..6d8fde1a 100644
--- a/resources/mail/account_deletion_request_admin.php
+++ b/resources/mail/account_deletion_request_admin.php
@@ -1,8 +1,7 @@
Subject = "Account Deletion Request";
-?>
+$this->Subject = "Account Deletion Request"; ?>
You can view the SSH public keys attached to your account on the diff --git a/test/functional/AccountDeletionRequestTest.php b/test/functional/AccountDeletionRequestTest.php index e3530642..d8c4bb04 100644 --- a/test/functional/AccountDeletionRequestTest.php +++ b/test/functional/AccountDeletionRequestTest.php @@ -22,9 +22,9 @@ 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(); @@ -38,15 +38,13 @@ public function testRequestAccountDeletionUserHasNoGroups() $this->assertEmpty($USER->getPIGroupGIDs()); $this->assertNumberAccountDeletionRequests(0); try { - http_post( - __DIR__ . "/../../webroot/panel/account.php", - ["form_type" => "account_deletion_request"] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "account_deletion_request", + ]); $this->assertNumberAccountDeletionRequests(1); - http_post( - __DIR__ . "/../../webroot/panel/account.php", - ["form_type" => "account_deletion_request"] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "account_deletion_request", + ]); $this->assertNumberAccountDeletionRequests(1); } finally { $SQL->deleteAccountDeletionRequest($USER->uid); @@ -62,10 +60,9 @@ public function testRequestAccountDeletionUserHasGroup() $this->assertNotEmpty($USER->getPIGroupGIDs()); $this->assertNumberAccountDeletionRequests(0); try { - http_post( - __DIR__ . "/../../webroot/panel/account.php", - ["form_type" => "account_deletion_request"] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "account_deletion_request", + ]); $this->assertNumberAccountDeletionRequests(0); } finally { $SQL->deleteAccountDeletionRequest($USER->uid); diff --git a/test/functional/InvalidEPPNTest.php b/test/functional/InvalidEPPNTest.php index 239d9d91..40cc454d 100644 --- a/test/functional/InvalidEPPNTest.php +++ b/test/functional/InvalidEPPNTest.php @@ -8,12 +8,7 @@ class InvalidEPPNTest extends TestCase { public static function provider() { - return [ - ["", false], - ["a", false], - ["a@b", true], - ["a@b@c", false], - ]; + return [["", false], ["a", false], ["a@b", true], ["a@b@c", false]]; } #[DataProvider("provider")] diff --git a/test/functional/LoginShellSetTest.php b/test/functional/LoginShellSetTest.php index 90233248..a03cebfa 100644 --- a/test/functional/LoginShellSetTest.php +++ b/test/functional/LoginShellSetTest.php @@ -23,16 +23,17 @@ public function tearDown(): void public static function getShells() { global $HTTP_HEADER_TEST_INPUTS; - return [["/bin/bash"]] + array_map(function($x){return [$x];}, $HTTP_HEADER_TEST_INPUTS); + return [["/bin/bash"]] + + array_map(function ($x) { + return [$x]; + }, $HTTP_HEADER_TEST_INPUTS); } 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")] @@ -42,10 +43,10 @@ public function testSetLoginShell(string $shell): void if (!$this->isShellValid($shell)) { $this->expectException("Exception"); } - http_post( - __DIR__ . "/../../webroot/panel/account.php", - ["form_type" => "loginshell", "shellSelect" => $shell] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "loginshell", + "shellSelect" => $shell, + ]); $this->assertEquals($shell, $USER->getLoginShell()); } } diff --git a/test/functional/NewUserTest.php b/test/functional/NewUserTest.php index e9254ec1..dc6d8f7b 100644 --- a/test/functional/NewUserTest.php +++ b/test/functional/NewUserTest.php @@ -8,7 +8,8 @@ class NewUserTest extends TestCase { - public static function provider() { + public static function provider() + { return [ getNonExistentUserAndExpectedUIDGIDNoCustomMapping(), getNonExistentUserAndExpectedUIDGIDWithCustomMapping(), @@ -20,78 +21,68 @@ private function assertRequestedPIGroup(bool $expected) global $USER, $SQL; $this->assertEquals( $expected, - $SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI) + $SQL->requestExists($USER->uid, UnitySQL::REQUEST_BECOME_PI), ); } private function assertRequestedMembership(bool $expected, string $gid) { global $USER, $SQL; - $this->assertEquals( - $expected, - $SQL->requestExists($USER->uid, $gid) - ); + $this->assertEquals($expected, $SQL->requestExists($USER->uid, $gid)); } private function requestGroupCreation() { - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["new_user_sel" => "pi", "eula" => "agree", "confirm_pi" => "agree"] - ); + http_post(__DIR__ . "/../../webroot/panel/new_account.php", [ + "new_user_sel" => "pi", + "eula" => "agree", + "confirm_pi" => "agree", + ]); } private function requestGroupMembership(string $gid) { - http_post( - __DIR__ . "/../../webroot/panel/new_account.php", - ["new_user_sel" => "not_pi", "eula" => "agree", "pi" => $gid] - ); + http_post(__DIR__ . "/../../webroot/panel/new_account.php", [ + "new_user_sel" => "not_pi", + "eula" => "agree", + "pi" => $gid, + ]); } private function cancelAllRequests() { http_post( __DIR__ . "/../../webroot/panel/new_account.php", - ["cancel" => "true"] // value of cancel is arbitrary + ["cancel" => "true"], // value of cancel is arbitrary ); } private function approveUserByAdmin($gid, $uid) { - http_post( - __DIR__ . "/../../webroot/admin/pi-mgmt.php", - [ - "form_type" => "reqChild", - "action" => "Approve", - "pi" => $gid, - "uid" => $uid, - ] - ); + http_post(__DIR__ . "/../../webroot/admin/pi-mgmt.php", [ + "form_type" => "reqChild", + "action" => "Approve", + "pi" => $gid, + "uid" => $uid, + ]); } private function approveUserByPI($uid) { - http_post( - __DIR__ . "/../../webroot/panel/pi.php", - [ - "form_type" => "userReq", - "action" => "Approve", - "uid" => $uid, - ] - ); + http_post(__DIR__ . "/../../webroot/panel/pi.php", [ + "form_type" => "userReq", + "action" => "Approve", + "uid" => $uid, + ]); } private function approveGroup($uid) { - http_post( - __DIR__ . "/../../webroot/admin/pi-mgmt.php", - [ - "form_type" => "req", - "action" => "Approve", - "uid" => $uid, - ] - ); + http_post(__DIR__ . "/../../webroot/admin/pi-mgmt.php", [ + "form_type" => "req", + "action" => "Approve", + "uid" => $uid, + ]); } // delete requests made by that user @@ -124,10 +115,15 @@ private function ensureUserDoesNotExist() "memberuid", // array_diff will break the contiguity of the array indexes // ldap_mod_replace requires contiguity, array_values restores contiguity - array_values(array_diff($all_member_uids, [$USER->uid])) + 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); } @@ -165,8 +161,10 @@ 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); @@ -174,7 +172,14 @@ public function testCreateUserByJoinGoupByPI($user_to_create_args, $expected_uid $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)); @@ -214,8 +219,14 @@ public function testCreateUserByJoinGoupByPI($user_to_create_args, $expected_uid $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 { @@ -271,15 +282,24 @@ 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)); @@ -319,8 +339,14 @@ public function testCreateUserByJoinGoupByAdmin($user_to_create_args, $expected_ $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 { @@ -340,14 +366,23 @@ public function testCreateUserByJoinGoupByAdmin($user_to_create_args, $expected_ } #[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(); @@ -382,8 +417,14 @@ public function testCreateUserByCreateGroup($user_to_create_args, $expected_uid_ $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 7b31e01b..c1a7dec0 100644 --- a/test/functional/PIMemberRequestTest.php +++ b/test/functional/PIMemberRequestTest.php @@ -5,21 +5,20 @@ class PiMemberRequestTest extends TestCase { - private function requestMembership(string $gid) { - http_post( - __DIR__ . "/../../webroot/panel/groups.php", - ["form_type" => "addPIform", "pi" => $gid], - ); + http_post(__DIR__ . "/../../webroot/panel/groups.php", [ + "form_type" => "addPIform", + "pi" => $gid, + ]); } private function cancelRequest(string $gid) { - http_post( - __DIR__ . "/../../webroot/panel/groups.php", - ["form_type" => "cancelPIForm", "pi" => $gid], - ); + http_post(__DIR__ . "/../../webroot/panel/groups.php", [ + "form_type" => "cancelPIForm", + "pi" => $gid, + ]); } public function testRequestMembership() @@ -31,12 +30,16 @@ 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 71d531dd..1d812b08 100644 --- a/test/functional/PageLoadTest.php +++ b/test/functional/PageLoadTest.php @@ -16,7 +16,10 @@ 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 abd446a1..6a549a5b 100644 --- a/test/functional/PiBecomeRequestTest.php +++ b/test/functional/PiBecomeRequestTest.php @@ -23,9 +23,11 @@ private function getNumberPiBecomeRequests() global $USER, $SQL; // FIXME table name, "admin" are private constants in UnitySQL // FIXME "admin" should be something else - $stmt = $SQL->getConn()->prepare( - "SELECT * FROM requests WHERE uid=:uid and request_for='admin'" - ); + $stmt = $SQL + ->getConn() + ->prepare( + "SELECT * FROM requests WHERE uid=:uid and request_for='admin'", + ); $uid = $USER->uid; $stmt->bindParam(":uid", $uid); $stmt->execute(); @@ -39,25 +41,21 @@ public function testRequestBecomePi() $this->assertFalse($USER->isPI()); $this->assertNumberPiBecomeRequests(0); try { - http_post( - __DIR__ . "/../../webroot/panel/account.php", - ["form_type" => "pi_request"] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "pi_request", + ]); $this->assertNumberPiBecomeRequests(1); - http_post( - __DIR__ . "/../../webroot/panel/account.php", - ["form_type" => "cancel_pi_request"] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "cancel_pi_request", + ]); $this->assertNumberPiBecomeRequests(0); - http_post( - __DIR__ . "/../../webroot/panel/account.php", - ["form_type" => "pi_request"] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "pi_request", + ]); $this->assertNumberPiBecomeRequests(1); - http_post( - __DIR__ . "/../../webroot/panel/account.php", - ["form_type" => "pi_request"] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "pi_request", + ]); $this->assertNumberPiBecomeRequests(1); } finally { if ($SQL->requestExists($USER, UnitySQL::REQUEST_BECOME_PI)) { @@ -69,15 +67,16 @@ 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)); try { - http_post( - __DIR__ . "/../../webroot/panel/account.php", - ["form_type" => "pi_request"] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "pi_request", + ]); $this->assertNumberPiBecomeRequests(0); } finally { if ($SQL->requestExists($USER, UnitySQL::REQUEST_BECOME_PI)) { diff --git a/test/functional/PiMemberApproveTest.php b/test/functional/PiMemberApproveTest.php index 020675ef..f8b3d700 100644 --- a/test/functional/PiMemberApproveTest.php +++ b/test/functional/PiMemberApproveTest.php @@ -6,42 +6,41 @@ use UnityWebPortal\lib\UnityGroup; use UnityWebPortal\lib\UnitySSO; -class PiMemberApproveTest extends TestCase { - static $userWithRequestSwitchArgs; - static $userWithoutRequestSwitchArgs; - static $piSwitchArgs; - static $pi; - static $userWithRequestUID; - static $userWithoutRequestUID; - static $piUID; - static $userWithRequest; - static $userWithoutRequest; - static $piGroup; - static $piGroupGID; +class PiMemberApproveTest extends TestCase +{ + static $userWithRequestSwitchArgs; + static $userWithoutRequestSwitchArgs; + static $piSwitchArgs; + static $pi; + static $userWithRequestUID; + static $userWithoutRequestUID; + static $piUID; + static $userWithRequest; + static $userWithoutRequest; + static $piGroup; + static $piGroupGID; private function approveUser(string $uid) { - http_post( - __DIR__ . "/../../webroot/panel/pi.php", - ["form_type" => "userReq", "action" => "Approve", "uid" => $uid] - ); + http_post(__DIR__ . "/../../webroot/panel/pi.php", [ + "form_type" => "userReq", + "action" => "Approve", + "uid" => $uid, + ]); } private function requestJoinPI(string $gid) { - http_post( - __DIR__ . "/../../webroot/panel/groups.php", - ["form_type" => "addPIform", "pi" => $gid] - ); + http_post(__DIR__ . "/../../webroot/panel/groups.php", [ + "form_type" => "addPIform", + "pi" => $gid, + ]); } private function assertGroupMembers(UnityGroup $group, array $members) { $this->assertTrue( - arraysAreEqualUnOrdered( - $members, - $group->getGroupMemberUIDs() - ) + arraysAreEqualUnOrdered($members, $group->getGroupMemberUIDs()), ); } diff --git a/test/functional/PiMemberDenyTest.php b/test/functional/PiMemberDenyTest.php index 08b944d3..373bab5b 100644 --- a/test/functional/PiMemberDenyTest.php +++ b/test/functional/PiMemberDenyTest.php @@ -4,10 +4,12 @@ use PHPUnit\Framework\Attributes\DataProvider; use UnityWebPortal\lib\UnityUser; -class PiMemberDenyTest extends TestCase { +class PiMemberDenyTest extends TestCase +{ static $requestUid; - public static function setUpBeforeClass(): void{ + public static function setUpBeforeClass(): void + { global $USER; switchUser(...getNormalUser()); self::$requestUid = $USER->uid; @@ -15,10 +17,11 @@ public static function setUpBeforeClass(): void{ private function denyUser(string $uid) { - post( - __DIR__ . "/../../webroot/panel/pi.php", - ["form_type" => "userReq", "action" => "approve", "uid" => $uid] - ); + post(__DIR__ . "/../../webroot/panel/pi.php", [ + "form_type" => "userReq", + "action" => "approve", + "uid" => $uid, + ]); } public function testDenyRequest() @@ -29,13 +32,17 @@ public function testDenyRequest() $piGroup = $USER->getPIGroup(); $this->assertTrue($piGroup->exists()); $this->assertTrue( - arraysAreEqualUnOrdered( - [$pi->uid], - $piGroup->getGroupMemberUIDs() - ) + 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, @@ -51,8 +58,8 @@ public function testDenyRequest() $this->assertTrue( arraysAreEqualUnOrdered( [$pi->uid], - $piGroup->getGroupMemberUIDs() - ) + $piGroup->getGroupMemberUIDs(), + ), ); $this->assertFalse($piGroup->memberExists($requestedUser)); } finally { diff --git a/test/functional/PiRemoveUserTest.php b/test/functional/PiRemoveUserTest.php index dc4e7773..e6858bd5 100644 --- a/test/functional/PiRemoveUserTest.php +++ b/test/functional/PiRemoveUserTest.php @@ -4,13 +4,14 @@ use PHPUnit\Framework\Attributes\DataProvider; use UnityWebPortal\lib\UnityUser; -class PiRemoveUserTest extends TestCase { +class PiRemoveUserTest extends TestCase +{ private function removeUser(string $uid) { - http_post( - __DIR__ . "/../../webroot/panel/pi.php", - ["form_type" => "remUser", "uid" => $uid] - ); + http_post(__DIR__ . "/../../webroot/panel/pi.php", [ + "form_type" => "remUser", + "uid" => $uid, + ]); } public function testRemoveUser() @@ -29,7 +30,14 @@ 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; } @@ -78,6 +86,6 @@ public function testRemovePIFromTheirOwnGroup() ); $piGroup->approveUser($pi); } - } + } } } diff --git a/test/functional/SSHKeyAddTest.php b/test/functional/SSHKeyAddTest.php index bd4abebb..c330ae58 100644 --- a/test/functional/SSHKeyAddTest.php +++ b/test/functional/SSHKeyAddTest.php @@ -7,30 +7,29 @@ class SSHKeyAddTest extends TestCase { - private function addSshKeysPaste(array $keys): void { + private function addSshKeysPaste(array $keys): void + { foreach ($keys as $key) { - http_post( - __DIR__ . "/../../webroot/panel/account.php", - [ - "form_type" => "addKey", - "add_type" => "paste", - "key" => $key - ] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "addKey", + "add_type" => "paste", + "key" => $key, + ]); } } - private function addSshKeysImport(array $keys): void { + private function addSshKeysImport(array $keys): void + { foreach ($keys as $key) { $tmp = tmpfile(); $tmp_path = stream_get_meta_data($tmp)["uri"]; fwrite($tmp, $key); $_FILES["keyfile"] = ["tmp_name" => $tmp_path]; try { - http_post( - __DIR__ . "/../../webroot/panel/account.php", - ["form_type" => "addKey", "add_type" => "import"] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "addKey", + "add_type" => "import", + ]); $this->assertFalse(file_exists($tmp_path)); } finally { unset($_FILES["keyfile"]); @@ -38,46 +37,44 @@ private function addSshKeysImport(array $keys): void { } } - private function addSshKeysGenerate(array $keys): void { + private function addSshKeysGenerate(array $keys): void + { foreach ($keys as $key) { - http_post( - __DIR__ . "/../../webroot/panel/account.php", - [ - "form_type" => "addKey", - "add_type" => "generate", - "gen_key" => $key - ] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "addKey", + "add_type" => "generate", + "gen_key" => $key, + ]); } } - private function addSshKeysGithub(array $keys): void { + private function addSshKeysGithub(array $keys): void + { global $GITHUB; $oldGithub = $GITHUB; $GITHUB = $this->createMock(UnityGithub::class); $GITHUB->method("getSshPublicKeys")->willReturn($keys); try { - http_post( - __DIR__ . "/../../webroot/panel/account.php", - [ - "form_type" => "addKey", - "add_type" => "github", - "gh_user" => "foobar" - ] - ); + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "addKey", + "add_type" => "github", + "gh_user" => "foobar", + ]); } finally { $GITHUB = $oldGithub; } } - public static function provider() { - $validKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+XqO25MUB9x/pS04I3JQ7rMGboWyGXh0GUzkOrTi7a foobar"; + public static function provider() + { + $validKey = + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+XqO25MUB9x/pS04I3JQ7rMGboWyGXh0GUzkOrTi7a foobar"; $invalidKey = "foobar"; $methods = [ "addSshKeysPaste", "addSshKeysImport", "addSshKeysGenerate", - "addSshKeysGithub" + "addSshKeysGithub", ]; $output = []; foreach ($methods as $method) { @@ -99,8 +96,11 @@ 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,7 +109,10 @@ public function testAddSshKeys(string $methodName, int $expectedKeysAdded, array 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/functional/SSHKeyDeleteTest.php b/test/functional/SSHKeyDeleteTest.php index d924acd3..c4a3aaab 100644 --- a/test/functional/SSHKeyDeleteTest.php +++ b/test/functional/SSHKeyDeleteTest.php @@ -3,26 +3,31 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\DataProvider; -class SSHKeyDeleteTest extends TestCase { +class SSHKeyDeleteTest extends TestCase +{ static $initialKeys; - public static function setUpBeforeClass(): void{ + public static function setUpBeforeClass(): void + { global $USER; switchUser(...getUserWithOneKey()); self::$initialKeys = $USER->getSSHKeys(true); } - private function deleteKey(string $index): void { - http_post( - __DIR__ . "/../../webroot/panel/account.php", - ["form_type" => "delKey", "delIndex" => $index] - ); + private function deleteKey(string $index): void + { + http_post(__DIR__ . "/../../webroot/panel/account.php", [ + "form_type" => "delKey", + "delIndex" => $index, + ]); } public static function getGarbageIndexArgs() { global $HTTP_HEADER_TEST_INPUTS; - return array_map(function($x){return [$x];}, $HTTP_HEADER_TEST_INPUTS); + return array_map(function ($x) { + return [$x]; + }, $HTTP_HEADER_TEST_INPUTS); } #[DataProvider("getGarbageIndexArgs")] diff --git a/test/functional/ViewAsUserTest.php b/test/functional/ViewAsUserTest.php index 12d6e70a..a4195e0d 100644 --- a/test/functional/ViewAsUserTest.php +++ b/test/functional/ViewAsUserTest.php @@ -14,13 +14,10 @@ public function _testViewAsUser(array $beforeUser, array $afterUser) // $this->assertTrue($USER->isAdmin()); $beforeUid = $USER->uid; // $this->assertNotEquals($afterUid, $beforeUid); - http_post( - __DIR__ . "/../../webroot/admin/user-mgmt.php", - [ - "form_type" => "viewAsUser", - "uid" => $afterUid, - ], - ); + http_post(__DIR__ . "/../../webroot/admin/user-mgmt.php", [ + "form_type" => "viewAsUser", + "uid" => $afterUid, + ]); $this->assertArrayHasKey("viewUser", $_SESSION); // redirect means that php process dies and user's browser will initiate a new one // this makes `require_once autoload.php` run again and init.php changes $USER @@ -29,10 +26,9 @@ public function _testViewAsUser(array $beforeUser, array $afterUser) // now we should be new user $this->assertEquals($afterUid, $USER->uid); // $this->assertTrue($_SESSION["user_exists"]); - http_post( - __DIR__ . "/../../resources/templates/header.php", - ["form_type" => "clearView"], - ); + http_post(__DIR__ . "/../../resources/templates/header.php", [ + "form_type" => "clearView", + ]); $this->assertArrayNotHasKey("viewUser", $_SESSION); // redirect means that php process dies and user's browser will initiate a new one // this makes `require_once autoload.php` run again and init.php changes $USER @@ -64,13 +60,10 @@ public function testNonAdminViewAsAdmin() $adminUid = $USER->uid; $this->assertTrue($USER->isAdmin()); switchUser(...getNormalUser()); - http_post( - __DIR__ . "/../../webroot/admin/user-mgmt.php", - [ - "form_type" => "viewAsUser", - "uid" => $adminUid, - ], - ); + http_post(__DIR__ . "/../../webroot/admin/user-mgmt.php", [ + "form_type" => "viewAsUser", + "uid" => $adminUid, + ]); $this->assertArrayNotHasKey("viewUser", $_SESSION); } } diff --git a/test/phpunit-bootstrap.php b/test/phpunit-bootstrap.php index 34b370d9..34f81f53 100644 --- a/test/phpunit-bootstrap.php +++ b/test/phpunit-bootstrap.php @@ -1,7 +1,9 @@ This is a paragraph
', + "", + "a", + "Hello, World!", + " Some text ", + " ", + "12345", + "abc123", + "Hello@World!", + str_repeat("a", 8190), // https://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfieldsize + "This is a paragraph
", "'; DROP TABLE users; --", "", - 'こんにちは世界', + "こんにちは世界", "Hello 👋 World 🌍", "Line 1\nLine 2", "Column1\tColumn2", - 'MiXeD cAsE', - 'https://www.example.com', - 'user@example.com', + "MiXeD cAsE", + "https://www.example.com", + "user@example.com", '{"key": "value"}', - 'SGVsbG8sIFdvcmxkIQ==', + "SGVsbG8sIFdvcmxkIQ==", "Hello\x00World", - mbConvertEncoding("Hello, World!", "UTF-16") + mbConvertEncoding("Hello, World!", "UTF-16"), ]; function arraysAreEqualUnOrdered(array $a, array $b): bool { - return (array_diff($a, $b) == [] && array_diff($b, $a) == []); + return array_diff($a, $b) == [] && array_diff($b, $a) == []; } - function switchUser( string $eppn, string $given_name, string $sn, string $mail, - ?string $session_id = null + ?string $session_id = null, ): void { - global $REDIS, $LDAP, $SQL, $MAILER, $WEBHOOK, $GITHUB, $SITE, $SSO, $OPERATOR, $USER, $SEND_PIMESG_TO_ADMINS, $LOC_HEADER, $LOC_FOOTER; + global $REDIS, + $LDAP, + $SQL, + $MAILER, + $WEBHOOK, + $GITHUB, + $SITE, + $SSO, + $OPERATOR, + $USER, + $SEND_PIMESG_TO_ADMINS, + $LOC_HEADER, + $LOC_FOOTER; session_write_close(); if (is_null($session_id)) { session_id(str_replace(["_", "@", "."], "-", uniqid($eppn . "_"))); @@ -80,17 +95,29 @@ function switchUser( $_SERVER["eppn"] = $eppn; $_SERVER["givenName"] = $given_name; $_SERVER["sn"] = $sn; - include __DIR__ . "/../resources/autoload.php"; + include __DIR__ . "/../resources/autoload.php"; ensure(!is_null($USER)); } function http_post(string $phpfile, array $post_data): void { - global $REDIS, $LDAP, $SQL, $MAILER, $WEBHOOK, $GITHUB, $SITE, $SSO, $OPERATOR, $USER, $SEND_PIMESG_TO_ADMINS, $LOC_HEADER, $LOC_FOOTER; + global $REDIS, + $LDAP, + $SQL, + $MAILER, + $WEBHOOK, + $GITHUB, + $SITE, + $SSO, + $OPERATOR, + $USER, + $SEND_PIMESG_TO_ADMINS, + $LOC_HEADER, + $LOC_FOOTER; $_PREVIOUS_SERVER = $_SERVER; $_SERVER["REQUEST_METHOD"] = "POST"; $_SERVER["PHP_SELF"] = preg_replace("/.*webroot\//", "/", $phpfile); - $_SERVER["REQUEST_URI"] = preg_replace("/.*webroot\//", "/", $phpfile); // Slightly imprecise because it doesn't include get parameters + $_SERVER["REQUEST_URI"] = preg_replace("/.*webroot\//", "/", $phpfile); // Slightly imprecise because it doesn't include get parameters $_POST = $post_data; ob_start(); $post_did_redirect_or_die = false; @@ -107,13 +134,25 @@ function http_post(string $phpfile, array $post_data): void ensure($post_did_redirect_or_die, "post did not redirect or die!"); } -function http_get(string $phpfile, array $get_data = array()): void +function http_get(string $phpfile, array $get_data = []): void { - global $REDIS, $LDAP, $SQL, $MAILER, $WEBHOOK, $GITHUB, $SITE, $SSO, $OPERATOR, $USER, $SEND_PIMESG_TO_ADMINS, $LOC_HEADER, $LOC_FOOTER; + global $REDIS, + $LDAP, + $SQL, + $MAILER, + $WEBHOOK, + $GITHUB, + $SITE, + $SSO, + $OPERATOR, + $USER, + $SEND_PIMESG_TO_ADMINS, + $LOC_HEADER, + $LOC_FOOTER; $_PREVIOUS_SERVER = $_SERVER; $_SERVER["REQUEST_METHOD"] = "GET"; $_SERVER["PHP_SELF"] = preg_replace("/.*webroot\//", "/", $phpfile); - $_SERVER["REQUEST_URI"] = preg_replace("/.*webroot\//", "/", $phpfile); // Slightly imprecise because it doesn't include get parameters + $_SERVER["REQUEST_URI"] = preg_replace("/.*webroot\//", "/", $phpfile); // Slightly imprecise because it doesn't include get parameters $_GET = $get_data; ob_start(); try { @@ -192,13 +231,19 @@ function getNonExistentUserAndExpectedUIDGIDNoCustomMapping() { // defaults/config.ini.default: ldap.offset_UIDGID=1000000 // test/custom_user_mappings/test.csv has reservations for 1000000-1000004 - return [["user2002@org998.test", "foo", "bar", "user2002@org998.test"], 1000005]; + return [ + ["user2002@org998.test", "foo", "bar", "user2002@org998.test"], + 1000005, + ]; } function getNonExistentUserAndExpectedUIDGIDWithCustomMapping() { // test/custom_user_mappings/test.csv: {user2001: 555} - return [["user2001@org998.test", "foo", "bar", "user2001@org998.test"], 555]; + return [ + ["user2001@org998.test", "foo", "bar", "user2001@org998.test"], + 555, + ]; } function getMultipleValueAttributesAndExpectedSSO() @@ -214,7 +259,7 @@ function getMultipleValueAttributesAndExpectedSSO() "firstname" => "foo", "lastname" => "bar", "mail" => "user2003@org998.test", - ] + ], ]; } diff --git a/test/unit/AjaxSshValidateTest.php b/test/unit/AjaxSshValidateTest.php index 43a3e685..e22cb0b2 100644 --- a/test/unit/AjaxSshValidateTest.php +++ b/test/unit/AjaxSshValidateTest.php @@ -12,7 +12,10 @@ public static function providerTestSshValidate() // sanity check only, see UnityHTTPDTest for more comprehensive test cases return [ [false, "foobar"], - [true, "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+XqO25MUB9x/pS04I3JQ7rMGboWyGXh0GUzkOrTi7a"], + [ + true, + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB+XqO25MUB9x/pS04I3JQ7rMGboWyGXh0GUzkOrTi7a", + ], ]; } diff --git a/test/unit/UnityGithubTest.php b/test/unit/UnityGithubTest.php index cd62d4c8..57cd5f8f 100644 --- a/test/unit/UnityGithubTest.php +++ b/test/unit/UnityGithubTest.php @@ -17,7 +17,12 @@ public static function providerTestGetGithubKeys() # user with no keys ["sheldor1510", []], # user with 1 key - ["simonLeary42", ["ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLeHpW10CCamJtXNXJui49WM07wRnQbQTbQ2MSvF4j8vBpBuAbjiEp14qERLDs3FoWdpbiUwL9mZq6PmUSxaTnk="]] + [ + "simonLeary42", + [ + "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLeHpW10CCamJtXNXJui49WM07wRnQbQTbQ2MSvF4j8vBpBuAbjiEp14qERLDs3FoWdpbiUwL9mZq6PmUSxaTnk=", + ], + ], ]; } diff --git a/test/unit/UnitySSOTest.php b/test/unit/UnitySSOTest.php index 12469626..bb4ae3aa 100644 --- a/test/unit/UnitySSOTest.php +++ b/test/unit/UnitySSOTest.php @@ -65,10 +65,9 @@ public function testFallbackAttribute() $this->assertEquals("foobar@baz", $sso["mail"]); } - public static function validEppnProvider() { - return [ - ["foo@bar.edu", "foo_bar_edu", "bar_edu"], - ]; + public static function validEppnProvider() + { + return [["foo@bar.edu", "foo_bar_edu", "bar_edu"]]; } #[DataProvider("validEppnProvider")] @@ -103,11 +102,12 @@ public function testEppnToOrg(string $eppn, string $_, string $expectedOrg) } } - public static function invalidEppnProvider() { + public static function invalidEppnProvider() + { return [ ["foo"], // missing @ ["foo@bar@baz"], // too many @ - [""] + [""], ]; } diff --git a/test/unit/UtilsTest.php b/test/unit/UtilsTest.php index 6f16a651..f024e0ef 100644 --- a/test/unit/UtilsTest.php +++ b/test/unit/UtilsTest.php @@ -11,9 +11,9 @@ public function testArrayGetReturnsValueWhenKeyExists() $array = [ "a" => [ "b" => [ - "c" => 123 - ] - ] + "c" => 123, + ], + ], ]; $result = \arrayGet($array, "a", "b", "c"); $this->assertSame(123, $result); @@ -23,8 +23,8 @@ public function testArrayGetReturnsArrayWhenTraversingPartially() { $array = [ "foo" => [ - "bar" => "baz" - ] + "bar" => "baz", + ], ]; $result = \arrayGet($array, "foo"); $this->assertSame(["bar" => "baz"], $result); @@ -120,10 +120,14 @@ public static function SSHKeyProvider() "gG7Fy2a+VWwcB6w0nzyxbqg16AP+luuqHxfVsvP6Uyde4C7LPeB3r3GhAfuU", "Nxnpz/bXGxbJu3+aCnbtaZMzGJ6UFBeJp8MtlmVajDnjx3oEuOGGmobTlaop", "HYVsQ3ySfQ==", - ]) + ]), ]; - $validKeysArgs = array_map(function($x){return [true, $x];}, $validKeys); - $invalidKeysArgs = array_map(function($x){return [false, $x];}, $HTTP_HEADER_TEST_INPUTS); + $validKeysArgs = array_map(function ($x) { + return [true, $x]; + }, $validKeys); + $invalidKeysArgs = array_map(function ($x) { + return [false, $x]; + }, $HTTP_HEADER_TEST_INPUTS); return $validKeysArgs + $invalidKeysArgs; } diff --git a/tools/docker-dev/docker-compose.yml b/tools/docker-dev/docker-compose.yml index 7d0d426e..3a712dc6 100644 --- a/tools/docker-dev/docker-compose.yml +++ b/tools/docker-dev/docker-compose.yml @@ -9,7 +9,11 @@ services: - "8010:80" - "389:389" healthcheck: - test: ["CMD-SHELL", "if [ -f /tmp/up ]; then (nc -z localhost 389 && touch /tmp/up); else true; fi"] + test: + [ + "CMD-SHELL", + "if [ -f /tmp/up ]; then (nc -z localhost 389 && touch /tmp/up); else true; fi", + ] interval: 1s sql: hostname: sql @@ -18,7 +22,11 @@ services: - "8020:80" - "3306:3306" healthcheck: - test: ["CMD-SHELL", "if [ -f /tmp/up ]; then (nc -z localhost 3306 && touch /tmp/up); else true; fi"] + test: + [ + "CMD-SHELL", + "if [ -f /tmp/up ]; then (nc -z localhost 3306 && touch /tmp/up); else true; fi", + ] interval: 1s smtp: hostname: smtp @@ -31,7 +39,11 @@ services: ports: - "6379:6379" healthcheck: - test: ["CMD-SHELL", "if [ -f /tmp/up ]; then (nc -z localhost 6379 && touch /tmp/up); else true; fi"] + test: + [ + "CMD-SHELL", + "if [ -f /tmp/up ]; then (nc -z localhost 6379 && touch /tmp/up); else true; fi", + ] interval: 1s web: hostname: web diff --git a/tools/docker-dev/identity/phpldapadmin-config.php b/tools/docker-dev/identity/phpldapadmin-config.php index 3bd9ef93..b4253ae0 100644 --- a/tools/docker-dev/identity/phpldapadmin-config.php +++ b/tools/docker-dev/identity/phpldapadmin-config.php @@ -1,15 +1,18 @@ custom->appearance['timezone'] = 'America/New_York'; -$config->custom->appearance['hide_template_warning'] = true; -$config->custom->appearance['friendly_attrs'] = array(); +$config->custom->appearance["timezone"] = "America/New_York"; +$config->custom->appearance["hide_template_warning"] = true; +$config->custom->appearance["friendly_attrs"] = []; $servers = new Datastore(); -$servers->newServer('ldap_pla'); -$servers->setValue('server', 'name', 'unity-web-portal-dev'); -$servers->setValue('server', 'host', 'identity'); -$servers->setValue('login', 'auth_type', 'config'); -$servers->setValue('login', 'bind_id', 'cn=admin,dc=unityhpc,dc=test'); -$servers->setValue('login', 'bind_pass', 'password'); -$servers->setValue('server', 'base', array('dc=unityhpc,dc=test')); -$servers->setValue('auto_number', 'min', array('uidNumber' => 30000,'gidNumber' => 30000)); +$servers->newServer("ldap_pla"); +$servers->setValue("server", "name", "unity-web-portal-dev"); +$servers->setValue("server", "host", "identity"); +$servers->setValue("login", "auth_type", "config"); +$servers->setValue("login", "bind_id", "cn=admin,dc=unityhpc,dc=test"); +$servers->setValue("login", "bind_pass", "password"); +$servers->setValue("server", "base", ["dc=unityhpc,dc=test"]); +$servers->setValue("auto_number", "min", [ + "uidNumber" => 30000, + "gidNumber" => 30000, +]); diff --git a/tools/docker-dev/sql/phpmyadmin-config.php b/tools/docker-dev/sql/phpmyadmin-config.php index 24716bf1..7814b5f8 100644 --- a/tools/docker-dev/sql/phpmyadmin-config.php +++ b/tools/docker-dev/sql/phpmyadmin-config.php @@ -1,15 +1,15 @@ * { - display: block; +form > * { + display: block; } -form>*:not(:first-child) { - margin-top: 5px; +form > *:not(:first-child) { + margin-top: 5px; } input:focus, textarea:focus, select:focus { - outline: var(--accent) solid 2px; + outline: var(--accent) solid 2px; } button:focus, -input[type=submit]:focus { - outline: none; +input[type="submit"]:focus { + outline: none; } -input[type=text], -input[type=password], -input[type=date] { - margin: 10px 0 10px 0; - border: 1px solid var(--light_borders); - padding: 5px; - width: calc(100% - 12px); - /* Factors in extra border and padding */ - max-width: 300px; - border-radius: 5px; +input[type="text"], +input[type="password"], +input[type="date"] { + margin: 10px 0 10px 0; + border: 1px solid var(--light_borders); + padding: 5px; + width: calc(100% - 12px); + /* Factors in extra border and padding */ + max-width: 300px; + border-radius: 5px; } -input[type=submit], +input[type="submit"], button { - background: var(--accent); - color: var(--accent_foreground); - cursor: pointer; - border: 0; - padding: 8px 12px 8px 12px; - border-radius: 5px; - transition: background 0.1s; - display: inline-block; + background: var(--accent); + color: var(--accent_foreground); + cursor: pointer; + border: 0; + padding: 8px 12px 8px 12px; + border-radius: 5px; + transition: background 0.1s; + display: inline-block; } -input[type=submit]:hover, +input[type="submit"]:hover, button:hover { - background: var(--accent_2); + background: var(--accent_2); } -input[type=submit]:disabled, +input[type="submit"]:disabled, button:disabled { - background: var(--accent_disabled); - cursor: default; + background: var(--accent_disabled); + cursor: default; } -input[type=checkbox], -input[type=radio] { - display: inline-block; +input[type="checkbox"], +input[type="radio"] { + display: inline-block; } label { - display: inline; - user-select: none; - font-size: 10pt; - color: var(--color-background-text-inactive); - overflow: hidden; + display: inline; + user-select: none; + font-size: 10pt; + color: var(--color-background-text-inactive); + overflow: hidden; } -input[type=radio] { - margin-bottom: 0; +input[type="radio"] { + margin-bottom: 0; } select { - border: 1px solid var(--light_borders); - background: white; - padding: 5px 10px 5px 20px; - max-width: 300px; - border-radius: 5px; + border: 1px solid var(--light_borders); + background: white; + padding: 5px 10px 5px 20px; + max-width: 300px; + border-radius: 5px; } textarea { - border: 1px solid var(--light_borders); - width: calc(100% - 12px); - min-height: 150px; - display: block; - margin: 10px 0 10px 0; - resize: vertical; - font-family: Arial, Helvetica, sans-serif; - font-size: 10pt; - border-radius: 5px; - padding: 5px; + border: 1px solid var(--light_borders); + width: calc(100% - 12px); + min-height: 150px; + display: block; + margin: 10px 0 10px 0; + resize: vertical; + font-family: Arial, Helvetica, sans-serif; + font-size: 10pt; + border-radius: 5px; + padding: 5px; } div.inline * { - display: inline; - margin-right: 10px; + display: inline; + margin-right: 10px; } /* @@ -224,122 +224,122 @@ div.inline * { /* WRAPPERS */ main { - flex: 1 0 auto; - padding: 15px 20px 20px 20px; - max-width: 1000px; - line-height: 24px; + flex: 1 0 auto; + padding: 15px 20px 20px 20px; + max-width: 1000px; + line-height: 24px; } /* FOOTER */ footer { - background: var(--light_footer_background); - flex-shrink: 0; - text-align: center; - font-size: 8pt; - color: var(--light_footer_foreground); - padding-bottom: 10px; + background: var(--light_footer_background); + flex-shrink: 0; + text-align: center; + font-size: 8pt; + color: var(--light_footer_foreground); + padding-bottom: 10px; } -footer>* { - display: table; - margin: 10px auto 0 auto; +footer > * { + display: table; + margin: 10px auto 0 auto; } footer #footerLogos img { - padding: 0 10px 0 10px; - max-width: 120px; - max-height: 90px; - margin-bottom: 10px; - vertical-align: middle; + padding: 0 10px 0 10px; + max-width: 120px; + max-height: 90px; + margin-bottom: 10px; + vertical-align: middle; } @media only screen and (min-width: 501px) { - footer #footerLogos>* { - display: inline-block; - } + footer #footerLogos > * { + display: inline-block; + } } @media only screen and (max-width: 500px) { - footer #footerLogos>* { - display: block; - } + footer #footerLogos > * { + display: block; + } } /* notices */ div.notice { - background: var(--light_panel_background); - border-radius: 10px; - margin: 20px 0 20px 0; - padding-bottom: 5px; + background: var(--light_panel_background); + border-radius: 10px; + margin: 20px 0 20px 0; + padding-bottom: 5px; } -div.notice>span.noticeTitle { - display: block; - background: var(--accent); - color: var(--accent_foreground); - border-radius: 8px 8px 0 0; - padding: 10px 10px 0 10px; - font-size: 14pt; - font-weight: bold; +div.notice > span.noticeTitle { + display: block; + background: var(--accent); + color: var(--accent_foreground); + border-radius: 8px 8px 0 0; + padding: 10px 10px 0 10px; + font-size: 14pt; + font-weight: bold; } -div.notice>span.noticeDate { - display: block; - background: var(--accent); - color: var(--accent_foreground); - padding: 0 10px 10px 10px; +div.notice > span.noticeDate { + display: block; + background: var(--accent); + color: var(--accent_foreground); + padding: 0 10px 10px 10px; } -div.notice>p { - margin: 10px 15px 10px 15px; - padding: 0; +div.notice > p { + margin: 10px 15px 10px 15px; + padding: 0; } -div.notice>div.noticeText { - padding: 0 10px 0 10px; +div.notice > div.noticeText { + padding: 0 10px 0 10px; } -div.notice>button { - margin: 0 0 5px 10px; +div.notice > button { + margin: 0 0 5px 10px; } #viewAsBar { - background: orange; - padding: 10px; - border-radius: 10px; - margin-bottom: 20px; + background: orange; + padding: 10px; + border-radius: 10px; + margin-bottom: 20px; } -#viewAsBar>* { - display: inline-block; +#viewAsBar > * { + display: inline-block; } -#viewAsBar input[type=submit] { - margin: 0 0 0 20px; +#viewAsBar input[type="submit"] { + margin: 0 0 0 20px; } /* Search Box CSS */ div.searchWrapper { - background: var(--light_background); - position: absolute; - top: 50px; - z-index: 200; - overflow: hidden; - font-size: 11pt; - user-select: none; - width: 100%; - margin-left: -2px; - border: 1px solid var(--light_borders); - border-radius: 5px; -} - -div.searchWrapper>* { - display: block; - cursor: pointer; - padding: 4px 10px 4px 10px; -} - -div.searchWrapper>*:hover { - background: var(--light_panel_background); + background: var(--light_background); + position: absolute; + top: 50px; + z-index: 200; + overflow: hidden; + font-size: 11pt; + user-select: none; + width: 100%; + margin-left: -2px; + border: 1px solid var(--light_borders); + border-radius: 5px; +} + +div.searchWrapper > * { + display: block; + cursor: pointer; + padding: 4px 10px 4px 10px; +} + +div.searchWrapper > *:hover { + background: var(--light_panel_background); } diff --git a/webroot/css/modal.css b/webroot/css/modal.css index 7252e62b..af0aa313 100644 --- a/webroot/css/modal.css +++ b/webroot/css/modal.css @@ -1,67 +1,66 @@ div.modalWrapper { - position: fixed; - top: 0; - bottom: 0; - left: 0; - right: 0; - background: rgba(0, 0, 0, 0.6); - z-index: 100; + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + background: rgba(0, 0, 0, 0.6); + z-index: 100; } div.modalContent { - position: absolute; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - background: var(--light_background); - padding: 15px; - width: calc(100% - 30px); - box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.4); - border-radius: 5px; - max-width: 600px; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + background: var(--light_background); + padding: 15px; + width: calc(100% - 30px); + box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.4); + border-radius: 5px; + max-width: 600px; } div.modalTitleWrapper { - overflow: hidden; - display: inline-block; + overflow: hidden; + display: inline-block; } span.modalTitle { - font-size: 13pt; + font-size: 13pt; } div.modalMessages { - color: var(--color-text-failure); - font-size: 11pt; + color: var(--color-text-failure); + font-size: 11pt; } -div.modalMessages>* { - margin-top: 7px; - display: block; +div.modalMessages > * { + margin-top: 7px; + display: block; } -div.modalBody>* { - margin: 0; +div.modalBody > * { + margin: 0; } .btnClose { - width: 30px; - height: 30px; - padding: 0; - text-align: center; - font-size: 20pt; + width: 30px; + height: 30px; + padding: 0; + text-align: center; + font-size: 20pt; } - .btnClose::before { - content: "\00d7"; + content: "\00d7"; } .buttonList { - margin-top: 10px; + margin-top: 10px; } -.buttonList>* { - display: inline-block; - margin-right: 10px; +.buttonList > * { + display: inline-block; + margin-right: 10px; } diff --git a/webroot/css/navbar.css b/webroot/css/navbar.css index 5f3e919a..42b73456 100644 --- a/webroot/css/navbar.css +++ b/webroot/css/navbar.css @@ -1,120 +1,120 @@ /* Navbar */ hr.navHR { - margin-left: 10px; - margin-right: 10px; + margin-left: 10px; + margin-right: 10px; } nav.mainNav { - background: var(--accent); - position: fixed; - left: 0; - top: 45px; - font-size: 11pt; - overflow: hidden; - white-space: nowrap; - z-index: 100; + background: var(--accent); + position: fixed; + left: 0; + top: 45px; + font-size: 11pt; + overflow: hidden; + white-space: nowrap; + z-index: 100; } nav.mainNav a { - color: var(--accent_foreground); - background: var(--accent_1); - border-radius: 10px; - display: block; - margin: 10px 8px 10px 8px; - padding: 8px; - text-decoration: none; - cursor: pointer; - transition: background 0.1s; + color: var(--accent_foreground); + background: var(--accent_1); + border-radius: 10px; + display: block; + margin: 10px 8px 10px 8px; + padding: 8px; + text-decoration: none; + cursor: pointer; + transition: background 0.1s; } nav.mainNav a:hover { - text-decoration: none; - background: var(--accent_2); + text-decoration: none; + background: var(--accent_2); } nav.mainNav a.active { - background: var(--accent_2); + background: var(--accent_2); } header { - background: var(--accent); - height: 50px; - width: 250px; - position: fixed; - top: 0; - left: 0; + background: var(--accent); + height: 50px; + width: 250px; + position: fixed; + top: 0; + left: 0; } -header>#imgLogo { - height: 65%; - margin-left: 10px; - margin-top: 8px; +header > #imgLogo { + height: 65%; + margin-left: 10px; + margin-top: 8px; } -header>a.unity-state { - background: var(--accent_foreground); - color: var(--accent); - display: block; - position: absolute; - top: 8px; - left: 140px; - padding: 1px 5px 1px 5px; - font-weight: bold; - font-size: 10pt; - border-radius: 5px; +header > a.unity-state { + background: var(--accent_foreground); + color: var(--accent); + display: block; + position: absolute; + top: 8px; + left: 140px; + padding: 1px 5px 1px 5px; + font-weight: bold; + font-size: 10pt; + border-radius: 5px; } -header>a.unity-state:hover { - text-decoration: none; +header > a.unity-state:hover { + text-decoration: none; } -header>button.hamburger { - background: var(--accent); - padding: 0; - right: 23px; - height: 60%; +header > button.hamburger { + background: var(--accent); + padding: 0; + right: 23px; + height: 60%; } -header>button.hamburger>img { - position: relative; - height: 100%; +header > button.hamburger > img { + position: relative; + height: 100%; } /* MOBILE VIEW */ @media only screen and (max-width: 1000px) { - nav.mainNav { - right: 0; - } - - header { - width: 100%; - } - - main { - /* Header element height + 2*element padding */ - margin-top: 45px; - } + nav.mainNav { + right: 0; + } + + header { + width: 100%; + } + + main { + /* Header element height + 2*element padding */ + margin-top: 45px; + } } /* DESKTOP VIEW */ @media only screen and (min-width: 1001px) { - nav.mainNav { - bottom: 0; - width: 250px; - } - - header>button.hamburger { - display: none; - } - - main { - margin-left: 250px; - } - - footer { - margin-left: 250px; - } + nav.mainNav { + bottom: 0; + width: 250px; + } + + header > button.hamburger { + display: none; + } + + main { + margin-left: 250px; + } + + footer { + margin-left: 250px; + } } diff --git a/webroot/css/tables.css b/webroot/css/tables.css index 132c1f5e..d867ae48 100644 --- a/webroot/css/tables.css +++ b/webroot/css/tables.css @@ -1,142 +1,142 @@ table { - border-collapse: collapse; - margin-bottom: 10px; - table-layout: fixed; - word-wrap: break-word; - max-width: 100%; + border-collapse: collapse; + margin-bottom: 10px; + table-layout: fixed; + word-wrap: break-word; + max-width: 100%; } table.longTable { - width: 100%; + width: 100%; } table.longTable tr:not(:last-child) { - border-bottom: 1px solid var(--light_borders); + border-bottom: 1px solid var(--light_borders); } table tr, table td { - padding: 0 20px 0 4px; - overflow: hidden; - white-space: nowrap; + padding: 0 20px 0 4px; + overflow: hidden; + white-space: nowrap; } table button, -table input[type=submit] { - padding: 5px 10px 5px 10px; +table input[type="submit"] { + padding: 5px 10px 5px 10px; } table form { - display: inline-block; + display: inline-block; } table form:not(:first-child) { - margin-left: 10px; + margin-left: 10px; } -table form>* { - margin: 0; +table form > * { + margin: 0; } tr.expanded { - border: 0; + border: 0; } -tr.expanded>td { - background: var(--light_panel_background); +tr.expanded > td { + background: var(--light_panel_background); } tr.expandable { - cursor: pointer; + cursor: pointer; } tr.expandable:hover { - background: var(--light_footer_background); + background: var(--light_footer_background); } -tr.expandable:hover>td:first-child { - border-top-left-radius: 10px; - border-bottom-left-radius: 10px; +tr.expandable:hover > td:first-child { + border-top-left-radius: 10px; + border-bottom-left-radius: 10px; } -tr.expandable:hover>td:last-child { - border-top-right-radius: 10px; - border-bottom-right-radius: 10px; +tr.expandable:hover > td:last-child { + border-top-right-radius: 10px; + border-bottom-right-radius: 10px; } -tr.expandable.first>td:first-child { - border-bottom-left-radius: 0; +tr.expandable.first > td:first-child { + border-bottom-left-radius: 0; } -tr.expandable.first>td:last-child { - border-bottom-right-radius: 0; +tr.expandable.first > td:last-child { + border-bottom-right-radius: 0; } tr.expanded.first { - border-bottom: 2px solid var(--light_borders); + border-bottom: 2px solid var(--light_borders); } -tr.expanded.first>td:first-child { - border-top-left-radius: 10px; +tr.expanded.first > td:first-child { + border-top-left-radius: 10px; } -tr.expanded.first>td:last-child { - border-top-right-radius: 10px; +tr.expanded.first > td:last-child { + border-top-right-radius: 10px; } -tr.expanded.last>td:first-child { - border-bottom-left-radius: 10px; +tr.expanded.last > td:first-child { + border-bottom-left-radius: 10px; } -tr.expanded.last>td:last-child { - border-bottom-right-radius: 10px; +tr.expanded.last > td:last-child { + border-bottom-right-radius: 10px; } tr.expanded:not(.expandable) { - padding-top: 0; - padding-bottom: 0; + padding-top: 0; + padding-bottom: 0; } -tr.expanded:not(.expandable)>td:first-child { - padding-left: 30px; +tr.expanded:not(.expandable) > td:first-child { + padding-left: 30px; } button.btnExpanded { - transform: rotate(90deg); + transform: rotate(90deg); } /* Buttons */ button.btnExpand { - margin: 0 10px 0 0; - padding: 0; - background: transparent; - color: var(--accent); + margin: 0 10px 0 0; + padding: 0; + background: transparent; + color: var(--accent); } button.btnExpand:hover { - background: transparent; + background: transparent; } button.btnExpanded { - transform: rotate(90deg); + transform: rotate(90deg); } -td:last-child>button { - float: right; +td:last-child > button { + float: right; } tr.key { - background: var(--light_panel_background); - text-align: center; - font-weight: bold; + background: var(--light_panel_background); + text-align: center; + font-weight: bold; } -tr.key>td:first-child { - border-top-left-radius: 10px; - border-bottom-left-radius: 10px; +tr.key > td:first-child { + border-top-left-radius: 10px; + border-bottom-left-radius: 10px; } -tr.key>td:last-child { - border-top-right-radius: 10px; - border-bottom-right-radius: 10px; +tr.key > td:last-child { + border-top-right-radius: 10px; + border-bottom-right-radius: 10px; } diff --git a/webroot/js/filter.js b/webroot/js/filter.js index af8d85a7..7e2bfa14 100644 --- a/webroot/js/filter.js +++ b/webroot/js/filter.js @@ -1,90 +1,102 @@ function getQueryVariable(variable) { - var query = window.location.search.substring(1); - var vars = query.split("&"); - for (var i = 0; i < vars.length; i++) { - var pair = vars[i].split("="); + var query = window.location.search.substring(1); + var vars = query.split("&"); + for (var i = 0; i < vars.length; i++) { + var pair = vars[i].split("="); - if (pair[0] == variable) { - return pair[1]; - } + if (pair[0] == variable) { + return pair[1]; } - return false; + } + return false; } function updateQueryStringParameter(uri, key, value) { - let currentURL = new URL(window.location.href); - let params = currentURL.searchParams; - if (params.has(key)) { - params.delete(key); - } - params.append(key, value); - window.history.pushState("object or string", "Title", currentURL.href); + let currentURL = new URL(window.location.href); + let params = currentURL.searchParams; + if (params.has(key)) { + params.delete(key); + } + params.append(key, value); + window.history.pushState("object or string", "Title", currentURL.href); } function updateFilterInput() { - const commonFilterInputBox = document.querySelector(".filterSearch"); - commonFilterInputBox.style.display = "none"; - commonFilterInputBox.style.visibility = "hidden"; - commonFilterInputBox.value = ""; - - var filter = getQueryVariable("filter"); - if (filter) { - commonFilterInputBox.style.display = "inline-block"; - commonFilterInputBox.style.visibility = "visible"; + const commonFilterInputBox = document.querySelector(".filterSearch"); + commonFilterInputBox.style.display = "none"; + commonFilterInputBox.style.visibility = "hidden"; + commonFilterInputBox.value = ""; - if (filter == "uid") { - commonFilterInputBox.placeholder = "Filter by " + filter.toUpperCase() + '...'; - } else { - commonFilterInputBox.placeholder = "Filter by " + filter.charAt(0).toUpperCase() + filter.slice(1) + '...'; - } + var filter = getQueryVariable("filter"); + if (filter) { + commonFilterInputBox.style.display = "inline-block"; + commonFilterInputBox.style.visibility = "visible"; - if (getQueryVariable("value") != false) { - commonFilterInputBox.value = getQueryVariable("value"); - filterRows(); - } + if (filter == "uid") { + commonFilterInputBox.placeholder = + "Filter by " + filter.toUpperCase() + "..."; + } else { + commonFilterInputBox.placeholder = + "Filter by " + filter.charAt(0).toUpperCase() + filter.slice(1) + "..."; + } - commonFilterInputBox.addEventListener("keyup", function(e) { - updateQueryStringParameter(window.location.href, "value", e.target.value); - filterRows(); - }); + if (getQueryVariable("value") != false) { + commonFilterInputBox.value = getQueryVariable("value"); + filterRows(); } + + commonFilterInputBox.addEventListener("keyup", function (e) { + updateQueryStringParameter(window.location.href, "value", e.target.value); + filterRows(); + }); + } } updateFilterInput(); var filters = document.querySelectorAll("span.filter"); -filters.forEach(function(filter) { - filter.addEventListener("click", function(e) { - e.preventDefault(); - e.stopPropagation(); - if (e.target.parentElement.id != getQueryVariable("filter")) { - updateQueryStringParameter(window.location.href, "filter", e.target.parentElement.id); - updateQueryStringParameter(window.location.href, "value", ""); - filterRows(); - } else { - updateQueryStringParameter(window.location.href, "filter", ""); - updateQueryStringParameter(window.location.href, "value", ""); - filterRows(); - } - updateFilterInput(); - }); +filters.forEach(function (filter) { + filter.addEventListener("click", function (e) { + e.preventDefault(); + e.stopPropagation(); + if (e.target.parentElement.id != getQueryVariable("filter")) { + updateQueryStringParameter( + window.location.href, + "filter", + e.target.parentElement.id, + ); + updateQueryStringParameter(window.location.href, "value", ""); + filterRows(); + } else { + updateQueryStringParameter(window.location.href, "filter", ""); + updateQueryStringParameter(window.location.href, "value", ""); + filterRows(); + } + updateFilterInput(); + }); }); function filterRows() { - var filter = getQueryVariable("filter"); - var filterValue = getQueryVariable("value"); + var filter = getQueryVariable("filter"); + var filterValue = getQueryVariable("value"); - if (filter) { - var table = document.querySelector("table.filterable"); - var rows = Array.from(table.querySelectorAll("tr:nth-child(n+2)")); - var column = table.querySelector("tr.key").querySelector("td#" + filter).cellIndex; - rows.forEach(function(row) { - if (row.cells[column].textContent.trim().toLowerCase().indexOf(filterValue.toLowerCase()) == -1) { - row.style.display = "none"; - } else { - row.style.display = ""; - } - } - ); - } + if (filter) { + var table = document.querySelector("table.filterable"); + var rows = Array.from(table.querySelectorAll("tr:nth-child(n+2)")); + var column = table + .querySelector("tr.key") + .querySelector("td#" + filter).cellIndex; + rows.forEach(function (row) { + if ( + row.cells[column].textContent + .trim() + .toLowerCase() + .indexOf(filterValue.toLowerCase()) == -1 + ) { + row.style.display = "none"; + } else { + row.style.display = ""; + } + }); + } } diff --git a/webroot/js/global.js b/webroot/js/global.js index cfaade95..933bd194 100644 --- a/webroot/js/global.js +++ b/webroot/js/global.js @@ -3,9 +3,9 @@ $(window).resize(setNav); function setNav() { if ($("button.hamburger").is(":visible")) { - $("nav.mainNav").hide(); // Mobile View + $("nav.mainNav").hide(); // Mobile View } else { - $("nav.mainNav").show(); // Desktop View + $("nav.mainNav").show(); // Desktop View } } @@ -19,36 +19,39 @@ $("button.hamburger").on("click", function () { }); $(window).click(function (e) { - if (!$(e.target).parent().hasClass("hamburger") && $("button.hamburger").is(":visible")) { + if ( + !$(e.target).parent().hasClass("hamburger") && + $("button.hamburger").is(":visible") + ) { $("nav.mainNav").fadeOut(100); } }); // Functions to set nav links as active. Sub links can activate parents by naming files with same prefix, for example: documentation.php and documentation_view.php activate the same link var url = location.pathname; -if (url.lastIndexOf('.') >= 0) { - url = url.substring(0, url.lastIndexOf('.')); +if (url.lastIndexOf(".") >= 0) { + url = url.substring(0, url.lastIndexOf(".")); } -if (url.lastIndexOf('/') >= 0) { - url = url.substring(url.lastIndexOf('/') + 1); +if (url.lastIndexOf("/") >= 0) { + url = url.substring(url.lastIndexOf("/") + 1); } -$('nav.mainNav a').each(function () { +$("nav.mainNav a").each(function () { var href = $(this).attr("href"); - if (href.lastIndexOf('.') >= 0) { - href = href.substring(0, href.lastIndexOf('.')); + if (href.lastIndexOf(".") >= 0) { + href = href.substring(0, href.lastIndexOf(".")); } - if (href.lastIndexOf('/') >= 0) { - href = href.substring(href.lastIndexOf('/') + 1); + if (href.lastIndexOf("/") >= 0) { + href = href.substring(href.lastIndexOf("/") + 1); } if (url.indexOf(href) == 0) { $(this).addClass("active"); } -}) +}); /** * btnDropdown Click Events @@ -64,9 +67,12 @@ $(window).click(function (e) { }); function downloadFile(text, filename) { - var element = document.createElement('a'); - element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); - element.setAttribute('download', filename); + var element = document.createElement("a"); + element.setAttribute( + "href", + "data:text/plain;charset=utf-8," + encodeURIComponent(text), + ); + element.setAttribute("download", filename); element.style.display = "none"; $("body").append(element); diff --git a/webroot/js/modal.js b/webroot/js/modal.js index 8cd681ff..d7c28b3d 100644 --- a/webroot/js/modal.js +++ b/webroot/js/modal.js @@ -1,17 +1,18 @@ function openModal(title, link, message = "") { - $("span.modalTitle").html(title); - $("div.modalMessages").html(message); - $.ajax({ - url: link, success: function (result) { - $("div.modalBody").html(result); - } - }); + $("span.modalTitle").html(title); + $("div.modalMessages").html(message); + $.ajax({ + url: link, + success: function (result) { + $("div.modalBody").html(result); + }, + }); - $("div.modalWrapper").fadeIn(100); // With Animation - //$("div.modalWrapper").show(); + $("div.modalWrapper").fadeIn(100); // With Animation + //$("div.modalWrapper").show(); } $("button.btnClose").click(function () { - //$("div.modalWrapper").fadeOut(50); // With Animation - $("div.modalWrapper").hide(); + //$("div.modalWrapper").fadeOut(50); // With Animation + $("div.modalWrapper").hide(); }); diff --git a/webroot/js/sort.js b/webroot/js/sort.js index 3ab04f28..5f8b7e1e 100644 --- a/webroot/js/sort.js +++ b/webroot/js/sort.js @@ -1,73 +1,89 @@ var table = document.querySelector("table.sortable"); -table.querySelectorAll("td").forEach(function(td) { - td.addEventListener("click", function(e) { - if (td.parentElement.classList.contains("key") && td.innerHTML != "Actions") { - if (e.target.classList.contains("filter")) { - updateQueryStringParameter(window.location.href, "filter", e.target.parentElement.id); - updateFilterInput(); - } else { - var column = td.cellIndex; - var rows = Array.from(table.querySelectorAll("tr:nth-child(n+2)")); - var order = td.classList.toggle("asc") ? 1 : -1; - rows.sort(function(a, b) { - return order * (a.cells[column].textContent.trim().localeCompare(b.cells[column].textContent.trim(), undefined, { - numeric: true - })); - }); - rows.forEach(function(row) { - table.appendChild(row); - }); - var keys = document.querySelectorAll("tr.key"); - keys.forEach(function(key) { - key.querySelectorAll("td").forEach(function(td) { - td.innerHTML = td.innerHTML.replace(/ ▲| ▼/, ""); - }); - }); - var orderSymbol = order == 1 ? "▲" : "▼"; - td.innerHTML = td.innerHTML + " " + orderSymbol; - updateQueryStringParameter(window.location.href, "sort", td.id); - updateQueryStringParameter(window.location.href, "order", order == 1 ? "asc" : "desc"); - } - } - }); +table.querySelectorAll("td").forEach(function (td) { + td.addEventListener("click", function (e) { + if ( + td.parentElement.classList.contains("key") && + td.innerHTML != "Actions" + ) { + if (e.target.classList.contains("filter")) { + updateQueryStringParameter( + window.location.href, + "filter", + e.target.parentElement.id, + ); + updateFilterInput(); + } else { + var column = td.cellIndex; + var rows = Array.from(table.querySelectorAll("tr:nth-child(n+2)")); + var order = td.classList.toggle("asc") ? 1 : -1; + rows.sort(function (a, b) { + return ( + order * + a.cells[column].textContent + .trim() + .localeCompare(b.cells[column].textContent.trim(), undefined, { + numeric: true, + }) + ); + }); + rows.forEach(function (row) { + table.appendChild(row); + }); + var keys = document.querySelectorAll("tr.key"); + keys.forEach(function (key) { + key.querySelectorAll("td").forEach(function (td) { + td.innerHTML = td.innerHTML.replace(/ ▲| ▼/, ""); + }); + }); + var orderSymbol = order == 1 ? "▲" : "▼"; + td.innerHTML = td.innerHTML + " " + orderSymbol; + updateQueryStringParameter(window.location.href, "sort", td.id); + updateQueryStringParameter( + window.location.href, + "order", + order == 1 ? "asc" : "desc", + ); + } + } + }); }); function getQueryVariable(variable) { - var query = window.location.search.substring(1); - var vars = query.split("&"); - for (var i = 0; i < vars.length; i++) { - var pair = vars[i].split("="); + var query = window.location.search.substring(1); + var vars = query.split("&"); + for (var i = 0; i < vars.length; i++) { + var pair = vars[i].split("="); - if (pair[0] == variable) { - return pair[1]; - } + if (pair[0] == variable) { + return pair[1]; } - return false; + } + return false; } function updateQueryStringParameter(uri, key, value) { - let currentURL = new URL(window.location.href); - let params = currentURL.searchParams; - if (params.has(key)) { - params.delete(key); - } - params.append(key, value); - window.history.pushState("object or string", "Title", currentURL.href); + let currentURL = new URL(window.location.href); + let params = currentURL.searchParams; + if (params.has(key)) { + params.delete(key); + } + params.append(key, value); + window.history.pushState("object or string", "Title", currentURL.href); } -window.onload = function() { - var sort = getQueryVariable("sort"); - var order = getQueryVariable("order"); - if (sort) { - var sortElement = document.getElementById(sort); - if (sortElement) { - if (order == "asc") { - sortElement.click(); - } else if (order == "desc") { - sortElement.click(); - sortElement.click(); - } - } +window.onload = function () { + var sort = getQueryVariable("sort"); + var order = getQueryVariable("order"); + if (sort) { + var sortElement = document.getElementById(sort); + if (sortElement) { + if (order == "asc") { + sortElement.click(); + } else if (order == "desc") { + sortElement.click(); + sortElement.click(); + } } - filterRows(); -} + } + filterRows(); +}; diff --git a/webroot/js/tables.js b/webroot/js/tables.js index a749b43e..aea1739e 100644 --- a/webroot/js/tables.js +++ b/webroot/js/tables.js @@ -1,54 +1,53 @@ +$("tr.expandable").on("click", function (e) { + var target = $(e.target); + if (target.is("button") || target.is("a") || target.is("input")) { + return; + } + + var button = $(this).find("button.btnExpand"); + button.trigger("click"); +}); -$("tr.expandable").on('click', function(e) { - var target = $(e.target); - if (target.is("button") || target.is("a") || target.is("input")) { - return; - } +$("button.btnExpand").click(function () { + var pi_wrapper = $(this).parent(); // parent column (td) + var piRow = pi_wrapper.parent(); // parent row (tr) + var piTree = piRow.parent(); // parent table (table) + var gid = pi_wrapper.next().html(); - var button = $(this).find("button.btnExpand"); - button.trigger("click"); -}); + if ($(this).hasClass("btnExpanded")) { + // already expanded + var currentNode = piRow.nextAll().first(); -$("button.btnExpand").click(function() { - var pi_wrapper = $(this).parent(); // parent column (td) - var piRow = pi_wrapper.parent(); // parent row (tr) - var piTree = piRow.parent(); // parent table (table) - var gid = pi_wrapper.next().html(); - - if ($(this).hasClass("btnExpanded")) { - // already expanded - var currentNode = piRow.nextAll().first(); - - while (!currentNode.hasClass("expandable") && currentNode.length != 0) { - var nextNode = currentNode.nextAll().first(); - currentNode.remove(); - currentNode = nextNode; - } - - $(this).removeClass("btnExpanded"); - piRow.removeClass("expanded"); - piRow.removeClass("first"); - } else { - $("button.btnExpanded").trigger("click"); - // not expanded - $.ajax({ - url: ajax_url + gid, - success: function(result) { - console.log(result); - piRow.after(result); - } - }); - - $(this).addClass("btnExpanded"); - piRow.addClass("expanded"); - piRow.addClass("first"); + while (!currentNode.hasClass("expandable") && currentNode.length != 0) { + var nextNode = currentNode.nextAll().first(); + currentNode.remove(); + currentNode = nextNode; } + + $(this).removeClass("btnExpanded"); + piRow.removeClass("expanded"); + piRow.removeClass("first"); + } else { + $("button.btnExpanded").trigger("click"); + // not expanded + $.ajax({ + url: ajax_url + gid, + success: function (result) { + console.log(result); + piRow.after(result); + }, + }); + + $(this).addClass("btnExpanded"); + piRow.addClass("expanded"); + piRow.addClass("first"); + } }); -$('#tableSearch').keyup(function() { - var value = $(this).val().toLowerCase(); +$("#tableSearch").keyup(function () { + var value = $(this).val().toLowerCase(); - $("table.searchable tr:not(:first-child)").filter(function() { - $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1) - }); + $("table.searchable tr:not(:first-child)").filter(function () { + $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1); + }); }); diff --git a/workers/clear-audit-log.php b/workers/clear-audit-log.php index 6a28dcd4..63cfee69 100755 --- a/workers/clear-audit-log.php +++ b/workers/clear-audit-log.php @@ -1,6 +1,5 @@ #!/usr/bin/env php getConn() + ->prepare("DELETE FROM audit_log WHERE timestamp < :daysAgo") + ->execute(["daysAgo" => $daysAgo]); -$SQL->getConn()->prepare( - "DELETE FROM audit_log WHERE timestamp < :daysAgo" -)->execute(['daysAgo' => $daysAgo]); diff --git a/workers/group_user_request_owner_reminder.php b/workers/group_user_request_owner_reminder.php index 4f463262..9464712c 100755 --- a/workers/group_user_request_owner_reminder.php +++ b/workers/group_user_request_owner_reminder.php @@ -1,6 +1,5 @@ #!/usr/bin/env php 1 && $daysDifference % 7 == 0) { $new_user = $request[0]; // send email to PI - $MAILER->sendMail( - $pi_user->getMail(), - "group_user_request_owner", - array( - "group" => $pi_group->gid, - "user" => $new_user->uid, - "name" => $new_user->getFullName(), - "email" => $new_user->getMail(), - "org" => $new_user->getOrg() - ) - ); + $MAILER->sendMail($pi_user->getMail(), "group_user_request_owner", [ + "group" => $pi_group->gid, + "user" => $new_user->uid, + "name" => $new_user->getFullName(), + "email" => $new_user->getMail(), + "org" => $new_user->getOrg(), + ]); } } } + diff --git a/workers/remove-users-from-group.php b/workers/remove-users-from-group.php index b293b841..01fe8c99 100755 --- a/workers/remove-users-from-group.php +++ b/workers/remove-users-from-group.php @@ -1,6 +1,5 @@ #!/usr/bin/env php exists()) { _die("No such group '$gid'\n"); } -$handle = fopen($filename, "r") or _die("Can't open '$filename'\n"); +($handle = fopen($filename, "r")) or _die("Can't open '$filename'\n"); while (($line = fgets($handle)) !== false) { $uid = trim($line); $user = new UnityUser($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); if (!$group->memberExists($user)) { - print("Skipping '$uid' who doesn't appear to be in '$gid'\n"); + print "Skipping '$uid' who doesn't appear to be in '$gid'\n"; continue; } $group->removeUser($user); } fclose($handle); + diff --git a/workers/update-ldap-cache.php b/workers/update-ldap-cache.php index 96bd02f0..0afc0153 100755 --- a/workers/update-ldap-cache.php +++ b/workers/update-ldap-cache.php @@ -1,6 +1,5 @@ #!/usr/bin/env php 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 { @@ -37,7 +39,11 @@ // 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); @@ -47,35 +53,57 @@ 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"; // phpcs:disable - $org_group_CNs = array_map(function($x){return $x["cn"][0];}, $org_groups); + $org_group_CNs = array_map(function ($x) { + return $x["cn"][0]; + }, $org_groups); // phpcs:enable sort($org_group_CNs); $REDIS->setCache("sorted_orgs", "", $org_group_CNs); foreach ($org_groups as $org_group) { $gid = $org_group["cn"][0]; - $REDIS->setCache($gid, "members", ($org_group["memberuid"] ?? [])); + $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"; // phpcs:disable - $pi_group_CNs = array_map(function($x){return $x["cn"][0];}, $pi_groups); + $pi_group_CNs = array_map(function ($x) { + return $x["cn"][0]; + }, $pi_groups); // phpcs:enable sort($pi_group_CNs); // FIXME should be sorted_pi_groups @@ -87,7 +115,7 @@ } foreach ($pi_groups as $pi_group) { $gid = $pi_group["cn"][0]; - $members = ($pi_group["memberuid"] ?? []); + $members = $pi_group["memberuid"] ?? []; foreach ($members as $uid) { if (in_array($uid, $user_CNs)) { array_push($user_pi_group_member_of[$uid], $gid); @@ -95,7 +123,7 @@ echo "warning: group '$gid' has member '$uid' who is not in the users group!\n"; } } - $REDIS->setCache($gid, "members", ($pi_group["memberuid"] ?? [])); + $REDIS->setCache($gid, "members", $pi_group["memberuid"] ?? []); } foreach ($user_pi_group_member_of as $uid => $pi_groups) { // FIXME should be pi_groups @@ -105,3 +133,4 @@ $REDIS->setCache("initialized", "", true); echo "done!\n"; } +