index.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. use function Hestiacp\quoteshellarg\quoteshellarg;
  3. ob_start();
  4. include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
  5. // Check token
  6. verify_csrf($_POST);
  7. if ($_SESSION["userContext"] === "admin" && !empty($_GET["user"])) {
  8. $user = quoteshellarg($_GET["user"]);
  9. $user_plain = $_GET["user"];
  10. }
  11. // Checks if API access is enabled
  12. $api_status =
  13. !empty($_SESSION["API_SYSTEM"]) && is_numeric($_SESSION["API_SYSTEM"])
  14. ? $_SESSION["API_SYSTEM"]
  15. : 0;
  16. if (
  17. ($user_plain == $_SESSION["ROOT_USER"] && $api_status < 1) ||
  18. ($user_plain != $_SESSION["ROOT_USER"] && $api_status < 2)
  19. ) {
  20. header("Location: /edit/user/");
  21. exit();
  22. }
  23. if (empty($_POST["key"])) {
  24. header("Location: /list/access-key/");
  25. exit();
  26. }
  27. if (empty($_POST["action"])) {
  28. header("Location: /list/access-key/");
  29. exit();
  30. }
  31. $key = $_POST["key"];
  32. $action = $_POST["action"];
  33. switch ($action) {
  34. case "delete":
  35. $cmd = "v-delete-access-key";
  36. break;
  37. default:
  38. header("Location: /list/access-key/");
  39. exit();
  40. }
  41. foreach ($key as $value) {
  42. $v_key = quoteshellarg(trim($value));
  43. // Key data
  44. exec(HESTIA_CMD . "v-list-access-key " . $v_key . " json", $output, $return_var);
  45. $key_data = json_decode(implode("", $output), true);
  46. unset($output);
  47. if (!empty($key_data) && $key_data["USER"] == $user_plain) {
  48. exec(HESTIA_CMD . $cmd . " " . $v_key, $output, $return_var);
  49. unset($output);
  50. }
  51. }
  52. header("Location: /list/access-key/");