index.php 2.4 KB

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