Skip to content
Merged
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
11 changes: 11 additions & 0 deletions .phpcs-ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<ruleset name="Unity">
<description>PSR12, with max line length = 100 characters</description>
<rule ref="PSR12"/>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="100"/>
<property name="absoluteLineLimit" value="100"/>
</properties>
</rule>
</ruleset>
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=PSR12, --colors]
args: [--standard=./.phpcs-ruleset.xml, --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=PSR12, --colors]
args: [--standard=./.phpcs-ruleset.xml, --colors]
- id: php-l
name: php -l
entry: php
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

This code base is currently using PHP version 8.3.
All files are required to be linted with PSR-12 standard.
The maximum line length for any PHP file is 100 characters, instead of PSR-12's 120 characters.
This repository will automatically check PRs for linting compliance.

## Development Environment
Expand Down
5 changes: 4 additions & 1 deletion resources/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@
$errorid = uniqid("sso-");
$eppn = $_SERVER["REMOTE_USER"];
UnitySite::errorLog("SSO Failure", "{$e} ($errorid)");
UnitySite::die("Invalid eppn: '$eppn'. Please contact {$CONFIG["mail"]["support"]} (id: $errorid)", true);
UnitySite::die(
"Invalid eppn: '$eppn'. Please contact {$CONFIG["mail"]["support"]} (id: $errorid)",
true
);
}
$_SESSION["SSO"] = $SSO;

