index.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  2. use function Hestiacp\quoteshellarg\quoteshellarg;
  3. ob_start();
  4. $TAB = "DNS";
  5. // Main include
  6. include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
  7. // Check domain name
  8. if (empty($_GET["domain"])) {
  9. header("Location: /list/dns/");
  10. exit();
  11. }
  12. // Edit as someone else?
  13. if ($_SESSION["userContext"] === "admin" && !empty($_GET["user"])) {
  14. $user = quoteshellarg($_GET["user"]);
  15. $user_plain = htmlentities($_GET["user"]);
  16. }
  17. // List ip addresses
  18. exec(HESTIA_CMD . "v-list-user-ips " . $user . " json", $output, $return_var);
  19. $v_ips = json_decode(implode("", $output), true);
  20. unset($output);
  21. // List dns domain
  22. if (!empty($_GET["domain"]) && empty($_GET["record_id"])) {
  23. $v_domain = quoteshellarg($_GET["domain"]);
  24. exec(
  25. HESTIA_CMD . "v-list-dns-domain " . $user . " " . $v_domain . " json",
  26. $output,
  27. $return_var,
  28. );
  29. check_return_code_redirect($return_var, $output, "/list/dns/");
  30. $data = json_decode(implode("", $output), true);
  31. unset($output);
  32. // Parse dns domain
  33. $v_username = $user;
  34. $v_domain = $_GET["domain"];
  35. $v_ip = $data[$v_domain]["IP"];
  36. $v_ipv6 = $data[$v_domain]["IP6"];
  37. $v_template = $data[$v_domain]["TPL"];
  38. $v_ttl = $data[$v_domain]["TTL"];
  39. $v_dnssec = $data[$v_domain]["DNSSEC"];
  40. $v_exp = $data[$v_domain]["EXP"];
  41. $v_soa = $data[$v_domain]["SOA"];
  42. $v_date = $data[$v_domain]["DATE"];
  43. $v_time = $data[$v_domain]["TIME"];
  44. $v_suspended = $data[$v_domain]["SUSPENDED"];
  45. if ($v_suspended == "yes") {
  46. $v_status = "suspended";
  47. } else {
  48. $v_status = "active";
  49. }
  50. // List dns templates
  51. exec(HESTIA_CMD . "v-list-dns-templates json", $output, $return_var);
  52. $templates = json_decode(implode("", $output), true);
  53. unset($output);
  54. }
  55. // List dns record
  56. if (!empty($_GET["domain"]) && !empty($_GET["record_id"])) {
  57. $v_domain = quoteshellarg($_GET["domain"]);
  58. $v_record_id = quoteshellarg($_GET["record_id"]);
  59. exec(
  60. HESTIA_CMD . "v-list-dns-records " . $user . " " . $v_domain . " 'json'",
  61. $output,
  62. $return_var,
  63. );
  64. check_return_code_redirect($return_var, $output, "/list/dns/");
  65. $data = json_decode(implode("", $output), true);
  66. unset($output);
  67. // Parse dns record
  68. $v_username = $user;
  69. $v_domain = $_GET["domain"];
  70. $v_record_id = $_GET["record_id"];
  71. $v_rec = $data[$v_record_id]["RECORD"];
  72. $v_type = $data[$v_record_id]["TYPE"];
  73. $v_val = $data[$v_record_id]["VALUE"];
  74. $v_priority = $data[$v_record_id]["PRIORITY"];
  75. $v_suspended = $data[$v_record_id]["SUSPENDED"];
  76. if ($v_suspended == "yes") {
  77. $v_status = "suspended";
  78. } else {
  79. $v_status = "active";
  80. }
  81. $v_date = $data[$v_record_id]["DATE"];
  82. $v_time = $data[$v_record_id]["TIME"];
  83. $v_ttl = $data[$v_record_id]["TTL"];
  84. }
  85. // Check POST request for dns domain
  86. if (!empty($_POST["save"]) && !empty($_GET["domain"]) && empty($_GET["record_id"])) {
  87. $v_domain = quoteshellarg($_POST["v_domain"]);
  88. // Check token
  89. verify_csrf($_POST);
  90. // Change domain IPV4
  91. if ($v_ip != $_POST["v_ip"] && empty($_SESSION["error_msg"])) {
  92. $v_ip = quoteshellarg($_POST["v_ip"]);
  93. exec(
  94. HESTIA_CMD .
  95. "v-change-dns-domain-ip " .
  96. $user .
  97. " " .
  98. $v_domain .
  99. " " .
  100. $v_ip .
  101. " 'no'",
  102. $output,
  103. $return_var,
  104. );
  105. check_return_code($return_var, $output);
  106. $restart_dns = "yes";
  107. unset($output);
  108. }
  109. // Change domain IPV6
  110. if ($v_ipv6 != $_POST["v_ipv6"] && empty($_SESSION["error_msg"])) {
  111. $v_ipv6 = quoteshellarg($_POST["v_ipv6"]);
  112. exec(
  113. HESTIA_CMD .
  114. "v-change-dns-domain-ipv6 " .
  115. $user .
  116. " " .
  117. $v_domain .
  118. " " .
  119. $v_ipv6 .
  120. " 'no'",
  121. $output,
  122. $return_var,
  123. );
  124. check_return_code($return_var, $output);
  125. $restart_dns = "yes";
  126. unset($output);
  127. }
  128. // Change domain template
  129. if ($v_template != $_POST["v_template"] && empty($_SESSION["error_msg"])) {
  130. $v_template = quoteshellarg($_POST["v_template"]);
  131. exec(
  132. HESTIA_CMD .
  133. "v-change-dns-domain-tpl " .
  134. $user .
  135. " " .
  136. $v_domain .
  137. " " .
  138. $v_template .
  139. " 'no'",
  140. $output,
  141. $return_var,
  142. );
  143. check_return_code($return_var, $output);
  144. unset($output);
  145. $restart_dns = "yes";
  146. }
  147. // Change SOA record
  148. if ($v_soa != $_POST["v_soa"] && empty($_SESSION["error_msg"])) {
  149. $v_soa = quoteshellarg($_POST["v_soa"]);
  150. exec(
  151. HESTIA_CMD .
  152. "v-change-dns-domain-soa " .
  153. $user .
  154. " " .
  155. $v_domain .
  156. " " .
  157. $v_soa .
  158. " 'no'",
  159. $output,
  160. $return_var,
  161. );
  162. check_return_code($return_var, $output);
  163. unset($output);
  164. $restart_dns = "yes";
  165. }
  166. // Change expiration date
  167. if ($v_exp != $_POST["v_exp"] && empty($_SESSION["error_msg"])) {
  168. $v_exp = quoteshellarg($_POST["v_exp"]);
  169. exec(
  170. HESTIA_CMD .
  171. "v-change-dns-domain-exp " .
  172. $user .
  173. " " .
  174. $v_domain .
  175. " " .
  176. $v_exp .
  177. " 'no'",
  178. $output,
  179. $return_var,
  180. );
  181. check_return_code($return_var, $output);
  182. unset($output);
  183. }
  184. // Change domain ttl
  185. if ($v_ttl != $_POST["v_ttl"] && empty($_SESSION["error_msg"])) {
  186. $v_ttl = quoteshellarg($_POST["v_ttl"]);
  187. exec(
  188. HESTIA_CMD .
  189. "v-change-dns-domain-ttl " .
  190. $user .
  191. " " .
  192. $v_domain .
  193. " " .
  194. $v_ttl .
  195. " 'no'",
  196. $output,
  197. $return_var,
  198. );
  199. check_return_code($return_var, $output);
  200. unset($output);
  201. $restart_dns = "yes";
  202. }
  203. // Change domain dnssec
  204. if ($_POST["v_dnssec"] == "" && $v_dnssec == "yes" && empty($_SESSION["error_msg"])) {
  205. exec(
  206. HESTIA_CMD . "v-change-dns-domain-dnssec " . $user . " " . $v_domain . " 'no'",
  207. $output,
  208. $return_var,
  209. );
  210. check_return_code($return_var, $output);
  211. unset($output);
  212. $v_dnssec = "no";
  213. $restart_dns = "yes";
  214. }
  215. // Change domain dnssec
  216. if ($_POST["v_dnssec"] == "yes" && $v_dnssec !== "yes" && empty($_SESSION["error_msg"])) {
  217. exec(
  218. HESTIA_CMD . "v-change-dns-domain-dnssec " . $user . " " . $v_domain . " 'yes'",
  219. $output,
  220. $return_var,
  221. );
  222. check_return_code($return_var, $output);
  223. unset($output);
  224. $v_dnssec = "yes";
  225. $restart_dns = "yes";
  226. }
  227. // Restart dns server
  228. if (!empty($restart_dns) && empty($_SESSION["error_msg"])) {
  229. exec(HESTIA_CMD . "v-restart-dns", $output, $return_var);
  230. check_return_code($return_var, $output);
  231. unset($output);
  232. }
  233. // Set success message
  234. if (empty($_SESSION["error_msg"])) {
  235. $_SESSION["ok_msg"] = _("Changes have been saved.");
  236. }
  237. // Restart dns server
  238. if (empty($_SESSION["error_msg"])) {
  239. exec(HESTIA_CMD . "v-restart-dns", $output, $return_var);
  240. check_return_code($return_var, $output);
  241. unset($output);
  242. }
  243. }
  244. // Check POST request for dns record
  245. if (!empty($_POST["save"]) && !empty($_GET["domain"]) && !empty($_GET["record_id"])) {
  246. // Check token
  247. verify_csrf($_POST);
  248. // Protect input
  249. $v_domain = quoteshellarg($_POST["v_domain"]);
  250. $v_record_id = quoteshellarg($_POST["v_record_id"]);
  251. // Change dns record
  252. if (
  253. $v_rec != $_POST["v_rec"] ||
  254. $v_type != $_POST["v_type"] ||
  255. $v_val != $_POST["v_val"] ||
  256. $v_priority != $_POST["v_priority"] ||
  257. ($v_ttl != $_POST["v_ttl"] && empty($_SESSION["error_msg"]))
  258. ) {
  259. $v_rec = quoteshellarg($_POST["v_rec"]);
  260. $v_type = quoteshellarg($_POST["v_type"]);
  261. $v_val = quoteshellarg($_POST["v_val"]);
  262. $v_priority = quoteshellarg($_POST["v_priority"]);
  263. $v_ttl = quoteshellarg($_POST["v_ttl"]);
  264. exec(
  265. HESTIA_CMD .
  266. "v-change-dns-record " .
  267. $user .
  268. " " .
  269. $v_domain .
  270. " " .
  271. $v_record_id .
  272. " " .
  273. $v_rec .
  274. " " .
  275. $v_type .
  276. " " .
  277. $v_val .
  278. " " .
  279. $v_priority .
  280. " yes " .
  281. $v_ttl,
  282. $output,
  283. $return_var,
  284. );
  285. check_return_code($return_var, $output);
  286. $v_rec = $_POST["v_rec"];
  287. $v_type = $_POST["v_type"];
  288. $v_val = $_POST["v_val"];
  289. unset($output);
  290. $restart_dns = "yes";
  291. }
  292. // Change dns record id
  293. if ($_GET["record_id"] != $_POST["v_record_id"] && empty($_SESSION["error_msg"])) {
  294. $v_old_record_id = quoteshellarg($_GET["record_id"]);
  295. exec(
  296. HESTIA_CMD .
  297. "v-change-dns-record-id " .
  298. $user .
  299. " " .
  300. $v_domain .
  301. " " .
  302. $v_old_record_id .
  303. " " .
  304. $v_record_id,
  305. $output,
  306. $return_var,
  307. );
  308. check_return_code($return_var, $output);
  309. unset($output);
  310. $restart_dns = "yes";
  311. }
  312. // Restart dns server
  313. if (!empty($restart_dns) && empty($_SESSION["error_msg"])) {
  314. exec(HESTIA_CMD . "v-restart-dns", $output, $return_var);
  315. check_return_code($return_var, $output);
  316. unset($output);
  317. }
  318. // Set success message
  319. if (empty($_SESSION["error_msg"])) {
  320. $_SESSION["ok_msg"] = _("Changes have been saved.");
  321. }
  322. // Change url if record id was changed
  323. if (empty($_SESSION["error_msg"]) && $_GET["record_id"] != $_POST["v_record_id"]) {
  324. header(
  325. "Location: /edit/dns/?domain=" .
  326. $_GET["domain"] .
  327. "&record_id=" .
  328. $_POST["v_record_id"],
  329. );
  330. exit();
  331. }
  332. }
  333. // Render page
  334. if (empty($_GET["record_id"])) {
  335. // Display body for dns domain
  336. render_page($user, $TAB, "edit_dns");
  337. } else {
  338. if (empty($data[$_GET["record_id"]])) {
  339. header("Location: /list/dns/");
  340. $_SESSION["error_msg"] = _("Error: unknown record ID.");
  341. }
  342. // Display body for dns record
  343. render_page($user, $TAB, "edit_dns_rec");
  344. }
  345. // Flush session messages
  346. unset($_SESSION["error_msg"]);
  347. unset($_SESSION["ok_msg"]);