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
+ pageIf 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 " -