#!/usr/local/bin/php
<?php
/*
shutdown_sched.php
part of FreeNAS (http://www.freenas.org)
Copyright (C) 2005-2010 Olivier Cochard-Labbe <olivier@freenas.org>.
All rights reserved.
Cron configuration from services_rsynclient.php improved by Mat Murdock <mmurdock@kimballequipment.com>
Based on m0n0wall (http://m0n0.ch/wall)
Copyright (C) 2003-2006 Manuel Kasper <mk@neon1.net>.
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.
*/
require("auth.inc");
require("guiconfig.inc");
$pgtitle = array(gettext("System"), gettext("Shutdown"), gettext("Scheduled"));
if (!is_array($config['shutdown'])){
$config['shutdown'] = array();
}
$pconfig['enable'] = isset($config['shutdown']['enable']);
$pconfig['minute'] = $config['shutdown']['minute'];
$pconfig['hour'] = $config['shutdown']['hour'];
$pconfig['day'] = $config['shutdown']['day'];
$pconfig['month'] = $config['shutdown']['month'];
$pconfig['weekday'] = $config['shutdown']['weekday'];
$pconfig['all_mins'] = $config['shutdown']['all_mins'];
$pconfig['all_hours'] = $config['shutdown']['all_hours'];
$pconfig['all_days'] = $config['shutdown']['all_days'];
$pconfig['all_months'] = $config['shutdown']['all_months'];
$pconfig['all_weekdays'] = $config['shutdown']['all_weekdays'];
$a_months = explode(" ",gettext("January February March April May June July August September October November December"));
$a_weekdays = explode(" ",gettext("Sunday Monday Tuesday Wednesday Thursday Friday Saturday"));
if ($_POST){
unset($input_errors);
$pconfig = $_POST;
// Validate synchronization time
if($_POST['enable']) {
do_input_validate_synctime($_POST, &$input_errors);
}
if (!$input_errors) {
$config['shutdown']['enable'] = $_POST['enable'] ? true : false;
$config['shutdown']['minute'] = $_POST['minute'];
$config['shutdown']['hour'] = $_POST['hour'];
$config['shutdown']['day'] = $_POST['day'];
$config['shutdown']['month'] = $_POST['month'];
$config['shutdown']['weekday'] = $_POST['weekday'];
$config['shutdown']['all_mins'] = $_POST['all_mins'];
$config['shutdown']['all_hours'] = $_POST['all_hours'];
$config['shutdown']['all_days'] = $_POST['all_days'];
$config['shutdown']['all_months'] = $_POST['all_months'];
$config['shutdown']['all_weekdays'] = $_POST['all_weekdays'];
write_config();
$retval = 0;
if (!file_exists($d_sysrebootreqd_path)) {
config_lock();
$retval |= rc_update_service("cron");
config_unlock();
}
$savemsg = get_std_save_message($retval);
}
}
?>
<?php include("fbegin.inc");?>
<script type="text/javascript">
<!--
function set_selected(name) {
document.getElementsByName(name)[1].checked = true;
}
function enable_change(enable_change) {
var endis = !(document.iform.enable.checked || enable_change);
document.iform.minutes1.disabled = endis;
document.iform.minutes2.disabled = endis;
document.iform.minutes3.disabled = endis;
document.iform.minutes4.disabled = endis;
document.iform.minutes5.disabled = endis;
document.iform.hours1.disabled = endis;
document.iform.hours2.disabled = endis;
document.iform.days1.disabled = endis;
document.iform.days2.disabled = endis;
document.iform.days3.disabled = endis;
document.iform.months.disabled = endis;
document.iform.weekdays.disabled = endis;
document.iform.all_mins1.disabled = endis;
document.iform.all_mins2.disabled = endis;
document.iform.all_hours1.disabled = endis;
document.iform.all_hours2.disabled = endis;
document.iform.all_days1.disabled = endis;
document.iform.all_days2.disabled = endis;
document.iform.all_months1.disabled = endis;
document.iform.all_months2.disabled = endis;
document.iform.all_weekdays1.disabled = endis;
document.iform.all_weekdays2.disabled = endis;
}
//-->
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="tabnavtbl">
<ul id="tabnav">
<li class="tabinact"><a href="shutdown.php"><span><?=gettext("Now");?></span></a></li>
<li class="tabact"><a href="shutdown_sched.php" title="<?=gettext("Reload page");?>"><span><?=gettext("Scheduled");?></span></a></li>
</ul>
</td>
</tr>
<tr>
<td class="tabcont">
<form action="shutdown_sched.php" method="post" name="iform" id="iform">
<?php if ($input_errors) print_input_errors($input_errors);?>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<?php html_titleline_checkbox("enable", gettext("Scheduled shutdown"), $pconfig['enable'] ? true : false, gettext("Enable"), "enable_change(false)");?>
<tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Time");?></td>
<td width="78%" class="vtable">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td class="listhdrlr"><?=gettext("Minutes");?></td>
<td class="listhdrr"><?=gettext("Hours");?></td>
<td class="listhdrr"><?=gettext("Days");?></td>
<td class="listhdrr"><?=gettext("Months");?></td>
<td class="listhdrr"><?=gettext("Week days");?></td>
</tr>
<tr>
<td class="listlr">
<input type="radio" name="all_mins" id="all_mins1" value="1" <?php if (1 == $pconfig['all_mins']) echo "checked=\"checked\"";?> />
<?=gettext("All");?><br />
<input type="radio" name="all_mins" id="all_mins2" value="0" <?php if (1 != $pconfig['all_mins']) echo "checked=\"checked\"";?> />
<?=gettext("Selected");?> ..<br />
<table>
<tr>
<td valign="top">
<select multiple="multiple" size="12" name="minute[]" id="minutes1" onchange="set_selected('all_mins')">
<?php for ($i = 0; $i <= 11; $i++):?>
<option value="<?=$i;?>" <?php if (is_array($pconfig['minute']) && in_array("$i", $pconfig['minute'])) echo "selected";?>><?=htmlspecialchars($i);?></option>
<?php endfor;?>
</select>
</td>
<td valign="top">
<select multiple="multiple" size="12" name="minute[]" id="minutes2" onchange="set_selected('all_mins')">
<?php for ($i = 12; $i <= 23; $i++):?>
<option value="<?=$i;?>" <?php if (is_array($pconfig['minute']) && in_array("$i", $pconfig['minute'])) echo "selected";?>><?=htmlspecialchars($i);?></option>
<?php endfor;?>
</select>
</td>
<td valign="top">
<select multiple="multiple" size="12" name="minute[]" id="minutes3" onchange="set_selected('all_mins')">
<?php for ($i = 24; $i <= 35; $i++):?>
<option value="<?=$i;?>" <?php if (is_array($pconfig['minute']) && in_array("$i", $pconfig['minute'])) echo "selected";?>><?=htmlspecialchars($i);?></option>
<?php endfor;?>
</select>
</td>
<td valign="top">
<select multiple="multiple" size="12" name="minute[]" id="minutes4" onchange="set_selected('all_mins')">
<?php for ($i = 36; $i <= 47; $i++):?>
<option value="<?=$i;?>" <?php if (is_array($pconfig['minute']) && in_array("$i", $pconfig['minute'])) echo "selected";?>><?=htmlspecialchars($i);?></option>
<?php endfor;?>
</select>
</td>
<td valign="top">
<select multiple="multiple" size="12" name="minute[]" id="minutes5" onchange="set_selected('all_mins')">
<?php for ($i = 48; $i <= 59; $i++):?>
<option value="<?=$i;?>" <?php if (is_array($pconfig['minute']) && in_array("$i", $pconfig['minute'])) echo "selected";?>><?=htmlspecialchars($i);?></option>
<?php endfor;?>
</select>
</td>
</tr>
</table>
<br />
</td>
<td class="listr" valign="top">
<input type="radio" name="all_hours" id="all_hours1" value="1" <?php if (1 == $pconfig['all_hours']) echo "checked=\"checked\"";?> />
<?=gettext("All");?><br />
<input type="radio" name="all_hours" id="all_hours2" value="0" <?php if (1 != $pconfig['all_hours']) echo "checked=\"checked\"";?> />
<?=gettext("Selected");?> ..<br />
<table>
<tr>
<td valign="top">
<select multiple="multiple" size="12" name="hour[]" id="hours1" onchange="set_selected('all_hours')">
<?php for ($i = 0; $i <= 11; $i++):?>
<option value="<?=$i;?>" <?php if (is_array($pconfig['hour']) && in_array("$i", $pconfig['hour'])) echo "selected";?>><?=htmlspecialchars($i);?></option>
<?php endfor;?>
</select>
</td>
<td valign="top">
<select multiple="multiple" size="12" name="hour[]" id="hours2" onchange="set_selected('all_hours')">
<?php for ($i = 12; $i <= 23; $i++):?>
<option value="<?=$i;?>" <?php if (is_array($pconfig['hour']) && in_array("$i", $pconfig['hour'])) echo "selected";?>><?=htmlspecialchars($i);?></option>
<?php endfor;?>
</select>
</td>
</tr>
</table>
</td>
<td class="listr" valign="top">
<input type="radio" name="all_days" id="all_days1" value="1" <?php if (1 == $pconfig['all_days']) echo "checked=\"checked\"";?> />
<?=gettext("All");?><br />
<input type="radio" name="all_days" id="all_days2" value="0" <?php if (1 != $pconfig['all_days']) echo "checked=\"checked\"";?> />
<?=gettext("Selected");?> ..<br />
<table>
<tr>
<td valign="top">
<select multiple="multiple" size="12" name="day[]" id="days1" onchange="set_selected('all_days')">
<?php for ($i = 1; $i <= 12; $i++):?>
<option value="<?=$i;?>" <?php if (is_array($pconfig['day']) && in_array("$i", $pconfig['day'])) echo "selected";?>><?=htmlspecialchars($i);?></option>
<?php endfor;?>
</select>
</td>
<td valign="top">
<select multiple="multiple" size="12" name="day[]" id="days2" onchange="set_selected('all_days')">
<?php for ($i = 13; $i <= 24; $i++):?>
<option value="<?=$i;?>" <?php if (is_array($pconfig['day']) && in_array("$i", $pconfig['day'])) echo "selected";?>><?=htmlspecialchars($i);?></option>
<?php endfor;?>
</select>
</td>
<td valign="top">
<select multiple="multiple" size="7" name="day[]" id="days3" onchange="set_selected('all_days')">
<?php for ($i = 25; $i <= 31; $i++):?>
<option value="<?=$i;?>" <?php if (is_array($pconfig['day']) && in_array("$i", $pconfig['day'])) echo "selected";?>><?=htmlspecialchars($i);?></option>
<?php endfor;?>
</select>
</td>
</tr>
</table>
</td>
<td class="listr" valign="top">
<input type="radio" name="all_months" id="all_months1" value="1" <?php if (1 == $pconfig['all_months']) echo "checked=\"checked\"";?> />
<?=gettext("All");?><br />
<input type="radio" name="all_months" id="all_months2" value="0" <?php if (1 != $pconfig['all_months']) echo "checked=\"checked\"";?> />
<?=gettext("Selected");?> ..<br />
<table>
<tr>
<td valign="top">
<select multiple="multiple" size="12" name="month[]" id="months" onchange="set_selected('all_months')">
<?php $i = 1; foreach ($a_months as $month):?>
<option value="<?=$i;?>" <?php if (isset($pconfig['month']) && in_array("$i", $pconfig['month'])) echo "selected";?>><?=htmlspecialchars($month);?></option>
<?php $i++; endforeach;?>
</select>
</td>
</tr>
</table>
</td>
<td class="listr" valign="top">
<input type="radio" name="all_weekdays" id="all_weekdays1" value="1" <?php if (1 == $pconfig['all_weekdays']) echo "checked=\"checked\"";?> />
<?=gettext("All");?><br />
<input type="radio" name="all_weekdays" id="all_weekdays2" value="0" <?php if (1 != $pconfig['all_weekdays']) echo "checked=\"checked\"";?> />
<?=gettext("Selected");?> ..<br />
<table>
<tr>
<td valign="top">
<select multiple="multiple" size="7" name="weekday[]" id="weekdays" onchange="set_selected('all_weekdays')">
<?php $i = 0; foreach ($a_weekdays as $day):?>
<option value="<?=$i;?>" <?php if (isset($pconfig['weekday']) && in_array("$i", $pconfig['weekday'])) echo "selected";?>><?=$day;?></option>
<?php $i++; endforeach;?>
</select>
</td>
</tr>
</table>
</td>
</tr>
</table>
<span class="vexpl"><?=gettext("Note: Ctrl-click (or command-click on the Mac) to select and de-select minutes, hours, days and months.");?></span>
</td>
</tr>
</table>
<div id="submit">
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Save");?>" onclick="enable_change(true)" />
</div>
<?php include("formend.inc");?>
</form>
</td>
</tr>
</table>
<script type="text/javascript">
<!--
enable_change(false);
//-->
</script>
<?php include("fend.inc");?>