PageRenderTime 44ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/fuel/modules/cronjobs/controllers/cronjobs.php

http://github.com/daylightstudio/FUEL-CMS
PHP | 114 lines | 88 code | 22 blank | 4 comment | 16 complexity | 939ddc801df44a0022b59e2bccbc908e MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. require_once(FUEL_PATH.'/libraries/Fuel_base_controller.php');
  3. class Cronjobs extends Fuel_base_controller {
  4. public $nav_selected = 'tools/cronjobs';
  5. public $view_location = 'cronjobs';
  6. function __construct()
  7. {
  8. parent::__construct();
  9. }
  10. function index()
  11. {
  12. $this->_validate_user('cronjobs');
  13. $this->load->module_config(CRONJOBS_FOLDER, 'cronjobs');
  14. $this->load->library('cronjob');
  15. $this->load->library('validator');
  16. $cronjobs_config = $this->config->item('cronjobs');
  17. $this->js_controller_params['method'] = 'cronjobs';
  18. $cronjob_path = INSTALL_ROOT.$cronjobs_config['crons_folder'].'crontab.php';
  19. $config['cronfile'] = $cronjob_path;
  20. $config['mailto'] = $this->input->post('mailto');
  21. $config['user'] = $cronjobs_config['cron_user'];
  22. $config['sudo_pwd'] = $cronjobs_config['sudo_pwd'];
  23. $this->cronjob->initialize($config);
  24. if (!empty($_POST))
  25. {
  26. if ($this->input->post('action') == 'remove')
  27. {
  28. $this->cronjob->remove();
  29. }
  30. else
  31. {
  32. $mailto = $this->input->post('mailto');
  33. $num = count($_POST['command']);
  34. $line = '';
  35. for ($i = 0; $i < $num; $i++)
  36. {
  37. if (!empty($_POST['command'][$i]) AND $_POST['command'][$i] != 'command')
  38. {
  39. $min = ($_POST['min'][$i] == 'min') ? NULL : $_POST['min'][$i];
  40. $hour = ($_POST['hour'][$i] == 'hour') ? NULL : $_POST['hour'][$i];
  41. $month_day = ($_POST['month_day'][$i] == 'month day') ? NULL : $_POST['month_day'][$i];
  42. $month_num = ($_POST['month_num'][$i] == 'month num') ? NULL : $_POST['month_num'][$i];
  43. $week_day = ($_POST['week_day'][$i] == 'week day') ? NULL : $_POST['week_day'][$i];
  44. $command = $_POST['command'][$i];
  45. $this->cronjob->add($min, $hour, $month_day, $month_num, $week_day, $command);
  46. }
  47. }
  48. $this->cronjob->create();
  49. }
  50. }
  51. $cronjob_file = $this->cronjob->view();
  52. $action = 'edit';
  53. $mailto = '';
  54. if (file_exists($cronjob_path) AND empty($cronjob_file))
  55. {
  56. // turn on output buffering so that php will work inside the crontab.php
  57. ob_start();
  58. include($cronjob_path);
  59. $cronjob_file = ob_get_clean();
  60. $cronjob_file = trim($cronjob_file);
  61. $action = 'create';
  62. }
  63. $cronjob_lines = array();
  64. if (!empty($cronjob_file))
  65. {
  66. if (is_string($cronjob_file))
  67. {
  68. $cronjob_lines = explode(PHP_EOL, $cronjob_file);
  69. }
  70. else
  71. {
  72. $cronjob_lines = (array) $cronjob_file;
  73. }
  74. }
  75. // clean up whitespace
  76. $cronjob_lines = array_map('trim', $cronjob_lines);
  77. if (!empty($cronjob_lines) AND strncasecmp($cronjob_lines[0], 'MAILTO', 6) === 0)
  78. {
  79. $mailto_arr = explode('=', $cronjob_lines[0]);
  80. $mailto = (count($mailto_arr) == 2) ? trim($mailto_arr[1]) : '';
  81. unset($cronjob_lines[0]);
  82. $cronjob_lines = array_values($cronjob_lines); // reset
  83. }
  84. $vars['cronjob_path'] = $cronjob_path;
  85. $vars['action'] = $action;
  86. $vars['mailto'] = $mailto;
  87. $vars['cronjob_lines'] = $cronjob_lines;
  88. $this->_render('cronjobs', $vars);
  89. }
  90. }
  91. /* End of file cronjobs.php */
  92. /* Location: ./fuel/modules/cronjobs/controllers/cronjobs.php */