index.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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(
  50. HESTIA_CMD .
  51. "v-add-cron-job " .
  52. $user .
  53. " " .
  54. $v_min .
  55. " " .
  56. $v_hour .
  57. " " .
  58. $v_day .
  59. " " .
  60. $v_month .
  61. " " .
  62. $v_wday .
  63. " " .
  64. $v_cmd,
  65. $output,
  66. $return_var,
  67. );
  68. check_return_code($return_var, $output);
  69. unset($output);
  70. }
  71. // Flush field values on success
  72. if (empty($_SESSION["error_msg"])) {
  73. $_SESSION["ok_msg"] = _("CRON_CREATED_OK");
  74. unset($v_min);
  75. unset($v_hour);
  76. unset($v_day);
  77. unset($v_month);
  78. unset($v_wday);
  79. unset($v_cmd);
  80. unset($output);
  81. }
  82. }
  83. if (empty($v_cmd)) {
  84. $v_cmd = "";
  85. }
  86. if (empty($v_month)) {
  87. $v_month = "";
  88. }
  89. if (empty($v_day)) {
  90. $v_day = "";
  91. }
  92. if (empty($v_wday)) {
  93. $v_wday = "";
  94. }
  95. if (empty($v_hour)) {
  96. $v_hour = "";
  97. }
  98. if (empty($v_min)) {
  99. $v_min = "";
  100. }
  101. // Render
  102. render_page($user, $TAB, "add_cron");
  103. // Flush session messages
  104. unset($_SESSION["error_msg"]);
  105. unset($_SESSION["ok_msg"]);