index.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 (empty($_POST["domain"])) {
  8. header("Location: /list/dns/");
  9. exit();
  10. }
  11. if (empty($_POST["action"])) {
  12. header("Location: /list/dns/");
  13. exit();
  14. }
  15. $domain = $_POST["domain"];
  16. if (empty($_POST["record"])) {
  17. $record = "";
  18. } else {
  19. $record = $_POST["record"];
  20. }
  21. $action = $_POST["action"];
  22. if ($_SESSION["userContext"] === "admin") {
  23. if (empty($_POST["record"])) {
  24. switch ($action) {
  25. case "rebuild":
  26. $cmd = "v-rebuild-dns-domain";
  27. break;
  28. case "delete":
  29. $cmd = "v-delete-dns-domain";
  30. break;
  31. case "suspend":
  32. $cmd = "v-suspend-dns-domain";
  33. break;
  34. case "unsuspend":
  35. $cmd = "v-unsuspend-dns-domain";
  36. break;
  37. default:
  38. header("Location: /list/dns/");
  39. exit();
  40. }
  41. } else {
  42. switch ($action) {
  43. case "delete":
  44. $cmd = "v-delete-dns-record";
  45. break;
  46. case "suspend":
  47. $cmd = "v-suspend-dns-record";
  48. break;
  49. case "unsuspend":
  50. $cmd = "v-unsuspend-dns-record";
  51. break;
  52. default:
  53. header("Location: /list/dns/?domain=" . $domain);
  54. exit();
  55. }
  56. }
  57. } else {
  58. if (empty($_POST["record"])) {
  59. switch ($action) {
  60. case "delete":
  61. $cmd = "v-delete-dns-domain";
  62. break;
  63. default:
  64. header("Location: /list/dns/");
  65. exit();
  66. }
  67. } else {
  68. switch ($action) {
  69. case "delete":
  70. $cmd = "v-delete-dns-record";
  71. break;
  72. default:
  73. header("Location: /list/dns/?domain=" . $domain);
  74. exit();
  75. }
  76. }
  77. }
  78. if (empty($_POST["record"])) {
  79. if (is_array($_POST["domain"])) {
  80. foreach ($domain as $value) {
  81. // DNS
  82. $value = quoteshellarg($value);
  83. exec(HESTIA_CMD . $cmd . " " . $user . " " . $value . " no", $output, $return_var);
  84. $restart = "yes";
  85. }
  86. } else {
  87. header("Location: /list/dns/?domain=" . $domain);
  88. }
  89. } else {
  90. foreach ($record as $value) {
  91. // DNS Record
  92. $value = quoteshellarg($value);
  93. $dom = quoteshellarg($domain);
  94. exec(
  95. HESTIA_CMD . $cmd . " " . $user . " " . $dom . " " . $value . " no",
  96. $output,
  97. $return_var,
  98. );
  99. $restart = "yes";
  100. }
  101. }
  102. if (!empty($restart)) {
  103. exec(HESTIA_CMD . "v-restart-dns", $output, $return_var);
  104. }
  105. if (empty($_POST["record"])) {
  106. header("Location: /list/dns/");
  107. exit();
  108. } else {
  109. header("Location: /list/dns/?domain=" . $domain);
  110. exit();
  111. }