Skip to content

Commit ff8a10b

Browse files
authored
Limit v-change-user-ns only to admin user (hestiacp#3761)
* Limit v-change-ns only to admin users * Fix bug with edit user and viewing / deleting logs * Allow admin always change state
1 parent e4e1a9f commit ff8a10b

File tree

6 files changed

+93
-85
lines changed

6 files changed

+93
-85
lines changed

web/add/cron/autoupdate/index.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
// Check token
66
verify_csrf($_GET);
77

8-
if ($_SESSION["userContext"] === "admin" && $_SESSION["POLICY_SYSTEM_HIDE_SERVICES"] == "no") {
8+
if (
9+
($_SESSION["userContext"] === "admin" && $_SESSION["POLICY_SYSTEM_HIDE_SERVICES"] == "no") ||
10+
$_SESSION["user"] == "admin"
11+
) {
912
exec(HESTIA_CMD . "v-add-cron-hestia-autoupdate", $output, $return_var);
1013
unset($output);
1114
}

web/delete/cron/autoupdate/index.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
// Check token
77
verify_csrf($_GET);
88

9-
if ($_SESSION["userContext"] === "admin" && $_SESSION["POLICY_SYSTEM_HIDE_SERVICES"] == "no") {
9+
if (
10+
($_SESSION["userContext"] === "admin" && $_SESSION["POLICY_SYSTEM_HIDE_SERVICES"] == "no") ||
11+
$_SESSION["user"] == "admin"
12+
) {
1013
exec(HESTIA_CMD . "v-delete-cron-hestia-autoupdate", $output, $return_var);
1114
unset($output);
1215
}

web/delete/log/auth/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
// Set correct page reload target
5454
if ($_SESSION["userContext"] === "admin" && !empty($_GET["user"])) {
55-
header("Location: /list/log/auth/?user=$user&token=$token");
55+
header("Location: /list/log/auth/?user=" . $_GET["user"] . "&token=$token");
5656
} else {
5757
header("Location: /list/log/auth/");
5858
}

web/delete/log/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// Set correct page reload target
2424
if ($_SESSION["userContext"] === "admin" && !empty($_GET["user"])) {
2525
if ($_GET["user"] != "system") {
26-
header("Location: /list/log/?user=$user&token=$token");
26+
header("Location: /list/log/?user=" . $_GET["user"] . "&token=$token");
2727
} else {
2828
header("Location: /list/log/?user=system&token=$token");
2929
}

web/edit/user/index.php

Lines changed: 79 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -452,90 +452,92 @@
452452
}
453453

454454
if (!empty($_SESSION["DNS_SYSTEM"])) {
455-
// Change NameServers
456-
if (empty($_POST["v_ns1"])) {
457-
$_POST["v_ns1"] = "";
458-
}
459-
if (empty($_POST["v_ns2"])) {
460-
$_POST["v_ns2"] = "";
461-
}
462-
if (empty($_POST["v_ns3"])) {
463-
$_POST["v_ns3"] = "";
464-
}
465-
if (empty($_POST["v_ns4"])) {
466-
$_POST["v_ns4"] = "";
467-
}
468-
if (empty($_POST["v_ns5"])) {
469-
$_POST["v_ns5"] = "";
470-
}
471-
if (empty($_POST["v_ns6"])) {
472-
$_POST["v_ns6"] = "";
473-
}
474-
if (empty($_POST["v_ns7"])) {
475-
$_POST["v_ns7"] = "";
476-
}
477-
if (empty($_POST["v_ns8"])) {
478-
$_POST["v_ns8"] = "";
479-
}
480-
481-
if (
482-
$v_ns1 != $_POST["v_ns1"] ||
483-
$v_ns2 != $_POST["v_ns2"] ||
484-
$v_ns3 != $_POST["v_ns3"] ||
485-
$v_ns4 != $_POST["v_ns4"] ||
486-
$v_ns5 != $_POST["v_ns5"] ||
487-
$v_ns6 != $_POST["v_ns6"] ||
488-
$v_ns7 != $_POST["v_ns7"] ||
489-
($v_ns8 != $_POST["v_ns8"] &&
490-
empty($_SESSION["error_msg"] && !empty($_POST["v_ns1"]) && $_POST["v_ns2"]))
491-
) {
492-
$v_ns1 = quoteshellarg($_POST["v_ns1"]);
493-
$v_ns2 = quoteshellarg($_POST["v_ns2"]);
494-
$v_ns3 = quoteshellarg($_POST["v_ns3"]);
495-
$v_ns4 = quoteshellarg($_POST["v_ns4"]);
496-
$v_ns5 = quoteshellarg($_POST["v_ns5"]);
497-
$v_ns6 = quoteshellarg($_POST["v_ns6"]);
498-
$v_ns7 = quoteshellarg($_POST["v_ns7"]);
499-
$v_ns8 = quoteshellarg($_POST["v_ns8"]);
500-
501-
$ns_cmd =
502-
HESTIA_CMD .
503-
"v-change-user-ns " .
504-
quoteshellarg($v_username) .
505-
" " .
506-
$v_ns1 .
507-
" " .
508-
$v_ns2;
509-
if (!empty($_POST["v_ns3"])) {
510-
$ns_cmd = $ns_cmd . " " . $v_ns3;
455+
if ($_SESSION["userContext"] === "admin") {
456+
// Change NameServers
457+
if (empty($_POST["v_ns1"])) {
458+
$_POST["v_ns1"] = "";
511459
}
512-
if (!empty($_POST["v_ns4"])) {
513-
$ns_cmd = $ns_cmd . " " . $v_ns4;
460+
if (empty($_POST["v_ns2"])) {
461+
$_POST["v_ns2"] = "";
514462
}
515-
if (!empty($_POST["v_ns5"])) {
516-
$ns_cmd = $ns_cmd . " " . $v_ns5;
463+
if (empty($_POST["v_ns3"])) {
464+
$_POST["v_ns3"] = "";
517465
}
518-
if (!empty($_POST["v_ns6"])) {
519-
$ns_cmd = $ns_cmd . " " . $v_ns6;
466+
if (empty($_POST["v_ns4"])) {
467+
$_POST["v_ns4"] = "";
520468
}
521-
if (!empty($_POST["v_ns7"])) {
522-
$ns_cmd = $ns_cmd . " " . $v_ns7;
469+
if (empty($_POST["v_ns5"])) {
470+
$_POST["v_ns5"] = "";
523471
}
524-
if (!empty($_POST["v_ns8"])) {
525-
$ns_cmd = $ns_cmd . " " . $v_ns8;
472+
if (empty($_POST["v_ns6"])) {
473+
$_POST["v_ns6"] = "";
474+
}
475+
if (empty($_POST["v_ns7"])) {
476+
$_POST["v_ns7"] = "";
477+
}
478+
if (empty($_POST["v_ns8"])) {
479+
$_POST["v_ns8"] = "";
526480
}
527-
exec($ns_cmd, $output, $return_var);
528-
check_return_code($return_var, $output);
529-
unset($output);
530481

531-
$v_ns1 = str_replace("'", "", $v_ns1);
532-
$v_ns2 = str_replace("'", "", $v_ns2);
533-
$v_ns3 = str_replace("'", "", $v_ns3);
534-
$v_ns4 = str_replace("'", "", $v_ns4);
535-
$v_ns5 = str_replace("'", "", $v_ns5);
536-
$v_ns6 = str_replace("'", "", $v_ns6);
537-
$v_ns7 = str_replace("'", "", $v_ns7);
538-
$v_ns8 = str_replace("'", "", $v_ns8);
482+
if (
483+
$v_ns1 != $_POST["v_ns1"] ||
484+
$v_ns2 != $_POST["v_ns2"] ||
485+
$v_ns3 != $_POST["v_ns3"] ||
486+
$v_ns4 != $_POST["v_ns4"] ||
487+
$v_ns5 != $_POST["v_ns5"] ||
488+
$v_ns6 != $_POST["v_ns6"] ||
489+
$v_ns7 != $_POST["v_ns7"] ||
490+
($v_ns8 != $_POST["v_ns8"] &&
491+
empty($_SESSION["error_msg"] && !empty($_POST["v_ns1"]) && $_POST["v_ns2"]))
492+
) {
493+
$v_ns1 = quoteshellarg($_POST["v_ns1"]);
494+
$v_ns2 = quoteshellarg($_POST["v_ns2"]);
495+
$v_ns3 = quoteshellarg($_POST["v_ns3"]);
496+
$v_ns4 = quoteshellarg($_POST["v_ns4"]);
497+
$v_ns5 = quoteshellarg($_POST["v_ns5"]);
498+
$v_ns6 = quoteshellarg($_POST["v_ns6"]);
499+
$v_ns7 = quoteshellarg($_POST["v_ns7"]);
500+
$v_ns8 = quoteshellarg($_POST["v_ns8"]);
501+
502+
$ns_cmd =
503+
HESTIA_CMD .
504+
"v-change-user-ns " .
505+
quoteshellarg($v_username) .
506+
" " .
507+
$v_ns1 .
508+
" " .
509+
$v_ns2;
510+
if (!empty($_POST["v_ns3"])) {
511+
$ns_cmd = $ns_cmd . " " . $v_ns3;
512+
}
513+
if (!empty($_POST["v_ns4"])) {
514+
$ns_cmd = $ns_cmd . " " . $v_ns4;
515+
}
516+
if (!empty($_POST["v_ns5"])) {
517+
$ns_cmd = $ns_cmd . " " . $v_ns5;
518+
}
519+
if (!empty($_POST["v_ns6"])) {
520+
$ns_cmd = $ns_cmd . " " . $v_ns6;
521+
}
522+
if (!empty($_POST["v_ns7"])) {
523+
$ns_cmd = $ns_cmd . " " . $v_ns7;
524+
}
525+
if (!empty($_POST["v_ns8"])) {
526+
$ns_cmd = $ns_cmd . " " . $v_ns8;
527+
}
528+
exec($ns_cmd, $output, $return_var);
529+
check_return_code($return_var, $output);
530+
unset($output);
531+
532+
$v_ns1 = str_replace("'", "", $v_ns1);
533+
$v_ns2 = str_replace("'", "", $v_ns2);
534+
$v_ns3 = str_replace("'", "", $v_ns3);
535+
$v_ns4 = str_replace("'", "", $v_ns4);
536+
$v_ns5 = str_replace("'", "", $v_ns5);
537+
$v_ns6 = str_replace("'", "", $v_ns6);
538+
$v_ns7 = str_replace("'", "", $v_ns7);
539+
$v_ns8 = str_replace("'", "", $v_ns8);
540+
}
539541
}
540542
}
541543

web/templates/pages/edit_user.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
</a>
88
<?php
99
if (($_SESSION['userContext'] === 'admin') && (!isset($_SESSION['look'])) && ($_SESSION['user'] !== $v_username)) {
10-
$ssh_key_url = "/list/key/?user=".htmlentities($user_plain)."&token=".$_SESSION['token']."";
11-
$log_url = "/list/log/?user=".htmlentities($user_plain)."&token=".$_SESSION['token']."";
12-
$keys_url = "/list/access-key/?user=".htmlentities($user_plain)."&token=".$_SESSION['token']."";
13-
} else {
10+
$ssh_key_url = "/list/key/?user=".htmlentities($_GET['user'])."&token=".$_SESSION['token']."";
11+
$log_url = "/list/log/?user=".htmlentities($_GET['user'])."&token=".$_SESSION['token']."";
12+
$keys_url = "/list/access-key/?user=".htmlentities($_GET['user'])."&token=".$_SESSION['token']."";
13+
}else{
1414
$ssh_key_url = "/list/key/";
1515
$log_url = "/list/log/";
1616
$keys_url = "/list/access-key/";

0 commit comments

Comments
 (0)