index.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. error_reporting(NULL);
  3. ob_start();
  4. $TAB = 'CRON';
  5. // Main include
  6. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  7. // Check POST request
  8. if (!empty($_POST['ok'])) {
  9. // Check token
  10. if ((!isset($_POST['token'])) || ($_SESSION['token'] != $_POST['token'])) {
  11. exit();
  12. }
  13. // Check empty fields
  14. if ((!isset($_POST['v_min'])) || ($_POST['v_min'] == '')) $errors[] = __('minute');
  15. if ((!isset($_POST['v_hour'])) || ($_POST['v_hour'] == '')) $errors[] = __('hour');
  16. if ((!isset($_POST['v_day'])) || ($_POST['v_day'] == '')) $errors[] = __('day');
  17. if ((!isset($_POST['v_month'])) || ($_POST['v_month'] == '')) $errors[] = __('month');
  18. if ((!isset($_POST['v_wday'])) || ($_POST['v_wday'] == '')) $errors[] = __('day of week');
  19. if ((!isset($_POST['v_cmd'])) || ($_POST['v_cmd'] == '')) $errors[] = __('cmd');
  20. if (!empty($errors[0])) {
  21. foreach ($errors as $i => $error) {
  22. if ( $i == 0 ) {
  23. $error_msg = $error;
  24. } else {
  25. $error_msg = $error_msg.", ".$error;
  26. }
  27. }
  28. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  29. }
  30. // Protect input
  31. $v_min = escapeshellarg($_POST['v_min']);
  32. $v_hour = escapeshellarg($_POST['v_hour']);
  33. $v_day = escapeshellarg($_POST['v_day']);
  34. $v_month = escapeshellarg($_POST['v_month']);
  35. $v_wday = escapeshellarg($_POST['v_wday']);
  36. $v_cmd = escapeshellarg($_POST['v_cmd']);
  37. // Add cron job
  38. if (empty($_SESSION['error_msg'])) {
  39. exec (VESTA_CMD."v-add-cron-job ".$user." ".$v_min." ".$v_hour." ".$v_day." ".$v_month." ".$v_wday." ".$v_cmd, $output, $return_var);
  40. check_return_code($return_var,$output);
  41. unset($output);
  42. }
  43. // Flush field values on success
  44. if (empty($_SESSION['error_msg'])) {
  45. $_SESSION['ok_msg'] = __('CRON_CREATED_OK');
  46. unset($v_min);
  47. unset($v_hour);
  48. unset($v_day);
  49. unset($v_month);
  50. unset($v_wday);
  51. unset($v_cmd);
  52. unset($output);
  53. }
  54. }
  55. $result = array(
  56. 'error_msg' => $_SESSION['error_msg'],
  57. 'ok_msg' => $_SESSION['ok_msg']
  58. );
  59. echo json_encode($result);
  60. // Flush session messages
  61. unset($_SESSION['error_msg']);
  62. unset($_SESSION['ok_msg']);