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: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ See the Docker Compose environment (`tools/docker-dev/`) for an (unsafe for prod
- Composer (`apt install composer` on Ubuntu)
- Dependencies:
- PHP extensions
- curl, intl, ldap, mbstring, mysql, pdo, redis, xml (`apt install php-<extension>` on Ubuntu)
- curl, intl, ldap, mbstring, mysql, pdo, xml (`apt install php-<extension>` on Ubuntu)
- Libraries
- `COMPOSER_ALLOW_SUPERUSER=1 composer --no-dev --no-scripts --no-plugins install`
- `httpd` `DocumentRoot` set to `webroot/`
Expand Down Expand Up @@ -139,14 +139,7 @@ Now, LDAP entries are created immediately for every user, so this is no longer n
$_SERVER["REMOTE_ADDR"] = "127.0.0.1";
require_once __DIR__ . "/../resources/autoload.php";
foreach ($SQL->getAllRequests() as $request) {
$user = new UnityUser(
$request["uid"],
$LDAP,
$SQL,
$MAILER,
$REDIS,
$WEBHOOK,
);
$user = new UnityUser($request["uid"], $LDAP, $SQL, $MAILER, $WEBHOOK);
if (!$user->exists()) {
echo "creating user: " . jsonEncode($request) . "\n";
$user->init(
Expand Down
4 changes: 0 additions & 4 deletions defaults/config.ini.default
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ user = "" ; smtp username, if exists
pass = "" ; smtp password, if exists
ssl_verify = "false" ; set to true to verify ssl certificates

[redis]
host = "redis"
port = "6379"

[colors]
light_background = "#ffffff" ; Background color when in light mode
light_foreground = "#1a1a1a" ; Text color when in light mode
Expand Down
1 change: 0 additions & 1 deletion resources/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
require_once __DIR__ . "/lib/UnityHTTPD.php";
require_once __DIR__ . "/lib/UnityConfig.php";
require_once __DIR__ . "/lib/UnityWebhook.php";
require_once __DIR__ . "/lib/UnityRedis.php";
require_once __DIR__ . "/lib/UnityGithub.php";
require_once __DIR__ . "/lib/utils.php";
require_once __DIR__ . "/lib/exceptions/NoDieException.php";
Expand Down
14 changes: 2 additions & 12 deletions resources/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use UnityWebPortal\lib\UnitySQL;
use UnityWebPortal\lib\UnitySSO;
use UnityWebPortal\lib\UnityUser;
use UnityWebPortal\lib\UnityRedis;
use UnityWebPortal\lib\UnityWebhook;
use UnityWebPortal\lib\UnityGithub;
use UnityWebPortal\lib\UnityHTTPD;
Expand All @@ -20,7 +19,6 @@

session_start();

$REDIS = new UnityRedis();
if (isset($GLOBALS["ldapconn"])) {
$LDAP = $GLOBALS["ldapconn"];
} else {
Expand All @@ -37,11 +35,11 @@
$SSO = UnitySSO::getSSO();
$_SESSION["SSO"] = $SSO;

$OPERATOR = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
$OPERATOR = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $WEBHOOK);
$_SESSION["is_admin"] = $OPERATOR->isAdmin();

if (isset($_SESSION["viewUser"]) && $_SESSION["is_admin"]) {
$USER = new UnityUser($_SESSION["viewUser"], $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK);
$USER = new UnityUser($_SESSION["viewUser"], $LDAP, $SQL, $MAILER, $WEBHOOK);
} else {
$USER = $OPERATOR;
}
Expand All @@ -51,14 +49,6 @@
$SEND_PIMESG_TO_ADMINS = CONFIG["mail"]["send_pimesg_to_admins"];

$SQL->addLog($OPERATOR->uid, $_SERVER["REMOTE_ADDR"], "user_login", $OPERATOR->uid);

if (!$_SESSION["user_exists"]) {
// populate cache
$REDIS->setCache($SSO["user"], "org", $SSO["org"]);
$REDIS->setCache($SSO["user"], "firstname", $SSO["firstname"]);
$REDIS->setCache($SSO["user"], "lastname", $SSO["lastname"]);
$REDIS->setCache($SSO["user"], "mail", $SSO["mail"]);
}
}

$LOC_HEADER = __DIR__ . "/templates/header.php";
Expand Down
66 changes: 5 additions & 61 deletions resources/lib/UnityGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ class UnityGroup
private UnitySQL $SQL;
private UnityMailer $MAILER;
private UnityWebhook $WEBHOOK;
private UnityRedis $REDIS;

public function __construct(
string $gid,
UnityLDAP $LDAP,
UnitySQL $SQL,
UnityMailer $MAILER,
UnityRedis $REDIS,
UnityWebhook $WEBHOOK,
) {
$gid = trim($gid);
Expand All @@ -35,7 +33,6 @@ public function __construct(
$this->LDAP = $LDAP;
$this->SQL = $SQL;
$this->MAILER = $MAILER;
$this->REDIS = $REDIS;
$this->WEBHOOK = $WEBHOOK;
}

Expand Down Expand Up @@ -184,17 +181,6 @@ public function cancelGroupJoinRequest(UnityUser $user, bool $send_mail = true):
// // now we delete the ldap entry
// $this->entry->ensureExists();
// $this->entry->delete();
// $default_value_getter = [$this->LDAP, "getSortedGroupsForRedis"];
// $this->REDIS->removeCacheArray("sorted_groups", "", $this->gid, $default_value_getter);
// foreach ($users as $user) {
// $this->REDIS->removeCacheArray(
// $user->uid,
// "groups",
// $this->gid,
// fn() => $this->getGroupMemberUIDs(true),
// );
// }
// // FIXME group not removed from user's groups array

// // send email to every user of the now deleted PI group
// if ($send_mail) {
Expand Down Expand Up @@ -315,49 +301,34 @@ public function getRequests(): array
$this->LDAP,
$this->SQL,
$this->MAILER,
$this->REDIS,
$this->WEBHOOK,
);
array_push($out, [$user, $request["timestamp"]]);
}
return $out;
}

public function getGroupMembers(bool $ignorecache = false): array
public function getGroupMembers(): array
{
$members = $this->getGroupMemberUIDs($ignorecache);
$members = $this->getGroupMemberUIDs();
$out = [];
foreach ($members as $member) {
$user_obj = new UnityUser(
$member,
$this->LDAP,
$this->SQL,
$this->MAILER,
$this->REDIS,
$this->WEBHOOK,
);
array_push($out, $user_obj);
}
return $out;
}

public function getGroupMemberUIDs(bool $ignorecache = false): array
public function getGroupMemberUIDs(): array
{
if (!$ignorecache) {
$cached_val = $this->REDIS->getCache($this->gid, "members");
if (!is_null($cached_val)) {
$members = $cached_val;
}
}
$updatecache = false;
if (!isset($members)) {
$members = $this->entry->getAttribute("memberuid");
$updatecache = true;
}
if (!$ignorecache && $updatecache) {
sort($members);
$this->REDIS->setCache($this->gid, "members", $members);
}
$members = $this->entry->getAttribute("memberuid");
sort($members);
return $members;
}

Expand All @@ -383,8 +354,6 @@ private function init(): void
$this->entry->setAttribute("gidnumber", strval($nextGID));
$this->entry->setAttribute("memberuid", [$owner->uid]);
$this->entry->write();
$default_value_getter = [$this->LDAP, "getSortedGroupsForRedis"];
$this->REDIS->appendCacheArray("sorted_groups", "", $this->gid, $default_value_getter);
// TODO if we ever make this project based,
// we need to update the cache here with the memberuid
}
Expand All @@ -393,36 +362,12 @@ private function addUserToGroup(UnityUser $new_user): void
{
$this->entry->appendAttribute("memberuid", $new_user->uid);
$this->entry->write();
$this->REDIS->appendCacheArray(
$this->gid,
"members",
$new_user->uid,
fn() => $this->getGroupMemberUIDs(true),
);
$this->REDIS->appendCacheArray(
$new_user->uid,
"groups",
$this->gid,
fn() => $this->LDAP->getPIGroupGIDsWithMemberUID($new_user->uid),
);
}

