index.php 2.3 KB

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