index.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 option
  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 .
  28. "v-change-sys-service-config " .
  29. $new_conf .
  30. " postgresql-hba " .
  31. $v_restart,
  32. $output,
  33. $return_var,
  34. );
  35. check_return_code($return_var, $output);
  36. unset($output);
  37. unlink($new_conf);
  38. }
  39. // Update config
  40. if (empty($_SESSION["error_msg"]) && !empty($_POST["v_config"])) {
  41. exec("mktemp", $mktemp_output, $return_var);
  42. $new_conf = $mktemp_output[0];
  43. $fp = fopen($new_conf, "w");
  44. fwrite($fp, str_replace("\r\n", "\n", $_POST["v_config"]));
  45. fclose($fp);
  46. exec(
  47. HESTIA_CMD . "v-change-sys-service-config " . $new_conf . " postgresql " . $v_restart,
  48. $output,
  49. $return_var,
  50. );
  51. check_return_code($return_var, $output);
  52. unset($output);
  53. unlink($new_conf);
  54. }
  55. // Set success message
  56. if (empty($_SESSION["error_msg"])) {
  57. $_SESSION["ok_msg"] = _("Changes have been saved.");
  58. }
  59. }
  60. // List config
  61. exec(HESTIA_CMD . "v-list-sys-pgsql-config json", $output, $return_var);
  62. $data = json_decode(implode("", $output), true);
  63. unset($output);
  64. $v_options_path = $data["CONFIG"]["pg_hba_path"];
  65. $v_config_path = $data["CONFIG"]["config_path"];
  66. $v_service_name = strtoupper("postgresql");
  67. // Read config
  68. $v_options = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_options_path);
  69. $v_config = shell_exec(HESTIA_CMD . "v-open-fs-config " . $v_config_path);
  70. // Render page
  71. render_page($user, $TAB, "edit_server_pgsql");
  72. // Flush session messages
  73. unset($_SESSION["error_msg"]);
  74. unset($_SESSION["ok_msg"]);