index.php 2.2 KB

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