index.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. header('location: /login/');
  12. exit();
  13. }
  14. // Check empty fields
  15. if ((!isset($_POST['v_min'])) || ($_POST['v_min'] == '')) $errors[] = __('minute');
  16. if ((!isset($_POST['v_hour'])) || ($_POST['v_hour'] == '')) $errors[] = __('hour');
  17. if ((!isset($_POST['v_day'])) || ($_POST['v_day'] == '')) $errors[] = __('day');
  18. if ((!isset($_POST['v_month'])) || ($_POST['v_month'] == '')) $errors[] = __('month');
  19. if ((!isset($_POST['v_wday'])) || ($_POST['v_wday'] == '')) $errors[] = __('day of week');
  20. if ((!isset($_POST['v_cmd'])) || ($_POST['v_cmd'] == '')) $errors[] = __('cmd');
  21. if (!empty($errors[0])) {
  22. foreach ($errors as $i => $error) {
  23. if ( $i == 0 ) {
  24. $error_msg = $error;
  25. } else {
  26. $error_msg = $error_msg.", ".$error;
  27. }
  28. }
  29. $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
  30. }
  31. // Protect input
  32. $v_min = escapeshellarg($_POST['v_min']);
  33. $v_hour = escapeshellarg($_POST['v_hour']);
  34. $v_day = escapeshellarg($_POST['v_day']);
  35. $v_month = escapeshellarg($_POST['v_month']);
  36. $v_wday = escapeshellarg($_POST['v_wday']);
  37. $v_cmd = escapeshellarg($_POST['v_cmd']);
  38. // Add cron job
  39. if (empty($_SESSION['error_msg'])) {
  40. exec (VESTA_CMD."v-add-cron-job ".$user." ".$v_min." ".$v_hour." ".$v_day." ".$v_month." ".$v_wday." ".$v_cmd, $output, $return_var);
  41. check_return_code($return_var,$output);
  42. unset($output);
  43. }
  44. // Flush field values on success
  45. if (empty($_SESSION['error_msg'])) {
  46. $_SESSION['ok_msg'] = __('CRON_CREATED_OK');
  47. unset($v_min);
  48. unset($v_hour);
  49. unset($v_day);
  50. unset($v_month);
  51. unset($v_wday);
  52. unset($v_cmd);
  53. unset($output);
  54. }
  55. }
  56. // Render
  57. render_page($user, $TAB, 'add_cron');
  58. // Flush session messages
  59. unset($_SESSION['error_msg']);
  60. unset($_SESSION['ok_msg']);