index.php 2.3 KB

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