index.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. use function Hestiacp\quoteshellarg\quoteshellarg;
  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 = quoteshellarg($_POST['v_min']);
  42. $v_hour = quoteshellarg($_POST['v_hour']);
  43. $v_day = quoteshellarg($_POST['v_day']);
  44. $v_month = quoteshellarg($_POST['v_month']);
  45. $v_wday = quoteshellarg($_POST['v_wday']);
  46. $v_cmd = quoteshellarg($_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. if (empty($v_cmd)) {
  66. $v_cmd = '';
  67. }
  68. if (empty($v_month)) {
  69. $v_month = '';
  70. }
  71. if (empty($v_day)) {
  72. $v_day = '';
  73. }
  74. if (empty($v_wday)) {
  75. $v_wday = '';
  76. }
  77. if (empty($v_hour)) {
  78. $v_hour = '';
  79. }
  80. if (empty($v_min)) {
  81. $v_min = '';
  82. }
  83. // Render
  84. render_page($user, $TAB, 'add_cron');
  85. // Flush session messages
  86. unset($_SESSION['error_msg']);
  87. unset($_SESSION['ok_msg']);