#!/usr/local/bin/php . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ // Title $pgtitle = array("Services", "Scheduler"); // m0n0wall & shared functions require_once("guiconfig.inc"); // Default config croen_set_default_config(); // Save if (isset($_POST['save']) || isset($_POST['apply'])) { unset($input_errors); // Validate if (!isset($_POST['apply'])) { // 1: Input validation (required fields exist) $reqdfields = Array('interval'); $reqdfieldsn = Array('Loop interval'); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); // 2: Input validation (field values) if (!$input_errors) { if (!ctype_digit($_POST['interval']) || (int)$_POST['interval'] < 1 || (int)$_POST['interval'] > 60) { $input_errors[] = "The loop interval has to be between 1 and 60"; } } // 3: Set config variables & write config if (!$input_errors) { // Config variables $config['croen']['interval'] = (int)$_POST['interval']; $config['croen']['enable'] = (isset($_POST['enable']) ? TRUE : FALSE); // Write config write_config(); } } // Restart service & retrieve save message if (!$input_errors) { $retval = 0; if (!file_exists($d_sysrebootreqd_path)) { config_lock(); $retval = services_croen_configure(); config_unlock(); } $savemsg = get_std_save_message($retval); if ($retval == 0) { if (file_exists($d_croendirty_path)) { unlink($d_croendirty_path); } } } } // Shared vars $data = croen_vars(Array('descr', 'repeat', 'date_once', 'date_weekly')); // Croen form vars $pconfig['enable'] = (isset($config['croen']['enable']) ? TRUE : FALSE); $pconfig['interval'] = (isset($config['croen']['interval']) ? $config['croen']['interval'] : 10); $pconfig['jobset'] = &$config['croen']['jobset']; // Actions $config_changed = FALSE; foreach ($_POST as $pn => $pv) { // Delete job if (preg_match("/^del_(\d+)_x$/", $pn, $matches)) { unset($pconfig['jobset'][$matches[1]]); $config_changed = TRUE; // Toggle job } elseif (preg_match("/^toggle_(\d+)_x$/", $pn, $matches)) { if (isset($pconfig['jobset'][$matches[1]])) { $pconfig['jobset'][$matches[1]]['disabled'] = !isset($pconfig['jobset'][$matches[1]]['disabled']); } $config_changed = TRUE; } } // Changed someting: Write config, set dirty & reroute if ($config_changed) { if ($pconfig['enable']) { touch($d_croendirty_path); } write_config(); header("Location: services_croen.php"); exit; } // Include webinterface include("fbegin.inc"); // JavaScript to modify forms echo ' '; // Show errors (if any) if ($input_errors) { print_input_errors($input_errors); } // Show savemsg (if any) if ($savemsg) { print_info_box($savemsg); } // Show form echo '
'; // Show dirty message (if dirty) if (file_exists($d_croendirty_path)) { echo '

'; print_info_box_np("The scheduler configuration has been changed.
You must apply the changes in order for them to take effect."); echo '

'; } echo '
  Enable scheduler
Loop interval minutes
The loop interval is used to compensate for sudden changes in time and date. An example would be the switch to daylight saving time/standard time or time correction from the NTP client.
Default is 10 minutes.
 

'; // Jobsets $arrow = ' '; foreach ($pconfig['jobset'] AS $job_id => $jobset) { echo ' '; } echo '
  Repeat Job(s) Description  
  '.(isset($jobset['syslog']) ? '' : ' ').' '. ($jobset['repeat'] == 'x_minute' ? str_replace("x minute", ($jobset['minute'] > 1 ? $jobset['minute']." minutes" : "minute"), $data['repeat'][$jobset['repeat']]) : $data['repeat'][$jobset['repeat']].',
'). ($jobset['repeat'] == 'once' ? date($data['date_once'], strtotime(htmlspecialchars($jobset['date']).' '.htmlspecialchars($jobset['time']))) : ($jobset['repeat'] == 'daily' ? htmlspecialchars($jobset['time']) : ($jobset['repeat'] == 'weekly' ? $data['date_weekly'][htmlspecialchars($jobset['weekday'])].', '.htmlspecialchars($jobset['time']) : ($jobset['repeat'] == 'monthly' ? htmlspecialchars($jobset['day']). ((int)$jobset['day'] == 1 || (int)$jobset['day'] == 21 ? 'st' : ((int)$jobset['day'] == 2 || (int)$jobset['day'] == 22 ? 'nd' : ((int)$jobset['day'] == 3 || (int)$jobset['day'] == 23 ? 'rd' : 'th'))) .', '.htmlspecialchars($jobset['time']) : '')))) .'
'; // Jobs $first = TRUE; foreach ($jobset['job'] AS $job) { echo '
'; $first = FALSE; $j = croen_job_exists($job['name'], Array('descr'), (isset($job['target']) ? Array('target' => $job['target']) : Array())); if ($j) { $jfirst = TRUE; foreach ($j['descr']['job'] AS $v) { echo (!$jfirst ? $arrow : '').$v; $jfirst = FALSE; } echo ''.(isset($j['descr']['target']) ? $arrow.$j['descr']['target'] : '').(isset($job['value']) ? $arrow.$job['value'] : '').(isset($j['descr']['input']) ? ' '.$j['descr']['input'] : '').''; } echo '
'; } echo '
'.(isset($jobset['descr']) && !empty($jobset['descr']) ? $jobset['descr'] : ' ').' edit job
add job
enabled log
disabled log (disabled)
'; // m0n0wall include("fend.inc"); ?>