index.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. error_reporting(null);
  3. $TAB = 'SERVER';
  4. // Main include
  5. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  6. // Check user
  7. if ($_SESSION['userContext'] != 'admin') {
  8. header("Location: /list/user");
  9. exit;
  10. }
  11. // Check POST request
  12. if (!empty($_POST['save'])) {
  13. // Check token
  14. verify_csrf($_POST);
  15. // Set restart flag
  16. $v_restart = 'yes';
  17. if (empty($_POST['v_restart'])) {
  18. $v_restart = 'no';
  19. }
  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(HESTIA_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(HESTIA_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(HESTIA_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(HESTIA_CMD."v-open-fs-config ".$v_options_path);
  58. $v_config = shell_exec(HESTIA_CMD."v-open-fs-config ".$v_config_path);
  59. // Render page
  60. render_page($user, $TAB, 'edit_server_pgsql');
  61. // Flush session messages
  62. unset($_SESSION['error_msg']);
  63. unset($_SESSION['ok_msg']);