1
|
<?php
|
2
|
/*
|
3
|
firewall_schedule.php
|
4
|
Copyright (C) 2004 Scott Ullrich
|
5
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
6
|
All rights reserved.
|
7
|
|
8
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
9
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
10
|
All rights reserved.
|
11
|
|
12
|
Redistribution and use in source and binary forms, with or without
|
13
|
modification, are permitted provided that the following conditions are met:
|
14
|
|
15
|
1. Redistributions of source code must retain the above copyright notice,
|
16
|
this list of conditions and the following disclaimer.
|
17
|
|
18
|
2. Redistributions in binary form must reproduce the above copyright
|
19
|
notice, this list of conditions and the following disclaimer in the
|
20
|
documentation and/or other materials provided with the distribution.
|
21
|
|
22
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
POSSIBILITY OF SUCH DAMAGE.
|
32
|
*/
|
33
|
/*
|
34
|
pfSense_MODULE: schedules
|
35
|
*/
|
36
|
##|+PRIV
|
37
|
##|*IDENT=page-firewall-schedules
|
38
|
##|*NAME=Firewall: Schedules page
|
39
|
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
|
40
|
##|*MATCH=firewall_schedule.php*
|
41
|
##|-PRIV
|
42
|
|
43
|
define('CLOCK', '🕐');
|
44
|
|
45
|
$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
|
46
|
$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'));
|
47
|
|
48
|
require("guiconfig.inc");
|
49
|
require_once("filter.inc");
|
50
|
require("shaper.inc");
|
51
|
|
52
|
$pgtitle = array(gettext("Firewall"),gettext("Schedules"));
|
53
|
|
54
|
if (!is_array($config['schedules']['schedule']))
|
55
|
$config['schedules']['schedule'] = array();
|
56
|
|
57
|
$a_schedules = &$config['schedules']['schedule'];
|
58
|
|
59
|
if ($_GET['act'] == "del") {
|
60
|
if ($a_schedules[$_GET['id']]) {
|
61
|
/* make sure rule is not being referenced by any nat or filter rules */
|
62
|
$is_schedule_referenced = false;
|
63
|
$referenced_by = false;
|
64
|
$schedule_name = $a_schedules[$_GET['id']]['name'];
|
65
|
|
66
|
if(is_array($config['filter']['rule'])) {
|
67
|
foreach($config['filter']['rule'] as $rule) {
|
68
|
//check for this later once this is established
|
69
|
if ($rule['sched'] == $schedule_name){
|
70
|
$referenced_by = $rule['descr'];
|
71
|
$is_schedule_referenced = true;
|
72
|
break;
|
73
|
}
|
74
|
}
|
75
|
}
|
76
|
|
77
|
if($is_schedule_referenced == true) {
|
78
|
$savemsg = sprintf(gettext("Cannot delete Schedule. Currently in use by %s"),$referenced_by);
|
79
|
} else {
|
80
|
unset($a_schedules[$_GET['id']]);
|
81
|
write_config();
|
82
|
header("Location: firewall_schedule.php");
|
83
|
exit;
|
84
|
}
|
85
|
}
|
86
|
}
|
87
|
|
88
|
include("head.inc");
|
89
|
|
90
|
if ($savemsg)
|
91
|
print_info_box($savemsg, 'success');
|
92
|
?>
|
93
|
|
94
|
<div class="panel panel-default">
|
95
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
|
96
|
<div class="panel-body table-responsive">
|
97
|
<table class="table table-striped table-hover table-condensed">
|
98
|
<thead>
|
99
|
<tr>
|
100
|
<th><!--"Active" indicator--></th>
|
101
|
<th><?=gettext("Name")?></th>
|
102
|
<th><?=gettext("Range: Date / Times / Name")?></th>
|
103
|
<th><?=gettext("Description")?></th>
|
104
|
<th><!--Buttons--></th>
|
105
|
</tr>
|
106
|
</thead>
|
107
|
<tbody>
|
108
|
<?php
|
109
|
$i = 0;
|
110
|
foreach ($a_schedules as $schedule):
|
111
|
$schedstatus = filter_get_time_based_rule_status($schedule);
|
112
|
?>
|
113
|
<tr>
|
114
|
<td>
|
115
|
<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
|
116
|
</td>
|
117
|
<td>
|
118
|
<?=htmlspecialchars($schedule['name'])?>
|
119
|
</td>
|
120
|
<td>
|
121
|
<?php
|
122
|
$first = true;
|
123
|
foreach($schedule['timerange'] as $timerange) {
|
124
|
$tempFriendlyTime = "";
|
125
|
$tempID = "";
|
126
|
$firstprint = false;
|
127
|
|
128
|
if ($timerange) {
|
129
|
$dayFriendly = "";
|
130
|
$tempFriendlyTime = "";
|
131
|
|
132
|
//get hours
|
133
|
$temptimerange = $timerange['hour'];
|
134
|
$temptimeseparator = strrpos($temptimerange, "-");
|
135
|
|
136
|
$starttime = substr ($temptimerange, 0, $temptimeseparator);
|
137
|
$stoptime = substr ($temptimerange, $temptimeseparator+1);
|
138
|
|
139
|
if ($timerange['month']) {
|
140
|
$tempmontharray = explode(",", $timerange['month']);
|
141
|
$tempdayarray = explode(",",$timerange['day']);
|
142
|
$arraycounter = 0;
|
143
|
$firstDayFound = false;
|
144
|
$firstPrint = false;
|
145
|
foreach ($tempmontharray as $monthtmp){
|
146
|
$month = $tempmontharray[$arraycounter];
|
147
|
$day = $tempdayarray[$arraycounter];
|
148
|
|
149
|
if (!$firstDayFound) {
|
150
|
$firstDay = $day;
|
151
|
$firstmonth = $month;
|
152
|
$firstDayFound = true;
|
153
|
}
|
154
|
|
155
|
$currentDay = $day;
|
156
|
$nextDay = $tempdayarray[$arraycounter+1];
|
157
|
$currentDay++;
|
158
|
|
159
|
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
|
160
|
if ($firstPrint)
|
161
|
$dayFriendly .= "<br />";
|
162
|
|
163
|
$currentDay--;
|
164
|
|
165
|
if ($currentDay != $firstDay)
|
166
|
$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
|
167
|
else
|
168
|
$dayFriendly .= $monthArray[$month-1] . " " . $day;
|
169
|
|
170
|
$firstDayFound = false;
|
171
|
$firstPrint = true;
|
172
|
}
|
173
|
$arraycounter++;
|
174
|
}
|
175
|
}
|
176
|
else {
|
177
|
$tempdayFriendly = $timerange['position'];
|
178
|
$firstDayFound = false;
|
179
|
$tempFriendlyDayArray = explode(",", $tempdayFriendly);
|
180
|
$currentDay = "";
|
181
|
$firstDay = "";
|
182
|
$nextDay = "";
|
183
|
$counter = 0;
|
184
|
|
185
|
foreach ($tempFriendlyDayArray as $day){
|
186
|
if ($day != ""){
|
187
|
if (!$firstDayFound)
|
188
|
{
|
189
|
$firstDay = $tempFriendlyDayArray[$counter];
|
190
|
$firstDayFound = true;
|
191
|
}
|
192
|
|
193
|
$currentDay =$tempFriendlyDayArray[$counter];
|
194
|
//get next day
|
195
|
$nextDay = $tempFriendlyDayArray[$counter+1];
|
196
|
$currentDay++;
|
197
|
|
198
|
if ($currentDay != $nextDay){
|
199
|
if ($firstprint)
|
200
|
$dayFriendly .= "<br />";
|
201
|
|
202
|
$currentDay--;
|
203
|
|
204
|
if ($currentDay != $firstDay)
|
205
|
$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
|
206
|
else
|
207
|
$dayFriendly .= $dayArray[$firstDay-1];
|
208
|
|
209
|
$firstDayFound = false;
|
210
|
$firstprint = true;
|
211
|
}
|
212
|
$counter++;
|
213
|
}
|
214
|
}
|
215
|
}
|
216
|
|
217
|
$timeFriendly = $starttime . "-" . $stoptime;
|
218
|
$description = $timerange['rangedescr'];
|
219
|
|
220
|
print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
|
221
|
}
|
222
|
$first = false;
|
223
|
}
|
224
|
?>
|
225
|
</td>
|
226
|
|
227
|
<td>
|
228
|
<?=htmlspecialchars($schedule['descr'])?>
|
229
|
</td>
|
230
|
|
231
|
<td>
|
232
|
<a href="firewall_schedule_edit.php?id=<?=$i?>" class="btn btn-xs btn-info"><?=gettext("Edit alias")?></a>
|
233
|
<a href="firewall_schedule.php?act=del&id=<?=$i?>" class="btn btn-xs btn-danger"><?=gettext("Delete")?></a>
|
234
|
|
235
|
</td>
|
236
|
</tr>
|
237
|
<?php
|
238
|
$i++;
|
239
|
endforeach;
|
240
|
?>
|
241
|
</tbody>
|
242
|
</table>
|
243
|
</div>
|
244
|
</div>
|
245
|
|
246
|
<?=($i > 0) ? gettext(CLOCK . ' Indicates that the scedule is currently active.'):''?>
|
247
|
|
248
|
<nav class="action-buttons">
|
249
|
<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success"><?=gettext("Add new schedule")?></a>
|
250
|
</nav>
|
251
|
|
252
|
<?php
|
253
|
|
254
|
print_info_box(gettext('Schedules act as placeholders for time ranges to be used in Firewall Rules.'));
|
255
|
|
256
|
include("foot.inc");
|