index.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. ob_start();
  3. $TAB = 'CRON';
  4. // Main include
  5. include($_SERVER['DOCUMENT_ROOT']."/inc/main.php");
  6. // Check POST request
  7. if (!empty($_POST['ok'])) {
  8. // Check token
  9. verify_csrf($_POST);
  10. // Check empty fields
  11. if ((!isset($_POST['v_min'])) || ($_POST['v_min'] == '')) {
  12. $errors[] = _('minute');
  13. }
  14. if ((!isset($_POST['v_hour'])) || ($_POST['v_hour'] == '')) {
  15. $errors[] = _('hour');
  16. }
  17. if ((!isset($_POST['v_day'])) || ($_POST['v_day'] == '')) {
  18. $errors[] = _('day');
  19. }
  20. if ((!isset($_POST['v_month'])) || ($_POST['v_month'] == '')) {
  21. $errors[] = _('month');
  22. }
  23. if ((!isset($_POST['v_wday'])) || ($_POST['v_wday'] == '')) {
  24. $errors[] = _('day of week');
  25. }
  26. if ((!isset($_POST['v_cmd'])) || ($_POST['v_cmd'] == '')) {
  27. $errors[] = _('cmd');
  28. }
  29. if (!empty($errors[0])) {
  30. foreach ($errors as $i => $error) {
  31. if ($i == 0) {
  32. $error_msg = $error;
  33. } else {
  34. $error_msg = $error_msg.", ".$error;
  35. }
  36. }
  37. $_SESSION['error_msg'] = sprintf(_('Field "%s" can not be blank.'), $error_msg);
  38. }
  39. // Protect input
  40. $v_min = escapeshellarg($_POST['v_min']);
  41. $v_hour = escapeshellarg($_POST['v_hour']);
  42. $v_day = escapeshellarg($_POST['v_day']);
  43. $v_month = escapeshellarg($_POST['v_month']);
  44. $v_wday = escapeshellarg($_POST['v_wday']);
  45. $v_cmd = escapeshellarg($_POST['v_cmd']);
  46. // Add cron job
  47. if (empty($_SESSION['error_msg'])) {
  48. exec(HESTIA_CMD."v-add-cron-job ".$user." ".$v_min." ".$v_hour." ".$v_day." ".$v_month." ".$v_wday." ".$v_cmd, $output, $return_var);
  49. check_return_code($return_var, $output);
  50. unset($output);
  51. }
  52. // Flush field values on success
  53. if (empty($_SESSION['error_msg'])) {
  54. $_SESSION['ok_msg'] = _('CRON_CREATED_OK');
  55. unset($v_min);
  56. unset($v_hour);
  57. unset($v_day);
  58. unset($v_month);
  59. unset($v_wday);
  60. unset($v_cmd);
  61. unset($output);
  62. }
  63. }
  64. if (empty($v_cmd)) {
  65. $v_cmd = '';
  66. }
  67. if (empty($v_month)) {
  68. $v_month = '';
  69. }
  70. if (empty($v_day)) {
  71. $v_day = '';
  72. }
  73. if (empty($v_wday)) {
  74. $v_wday = '';
  75. }
  76. if (empty($v_hour)) {
  77. $v_hour = '';
  78. }
  79. if (empty($v_min)) {
  80. $v_min = '';
  81. }
  82. // Render
  83. render_page($user, $TAB, 'add_cron');
  84. // Flush session messages
  85. unset($_SESSION['error_msg']);
  86. unset($_SESSION['ok_msg']);