diff --git a/defaults/config.ini.default b/defaults/config.ini.default index a505140f..5b65a687 100644 --- a/defaults/config.ini.default +++ b/defaults/config.ini.default @@ -8,7 +8,7 @@ repo = "https://github.com/UnityHPC/unity-web-portal" ; Upstream URL for the we [site] prefix = "" ; prefix of website, no ending / should be included name = "Unity Cluster" ; Name of the website -url = "https://127.0.0.1:8000/" ; URL of the website +url = "http://127.0.0.1:8000/" ; URL of the website description = "The Unity Web Portal is a lightweight HPC cluster front-end" ; Description of the website logo = "logo.png" ; path to logo file, in the webroot/assets/branding folder terms_of_service_url = "https://github.com" ; this can be external or a portal page created with "content management" diff --git a/resources/lib/UnityHTTPD.php b/resources/lib/UnityHTTPD.php index bed4bb95..0b722344 100644 --- a/resources/lib/UnityHTTPD.php +++ b/resources/lib/UnityHTTPD.php @@ -41,7 +41,7 @@ public static function die(mixed $x = null, bool $show_user = false): never */ public static function redirect(?string $dest = null): never { - $dest ??= pathJoin(CONFIG["site"]["prefix"], $_SERVER["REQUEST_URI"]); + $dest ??= getURL($_SERVER["REQUEST_URI"]); $dest = htmlspecialchars($dest); header("Location: $dest"); http_response_code(302); diff --git a/resources/lib/UnityMailer.php b/resources/lib/UnityMailer.php index 51a1aeba..da5b85ef 100644 --- a/resources/lib/UnityMailer.php +++ b/resources/lib/UnityMailer.php @@ -13,7 +13,6 @@ class UnityMailer extends PHPMailer private string $template_dir = __DIR__ . "/../mail"; // location of all email templates private string $override_template_dir = __DIR__ . "/../../deployment/mail_overrides"; - private string $MSG_LINKREF; private string $MSG_SENDER_EMAIL; private string $MSG_SENDER_NAME; private string $MSG_SUPPORT_EMAIL; @@ -28,7 +27,6 @@ public function __construct() parent::__construct(); $this->isSMTP(); - $this->MSG_LINKREF = CONFIG["site"]["url"] . CONFIG["site"]["prefix"]; $this->MSG_SENDER_EMAIL = CONFIG["mail"]["sender"]; $this->MSG_SENDER_NAME = CONFIG["mail"]["sender_name"]; $this->MSG_SUPPORT_EMAIL = CONFIG["mail"]["support"]; diff --git a/resources/lib/UnityWebhook.php b/resources/lib/UnityWebhook.php index 80203762..522b644a 100644 --- a/resources/lib/UnityWebhook.php +++ b/resources/lib/UnityWebhook.php @@ -7,13 +7,8 @@ class UnityWebhook private string $template_dir = __DIR__ . "/../mail"; private string $override_template_dir = __DIR__ . "/../../deployment/mail_overrides"; private string $url = CONFIG["webhook"]["url"]; - private string $MSG_LINKREF; private string $Subject; // set by template - public function __construct() - { - $this->MSG_LINKREF = CONFIG["site"]["url"] . CONFIG["site"]["prefix"]; - } public function htmlToMarkdown(string $html): string { // Define regex patterns for each markdown format diff --git a/resources/lib/utils.php b/resources/lib/utils.php index a9a04aa8..4250cfd6 100644 --- a/resources/lib/utils.php +++ b/resources/lib/utils.php @@ -72,13 +72,28 @@ function mbDetectEncoding(string $string, ?array $encodings = null, mixed $_ = n } /* https://stackoverflow.com/a/15575293/18696276 */ -function pathJoin() +function pathNormalize(string $path) { - $paths = []; - foreach (func_get_args() as $arg) { - if ($arg !== "") { - $paths[] = $arg; - } + return preg_replace("#/+#", "/", $path); +} + +function getURL(...$relative_url_components) +{ + if (!preg_match("#^\w+://#", CONFIG["site"]["url"])) { + throw new RuntimeException('CONFIG[site][url] does not have a scheme! (ex: "https://")'); } - return preg_replace("#/+#", "/", join("/", $paths)); + $matches = []; + preg_match("#(^\w+://)(.*)#", CONFIG["site"]["url"], $matches); + [$_, $site_url_scheme, $site_url_noscheme] = $matches; + $path = join("/", [$site_url_noscheme, CONFIG["site"]["prefix"], ...$relative_url_components]); + $path_normalized = pathNormalize($path); + return $site_url_scheme . $path_normalized; +} + +function getHyperlink($text, ...$url_components) +{ + $text = htmlspecialchars($text); + $url_components = array_map("htmlspecialchars", $url_components); + $url = getURL(...$url_components); + return "$text"; } diff --git a/resources/mail/footer.php b/resources/mail/footer.php index 9e6a712b..79e80fce 100644 --- a/resources/mail/footer.php +++ b/resources/mail/footer.php @@ -3,7 +3,7 @@ > You are receiving this email because you have an account - on the Unity Cluster. + on the . If you would like to stop receiving these emails, you may request to close your account by replying to this email. diff --git a/resources/mail/group_created.php b/resources/mail/group_created.php index 618ef57f..09c9c7d0 100644 --- a/resources/mail/group_created.php +++ b/resources/mail/group_created.php @@ -8,7 +8,7 @@

Your request for a PI account on the Unity cluster has been approved. You can access the management page for your group -on this page. +.

Do not hesitate to reply if you have any questions!

diff --git a/resources/mail/group_request_admin.php b/resources/mail/group_request_admin.php index 8fe51027..0dfd8201 100644 --- a/resources/mail/group_request_admin.php +++ b/resources/mail/group_request_admin.php @@ -19,6 +19,6 @@

You can approve this account -here + .

diff --git a/resources/mail/group_user_added.php b/resources/mail/group_user_added.php index 9c42b8cc..1fb9d6bd 100644 --- a/resources/mail/group_user_added.php +++ b/resources/mail/group_user_added.php @@ -6,7 +6,7 @@

Hello,

You have been approved to join the PI group . -Navigate to the my groups +Navigate to the page to see your PI groups.

If you believe this to be a mistake, please reply to this email as soon as possible.

diff --git a/resources/mail/group_user_request_owner.php b/resources/mail/group_user_request_owner.php index 9ad4db55..b2db8638 100644 --- a/resources/mail/group_user_request_owner.php +++ b/resources/mail/group_user_request_owner.php @@ -22,4 +22,4 @@

You can approve or deny this user on the - my users page

+ page

diff --git a/resources/mail/user_loginshell.php b/resources/mail/user_loginshell.php index c21337dd..393bfdc5 100644 --- a/resources/mail/user_loginshell.php +++ b/resources/mail/user_loginshell.php @@ -7,6 +7,6 @@

You have updated your login shell on the Unity cluster to . You can view the login shell settings on the -account settings page

+ page

If you believe this to be a mistake, please reply to this email as soon as possible.

diff --git a/resources/mail/user_qualified.php b/resources/mail/user_qualified.php index 512930c3..e3c348bc 100644 --- a/resources/mail/user_qualified.php +++ b/resources/mail/user_qualified.php @@ -15,6 +15,6 @@

Please login to the web portal to access Unity. If you need console access, you will need to set your SSH keys in the - account settings page.

+ page.

If you believe this to be a mistake, please reply to this email as soon as possible.

diff --git a/resources/mail/user_sshkey.php b/resources/mail/user_sshkey.php index 5a4a8076..8ec90a86 100644 --- a/resources/mail/user_sshkey.php +++ b/resources/mail/user_sshkey.php @@ -15,7 +15,7 @@

You can view the SSH public keys attached to your account on the -account settings + page.

diff --git a/resources/templates/footer.php b/resources/templates/footer.php index e5cd3d2c..a363d91a 100644 --- a/resources/templates/footer.php +++ b/resources/templates/footer.php @@ -10,7 +10,7 @@ for ($i = 0; $i < count($footer_logos); $i++) { echo " - "; } ?> @@ -29,10 +29,10 @@ - - - - - - +"; +} +?> diff --git a/resources/templates/header.php b/resources/templates/header.php index 2e466f85..c362c7dd 100644 --- a/resources/templates/header.php +++ b/resources/templates/header.php @@ -8,7 +8,7 @@ && ($_POST["form_type"] ?? null) == "clearView" ) { unset($_SESSION["viewUser"]); - UnityHTTPD::redirect(CONFIG["site"]["prefix"] . "/admin/user-mgmt.php"); + UnityHTTPD::redirect(getURL("admin/user-mgmt.php")); } // Webroot files need to handle their own POSTs before loading the header // so that they can do UnityHTTPD::badRequest before anything else has been printed. @@ -24,7 +24,7 @@ !$_SESSION["user_exists"] && !str_ends_with($_SERVER['PHP_SELF'], "/panel/new_account.php") ) { - UnityHTTPD::redirect(CONFIG["site"]["prefix"] . "/panel/new_account.php"); + UnityHTTPD::redirect(getURL("panel/new_account.php")); } } @@ -49,15 +49,10 @@ - - - - - - "; + foreach (["global", "navbar", "modal", "tables", "filters", "messages"] as $x) { + $url = getURL("css/$x.css"); + echo ""; + } ?> @@ -70,11 +65,11 @@
/assets/"> + src=""> @@ -82,9 +77,8 @@ @@ -136,7 +130,7 @@
- +
diff --git a/test/unit/UtilsTest.php b/test/unit/UtilsTest.php index 3644afd3..11a12077 100644 --- a/test/unit/UtilsTest.php +++ b/test/unit/UtilsTest.php @@ -80,4 +80,29 @@ public function testTestValidSSHKey(bool $expected, string $key) { $this->assertEquals($expected, testValidSSHKey($key)); } + + public static function URLComponentProvider() + { + if (CONFIG["site"]["url"] != "http://127.0.0.1:8000/") { + throw new RuntimeException("site url has changed!"); + } + return [ + [["", ""], "http://127.0.0.1:8000/"], + [["", "/"], "http://127.0.0.1:8000/"], + [["/", "a"], "http://127.0.0.1:8000/a"], + [["/", "/a"], "http://127.0.0.1:8000/a"], + [["abc", "def"], "http://127.0.0.1:8000/abc/def"], + [["abc", "/def"], "http://127.0.0.1:8000/abc/def"], + [["/abc", "def"], "http://127.0.0.1:8000/abc/def"], + [["/abc", "def///"], "http://127.0.0.1:8000/abc/def/"], + [["", "foo.jpg"], "http://127.0.0.1:8000/foo.jpg"], + [["dir", "0", "a.jpg"], "http://127.0.0.1:8000/dir/0/a.jpg"], + ]; + } + + #[DataProvider("URLComponentProvider")] + public function testGetURL(array $relative_url_components, string $expected) + { + $this->assertEquals($expected, getURL(...$relative_url_components)); + } } diff --git a/webroot/admin/content.php b/webroot/admin/content.php index 620a8fac..24a9efcd 100644 --- a/webroot/admin/content.php +++ b/webroot/admin/content.php @@ -51,10 +51,10 @@ .catch(error => { console.error(error) }); - const prefix = ''; + const url = ''; $("#pageForm > select[name=pageSel]").change(function(e) { $.ajax({ - url: `${prefix}/admin/ajax/get_page_contents.php?pageid=` + $(this).val(), + url: `${url}?pageid=` + $(this).val(), success: function(result) { mainEditor.setData(result); }}); diff --git a/webroot/admin/pi-mgmt.php b/webroot/admin/pi-mgmt.php index 7b161a4b..09b461c1 100644 --- a/webroot/admin/pi-mgmt.php +++ b/webroot/admin/pi-mgmt.php @@ -143,7 +143,7 @@ class="filterSearch" } }); - var ajax_url = "/admin/ajax/get_group_members.php?gid="; + var ajax_url = "?gid="; You are curently a qualified user on the Unity Cluster

"; } else { $tos_url = CONFIG["site"]["terms_of_service_url"]; - $sitePrefix = CONFIG["site"]["prefix"]; + $form_url = getURL("panel/groups.php"); echo "

You are currently an unqualified user, and will be @@ -137,7 +137,7 @@ Do not request a PI group if you are a student.


-
+