index.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. $TAB = "SERVER";
  3. // Main include
  4. include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
  5. // Check user
  6. if ($_SESSION["userContext"] != "admin") {
  7. header("Location: /list/user");
  8. exit();
  9. }
  10. // Check POST request
  11. if (!empty($_POST["save"])) {
  12. // Check token
  13. verify_csrf($_POST);
  14. // Set restart flag
  15. $v_restart = "yes";
  16. if (empty($_POST["v_restart"])) {
  17. $v_restart = "no";
  18. }
  19. // Update options
  20. if (!empty($_POST["v_options"])) {
  21. exec("mktemp", $mktemp_output, $return_var);
  22. $new_conf = $mktemp_output[0];
  23. $fp = fopen($new_conf, "w");
  24. fwrite($fp, str_replace("\r\n", "\n", $_POST["v_options"]));
  25. fclose($fp);
  26. exec(
  27. HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " bind9-opt " . $v_restart,
  28. $output,
  29. $return_var,
  30. );
  31. check_return_code($return_var, $output);
  32. unset($output);
  33. unlink($new_conf);
  34. }
  35. // Update config
  36. if (empty($_SESSION["error_msg"]) && !empty($_POST["v_config"])) {
  37. exec("mktemp", $mktemp_output, $return_var);
  38. $new_conf = $mktemp_output[0];
  39. $fp = fopen($new_conf, "w");
  40. fwrite($fp, str_replace("\r\n", "\n", $_POST["v_config"]));
  41. fclose($fp);
  42. exec(
  43. HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " bind9 " . $v_restart,
  44. $output,
  45. $return_var,
  46. );
  47. check_return_code($return_var, $output);
  48. unset($output);
  49. unlink($new_conf);
  50. }
  51. // Set success message
  52. if (empty($_SESSION["error_msg"])) {
  53. $_SESSION["ok_msg"] = _("Changes have been saved.");
  54. }
  55. }
  56. $v_options_path = "/etc/bind/named.conf.options";
  57. $v_config_path = "/etc/bind/named.conf";
  58. $v_service_name = strtoupper("bind9");
  59. // Read config
  60. $v_options = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_options_path);
  61. $v_config = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path);
  62. // Render page
  63. render_page($user, $TAB, "edit_server_bind9");
  64. // Flush session messages
  65. unset($_SESSION["error_msg"]);
  66. unset($_SESSION["ok_msg"]);