index.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 (($user_plain == "admin" && $api_status < 1) || ($user_plain != "admin" && $api_status < 2)) {
  17. header("Location: /edit/user/");
  18. exit();
  19. }
  20. if (empty($_POST["key"])) {
  21. header("Location: /list/access-key/");
  22. exit();
  23. }
  24. if (empty($_POST["action"])) {
  25. header("Location: /list/access-key/");
  26. exit();
  27. }
  28. $key = $_POST["key"];
  29. $action = $_POST["action"];
  30. switch ($action) {
  31. case "delete":
  32. $cmd = "v-delete-access-key";
  33. break;
  34. default:
  35. header("Location: /list/access-key/");
  36. exit();
  37. }
  38. foreach ($key as $value) {
  39. $v_key = quoteshellarg(trim($value));
  40. // Key data
  41. exec(HESTIA_CMD . "v-list-access-key " . $v_key . " json", $output, $return_var);
  42. $key_data = json_decode(implode("", $output), true);
  43. unset($output);
  44. if (!empty($key_data) && $key_data["USER"] == $user_plain) {
  45. exec(HESTIA_CMD . $cmd . " " . $v_key, $output, $return_var);
  46. unset($output);
  47. }
  48. }
  49. header("Location: /list/access-key/");