1 |
615b27bc
|
Scott Dale
|
<?php
|
2 |
|
|
/*
|
3 |
dcef097d
|
Scott Dale
|
firewall_schedule.php
|
4 |
615b27bc
|
Scott Dale
|
Copyright (C) 2004 Scott Ullrich
|
5 |
|
|
All rights reserved.
|
6 |
|
|
|
7 |
|
|
originially part of m0n0wall (http://m0n0.ch/wall)
|
8 |
|
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9 |
|
|
All rights reserved.
|
10 |
|
|
|
11 |
|
|
Redistribution and use in source and binary forms, with or without
|
12 |
|
|
modification, are permitted provided that the following conditions are met:
|
13 |
|
|
|
14 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
this list of conditions and the following disclaimer.
|
16 |
|
|
|
17 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
18 |
|
|
notice, this list of conditions and the following disclaimer in the
|
19 |
|
|
documentation and/or other materials provided with the distribution.
|
20 |
|
|
|
21 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
31 |
|
|
*/
|
32 |
7ac5a4cb
|
Scott Ullrich
|
/*
|
33 |
|
|
pfSense_MODULE: schedules
|
34 |
|
|
*/
|
35 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
36 |
|
|
##|*IDENT=page-firewall-schedules
|
37 |
|
|
##|*NAME=Firewall: Schedules page
|
38 |
|
|
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
|
39 |
|
|
##|*MATCH=firewall_schedule.php*
|
40 |
|
|
##|-PRIV
|
41 |
|
|
|
42 |
fa227734
|
Rafael Lucas
|
$pgtitle = array(gettext("Firewall"),gettext("Schedules"));
|
43 |
615b27bc
|
Scott Dale
|
|
44 |
fa227734
|
Rafael Lucas
|
$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
|
45 |
|
|
$monthArray = array (gettext('January'),gettext('February'),gettext('March'),gettext('April'),gettext('May'),gettext('June'),gettext('July'),gettext('August'),gettext('September'),gettext('October'),gettext('November'),gettext('December'));
|
46 |
615b27bc
|
Scott Dale
|
|
47 |
|
|
require("guiconfig.inc");
|
48 |
1a03cf69
|
Scott Ullrich
|
require("filter.inc");
|
49 |
|
|
require("shaper.inc");
|
50 |
615b27bc
|
Scott Dale
|
|
51 |
|
|
if (!is_array($config['schedules']['schedule']))
|
52 |
|
|
$config['schedules']['schedule'] = array();
|
53 |
|
|
|
54 |
|
|
$a_schedules = &$config['schedules']['schedule'];
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
if ($_GET['act'] == "del") {
|
58 |
|
|
if ($a_schedules[$_GET['id']]) {
|
59 |
|
|
/* make sure rule is not being referenced by any nat or filter rules */
|
60 |
|
|
$is_schedule_referenced = false;
|
61 |
|
|
$referenced_by = false;
|
62 |
|
|
$schedule_name = $a_schedules[$_GET['id']]['name'];
|
63 |
|
|
|
64 |
|
|
if(is_array($config['filter']['rule'])) {
|
65 |
|
|
foreach($config['filter']['rule'] as $rule) {
|
66 |
|
|
//check for this later once this is established
|
67 |
273c8b1c
|
Scott Dale
|
if ($rule['sched'] == $schedule_name){
|
68 |
615b27bc
|
Scott Dale
|
$referenced_by = $rule['descr'];
|
69 |
|
|
$is_schedule_referenced = true;
|
70 |
273c8b1c
|
Scott Dale
|
break;
|
71 |
615b27bc
|
Scott Dale
|
}
|
72 |
|
|
}
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
if($is_schedule_referenced == true) {
|
76 |
fa227734
|
Rafael Lucas
|
$savemsg = sprintf(gettext("Cannot delete Schedule. Currently in use by %s"),$referenced_by);
|
77 |
615b27bc
|
Scott Dale
|
} else {
|
78 |
|
|
unset($a_schedules[$_GET['id']]);
|
79 |
|
|
write_config();
|
80 |
|
|
header("Location: firewall_schedule.php");
|
81 |
|
|
exit;
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
include("head.inc");
|
87 |
|
|
?>
|
88 |
|
|
|
89 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
90 |
|
|
<?php include("fbegin.inc"); ?>
|
91 |
|
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
92 |
|
|
<form action="firewall_schedule.php" method="post">
|
93 |
ff9d6728
|
Scott Ullrich
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
|
94 |
615b27bc
|
Scott Dale
|
<tr>
|
95 |
2db2df36
|
Vinicius Coque
|
<td width="25%" class="listhdrr"><?=gettext("Name");?></td>
|
96 |
|
|
<td width="35%" class="listhdrr"><?=gettext("Time Range(s)");?></td>
|
97 |
|
|
<td width="35%" class="listhdr"><?=gettext("Description");?></td>
|
98 |
d415d821
|
Seth Mos
|
<td width="5%" class="list sort_ignore">
|
99 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
100 |
|
|
<tr>
|
101 |
|
|
<td width="17"></td>
|
102 |
|
|
<td valign="middle"><a href="firewall_schedule_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add a new schedule");?>" alt="" /></a></td>
|
103 |
|
|
</tr>
|
104 |
|
|
</table>
|
105 |
|
|
</td>
|
106 |
615b27bc
|
Scott Dale
|
</tr>
|
107 |
|
|
<?php $i = 0; foreach ($a_schedules as $schedule): ?>
|
108 |
|
|
<tr>
|
109 |
|
|
<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
|
110 |
774c288f
|
Scott Dale
|
<?=htmlspecialchars($schedule['name']);
|
111 |
60120e37
|
Ermal Lu?i
|
$schedstatus = filter_get_time_based_rule_status($schedule);
|
112 |
774c288f
|
Scott Dale
|
if ($schedstatus) { ?>
|
113 |
fa227734
|
Rafael Lucas
|
<img src="./themes/<?= $g['theme']; ?>/images/icons/icon_frmfld_time.png" title="<?=gettext("Schedule is currently active");?>" width="17" height="17" border="0">
|
114 |
774c288f
|
Scott Dale
|
<?php } ?>
|
115 |
|
|
|
116 |
615b27bc
|
Scott Dale
|
</td>
|
117 |
|
|
<td class="listlr" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
|
118 |
1a4f3123
|
Scott Dale
|
<table width="98%" border="0" cellpadding="0" cellspacing="0">
|
119 |
774c288f
|
Scott Dale
|
<?php
|
120 |
|
|
|
121 |
|
|
foreach($schedule['timerange'] as $timerange) {
|
122 |
273c8b1c
|
Scott Dale
|
$tempFriendlyTime = "";
|
123 |
|
|
$tempID = "";
|
124 |
|
|
$firstprint = false;
|
125 |
|
|
if ($timerange){
|
126 |
|
|
$dayFriendly = "";
|
127 |
|
|
$tempFriendlyTime = "";
|
128 |
|
|
|
129 |
|
|
//get hours
|
130 |
|
|
$temptimerange = $timerange['hour'];
|
131 |
615b27bc
|
Scott Dale
|
$temptimeseparator = strrpos($temptimerange, "-");
|
132 |
273c8b1c
|
Scott Dale
|
|
133 |
615b27bc
|
Scott Dale
|
$starttime = substr ($temptimerange, 0, $temptimeseparator);
|
134 |
|
|
$stoptime = substr ($temptimerange, $temptimeseparator+1);
|
135 |
273c8b1c
|
Scott Dale
|
|
136 |
|
|
if ($timerange['month']){
|
137 |
|
|
$tempmontharray = explode(",", $timerange['month']);
|
138 |
|
|
$tempdayarray = explode(",",$timerange['day']);
|
139 |
|
|
$arraycounter = 0;
|
140 |
1a4f3123
|
Scott Dale
|
$firstDayFound = false;
|
141 |
|
|
$firstPrint = false;
|
142 |
273c8b1c
|
Scott Dale
|
foreach ($tempmontharray as $monthtmp){
|
143 |
|
|
$month = $tempmontharray[$arraycounter];
|
144 |
|
|
$day = $tempdayarray[$arraycounter];
|
145 |
1a4f3123
|
Scott Dale
|
|
146 |
|
|
if (!$firstDayFound)
|
147 |
|
|
{
|
148 |
|
|
$firstDay = $day;
|
149 |
|
|
$firstmonth = $month;
|
150 |
|
|
$firstDayFound = true;
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
$currentDay = $day;
|
154 |
|
|
$nextDay = $tempdayarray[$arraycounter+1];
|
155 |
|
|
$currentDay++;
|
156 |
|
|
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
|
157 |
|
|
if ($firstPrint)
|
158 |
|
|
$dayFriendly .= "<br/>";
|
159 |
|
|
$currentDay--;
|
160 |
|
|
if ($currentDay != $firstDay)
|
161 |
|
|
$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
|
162 |
|
|
else
|
163 |
|
|
$dayFriendly .= $monthArray[$month-1] . " " . $day;
|
164 |
|
|
$firstDayFound = false;
|
165 |
|
|
$firstPrint = true;
|
166 |
|
|
}
|
167 |
|
|
$arraycounter++;
|
168 |
615b27bc
|
Scott Dale
|
}
|
169 |
|
|
}
|
170 |
273c8b1c
|
Scott Dale
|
else
|
171 |
|
|
{
|
172 |
fdb29c8a
|
Scott Dale
|
$tempdayFriendly = $timerange['position'];
|
173 |
273c8b1c
|
Scott Dale
|
$firstDayFound = false;
|
174 |
|
|
$tempFriendlyDayArray = explode(",", $tempdayFriendly);
|
175 |
|
|
$currentDay = "";
|
176 |
|
|
$firstDay = "";
|
177 |
|
|
$nextDay = "";
|
178 |
|
|
$counter = 0;
|
179 |
|
|
foreach ($tempFriendlyDayArray as $day){
|
180 |
|
|
if ($day != ""){
|
181 |
|
|
if (!$firstDayFound)
|
182 |
|
|
{
|
183 |
|
|
$firstDay = $tempFriendlyDayArray[$counter];
|
184 |
|
|
$firstDayFound = true;
|
185 |
|
|
}
|
186 |
|
|
$currentDay =$tempFriendlyDayArray[$counter];
|
187 |
|
|
//get next day
|
188 |
|
|
$nextDay = $tempFriendlyDayArray[$counter+1];
|
189 |
|
|
$currentDay++;
|
190 |
|
|
if ($currentDay != $nextDay){
|
191 |
|
|
if ($firstprint)
|
192 |
1a4f3123
|
Scott Dale
|
$dayFriendly .= "<br/>";
|
193 |
273c8b1c
|
Scott Dale
|
$currentDay--;
|
194 |
|
|
if ($currentDay != $firstDay)
|
195 |
6a6d2f63
|
Scott Dale
|
$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
|
196 |
273c8b1c
|
Scott Dale
|
else
|
197 |
6a6d2f63
|
Scott Dale
|
$dayFriendly .= $dayArray[$firstDay-1];
|
198 |
273c8b1c
|
Scott Dale
|
$firstDayFound = false;
|
199 |
|
|
$firstprint = true;
|
200 |
|
|
}
|
201 |
|
|
$counter++;
|
202 |
615b27bc
|
Scott Dale
|
}
|
203 |
1a4f3123
|
Scott Dale
|
}
|
204 |
273c8b1c
|
Scott Dale
|
}
|
205 |
1a4f3123
|
Scott Dale
|
$timeFriendly = $starttime . "-" . $stoptime;
|
206 |
|
|
$description = $timerange['rangedescr'];
|
207 |
|
|
|
208 |
02dee88e
|
Scott Ullrich
|
?><tr><td><?echo $dayFriendly;?></td><td><?echo $timeFriendly;?></td><td><?echo $description;?></td><tr/><?php
|
209 |
615b27bc
|
Scott Dale
|
}
|
210 |
1a4f3123
|
Scott Dale
|
}//end for?></table>
|
211 |
615b27bc
|
Scott Dale
|
</td>
|
212 |
|
|
<td class="listbg" ondblclick="document.location='firewall_schedule_edit.php?id=<?=$i;?>';">
|
213 |
|
|
<?=htmlspecialchars($schedule['descr']);?>
|
214 |
|
|
</td>
|
215 |
|
|
<td valign="middle" nowrap class="list">
|
216 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
217 |
|
|
<tr>
|
218 |
fa227734
|
Rafael Lucas
|
<td valign="middle"><a href="firewall_schedule_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" title="<?=gettext("edit alias");?>"></a></td>
|
219 |
2db2df36
|
Vinicius Coque
|
<td><a href="firewall_schedule.php?act=del&id=<?=$i;?>" onclick="return confirm('<?=gettext('Do you really want to delete this schedule?');?>')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" title="<?=gettext("delete alias");?>"></a></td>
|
220 |
615b27bc
|
Scott Dale
|
</tr>
|
221 |
|
|
</table>
|
222 |
|
|
</td>
|
223 |
|
|
</tr>
|
224 |
|
|
<?php $i++; endforeach; ?>
|
225 |
|
|
<tr>
|
226 |
|
|
<td class="list" colspan="3"></td>
|
227 |
|
|
<td class="list">
|
228 |
|
|
<table border="0" cellspacing="0" cellpadding="1">
|
229 |
|
|
<tr>
|
230 |
d415d821
|
Seth Mos
|
<td width="17"></td>
|
231 |
|
|
<td valign="middle"><a href="firewall_schedule_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add a new schedule");?>" alt="" /></a></td>
|
232 |
|
|
</tr>
|
233 |
|
|
</table>
|
234 |
|
|
</td>
|
235 |
|
|
</tr>
|
236 |
|
|
<tr>
|
237 |
|
|
<td class="tabcont" colspan="3">
|
238 |
2db2df36
|
Vinicius Coque
|
<p><span class="vexpl"><span class="red"><strong><?=gettext("Note");?>:<br></strong></span><?=gettext("Schedules act as placeholders for time ranges to be used in Firewall Rules.");?></span></p>
|
239 |
d415d821
|
Seth Mos
|
</td>
|
240 |
|
|
</tr>
|
241 |
|
|
</table>
|
242 |
615b27bc
|
Scott Dale
|
|
243 |
|
|
</form>
|
244 |
|
|
|
245 |
|
|
<?php include("fend.inc"); ?>
|
246 |
|
|
</body>
|
247 |
|
|
</html>
|