From d8407d05e62da00bc68380c3cb5a58f9368840c0 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Wed, 10 Sep 2025 11:01:10 -0400 Subject: [PATCH 01/11] make CONFIG a constant --- resources/autoload.php | 2 +- resources/config.php | 5 +++ resources/init.php | 77 ++++++++++++++++----------------- resources/templates/footer.php | 22 +++++----- resources/templates/header.php | 34 +++++++-------- test/phpunit-bootstrap.php | 6 +-- webroot/admin/content.php | 2 +- webroot/admin/pi-mgmt.php | 2 +- webroot/admin/user-mgmt.php | 2 +- webroot/index.php | 2 +- webroot/panel/account.php | 4 +- webroot/panel/groups.php | 10 ++--- webroot/panel/modal/new_key.php | 6 +-- webroot/panel/modal/new_pi.php | 4 +- webroot/panel/new_account.php | 12 ++--- webroot/panel/pi.php | 2 +- webroot/panel/support.php | 2 +- workers/update-ldap-cache.php | 6 +-- 18 files changed, 102 insertions(+), 98 deletions(-) create mode 100644 resources/config.php diff --git a/resources/autoload.php b/resources/autoload.php index 0942efc6..2eb533a1 100644 --- a/resources/autoload.php +++ b/resources/autoload.php @@ -26,5 +26,5 @@ require_once __DIR__ . "/lib/UnityGithub.php"; require_once __DIR__ . "/lib/exceptions/SSOException.php"; -// run init script +require_once __DIR__ . "/config.php"; require __DIR__ . "/init.php"; diff --git a/resources/config.php b/resources/config.php new file mode 100644 index 00000000..ac43e9ed --- /dev/null +++ b/resources/config.php @@ -0,0 +1,5 @@ +exists(); $_SESSION["is_pi"] = $USER->isPI(); - $SEND_PIMESG_TO_ADMINS = $CONFIG["mail"]["send_pimesg_to_admins"]; + $SEND_PIMESG_TO_ADMINS = CONFIG["mail"]["send_pimesg_to_admins"]; $SQL->addLog( $OPERATOR->uid, diff --git a/resources/templates/footer.php b/resources/templates/footer.php index 9c74c223..e5cd3d2c 100644 --- a/resources/templates/footer.php +++ b/resources/templates/footer.php @@ -4,13 +4,13 @@
- "; } ?> @@ -19,20 +19,20 @@
Unity Web Portal Version - "> - + "> +  | - ">Terms of Service + ">Terms of Service
- - - - + + + + diff --git a/resources/templates/header.php b/resources/templates/header.php index adb42b3a..496c79f1 100644 --- a/resources/templates/header.php +++ b/resources/templates/header.php @@ -8,7 +8,7 @@ && (@$_POST["form_type"] ?? null) == "clearView" ) { unset($_SESSION["viewUser"]); - UnitySite::redirect($CONFIG["site"]["prefix"] . "/admin/user-mgmt.php"); + UnitySite::redirect(CONFIG["site"]["prefix"] . "/admin/user-mgmt.php"); } // Webroot files need to handle their own POSTs before loading the header // so that they can do UnitySite::badRequest before anything else has been printed. @@ -16,7 +16,7 @@ // header also needs to handle POST data. So this header does the PRG redirect // for all pages. unset($_POST); // unset ensures that header must not come before POST handling - UnitySite::redirect($CONFIG["site"]["prefix"] . $_SERVER['REQUEST_URI']); + UnitySite::redirect(CONFIG["site"]["prefix"] . $_SERVER['REQUEST_URI']); } if (isset($SSO)) { @@ -24,7 +24,7 @@ !$_SESSION["user_exists"] && !str_ends_with($_SERVER['PHP_SELF'], "/panel/new_account.php") ) { - UnitySite::redirect($CONFIG["site"]["prefix"] . "/panel/new_account.php"); + UnitySite::redirect(CONFIG["site"]["prefix"] . "/panel/new_account.php"); } } @@ -41,7 +41,7 @@ $var_value) { + foreach (CONFIG["colors"] as $var_name => $var_value) { echo "--$var_name: $var_value;"; } echo "}"; @@ -49,7 +49,7 @@ @@ -60,20 +60,20 @@ ?> - "> + "> - <?php echo $CONFIG["site"]["name"]; ?> + <?php echo CONFIG["site"]["name"]; ?>
/assets/"> + src="/assets/"> @@ -81,14 +81,14 @@
- +
diff --git a/test/phpunit-bootstrap.php b/test/phpunit-bootstrap.php index 6aba6af2..4fe54777 100644 --- a/test/phpunit-bootstrap.php +++ b/test/phpunit-bootstrap.php @@ -64,7 +64,7 @@ function switchUser( string $mail, string|null $session_id = null ): void { - global $CONFIG, $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 . "_"))); @@ -83,7 +83,7 @@ function switchUser( function http_post(string $phpfile, array $post_data): void { - global $CONFIG, $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); @@ -106,7 +106,7 @@ function http_post(string $phpfile, array $post_data): void function http_get(string $phpfile, array $get_data = array()): void { - global $CONFIG, $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); diff --git a/webroot/admin/content.php b/webroot/admin/content.php index d0821e07..9cab5ba8 100644 --- a/webroot/admin/content.php +++ b/webroot/admin/content.php @@ -51,7 +51,7 @@ .catch(error => { console.error(error) }); - const prefix = ''; + const prefix = ''; $("#pageForm > select[name=pageSel]").change(function(e) { $.ajax({ url: `${prefix}/admin/ajax/get_page_contents.php?pageid=` + $(this).val(), diff --git a/webroot/admin/pi-mgmt.php b/webroot/admin/pi-mgmt.php index efcf798f..86edbd0a 100644 --- a/webroot/admin/pi-mgmt.php +++ b/webroot/admin/pi-mgmt.php @@ -135,7 +135,7 @@ class="filterSearch" } }); - var ajax_url = "/admin/ajax/get_group_members.php?gid="; + var ajax_url = "/admin/ajax/get_group_members.php?gid="; getPage($CONFIG["page"]["home"])["content"]; +echo $SQL->getPage(CONFIG["page"]["home"])["content"]; ?>

Cluster Notices

diff --git a/webroot/panel/account.php b/webroot/panel/account.php index 7eac043f..d8a51c93 100644 --- a/webroot/panel/account.php +++ b/webroot/panel/account.php @@ -204,7 +204,7 @@
@@ -69,7 +69,7 @@ function generateKey(type) { var endingSection = ""; $.ajax({ - url: "/js/ajax/ssh_generate.php?type=" + type, + url: "/js/ajax/ssh_generate.php?type=" + type, success: function(result) { var pubKey = result.substr(result.indexOf(pubSection) + pubSection.length, result.indexOf(endingSection) - result.indexOf(pubSection) - pubSection.length); @@ -98,7 +98,7 @@ function generateKey(type) { $("textarea[name=key]").on("input", function() { var key = $(this).val(); $.ajax({ - url: "/js/ajax/ssh_validate.php", + url: "/js/ajax/ssh_validate.php", type: "POST", data: { key: key diff --git a/webroot/panel/modal/new_pi.php b/webroot/panel/modal/new_pi.php index 9394be5e..53368e96 100644 --- a/webroot/panel/modal/new_pi.php +++ b/webroot/panel/modal/new_pi.php @@ -6,7 +6,7 @@
/panel/groups.php" + action="/panel/groups.php" >
@@ -19,7 +19,7 @@