Expand Down
33 changes: 25 additions & 8 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function __construct($gid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK)
public function equals($other_group)
{
if (!is_a($other_group, self::class)) {
throw new Exception("Unable to check equality because the parameter is not a " . self::class . " object");
throw new Exception(
"Unable to check equality because the parameter is not a " . self::class . " object"
);
}

return $this->gid == $other_group->gid;
Expand All @@ -69,8 +71,14 @@ public function exists()
// Portal-facing methods, these are the methods called by scripts in webroot
//

public function requestGroup($firstname, $lastname, $email, $org, $send_mail_to_admins, $send_mail = true)
{
public function requestGroup(
$firstname,
$lastname,
$email,
$org,
$send_mail_to_admins,
$send_mail = true
) {
// check for edge cases...
if ($this->exists()) {
return;
Expand Down Expand Up @@ -150,7 +158,8 @@ public function approveGroup($operator = null, $send_mail = true)
);
}

// initialize ldap objects, if this fails the script will crash, but nothing will persistently break
// initialize ldap objects, if this fails the script will crash,
// but nothing will persistently break
$this->init();

// remove the request from the sql table
Expand Down Expand Up @@ -279,7 +288,8 @@ public function cancelGroupJoinRequest($user, $send_mail = true)
// }

/**
* This method is executed when a user is approved to join the group (either by admin or the group owner)
* This method is executed when a user is approved to join the group
* (either by admin or the group owner)
*/
public function approveUser($new_user, $send_mail = true)
{
Expand Down Expand Up @@ -388,8 +398,14 @@ public function removeUser($new_user, $send_mail = true)
}
}

public function newUserRequest($new_user, $firstname, $lastname, $email, $org, $send_mail = true)
{
public function newUserRequest(
$new_user,
$firstname,
$lastname,
$email,
$org,
$send_mail = true
) {
if ($this->userExists($new_user)) {
UnitySite::errorLog("warning", "user '$new_user' already in group");
return;
Expand Down Expand Up @@ -532,7 +548,8 @@ private function init()

$this->REDIS->appendCacheArray("sorted_groups", "", $this->gid);

// TODO if we ever make this project based, we need to update the cache here with the memberuid
// TODO if we ever make this project based,
// we need to update the cache here with the memberuid
}

private function addUserToGroup($new_user)
Expand Down
56 changes: 46 additions & 10 deletions resources/lib/UnityLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,30 @@ public function getAllUsersUIDs()
//
// Functions that return user/group objects
//
public function getAllUsers($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
{
public function getAllUsers(
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook,
$ignorecache = false
) {
$out = array();

if (!$ignorecache) {
$users = $UnityRedis->getCache("sorted_users", "");
if (!is_null($users)) {
foreach ($users as $user) {
array_push($out, new UnityUser($user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook));
array_push(
$out,
new UnityUser(
$user,
$this,
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook
)
);
}
return $out;
}
Expand Down Expand Up @@ -273,15 +288,22 @@ public function getAllUsersAttributes($attributes)
return $user_attributes;
}

public function getAllPIGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
{
public function getAllPIGroups(
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook,
$ignorecache = false
) {
$out = array();

if (!$ignorecache) {
$groups = $UnityRedis->getCache("sorted_groups", "");
if (!is_null($groups)) {
foreach ($groups as $group) {
$params = array($group, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook);
$params = array(
$group, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook
);
array_push($out, new UnityGroup(...$params));
}

Expand Down Expand Up @@ -362,17 +384,31 @@ public function getAllUID2PIGIDs()
return $uid2pigids;
}

public function getAllOrgGroups($UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook, $ignorecache = false)
{
public function getAllOrgGroups(
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook,
$ignorecache = false
) {
$out = array();

if (!$ignorecache) {
$orgs = $UnityRedis->getCache("sorted_orgs", "");
if (!is_null($orgs)) {
foreach ($orgs as $org) {
array_push($out, new UnityOrg($org, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook));
array_push(
$out,
new UnityOrg(
$org,
$this,
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook
)
);
}

return $out;
}
}
Expand Down
4 changes: 3 additions & 1 deletion resources/lib/UnityMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public function __construct(

$security_conf_valid = empty($security) || $security == "tls" || $security == "ssl";
if (!$security_conf_valid) {
throw new Exception("SMTP security is not set correctly, leave empty, use 'tls', or 'ssl'");
throw new Exception(
"SMTP security is not set correctly, leave empty, use 'tls', or 'ssl'"
);
}
$this->SMTPSecure = $security;

Expand Down
20 changes: 16 additions & 4 deletions resources/lib/UnityPerms.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public function checkApproveUser($uid, $operated_on, $group)

$role = $this->SQL->getRole($uid, $group);

if ($this->SQL->hasPerm($role, 'unity.admin') || $this->SQL->hasPerm($role, 'unity.admin_no_grant')) {
if (
$this->SQL->hasPerm($role, 'unity.admin')
|| $this->SQL->hasPerm($role, 'unity.admin_no_grant')
) {
return true;
}

Expand All @@ -46,7 +49,10 @@ public function checkDenyUser($uid, $operated_on, $group)

$role = $this->SQL->getRole($uid, $group);

if ($this->SQL->hasPerm($role, 'unity.admin') || $this->SQL->hasPerm($role, 'unity.admin_no_grant')) {
if (
$this->SQL->hasPerm($role, 'unity.admin')
|| $this->SQL->hasPerm($role, 'unity.admin_no_grant')
) {
return true;
}

Expand Down Expand Up @@ -79,7 +85,10 @@ public function checkGrantRole($uid, $group, $role)
return false;
}

if ($this->SQL->hasPerm($user_role, 'unity.admin') || $this->SQL->hasPerm($user_role, 'unity.admin_no_grant')) {
if (
$this->SQL->hasPerm($user_role, 'unity.admin')
|| $this->SQL->hasPerm($user_role, 'unity.admin_no_grant')
) {
return true;
}

Expand Down Expand Up @@ -112,7 +121,10 @@ public function checkRevokeRole($uid, $group, $role)
return false;
}

if ($this->SQL->hasPerm($user_role, 'unity.admin') || $this->SQL->hasPerm($user_role, 'unity.admin_no_grant')) {
if (
$this->SQL->hasPerm($user_role, 'unity.admin')
|| $this->SQL->hasPerm($user_role, 'unity.admin_no_grant')
) {
return true;
}

Expand Down
31 changes: 19 additions & 12 deletions resources/lib/UnitySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class UnitySQL
private const TABLE_GROUP_JOIN_REQUESTS = "groupJoinRequests";


// FIXME this string should be changed to something more intuitive, requires production sql change
// FIXME this string should be changed to something more intuitive, requires production change
public const REQUEST_BECOME_PI = "admin";

private $conn;
Expand All @@ -38,8 +38,14 @@ public function getConn()
//
// requests table methods
//
public function addRequest($requestor, $firstname, $lastname, $email, $org, $dest = self::REQUEST_BECOME_PI)
{
public function addRequest(
$requestor,
$firstname,
$lastname,
$email,
$org,
$dest = self::REQUEST_BECOME_PI
) {
if ($this->requestExists($requestor, $dest)) {
return;
}
Expand Down Expand Up @@ -156,8 +162,9 @@ public function deleteRequestsByUser($user)

public function addNotice($title, $date, $content, $operator)
{
$table = self::TABLE_NOTICES;
$stmt = $this->conn->prepare(
"INSERT INTO " . self::TABLE_NOTICES . " (date, title, message) VALUES (:date, :title, :message)"
"INSERT INTO $table (date, title, message) VALUES (:date, :title, :message)"
);
$stmt->bindParam(":date", $date);
$stmt->bindParam(":title", $title);
Expand All @@ -175,8 +182,9 @@ public function addNotice($title, $date, $content, $operator)

public function editNotice($id, $title, $date, $content)
{
$table = self::TABLE_NOTICES;
$stmt = $this->conn->prepare(
"UPDATE " . self::TABLE_NOTICES . " SET date=:date, title=:title, message=:message WHERE id=:id"
"UPDATE $table SET date=:date, title=:title, message=:message WHERE id=:id"
);
$stmt->bindParam(":date", $date);
$stmt->bindParam(":title", $title);
Expand Down Expand Up @@ -261,8 +269,9 @@ public function editPage($id, $content, $operator)
// audit log table methods
public function addLog($operator, $operator_ip, $action_type, $recipient)
{
$table = self::TABLE_AUDIT_LOG;
$stmt = $this->conn->prepare(
"INSERT INTO " . self::TABLE_AUDIT_LOG . " (operator, operator_ip, action_type, recipient)
"INSERT INTO $table (operator, operator_ip, action_type, recipient)
VALUE (:operator, :operator_ip, :action_type, :recipient)"
);
$stmt->bindParam(":operator", $operator);
Expand Down Expand Up @@ -332,9 +341,8 @@ public function updateSiteVar($name, $value)

public function getRole($uid, $group)
{
$stmt = $this->conn->prepare(
"SELECT * FROM " . self::TABLE_GROUP_ROLE_ASSIGNMENTS . " WHERE user=:uid AND `group`=:group"
);
$table = self::TABLE_GROUP_ROLE_ASSIGNMENTS;
$stmt = $this->conn->prepare("SELECT * FROM $table WHERE user=:uid AND `group`=:group");
$stmt->bindParam(":uid", $uid);
$stmt->bindParam(":group", $group);

Expand Down Expand Up @@ -372,9 +380,8 @@ public function getPriority($role)

public function roleAvailableInGroup($uid, $group, $role)
{
$stmt = $this->conn->prepare(
"SELECT * FROM " . self::TABLE_GROUP_ROLE_ASSIGNMENTS . " WHERE user=:uid AND `group`=:group"
);
$table = self::TABLE_GROUP_ROLE_ASSIGNMENTS;
$stmt = $this->conn->prepare("SELECT * FROM $table WHERE user=:uid AND `group`=:group");
$stmt->bindParam(":uid", $uid);
$stmt->bindParam(":group", $group);

Expand Down
7 changes: 5 additions & 2 deletions resources/lib/UnityUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function __construct($uid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK)
public function equals($other_user)
{
if (!is_a($other_user, self::class)) {
throw new Exception("Unable to check equality because the parameter is not a " . self::class . " object");
throw new Exception(
"Unable to check equality because the parameter is not a " . self::class . " object"
);
}

return $this->uid == $other_user->uid;
Expand Down Expand Up @@ -594,7 +596,8 @@ public function getPIGroupGIDs($ignorecache = false)
}

/**
* Sends an email to admins about account deletion request and also adds it to a table in the database
* Sends an email to admins about account deletion request
* and also adds it to a table in the database
*/
public function requestAccountDeletion()
{
Expand Down
14 changes: 9 additions & 5 deletions resources/mail/footer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<footer style="text-align: center; font-size: 8pt; color: #aaaaaa; border-top: 1px solid #dddddd; padding-top: 10px;">
<span>You are receiving this email because you have an account
on the <a target='_blank' href='<?php echo $this->MSG_LINKREF; ?>'>Unity Cluster</a>.
If you would like to stop receiving these emails,
you may request to close your account by replying to this email.</span>
<footer
style="text-align:center; font-size:8pt; color:#aaa; border-top:1px solid #ddd; padding-top:10px;"
>
<span>
You are receiving this email because you have an account
on the <a target='_blank' href='<?php echo $this->MSG_LINKREF; ?>'>Unity Cluster</a>.
If you would like to stop receiving these emails,
you may request to close your account by replying to this email.
</span>
</footer>
Loading