index.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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." clamd ".$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. $v_config_path = shell_exec(VESTA_CMD.'v-list-sys-clamd-config plain');
  38. $v_service_name = strtoupper('clamav');
  39. // Read config
  40. $v_config = shell_exec(VESTA_CMD."v-open-fs-config ".$v_config_path);
  41. $result = array(
  42. 'config_path' => $v_config_path,
  43. 'service_name' => $v_service_name,
  44. 'config' => $v_config,
  45. 'error_msg' => $_SESSION['error_msg'],
  46. 'ok_msg' => $_SESSION['ok_msg']
  47. );
  48. echo json_encode($result);
  49. // Flush session messages
  50. unset($_SESSION['error_msg']);
  51. unset($_SESSION['ok_msg']);