Skip to content
Merged

Psr12 #294

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:
entry: phpcbf
language: system
files: \.php$
args: [--standard=PSR2, --colors]
args: [--standard=PSR12, --colors]

# linters (work required) ########################################################################
# - repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -41,7 +41,7 @@ repos:
entry: phpcs
language: system
files: \.php$
args: [--standard=PSR2, --colors]
args: [--standard=PSR12, --colors]
- id: php-l
name: php -l
entry: php
Expand Down
6 changes: 3 additions & 3 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class UnityGroup
/**
* Constructor for the object
*
* @param string $gid PI UID in the format <PI_PREFIX><OWNER_UID>
* @param LDAP $LDAP LDAP Connection
* @param SQL $SQL SQL Connection
* @param string $gid PI UID in the format <PI_PREFIX><OWNER_UID>
* @param LDAP $LDAP LDAP Connection
* @param SQL $SQL SQL Connection
*/
public function __construct($gid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK)
{
Expand Down
72 changes: 40 additions & 32 deletions resources/lib/UnityLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
class UnityLDAP extends ldapConn
{
// User Specific Constants
// User Specific Constants
private const RDN = "cn"; // The defauls RDN for LDAP entries is set to "common name"

public const POSIX_ACCOUNT_CLASS = array(
Expand All @@ -25,15 +25,15 @@ class UnityLDAP extends ldapConn
"top"
);

// string vars for OUs
// string vars for OUs
private $STR_BASEOU;
private $STR_USEROU;
private $STR_GROUPOU;
private $STR_PIGROUPOU;
private $STR_ORGGROUPOU;
private $STR_ADMINGROUP;

// Instance vars for various ldapEntry objects
// Instance vars for various ldapEntry objects
private $baseOU;
private $userOU;
private $groupOU;
Expand Down Expand Up @@ -69,7 +69,7 @@ public function __construct(
$this->STR_ORGGROUPOU = $orggroup_ou;
$this->STR_ADMINGROUP = $admin_group;

// Get Global Entries
// Get Global Entries
$this->baseOU = $this->getEntry($base_ou);
$this->userOU = $this->getEntry($user_ou);
$this->groupOU = $this->getEntry($group_ou);
Expand All @@ -83,9 +83,9 @@ public function __construct(
$this->def_user_shell = $def_user_shell;
}

//
// Get methods for OU
//
//
// Get methods for OU
//
public function getUserOU()
{
return $this->userOU;
Expand Down Expand Up @@ -121,9 +121,9 @@ public function getDefUserShell()
return $this->def_user_shell;
}

//
// ID Number selection functions
//
//
// ID Number selection functions
//
public function getNextUIDNumber($UnitySQL)
{
$max_uid = $UnitySQL->getSiteVar('MAX_UID');
Expand Down Expand Up @@ -198,7 +198,7 @@ private function IDNumInUse($id)
public function getUnassignedID($uid, $UnitySQL)
{
$netid = strtok($uid, "_"); // extract netid
// scrape all files in custom folder
// scrape all files in custom folder
$dir = new \DirectoryIterator($this->custom_mappings_path);
foreach ($dir as $fileinfo) {
if ($fileinfo->getExtension() == "csv") {
Expand All @@ -218,7 +218,7 @@ public function getUnassignedID($uid, $UnitySQL)
}
}

// didn't find anything from existing mappings, use next available
// didn't find anything from existing mappings, use next available
$next_uid = $this->getNextUIDNumber($UnitySQL);

return $next_uid;
Expand All @@ -231,9 +231,9 @@ public function getAllUsersUIDs()
return $this->userGroup->getAttribute("memberuid");
}

//
// Functions that return user/group objects
//
//
// Functions that return user/group objects
//
public function getAllUsers($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
{
$out = array();
Expand Down Expand Up @@ -292,14 +292,17 @@ public function getAllPIGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebho
$pi_groups = $this->pi_groupOU->getChildren(true);

foreach ($pi_groups as $pi_group) {
array_push($out, new UnityGroup(
$pi_group->getAttribute("cn")[0],
$this,
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook
));
array_push(
$out,
new UnityGroup(
$pi_group->getAttribute("cn")[0],
$this,
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook
)
);
}

return $out;
Expand Down Expand Up @@ -341,7 +344,9 @@ public function getAllPIGroupOwnerAttributes($attributes)
return $owner_attributes;
}

/** Returns an associative array where keys are UIDs and values are arrays of PI GIDs */
/**
* Returns an associative array where keys are UIDs and values are arrays of PI GIDs
*/
public function getAllUID2PIGIDs()
{
// initialize output so each UID is a key with an empty array as its value
Expand Down Expand Up @@ -375,14 +380,17 @@ public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebh
$org_groups = $this->org_groupOU->getChildren(true);

foreach ($org_groups as $org_group) {
array_push($out, new UnityOrg(
$org_group->getAttribute("cn")[0],
$this,
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook
));
array_push(
$out,
new UnityOrg(
$org_group->getAttribute("cn")[0],
$this,
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook
)
);
}

return $out;
Expand Down
6 changes: 3 additions & 3 deletions resources/lib/UnitySite.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public static function testValidSSHKey($key_str)
try {
PublicKeyLoader::load($key_str);
return true;
// phpseclib should throw only NoKeyLoadedException but that is not the case
// https://github.com/phpseclib/phpseclib/pull/2078
// } catch (\phpseclib3\Exception\NoKeyLoadedException $e) {
// phpseclib should throw only NoKeyLoadedException but that is not the case
// https://github.com/phpseclib/phpseclib/pull/2078
// } catch (\phpseclib3\Exception\NoKeyLoadedException $e) {
} catch (\Throwable $e) {
return false;
}
Expand Down
15 changes: 8 additions & 7 deletions resources/lib/UnityUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public function __toString()
/**
* This is the method that is run when a new account is created
*
* @param string $firstname First name of new account
* @param string $lastname Last name of new account
* @param string $email email of new account
* @param string $org organization name of new account
* @param bool $isPI boolean value for if the user checked the "I am a PI box"
* @param string $firstname First name of new account
* @param string $lastname Last name of new account
* @param string $email email of new account
* @param string $org organization name of new account
* @param bool $isPI boolean value for if the user checked the "I am a PI box"
* @return void
*/
public function init($firstname, $lastname, $email, $org, $send_mail = true)
Expand Down Expand Up @@ -575,6 +575,7 @@ public function getOrgGroup()

/**
* Gets the groups this user is assigned to, can be more than one
*
* @return string[]
*/
public function getPIGroupGIDs($ignorecache = false)
Expand Down Expand Up @@ -621,11 +622,11 @@ public function hasRequestedAccountDeletion()

/**
* Checks whether a user is in a group or not
* @param string $uid uid of the user
*
* @param string $uid uid of the user
* @param string or object $group group to check
* @return boolean true if user is in group, false if not
*/

public function isInGroup($uid, $group)
{
if (gettype($group) == "string") {
Expand Down
1 change: 1 addition & 0 deletions resources/lib/exceptions/PhpUnitNoDieException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace UnityWebPortal\lib\exceptions;

class PhpUnitNoDieException extends \Exception
Expand Down
1 change: 1 addition & 0 deletions resources/lib/exceptions/SSOException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace UnityWebPortal\lib\exceptions;

class SSOException extends \Exception
Expand Down
16 changes: 9 additions & 7 deletions resources/templates/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use UnityWebPortal\lib\UnitySite;

if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ((@$_SESSION["is_admin"] ?? false) == true
if (
(@$_SESSION["is_admin"] ?? false) == true
&& (@$_POST["form_type"] ?? null) == "clearView"
) {
unset($_SESSION["viewUser"]);
Expand Down Expand Up @@ -78,27 +79,27 @@
}

if (isset($_SESSION["user_exists"]) && $_SESSION["user_exists"]) {
// Menu Items for Present Users
// Menu Items for Present Users
echo "<a href='" . $CONFIG["site"]["prefix"] . "/panel/support.php'>Support</a>";
echo "<a href='" . $CONFIG["site"]["prefix"] . "/panel/account.php'>Account Settings</a>";
echo "<a href='" . $CONFIG["site"]["prefix"] . "/panel/groups.php'>My PIs</a>";

if (isset($_SESSION["is_pi"]) && $_SESSION["is_pi"]) {
// PI only pages
// PI only pages
echo "<a href='" . $CONFIG["site"]["prefix"] . "/panel/pi.php'>My Users</a>";
}

// additional branding items
// additional branding items
$num_additional_items = count($CONFIG["menuitems_secure"]["labels"]);
for ($i = 0; $i < $num_additional_items; $i++) {
echo "<a target='_blank' href='" . $CONFIG["menuitems_secure"]["links"][$i] . "'>" .
$CONFIG["menuitems_secure"]["labels"][$i] . "</a>";
}

// admin pages
// admin pages
if (isset($_SESSION["is_admin"]) && $_SESSION["is_admin"] && !isset($_SESSION["viewUser"])) {
echo "<hr class='navHR'>";
// Admin only pages
// Admin only pages
echo "<a href='" . $CONFIG["site"]["prefix"] . "/admin/user-mgmt.php'>User Management</a>";
echo "<a href='" . $CONFIG["site"]["prefix"] . "/admin/pi-mgmt.php'>PI Management</a>";
echo "<a href='" . $CONFIG["site"]["prefix"] . "/admin/notices.php'>Cluster Notices</a>";
Expand Down Expand Up @@ -132,7 +133,8 @@
<main>

<?php
if (isset($_SESSION["is_admin"])
if (
isset($_SESSION["is_admin"])
&& $_SESSION["is_admin"]
&& isset($_SESSION["viewUser"])
) {
Expand Down
4 changes: 2 additions & 2 deletions webroot/admin/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
}

include $LOC_HEADER;
require $LOC_HEADER;
?>

<h1>Page Content Management</h1>
Expand Down Expand Up @@ -67,4 +67,4 @@
</script>

<?php
include $LOC_FOOTER;
require $LOC_FOOTER;
4 changes: 2 additions & 2 deletions webroot/admin/notices.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
}

include $LOC_HEADER;
require $LOC_HEADER;
?>

<h1>Cluster Notice Management</h1>
Expand Down Expand Up @@ -153,4 +153,4 @@
</script>

<?php
include $LOC_FOOTER;
require $LOC_FOOTER;
4 changes: 2 additions & 2 deletions webroot/admin/pi-mgmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
}
}

include $LOC_HEADER;
require $LOC_HEADER;
?>

<h1>PI Management</h1>
Expand Down Expand Up @@ -136,4 +136,4 @@
</script>

<?php
include $LOC_FOOTER;
require $LOC_FOOTER;
4 changes: 2 additions & 2 deletions webroot/admin/user-mgmt.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
}

include $LOC_HEADER;
require $LOC_HEADER;
?>

<h1>User Management</h1>
Expand Down Expand Up @@ -74,4 +74,4 @@
</table>

<?php
include $LOC_FOOTER;
require $LOC_FOOTER;
2 changes: 1 addition & 1 deletion webroot/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_once __DIR__ . "/../resources/autoload.php";

include $LOC_HEADER;
require $LOC_HEADER;
?>


Expand Down
2 changes: 1 addition & 1 deletion webroot/panel/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
}
}

include $LOC_HEADER;
require $LOC_HEADER;

$uid = $USER->uid;
$org = $USER->getOrg();
Expand Down
4 changes: 2 additions & 2 deletions webroot/panel/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
}
}

include $LOC_HEADER;
require $LOC_HEADER;
?>

<h1>My Principal Investigators</h1>
Expand Down Expand Up @@ -192,4 +192,4 @@
</style>

<?php
include $LOC_FOOTER;
require $LOC_FOOTER;
Loading