From 7556990fcca87cef16d9b1dc97b2897a24fec359 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 13:02:24 -0400 Subject: [PATCH 1/2] replace hacky JS with standard alert function --- resources/lib/UnitySite.php | 4 ++++ webroot/panel/account.php | 8 +++----- webroot/panel/groups.php | 26 ++++++++------------------ 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/resources/lib/UnitySite.php b/resources/lib/UnitySite.php index 2bedf8a6..3bd9773c 100644 --- a/resources/lib/UnitySite.php +++ b/resources/lib/UnitySite.php @@ -56,4 +56,8 @@ public static function testValidSSHKey($key_str) return false; } } + + public function alert(string $msg): void{ + echo ""; + } } diff --git a/webroot/panel/account.php b/webroot/panel/account.php index c45602ca..59d2c282 100644 --- a/webroot/panel/account.php +++ b/webroot/panel/account.php @@ -6,9 +6,7 @@ require_once $LOC_HEADER; -$invalid_ssh_dialogue = ""; +$invalid_ssh_dialogue = "Invalid SSH key. Please verify your public key file is valid."; if ($_SERVER['REQUEST_METHOD'] == "POST") { switch ($_POST["form_type"]) { @@ -21,7 +19,7 @@ if (UnitySite::testValidSSHKey($key)) { array_push($added_keys, $key); } else { - echo $invalid_ssh_dialogue; + $SITE->alert($invalid_ssh_dialogue); } break; case "import": @@ -30,7 +28,7 @@ if (UnitySite::testValidSSHKey($key)) { array_push($added_keys, $key); } else { - echo $invalid_ssh_dialogue; + $SITE->alert($invalid_ssh_dialogue); } break; case "generate": diff --git a/webroot/panel/groups.php b/webroot/panel/groups.php index d1b2a013..a8c76d6e 100644 --- a/webroot/panel/groups.php +++ b/webroot/panel/groups.php @@ -9,11 +9,12 @@ $errors = array(); if (isset($_POST["form_name"])) { + $ok = true; if (isset($_POST["pi"])) { $pi_account = new UnityGroup(trim($_POST["pi"]), $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK); if (!$pi_account->exists()) { - // "\'" instead of "'", otherwise it will close a single quote used to place the message - array_push($modalErrors, "This PI doesn\'t exist"); + $SITE->alert("This PI doesn't exist"); + $ok = false; } } @@ -23,15 +24,17 @@ // existing PI request if ($pi_account->requestExists($USER)) { - array_push($modalErrors, "You\'ve already requested this"); + $SITE->alert("You\'ve already requested this"); + $ok = false; } if ($pi_account->userExists($USER)) { - array_push($modalErrors, "You\'re already in this PI group"); + $SITE->alert("You\'re already in this PI group"); + $ok = false; } // Add row to sql - if (empty($modalErrors)) { + if ($ok) { $pi_account->newUserRequest($USER); } break; @@ -145,19 +148,6 @@ openModal("Add New PI", "/panel/modal/new_pi.php"); }); - 0) { - $errorHTML = ""; - foreach ($modalErrors as $error) { - $errorHTML .= "$error"; - } - - echo "openModal('Add New PI', '" . - $CONFIG["site"]["prefix"] . "/panel/modal/new_pi.php', '" . $errorHTML . "');"; - } - ?> - var ajax_url = "/panel/ajax/get_group_members.php?pi_uid="; From cf6072dd78363cf7705c1475d7bcef3ae9e3c34d Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Mon, 7 Apr 2025 13:40:53 -0400 Subject: [PATCH 2/2] fix style --- resources/lib/UnitySite.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/lib/UnitySite.php b/resources/lib/UnitySite.php index 3bd9773c..78a4eace 100644 --- a/resources/lib/UnitySite.php +++ b/resources/lib/UnitySite.php @@ -57,7 +57,8 @@ public static function testValidSSHKey($key_str) } } - public function alert(string $msg): void{ + public function alert(string $msg): void + { echo ""; } }