1 |
615b27bc
|
Scott Dale
|
<?php
|
2 |
|
|
/*
|
3 |
c5d81585
|
Renato Botelho
|
* firewall_schedule.php
|
4 |
|
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8 |
a68f7a3d
|
Luiz Otavio O Souza
|
* Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
|
9 |
c5d81585
|
Renato Botelho
|
* All rights reserved.
|
10 |
|
|
*
|
11 |
|
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
12 |
|
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
13 |
|
|
* All rights reserved.
|
14 |
|
|
*
|
15 |
b12ea3fb
|
Renato Botelho
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
16 |
|
|
* you may not use this file except in compliance with the License.
|
17 |
|
|
* You may obtain a copy of the License at
|
18 |
c5d81585
|
Renato Botelho
|
*
|
19 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
20 |
c5d81585
|
Renato Botelho
|
*
|
21 |
b12ea3fb
|
Renato Botelho
|
* Unless required by applicable law or agreed to in writing, software
|
22 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
23 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
24 |
|
|
* See the License for the specific language governing permissions and
|
25 |
|
|
* limitations under the License.
|
26 |
fd9ebcd5
|
Stephen Beaver
|
*/
|
27 |
6aa3723a
|
Renato Botelho
|
|
28 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
29 |
|
|
##|*IDENT=page-firewall-schedules
|
30 |
5230f468
|
jim-p
|
##|*NAME=Firewall: Schedules
|
31 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
|
32 |
|
|
##|*MATCH=firewall_schedule.php*
|
33 |
|
|
##|-PRIV
|
34 |
|
|
|
35 |
c1d304b3
|
Marcos Mendoza
|
define('CLOCK', '<i class="fa-regular fa-clock icon-black"></i>');
|
36 |
615b27bc
|
Scott Dale
|
|
37 |
6c07db48
|
Phil Davis
|
$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
|
38 |
|
|
$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'));
|
39 |
615b27bc
|
Scott Dale
|
|
40 |
c81ef6e2
|
Phil Davis
|
require_once("guiconfig.inc");
|
41 |
f6339216
|
jim-p
|
require_once("filter.inc");
|
42 |
c81ef6e2
|
Phil Davis
|
require_once("shaper.inc");
|
43 |
e2bb3424
|
Steve Beaver
|
require_once("firewall_schedule.inc");
|
44 |
615b27bc
|
Scott Dale
|
|
45 |
6c07db48
|
Phil Davis
|
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
|
46 |
7102bd3c
|
Carlos Eduardo Ramos
|
|
47 |
63d6bb4f
|
Marcos Mendoza
|
config_init_path('schedules/schedule');
|
48 |
615b27bc
|
Scott Dale
|
|
49 |
e3947e77
|
Steve Beaver
|
if ($_POST['act'] == "del") {
|
50 |
e2bb3424
|
Steve Beaver
|
$errmsg = deleteSchedule($_POST);
|
51 |
615b27bc
|
Scott Dale
|
}
|
52 |
|
|
|
53 |
|
|
include("head.inc");
|
54 |
416cbf3c
|
sbeaver
|
|
55 |
e2bb3424
|
Steve Beaver
|
if ($errmsg) {
|
56 |
|
|
print_info_box($errmsg, 'danger');
|
57 |
67c2baf1
|
Phil Davis
|
}
|
58 |
615b27bc
|
Scott Dale
|
?>
|
59 |
|
|
|
60 |
416b6a09
|
sbeaver
|
<div class="panel panel-default">
|
61 |
f17594c7
|
Sjon Hortensius
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
|
62 |
416b6a09
|
sbeaver
|
<div class="panel-body table-responsive">
|
63 |
54691fc6
|
PiBa-NL
|
<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
|
64 |
416b6a09
|
sbeaver
|
<thead>
|
65 |
|
|
<tr>
|
66 |
|
|
<th><!--"Active" indicator--></th>
|
67 |
|
|
<th><?=gettext("Name")?></th>
|
68 |
|
|
<th><?=gettext("Range: Date / Times / Name")?></th>
|
69 |
|
|
<th><?=gettext("Description")?></th>
|
70 |
70dc5cd6
|
Phil Davis
|
<th><?=gettext("Actions")?></th>
|
71 |
416b6a09
|
sbeaver
|
</tr>
|
72 |
|
|
</thead>
|
73 |
|
|
<tbody>
|
74 |
416cbf3c
|
sbeaver
|
<?php
|
75 |
|
|
$i = 0;
|
76 |
4b9165e5
|
Marcos Mendoza
|
foreach (config_get_path('schedules/schedule', []) as $schedule):
|
77 |
416cbf3c
|
sbeaver
|
$schedstatus = filter_get_time_based_rule_status($schedule);
|
78 |
|
|
?>
|
79 |
416b6a09
|
sbeaver
|
<tr>
|
80 |
|
|
<td>
|
81 |
10fe1eb5
|
Stephen Beaver
|
<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
|
82 |
416b6a09
|
sbeaver
|
</td>
|
83 |
|
|
<td>
|
84 |
|
|
<?=htmlspecialchars($schedule['name'])?>
|
85 |
|
|
</td>
|
86 |
|
|
<td>
|
87 |
416cbf3c
|
sbeaver
|
<?php
|
88 |
|
|
$first = true;
|
89 |
e6f34d22
|
Phil Davis
|
foreach ($schedule['timerange'] as $timerange) {
|
90 |
416cbf3c
|
sbeaver
|
$tempFriendlyTime = "";
|
91 |
|
|
$tempID = "";
|
92 |
|
|
$firstprint = false;
|
93 |
|
|
|
94 |
|
|
if ($timerange) {
|
95 |
|
|
$dayFriendly = "";
|
96 |
|
|
$tempFriendlyTime = "";
|
97 |
|
|
|
98 |
|
|
//get hours
|
99 |
|
|
$temptimerange = $timerange['hour'];
|
100 |
|
|
$temptimeseparator = strrpos($temptimerange, "-");
|
101 |
|
|
|
102 |
|
|
$starttime = substr ($temptimerange, 0, $temptimeseparator);
|
103 |
|
|
$stoptime = substr ($temptimerange, $temptimeseparator+1);
|
104 |
|
|
|
105 |
|
|
if ($timerange['month']) {
|
106 |
|
|
$tempmontharray = explode(",", $timerange['month']);
|
107 |
e6f34d22
|
Phil Davis
|
$tempdayarray = explode(",", $timerange['day']);
|
108 |
416cbf3c
|
sbeaver
|
$arraycounter = 0;
|
109 |
|
|
$firstDayFound = false;
|
110 |
|
|
$firstPrint = false;
|
111 |
e6f34d22
|
Phil Davis
|
foreach ($tempmontharray as $monthtmp) {
|
112 |
416cbf3c
|
sbeaver
|
$month = $tempmontharray[$arraycounter];
|
113 |
|
|
$day = $tempdayarray[$arraycounter];
|
114 |
|
|
|
115 |
|
|
if (!$firstDayFound) {
|
116 |
|
|
$firstDay = $day;
|
117 |
|
|
$firstmonth = $month;
|
118 |
|
|
$firstDayFound = true;
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
$currentDay = $day;
|
122 |
|
|
$nextDay = $tempdayarray[$arraycounter+1];
|
123 |
|
|
$currentDay++;
|
124 |
|
|
|
125 |
e6f34d22
|
Phil Davis
|
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
|
126 |
67c2baf1
|
Phil Davis
|
if ($firstPrint) {
|
127 |
416cbf3c
|
sbeaver
|
$dayFriendly .= "<br />";
|
128 |
67c2baf1
|
Phil Davis
|
}
|
129 |
416cbf3c
|
sbeaver
|
|
130 |
|
|
$currentDay--;
|
131 |
|
|
|
132 |
67c2baf1
|
Phil Davis
|
if ($currentDay != $firstDay) {
|
133 |
416cbf3c
|
sbeaver
|
$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
|
134 |
67c2baf1
|
Phil Davis
|
} else {
|
135 |
416cbf3c
|
sbeaver
|
$dayFriendly .= $monthArray[$month-1] . " " . $day;
|
136 |
67c2baf1
|
Phil Davis
|
}
|
137 |
416cbf3c
|
sbeaver
|
|
138 |
|
|
$firstDayFound = false;
|
139 |
|
|
$firstPrint = true;
|
140 |
|
|
}
|
141 |
|
|
$arraycounter++;
|
142 |
|
|
}
|
143 |
67c2baf1
|
Phil Davis
|
} else {
|
144 |
416cbf3c
|
sbeaver
|
$tempdayFriendly = $timerange['position'];
|
145 |
|
|
$firstDayFound = false;
|
146 |
|
|
$tempFriendlyDayArray = explode(",", $tempdayFriendly);
|
147 |
|
|
$currentDay = "";
|
148 |
|
|
$firstDay = "";
|
149 |
|
|
$nextDay = "";
|
150 |
|
|
$counter = 0;
|
151 |
|
|
|
152 |
e6f34d22
|
Phil Davis
|
foreach ($tempFriendlyDayArray as $day) {
|
153 |
|
|
if ($day != "") {
|
154 |
67c2baf1
|
Phil Davis
|
if (!$firstDayFound) {
|
155 |
416cbf3c
|
sbeaver
|
$firstDay = $tempFriendlyDayArray[$counter];
|
156 |
|
|
$firstDayFound = true;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
$currentDay =$tempFriendlyDayArray[$counter];
|
160 |
|
|
//get next day
|
161 |
|
|
$nextDay = $tempFriendlyDayArray[$counter+1];
|
162 |
|
|
$currentDay++;
|
163 |
|
|
|
164 |
e6f34d22
|
Phil Davis
|
if ($currentDay != $nextDay) {
|
165 |
67c2baf1
|
Phil Davis
|
if ($firstprint) {
|
166 |
416cbf3c
|
sbeaver
|
$dayFriendly .= "<br />";
|
167 |
67c2baf1
|
Phil Davis
|
}
|
168 |
416cbf3c
|
sbeaver
|
|
169 |
|
|
$currentDay--;
|
170 |
|
|
|
171 |
67c2baf1
|
Phil Davis
|
if ($currentDay != $firstDay) {
|
172 |
416cbf3c
|
sbeaver
|
$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
|
173 |
67c2baf1
|
Phil Davis
|
} else {
|
174 |
416cbf3c
|
sbeaver
|
$dayFriendly .= $dayArray[$firstDay-1];
|
175 |
67c2baf1
|
Phil Davis
|
}
|
176 |
416cbf3c
|
sbeaver
|
|
177 |
|
|
$firstDayFound = false;
|
178 |
|
|
$firstprint = true;
|
179 |
615b27bc
|
Scott Dale
|
}
|
180 |
416cbf3c
|
sbeaver
|
$counter++;
|
181 |
|
|
}
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
$timeFriendly = $starttime . "-" . $stoptime;
|
186 |
2f7d3a1f
|
jim-p
|
$description = htmlspecialchars($timerange['rangedescr']);
|
187 |
416cbf3c
|
sbeaver
|
|
188 |
|
|
print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
|
189 |
|
|
}
|
190 |
|
|
$first = false;
|
191 |
|
|
}
|
192 |
|
|
?>
|
193 |
416b6a09
|
sbeaver
|
</td>
|
194 |
416cbf3c
|
sbeaver
|
|
195 |
416b6a09
|
sbeaver
|
<td>
|
196 |
|
|
<?=htmlspecialchars($schedule['descr'])?>
|
197 |
|
|
</td>
|
198 |
416cbf3c
|
sbeaver
|
|
199 |
416b6a09
|
sbeaver
|
<td>
|
200 |
e0cb987c
|
Marcos Mendoza
|
<a class="fa-solid fa-pencil" title="<?=gettext("Edit schedule"); ?>" href="firewall_schedule_edit.php?id=<?=$i?>"></a>
|
201 |
c1d304b3
|
Marcos Mendoza
|
<a class="fa-solid fa-trash-can" title="<?=gettext("Delete schedule")?>" href="firewall_schedule.php?act=del&id=<?=$i?>" usepost></a>
|
202 |
416cbf3c
|
sbeaver
|
|
203 |
416b6a09
|
sbeaver
|
</td>
|
204 |
|
|
</tr>
|
205 |
416cbf3c
|
sbeaver
|
<?php
|
206 |
|
|
$i++;
|
207 |
|
|
endforeach;
|
208 |
|
|
?>
|
209 |
416b6a09
|
sbeaver
|
</tbody>
|
210 |
|
|
</table>
|
211 |
416cbf3c
|
sbeaver
|
</div>
|
212 |
416b6a09
|
sbeaver
|
</div>
|
213 |
416cbf3c
|
sbeaver
|
|
214 |
b96cb0a5
|
Stephen Beaver
|
<?=($i > 0) ? CLOCK . gettext(' Indicates that the schedule is currently active.'):''?>
|
215 |
416cbf3c
|
sbeaver
|
|
216 |
c10cb196
|
Stephen Beaver
|
<nav class="action-buttons">
|
217 |
84147b7b
|
Steve Beaver
|
<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success">
|
218 |
e0cb987c
|
Marcos Mendoza
|
<i class="fa-solid fa-plus icon-embed-btn"></i>
|
219 |
2ec8f0ba
|
Stephen Beaver
|
<?=gettext("Add")?>
|
220 |
|
|
</a>
|
221 |
416b6a09
|
sbeaver
|
</nav>
|
222 |
416cbf3c
|
sbeaver
|
|
223 |
35681930
|
Stephen Beaver
|
<div class="infoblock">
|
224 |
f6aebbcc
|
NewEraCracker
|
<?php print_info_box(gettext('Schedules act as placeholders for time ranges to be used in firewall rules.'), 'info', false); ?>
|
225 |
2ec8f0ba
|
Stephen Beaver
|
</div>
|
226 |
416cbf3c
|
sbeaver
|
|
227 |
2ec8f0ba
|
Stephen Beaver
|
<?php
|
228 |
416cbf3c
|
sbeaver
|
|
229 |
2de1c196
|
heper
|
include("foot.inc");
|