Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions resources/lib/UnitySite.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public static function testValidSSHKey($key_str)
return false;
}
}

public function alert(string $msg): void
{
echo "<script type='text/javascript'>alert(" . json_encode($msg) . ");</script>";
}
}
8 changes: 3 additions & 5 deletions webroot/panel/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

require_once $LOC_HEADER;

$invalid_ssh_dialogue = "<script type='text/javascript'>
alert('Invalid SSH key. Please verify your public key file is valid.');
</script>";
$invalid_ssh_dialogue = "Invalid SSH key. Please verify your public key file is valid.";

if ($_SERVER['REQUEST_METHOD'] == "POST") {
switch ($_POST["form_type"]) {
Expand All @@ -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":
Expand All @@ -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":
Expand Down
26 changes: 8 additions & 18 deletions webroot/panel/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand All @@ -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;
Expand Down Expand Up @@ -145,19 +148,6 @@
openModal("Add New PI", "<?php echo $CONFIG["site"]["prefix"]; ?>/panel/modal/new_pi.php");
});

<?php
// This is here to re-open the modal if there are errors
if (isset($modalErrors) && is_array($modalErrors) && count($modalErrors) > 0) {
$errorHTML = "";
foreach ($modalErrors as $error) {
$errorHTML .= "<span>$error</span>";
}

echo "openModal('Add New PI', '" .
$CONFIG["site"]["prefix"] . "/panel/modal/new_pi.php', '" . $errorHTML . "');";
}
?>

var ajax_url = "<?php echo $CONFIG["site"]["prefix"]; ?>/panel/ajax/get_group_members.php?pi_uid=";
</script>

Expand Down
Loading