Skip to content

Commit 546fa23

Browse files
authored
Merge pull request #61 from hakasapl/main
1.1.1 Patch to add Redis Support
2 parents 4705570 + b8a2dd5 commit 546fa23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+36643
-714
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ vendor
1313
composer.lock
1414

1515
# don't track site configs
16-
config/**/*.ini
16+
deployment/*
17+
!deployment/**/README.md
18+
!deployment/deploy.sh

Diff for: CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 1.1.1
2+
3+
2023-3-15
4+
5+
* [Feature] Added Redis support for caching
6+
* [Feature] Added new deployment folder
7+
* [Feature] Added workers folder with flush cache script
8+
* [Dev] Added many more test users
9+
* [Bug] Fixes admin page styles
10+
111
# 1.1.0
212

313
2023-3-13

Diff for: README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Unity Web Portal is a PHP application built in top of MariaDB and LDAP which act
2323
1. PHP Extensions
2424
1. `php-ldap`
2525
2. `php-curl`
26+
3. `php-redis`
27+
4. `php-cli`
28+
5. `php-mysql`
29+
6. `php-pdo`
2630
2. Composer packages
2731
1. `cd` to this repository
2832
2. Install packages `composer update`
@@ -43,7 +47,7 @@ The update process is similar to the installation process:
4347
1. Clone the release and follow installation instructions 1 and 2 from above.
4448
2. Copy the following folders from the old installation to the new one:
4549
1. `config`
46-
2. `webroot/res/footer_logos`
50+
2. `webroot/assets/footer_logos`
4751

4852
We recommend a deployment where each version of the portal is its own clone, then just change a symlink to point to the new version. This way a rollback is much easier.
4953

Diff for: config/branding/overrides/unity.uri.edu.ini.example

-24
This file was deleted.

Diff for: config/config.ini.default

-35
This file was deleted.

Diff for: config/branding/config.ini.default renamed to defaults/config.ini.default

+38-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,46 @@
1-
; Branding Defaults
2-
; DO NOT EDIT THIS FILE. Instead make a config.ini in the same location as this file
1+
; Config file for Site
2+
; DO NOT EDIT THIS FILE. Instead make a config.ini file in the config folder.
33
;
4+
[upstream]
5+
version = "1.1.1" ; Current upstream version of the web portal
6+
repo = "https://github.com/UnityHPC/unity-web-portal" ; Upstream URL for the web portal
7+
48
[site]
9+
prefix = "" ; prefix of website, no ending / should be included
510
name = "Unity Cluster" ; Name of the website
611
url = "https://127.0.0.1:8000/" ; URL of the website
712
description = "The Unity Web Portal is a lightweight HPC cluster front-end" ; Description of the website
8-
logo = "logo.png" ; path to logo file, in the webroot/res/branding folder
13+
logo = "logo.png" ; path to logo file, in the webroot/assets/branding folder
14+
15+
[ldap]
16+
uri = "ldap://identity" ; URI of remote LDAP server
17+
user = "cn=admin,dc=unityhpc,dc=test" ; Admin bind DN LDAP user
18+
pass = "password" ; Admin bind password
19+
basedn = "dc=unityhpc,dc=test" ; Base search DN
20+
user_ou = "ou=users,dc=unityhpc,dc=test" ; User organizational unit
21+
group_ou = "ou=groups,dc=unityhpc,dc=test" ; Group organizational unit
22+
pigroup_ou = "ou=pi_groups,dc=unityhpc,dc=test" ; PI Group organizational unit
23+
orggroup_ou = "ou=org_groups,dc=unityhpc,dc=test" ; ORG group organizational unit
24+
admin_group = "cn=sudo,dc=unityhpc,dc=test" ; admin dn (members of this group are admins on the web portal)
25+
def_user_shell = "/bin/bash" ; Default shell for new users
26+
27+
[sql]
28+
host = "sql" ; mariadb hostname
29+
user = "unity" ; mariadb username
30+
pass = "password" ; mariadb password
31+
dbname = "unity" ; mariadb database name
32+
33+
[smtp]
34+
host = "smtp" ; hostname of remote smtp server
35+
port = "1025" ; port of remote smtp server
36+
security = "" ; leave blank for no encryption, "ssl", or "tls"
37+
user = "" ; smtp username, if exists
38+
pass = "" ; smtp password, if exists
39+
ssl_verify = "false" ; set to true to verify ssl certificates
40+
41+
[redis]
42+
host = "redis"
43+
port = "6379"
944

