1 |
615b27bc
|
Scott Dale
|
<?php
|
2 |
|
|
/*
|
3 |
dcef097d
|
Scott Dale
|
firewall_schedule.php
|
4 |
615b27bc
|
Scott Dale
|
*/
|
5 |
fd9ebcd5
|
Stephen Beaver
|
/* ====================================================================
|
6 |
016231d0
|
Stephen Beaver
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7 |
9da2cf1c
|
Stephen Beaver
|
*
|
8 |
cb41dd63
|
Renato Botelho
|
* Some or all of this file is based on the m0n0wall project which is
|
9 |
|
|
* Copyright (c) 2004 Manuel Kasper (BSD 2 clause)
|
10 |
fd9ebcd5
|
Stephen Beaver
|
*
|
11 |
016231d0
|
Stephen Beaver
|
* Redistribution and use in source and binary forms, with or without modification,
|
12 |
|
|
* are permitted provided that the following conditions are met:
|
13 |
fd9ebcd5
|
Stephen Beaver
|
*
|
14 |
016231d0
|
Stephen Beaver
|
* 1. Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
* this list of conditions and the following disclaimer.
|
16 |
fd9ebcd5
|
Stephen Beaver
|
*
|
17 |
016231d0
|
Stephen Beaver
|
* 2. Redistributions in binary form must reproduce the above copyright
|
18 |
|
|
* notice, this list of conditions and the following disclaimer in
|
19 |
|
|
* the documentation and/or other materials provided with the
|
20 |
|
|
* distribution.
|
21 |
fd9ebcd5
|
Stephen Beaver
|
*
|
22 |
016231d0
|
Stephen Beaver
|
* 3. All advertising materials mentioning features or use of this software
|
23 |
|
|
* must display the following acknowledgment:
|
24 |
|
|
* "This product includes software developed by the pfSense Project
|
25 |
|
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
26 |
fd9ebcd5
|
Stephen Beaver
|
*
|
27 |
016231d0
|
Stephen Beaver
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
28 |
|
|
* endorse or promote products derived from this software without
|
29 |
|
|
* prior written permission. For written permission, please contact
|
30 |
|
|
* coreteam@pfsense.org.
|
31 |
fd9ebcd5
|
Stephen Beaver
|
*
|
32 |
016231d0
|
Stephen Beaver
|
* 5. Products derived from this software may not be called "pfSense"
|
33 |
|
|
* nor may "pfSense" appear in their names without prior written
|
34 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
35 |
fd9ebcd5
|
Stephen Beaver
|
*
|
36 |
016231d0
|
Stephen Beaver
|
* 6. Redistributions of any form whatsoever must retain the following
|
37 |
|
|
* acknowledgment:
|
38 |
fd9ebcd5
|
Stephen Beaver
|
*
|
39 |
016231d0
|
Stephen Beaver
|
* "This product includes software developed by the pfSense Project
|
40 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
41 |
919d91f9
|
Phil Davis
|
*
|
42 |
016231d0
|
Stephen Beaver
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
43 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
44 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
45 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
46 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
47 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
48 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
49 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
50 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
51 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
52 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
53 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
54 |
fd9ebcd5
|
Stephen Beaver
|
*
|
55 |
016231d0
|
Stephen Beaver
|
* ====================================================================
|
56 |
fd9ebcd5
|
Stephen Beaver
|
*
|
57 |
|
|
*/
|
58 |
6aa3723a
|
Renato Botelho
|
|
59 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
60 |
|
|
##|*IDENT=page-firewall-schedules
|
61 |
5230f468
|
jim-p
|
##|*NAME=Firewall: Schedules
|
62 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
|
63 |
|
|
##|*MATCH=firewall_schedule.php*
|
64 |
|
|
##|-PRIV
|
65 |
|
|
|
66 |
b96cb0a5
|
Stephen Beaver
|
define('CLOCK', '<i class="fa fa-clock-o icon-black"></i>');
|
67 |
615b27bc
|
Scott Dale
|
|
68 |
6c07db48
|
Phil Davis
|
$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
|
69 |
|
|
$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'));
|
70 |
615b27bc
|
Scott Dale
|
|
71 |
|
|
require("guiconfig.inc");
|
72 |
f6339216
|
jim-p
|
require_once("filter.inc");
|
73 |
1a03cf69
|
Scott Ullrich
|
require("shaper.inc");
|
74 |
615b27bc
|
Scott Dale
|
|
75 |
6c07db48
|
Phil Davis
|
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
|
76 |
7102bd3c
|
Carlos Eduardo Ramos
|
|
77 |
bedc00c8
|
Phil Davis
|
if (!is_array($config['schedules']['schedule'])) {
|
78 |
615b27bc
|
Scott Dale
|
$config['schedules']['schedule'] = array();
|
79 |
bedc00c8
|
Phil Davis
|
}
|
80 |
615b27bc
|
Scott Dale
|
|
81 |
|
|
$a_schedules = &$config['schedules']['schedule'];
|
82 |
|
|
|
83 |
|
|
if ($_GET['act'] == "del") {
|
84 |
|
|
if ($a_schedules[$_GET['id']]) {
|
85 |
|
|
/* make sure rule is not being referenced by any nat or filter rules */
|
86 |
|
|
$is_schedule_referenced = false;
|
87 |
|
|
$referenced_by = false;
|
88 |
|
|
$schedule_name = $a_schedules[$_GET['id']]['name'];
|
89 |
|
|
|
90 |
bedc00c8
|
Phil Davis
|
if (is_array($config['filter']['rule'])) {
|
91 |
|
|
foreach ($config['filter']['rule'] as $rule) {
|
92 |
615b27bc
|
Scott Dale
|
//check for this later once this is established
|
93 |
bedc00c8
|
Phil Davis
|
if ($rule['sched'] == $schedule_name) {
|
94 |
615b27bc
|
Scott Dale
|
$referenced_by = $rule['descr'];
|
95 |
|
|
$is_schedule_referenced = true;
|
96 |
273c8b1c
|
Scott Dale
|
break;
|
97 |
615b27bc
|
Scott Dale
|
}
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
|
101 |
bedc00c8
|
Phil Davis
|
if ($is_schedule_referenced == true) {
|
102 |
e6f34d22
|
Phil Davis
|
$savemsg = sprintf(gettext("Cannot delete Schedule. Currently in use by %s"), $referenced_by);
|
103 |
615b27bc
|
Scott Dale
|
} else {
|
104 |
|
|
unset($a_schedules[$_GET['id']]);
|
105 |
|
|
write_config();
|
106 |
|
|
header("Location: firewall_schedule.php");
|
107 |
|
|
exit;
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
include("head.inc");
|
113 |
416cbf3c
|
sbeaver
|
|
114 |
67c2baf1
|
Phil Davis
|
if ($savemsg) {
|
115 |
416cbf3c
|
sbeaver
|
print_info_box($savemsg, 'success');
|
116 |
67c2baf1
|
Phil Davis
|
}
|
117 |
615b27bc
|
Scott Dale
|
?>
|
118 |
|
|
|
119 |
416b6a09
|
sbeaver
|
<div class="panel panel-default">
|
120 |
f17594c7
|
Sjon Hortensius
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
|
121 |
416b6a09
|
sbeaver
|
<div class="panel-body table-responsive">
|
122 |
|
|
<table class="table table-striped table-hover table-condensed">
|
123 |
|
|
<thead>
|
124 |
|
|
<tr>
|
125 |
|
|
<th><!--"Active" indicator--></th>
|
126 |
|
|
<th><?=gettext("Name")?></th>
|
127 |
|
|
<th><?=gettext("Range: Date / Times / Name")?></th>
|
128 |
|
|
<th><?=gettext("Description")?></th>
|
129 |
|
|
<th><!--Buttons--></th>
|
130 |
|
|
</tr>
|
131 |
|
|
</thead>
|
132 |
|
|
<tbody>
|
133 |
416cbf3c
|
sbeaver
|
<?php
|
134 |
|
|
$i = 0;
|
135 |
|
|
foreach ($a_schedules as $schedule):
|
136 |
|
|
$schedstatus = filter_get_time_based_rule_status($schedule);
|
137 |
|
|
?>
|
138 |
416b6a09
|
sbeaver
|
<tr>
|
139 |
|
|
<td>
|
140 |
10fe1eb5
|
Stephen Beaver
|
<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
|
141 |
416b6a09
|
sbeaver
|
</td>
|
142 |
|
|
<td>
|
143 |
|
|
<?=htmlspecialchars($schedule['name'])?>
|
144 |
|
|
</td>
|
145 |
|
|
<td>
|
146 |
416cbf3c
|
sbeaver
|
<?php
|
147 |
|
|
$first = true;
|
148 |
e6f34d22
|
Phil Davis
|
foreach ($schedule['timerange'] as $timerange) {
|
149 |
416cbf3c
|
sbeaver
|
$tempFriendlyTime = "";
|
150 |
|
|
$tempID = "";
|
151 |
|
|
$firstprint = false;
|
152 |
|
|
|
153 |
|
|
if ($timerange) {
|
154 |
|
|
$dayFriendly = "";
|
155 |
|
|
$tempFriendlyTime = "";
|
156 |
|
|
|
157 |
|
|
//get hours
|
158 |
|
|
$temptimerange = $timerange['hour'];
|
159 |
|
|
$temptimeseparator = strrpos($temptimerange, "-");
|
160 |
|
|
|
161 |
|
|
$starttime = substr ($temptimerange, 0, $temptimeseparator);
|
162 |
|
|
$stoptime = substr ($temptimerange, $temptimeseparator+1);
|
163 |
|
|
|
164 |
|
|
if ($timerange['month']) {
|
165 |
|
|
$tempmontharray = explode(",", $timerange['month']);
|
166 |
e6f34d22
|
Phil Davis
|
$tempdayarray = explode(",", $timerange['day']);
|
167 |
416cbf3c
|
sbeaver
|
$arraycounter = 0;
|
168 |
|
|
$firstDayFound = false;
|
169 |
|
|
$firstPrint = false;
|
170 |
e6f34d22
|
Phil Davis
|
foreach ($tempmontharray as $monthtmp) {
|
171 |
416cbf3c
|
sbeaver
|
$month = $tempmontharray[$arraycounter];
|
172 |
|
|
$day = $tempdayarray[$arraycounter];
|
173 |
|
|
|
174 |
|
|
if (!$firstDayFound) {
|
175 |
|
|
$firstDay = $day;
|
176 |
|
|
$firstmonth = $month;
|
177 |
|
|
$firstDayFound = true;
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
$currentDay = $day;
|
181 |
|
|
$nextDay = $tempdayarray[$arraycounter+1];
|
182 |
|
|
$currentDay++;
|
183 |
|
|
|
184 |
e6f34d22
|
Phil Davis
|
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
|
185 |
67c2baf1
|
Phil Davis
|
if ($firstPrint) {
|
186 |
416cbf3c
|
sbeaver
|
$dayFriendly .= "<br />";
|
187 |
67c2baf1
|
Phil Davis
|
}
|
188 |
416cbf3c
|
sbeaver
|
|
189 |
|
|
$currentDay--;
|
190 |
|
|
|
191 |
67c2baf1
|
Phil Davis
|
if ($currentDay != $firstDay) {
|
192 |
416cbf3c
|
sbeaver
|
$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
|
193 |
67c2baf1
|
Phil Davis
|
} else {
|
194 |
416cbf3c
|
sbeaver
|
$dayFriendly .= $monthArray[$month-1] . " " . $day;
|
195 |
67c2baf1
|
Phil Davis
|
}
|
196 |
416cbf3c
|
sbeaver
|
|
197 |
|
|
$firstDayFound = false;
|
198 |
|
|
$firstPrint = true;
|
199 |
|
|
}
|
200 |
|
|
$arraycounter++;
|
201 |
|
|
}
|
202 |
67c2baf1
|
Phil Davis
|
} else {
|
203 |
416cbf3c
|
sbeaver
|
$tempdayFriendly = $timerange['position'];
|
204 |
|
|
$firstDayFound = false;
|
205 |
|
|
$tempFriendlyDayArray = explode(",", $tempdayFriendly);
|
206 |
|
|
$currentDay = "";
|
207 |
|
|
$firstDay = "";
|
208 |
|
|
$nextDay = "";
|
209 |
|
|
$counter = 0;
|
210 |
|
|
|
211 |
e6f34d22
|
Phil Davis
|
foreach ($tempFriendlyDayArray as $day) {
|
212 |
|
|
if ($day != "") {
|
213 |
67c2baf1
|
Phil Davis
|
if (!$firstDayFound) {
|
214 |
416cbf3c
|
sbeaver
|
$firstDay = $tempFriendlyDayArray[$counter];
|
215 |
|
|
$firstDayFound = true;
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
$currentDay =$tempFriendlyDayArray[$counter];
|
219 |
|
|
//get next day
|
220 |
|
|
$nextDay = $tempFriendlyDayArray[$counter+1];
|
221 |
|
|
$currentDay++;
|
222 |
|
|
|
223 |
e6f34d22
|
Phil Davis
|
if ($currentDay != $nextDay) {
|
224 |
67c2baf1
|
Phil Davis
|
if ($firstprint) {
|
225 |
416cbf3c
|
sbeaver
|
$dayFriendly .= "<br />";
|
226 |
67c2baf1
|
Phil Davis
|
}
|
227 |
416cbf3c
|
sbeaver
|
|
228 |
|
|
$currentDay--;
|
229 |
|
|
|
230 |
67c2baf1
|
Phil Davis
|
if ($currentDay != $firstDay) {
|
231 |
416cbf3c
|
sbeaver
|
$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
|
232 |
67c2baf1
|
Phil Davis
|
} else {
|
233 |
416cbf3c
|
sbeaver
|
$dayFriendly .= $dayArray[$firstDay-1];
|
234 |
67c2baf1
|
Phil Davis
|
}
|
235 |
416cbf3c
|
sbeaver
|
|
236 |
|
|
$firstDayFound = false;
|
237 |
|
|
$firstprint = true;
|
238 |
615b27bc
|
Scott Dale
|
}
|
239 |
416cbf3c
|
sbeaver
|
$counter++;
|
240 |
|
|
}
|
241 |
|
|
}
|
242 |
|
|
}
|
243 |
|
|
|
244 |
|
|
$timeFriendly = $starttime . "-" . $stoptime;
|
245 |
|
|
$description = $timerange['rangedescr'];
|
246 |
|
|
|
247 |
|
|
print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
|
248 |
|
|
}
|
249 |
|
|
$first = false;
|
250 |
|
|
}
|
251 |
|
|
?>
|
252 |
416b6a09
|
sbeaver
|
</td>
|
253 |
416cbf3c
|
sbeaver
|
|
254 |
416b6a09
|
sbeaver
|
<td>
|
255 |
|
|
<?=htmlspecialchars($schedule['descr'])?>
|
256 |
|
|
</td>
|
257 |
416cbf3c
|
sbeaver
|
|
258 |
416b6a09
|
sbeaver
|
<td>
|
259 |
2de1c196
|
heper
|
<a class="fa fa-pencil" title="<?=gettext("Edit schedule"); ?>" href="firewall_schedule_edit.php?id=<?=$i?>"></a>
|
260 |
33f0b0d5
|
Stephen Beaver
|
<a class="fa fa-trash" title="<?=gettext("Delete schedule")?>" href="firewall_schedule.php?act=del&id=<?=$i?>"></a>
|
261 |
416cbf3c
|
sbeaver
|
|
262 |
416b6a09
|
sbeaver
|
</td>
|
263 |
|
|
</tr>
|
264 |
416cbf3c
|
sbeaver
|
<?php
|
265 |
|
|
$i++;
|
266 |
|
|
endforeach;
|
267 |
|
|
?>
|
268 |
416b6a09
|
sbeaver
|
</tbody>
|
269 |
|
|
</table>
|
270 |
416cbf3c
|
sbeaver
|
</div>
|
271 |
416b6a09
|
sbeaver
|
</div>
|
272 |
416cbf3c
|
sbeaver
|
|
273 |
b96cb0a5
|
Stephen Beaver
|
<?=($i > 0) ? CLOCK . gettext(' Indicates that the schedule is currently active.'):''?>
|
274 |
416cbf3c
|
sbeaver
|
|
275 |
c10cb196
|
Stephen Beaver
|
<nav class="action-buttons">
|
276 |
2ec8f0ba
|
Stephen Beaver
|
<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success">
|
277 |
9d5a20cf
|
heper
|
<i class="fa fa-plus icon-embed-btn"></i>
|
278 |
2ec8f0ba
|
Stephen Beaver
|
<?=gettext("Add")?>
|
279 |
|
|
</a>
|
280 |
416b6a09
|
sbeaver
|
</nav>
|
281 |
416cbf3c
|
sbeaver
|
|
282 |
35681930
|
Stephen Beaver
|
<div class="infoblock">
|
283 |
5bff8af8
|
NewEraCracker
|
<?=print_info_box(gettext('Schedules act as placeholders for time ranges to be used in Firewall Rules.'), 'info')?>
|
284 |
2ec8f0ba
|
Stephen Beaver
|
</div>
|
285 |
416cbf3c
|
sbeaver
|
|
286 |
2ec8f0ba
|
Stephen Beaver
|
<?php
|
287 |
416cbf3c
|
sbeaver
|
|
288 |
2de1c196
|
heper
|
include("foot.inc");
|