index.php 2.2 KB

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