1045
[colors]
1146
light_background = "#ffffff" ; Background color when in light mode

Diff for: deployment/config/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Config
2+
3+
In this folder only one file can be created at this time: `config.ini`.
4+
5+
In this file you can override any of the config from the default file in `defaults/config.ini.default`. **Every deployment needs this**
File renamed without changes.
File renamed without changes.

Diff for: deployment/overrides/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Overrides
2+
3+
In this location you can make folders which have the hostname of the portal.
4+
5+
For example, if the primary virtual host is `example.com`, but you wanted to host `example.org` as well, create an `example.org` folder in this location and structure it like the main deployment folder is structured. For now, you can override the following:
6+
7+
```
8+
<override_hostname>
9+
config
10+
config.ini
11+
```
12+
13+
Everything else in the deployment folder cannot be overridden.

Diff for: resources/autoload.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
require_once __DIR__ . "/lib/UnityMailer.php";
1717
require_once __DIR__ . "/lib/UnitySSO.php";
1818
require_once __DIR__ . "/lib/UnitySite.php";
19-
require_once __DIR__ . "/lib/UnityBranding.php";
19+
require_once __DIR__ . "/lib/UnityConfig.php";
20+
require_once __DIR__ . "/lib/UnityRedis.php";
2021

2122
// run init script
2223
require __DIR__ . "/init.php";

Diff for: resources/init.php

+31-27
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
*/
66

77
use UnityWebPortal\lib\{
8-
UnityBranding,
9-
UnitySite,
8+
UnityConfig,
109
UnityLDAP,
1110
UnityMailer,
1211
UnitySQL,
1312
UnitySSO,
14-
UnityUser
13+
UnityUser,
14+
UnityRedis
1515
};
1616

1717
//
@@ -22,19 +22,24 @@
2222
//
2323
// Config INIT
2424
//
25-
$CONFIG = UnitySite::getConfig(__DIR__ . "/../config");
26-
$BRANDING = UnityBranding::getBranding(__DIR__ . "/../config/branding");
25+
$CONFIG = UnityConfig::getConfig(__DIR__ . "/../defaults", __DIR__ . "/../deployment");
2726

2827
//
2928
// Service Init
3029
//
3130

