index.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. header("Location: /list/user");
  10. exit;
  11. }
  12. // Check POST request
  13. if (!empty($_POST['save'])) {
  14. // Check token
  15. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  16. exit();
  17. }
  18. // Set restart flag
  19. $v_restart = 'yes';
  20. if (empty($_POST['v_restart'])) $v_restart = 'no';
  21. // Update config
  22. if (!empty($_POST['v_config'])) {
  23. exec ('mktemp', $mktemp_output, $return_var);
  24. $new_conf = $mktemp_output[0];
  25. $fp = fopen($new_conf, 'w');
  26. fwrite($fp, str_replace("\r\n", "\n", $_POST['v_config']));
  27. fclose($fp);
  28. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." apache2 ".$v_restart, $output, $return_var);
  29. check_return_code($return_var,$output);
  30. unset($output);
  31. unlink($new_conf);
  32. }
  33. // Set success message
  34. if (empty($_SESSION['error_msg'])) {
  35. $_SESSION['ok_msg'] = __('Changes has been saved.');
  36. }
  37. }
  38. $v_config_path = '/etc/apache2/apache2.conf';
  39. $v_service_name = strtoupper('apache2');
  40. // Read config
  41. $v_config = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path);
  42. $result = array(
  43. 'config_path' => $v_config_path,
  44. 'service_name' => $v_service_name,
  45. 'config' => $v_config,
  46. 'error_msg' => $_SESSION['error_msg'],
  47. 'ok_msg' => $_SESSION['ok_msg']
  48. );
  49. echo json_encode($result);
  50. // Flush session messages
  51. unset($_SESSION['error_msg']);
  52. unset($_SESSION['ok_msg']);