private function removeUserFromGroup(UnityUser $old_user): void
{
$this->entry->removeAttributeEntryByValue("memberuid", $old_user->uid);
$this->entry->write();
$this->REDIS->removeCacheArray(
$this->gid,
"members",
$old_user->uid,
fn() => $this->getGroupMemberUIDs(true),
);
$this->REDIS->removeCacheArray(
$old_user->uid,
"groups",
$this->gid,
fn() => $this->LDAP->getPIGroupGIDsWithMemberUID($old_user->uid),
);
}

public function memberExists(UnityUser $user): bool
Expand All @@ -442,7 +387,6 @@ public function getOwner(): UnityUser
$this->LDAP,
$this->SQL,
$this->MAILER,
$this->REDIS,
$this->WEBHOOK,
);
}
Expand Down
99 changes: 5 additions & 94 deletions resources/lib/UnityLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,39 +194,14 @@ public function getQualifiedUsersUIDs(): array
return $this->qualifiedUserGroup->getAttribute("memberuid");
}

public function getQualifiedUsers(
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook,
$ignorecache = false,
): array {
public function getQualifiedUsers($UnitySQL, $UnityMailer, $UnityWebhook): array
{
$out = [];

if (!$ignorecache) {
$qualifiedUsers = $UnityRedis->getCache("sorted_qualified_users", "");
if (!is_null($qualifiedUsers)) {
foreach ($qualifiedUsers as $user) {
array_push(
$out,
new UnityUser(
$user,
$this,
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook,
),
);
}
return $out;
}
}

$qualifiedUsers = $this->getQualifiedUsersUIDs();
sort($qualifiedUsers);
foreach ($qualifiedUsers as $user) {
$params = [$user, $this, $UnitySQL, $UnityMailer, $UnityRedis, $UnityWebhook];
$params = [$user, $this, $UnitySQL, $UnityMailer, $UnityWebhook];
array_push($out, new UnityUser(...$params));
}
return $out;
Expand Down Expand Up @@ -254,24 +229,10 @@ public function getQualifiedUsersAttributes(
public function getAllPIGroups(
UnitySQL $UnitySQL,
UnityMailer $UnityMailer,
UnityRedis $UnityRedis,
UnityWebhook $UnityWebhook,
bool $ignorecache = false,
) {
$out = [];

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

return $out;
}
}

$pi_groups = $this->pi_groupOU->getChildren(true);

foreach ($pi_groups as $pi_group) {
Expand All @@ -282,7 +243,6 @@ public function getAllPIGroups(
$this,
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook,
),
);
Expand Down Expand Up @@ -373,35 +333,10 @@ public function getQualifiedUID2PIGIDs(): array
return $uid2pigids;
}

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

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,
),
);
}
return $out;
}
}

$org_groups = $this->org_groupOU->getChildren(true);

foreach ($org_groups as $org_group) {
Expand All @@ -412,7 +347,6 @@ public function getAllOrgGroups(
$this,
$UnitySQL,
$UnityMailer,
$UnityRedis,
$UnityWebhook,
),
);
Expand Down Expand Up @@ -466,29 +400,6 @@ public function getUidFromEmail(string $email): LDAPEntry
throw new exceptions\EntryNotFoundException($email);
}

public function getSortedQualifiedUsersForRedis(): array
{
$qualified_users = $this->getQualifiedUsersUIDs();
sort($qualified_users);
return $qualified_users;
}

public function getSortedOrgsForRedis(): array
{
$attributes = $this->getAllOrgGroupsAttributes(["cn"]);
$groups = array_map(fn($x) => $x["cn"][0], $attributes);
sort($groups);
return $groups;
}

public function getSortedGroupsForRedis(): array
{
$attributes = $this->getAllPIGroupsAttributes(["cn"]);
$groups = array_map(fn($x) => $x["cn"][0], $attributes);
sort($groups);
return $groups;
}

/**
* returns an array with each UID as an array key
* @throws \UnityWebPortal\lib\exceptions\EntryNotFoundException
Expand Down
Loading