31+
// Creates REDIS service
32+
$REDIS = new UnityRedis(
33+
$CONFIG["redis"]["host"],
34+
$CONFIG["redis"]["port"]
35+
);
36+
3237
// Creates LDAP service
3338
$LDAP = new UnityLDAP(
3439
$CONFIG["ldap"]["uri"],
3540
$CONFIG["ldap"]["user"],
3641
$CONFIG["ldap"]["pass"],
37-
__DIR__ . "/../config/custom_user_mappings",
42+
__DIR__ . "/../deployment/custom_user_mappings",
3843
$CONFIG["ldap"]["user_ou"],
3944
$CONFIG["ldap"]["group_ou"],
4045
$CONFIG["ldap"]["pigroup_ou"],
@@ -54,22 +59,22 @@
5459
// Creates SMTP service
5560
$MAILER = new UnityMailer(
5661
__DIR__ . "/mail",
57-
__DIR__ . "/../config/mail_overrides",
62+
__DIR__ . "/../deployment/mail_overrides",
5863
$CONFIG["smtp"]["host"],
5964
$CONFIG["smtp"]["port"],
6065
$CONFIG["smtp"]["security"],
6166
$CONFIG["smtp"]["user"],
6267
$CONFIG["smtp"]["pass"],
6368
$CONFIG["smtp"]["ssl_verify"],
64-
$BRANDING["site"]["url"] . $CONFIG["site"]["prefix"],
65-
$BRANDING["mail"]["sender"],
66-
$BRANDING["mail"]["sender_name"],
67-
$BRANDING["mail"]["support"],
68-
$BRANDING["mail"]["support_name"],
69-
$BRANDING["mail"]["admin"],
70-
$BRANDING["mail"]["admin_name"],
71-
$BRANDING["mail"]["pi_approve"],
72-
$BRANDING["mail"]["pi_approve_name"]
69+
$CONFIG["site"]["url"] . $CONFIG["site"]["prefix"],
70+
$CONFIG["mail"]["sender"],
71+
$CONFIG["mail"]["sender_name"],
72+
$CONFIG["mail"]["support"],
73+
$CONFIG["mail"]["support_name"],
74+
$CONFIG["mail"]["admin"],
75+
$CONFIG["mail"]["admin_name"],
76+
$CONFIG["mail"]["pi_approve"],
77+
$CONFIG["mail"]["pi_approve_name"]
7378
);
7479

7580
//
@@ -81,24 +86,23 @@
8186
// SSO is available
8287
$_SESSION["SSO"] = $SSO;
8388

84-
// add sso login entry to mysql table
85-
$SQL->addSSOEntry(
86-
$SSO["user"],
87-
$SSO["org"],
88-
$SSO["firstname"],
89-
$SSO["lastname"],
90-
$SSO["mail"]
91-
);
92-
93-
$USER = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER);
89+
$USER = new UnityUser($SSO["user"], $LDAP, $SQL, $MAILER, $REDIS);
9490
$_SESSION["is_admin"] = $USER->isAdmin();
9591

9692
if (isset($_SESSION["viewUser"]) && $_SESSION["is_admin"]) {
97-
$USER = new UnityUser($_SESSION["viewUser"], $LDAP, $SQL, $MAILER);
93+
$USER = new UnityUser($_SESSION["viewUser"], $LDAP, $SQL, $MAILER, $REDIS);
9894
}
9995

10096
$_SESSION["user_exists"] = $USER->exists();
10197
$_SESSION["is_pi"] = $USER->isPI();
98+
99+
if (!$_SESSION["user_exists"]) {
100+
// populate cache
101+
$REDIS->setCache($SSO["user"], "org", $SSO["org"]);
102+
$REDIS->setCache($SSO["user"], "firstname", $SSO["firstname"]);
103+
$REDIS->setCache($SSO["user"], "lastname", $SSO["lastname"]);
104+
$REDIS->setCache($SSO["user"], "mail", $SSO["mail"]);
105+
}
102106
}
103107

104108
//

Diff for: resources/lib/UnityBranding.php

-25
This file was deleted.

Diff for: resources/lib/UnityConfig.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace UnityWebPortal\lib;
4+
5+
class UnityConfig
6+
{
7+
public static function getConfig($def_config_loc, $deploy_loc)
8+
{
9+
// Loading branding
10+
$CONFIG = parse_ini_file($def_config_loc . "/config.ini.default", true);
11+
12+
$CONFIG = self::pullConfig($CONFIG, $deploy_loc);
13+
14+
// URL-based override
15+
if (array_key_exists("HTTP_HOST", $_SERVER)) {
16+
$cur_url = $_SERVER['HTTP_HOST'];
17+
$url_override_path = $deploy_loc . "/overrides/" . $cur_url;
18+
if (is_dir($url_override_path)) {
19+
$CONFIG = self::pullConfig($CONFIG, $url_override_path);
20+
}
21+
}
22+
23+
return $CONFIG;
24+
}
25+
26+
private static function pullConfig($CONFIG, $loc)
27+
{
28+
$file_loc = $loc . "/config/config.ini";
29+
if (file_exists(($file_loc))) {
30+
$CONFIG_override = parse_ini_file($file_loc, true);
31+
return array_replace_recursive($CONFIG, $CONFIG_override);
32+
} else {
33+
return $CONFIG;
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)