index.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 config
  21. if (!empty($_POST['v_config'])) {
  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_config']));
  26. fclose($fp);
  27. exec (VESTA_CMD."v-change-sys-service-config ".$new_conf." mysql ".$v_restart, $output, $return_var);
  28. check_return_code($return_var,$output);
  29. unset($output);
  30. unlink($new_conf);
  31. }
  32. // Set success message
  33. if (empty($_SESSION['error_msg'])) {
  34. $_SESSION['ok_msg'] = __('Changes has been saved.');
  35. }
  36. }
  37. // List config
  38. exec (VESTA_CMD."v-list-sys-mysql-config json", $output, $return_var);
  39. $data = json_decode(implode('', $output), true);
  40. unset($output);
  41. $v_max_user_connections = $data['CONFIG']['max_user_connections'];
  42. $v_max_connections = $data['CONFIG']['max_connections'];
  43. $v_wait_timeout = $data['CONFIG']['wait_timeout'];
  44. $v_interactive_timeout = $data['CONFIG']['interactive_timeout'];
  45. $v_max_allowed_packet = $data['CONFIG']['max_allowed_packet'];
  46. $v_config_path = $data['CONFIG']['config_path'];
  47. $v_service_name = strtoupper('mysql');
  48. # Read config
  49. $v_config = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path);
  50. $result = array(
  51. 'max_user_connections' => $v_max_user_connections,
  52. 'max_connections' => $v_max_connections,
  53. 'wait_timeout' => $v_wait_timeout,
  54. 'interactive_timeout' => $v_interactive_timeout,
  55. 'max_allowed_packet' => $v_max_allowed_packet,
  56. 'config_path' => $v_config_path,
  57. 'service_name' => $v_service_name,
  58. 'config' => $v_config,
  59. 'error_msg' => $_SESSION['error_msg'],
  60. 'ok_msg' => $_SESSION['ok_msg']
  61. );
  62. echo json_encode($result);
  63. // Flush session messages
  64. unset($_SESSION['error_msg']);
  65. unset($_SESSION['ok_msg']);