index.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 option
  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." postgresql-hba ".$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($new_conf);
  39. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." postgresql " .$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. // List config
  50. exec (VESTA_CMD."v-list-sys-pgsql-config json", $output, $return_var);
  51. $data = json_decode(implode('', $output), true);
  52. unset($output);
  53. $v_options_path = $data['CONFIG']['pg_hba_path'];
  54. $v_config_path = $data['CONFIG']['config_path'];
  55. $v_service_name = strtoupper('postgresql');
  56. // Read config
  57. $v_options = shell_exec(VESTA_CMD."v-open-fs-config ".$v_options_path);
  58. $v_config = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path);
  59. $result = array(
  60. 'options_path' => $v_options_path,
  61. 'config_path' => $v_config_path,
  62. 'service_name' => $v_service_name,
  63. 'options' => $v_options,
  64. 'config' => $v_config,
  65. 'error_msg' => $_SESSION['error_msg'],
  66. 'ok_msg' => $_SESSION['ok_msg']
  67. );
  68. echo json_encode($result);
  69. // Flush session messages
  70. unset($_SESSION['error_msg']);
  71. unset($_SESSION['ok_msg']);