Project

General

Profile

Download (7.09 KB) Statistics
| Branch: | Tag: | Revision:
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 0284d79e jim-p
 * Copyright (c) 2014-2020 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 b96cb0a5 Stephen Beaver
define('CLOCK', '<i class="fa fa-clock-o 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 615b27bc Scott Dale
44 6c07db48 Phil Davis
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
45 7102bd3c Carlos Eduardo Ramos
46 4c3669ea jim-p
init_config_arr(array('schedules', 'schedule'));
47 615b27bc Scott Dale
$a_schedules = &$config['schedules']['schedule'];
48
49 e3947e77 Steve Beaver
if ($_POST['act'] == "del") {
50
	if ($a_schedules[$_POST['id']]) {
51 615b27bc Scott Dale
		/* make sure rule is not being referenced by any nat or filter rules */
52
		$is_schedule_referenced = false;
53
		$referenced_by = false;
54 e3947e77 Steve Beaver
		$schedule_name = $a_schedules[$_POST['id']]['name'];
55 615b27bc Scott Dale
56 bedc00c8 Phil Davis
		if (is_array($config['filter']['rule'])) {
57
			foreach ($config['filter']['rule'] as $rule) {
58 615b27bc Scott Dale
				//check for this later once this is established
59 bedc00c8 Phil Davis
				if ($rule['sched'] == $schedule_name) {
60 615b27bc Scott Dale
					$referenced_by = $rule['descr'];
61
					$is_schedule_referenced = true;
62 273c8b1c Scott Dale
					break;
63 615b27bc Scott Dale
				}
64
			}
65
		}
66
67 bedc00c8 Phil Davis
		if ($is_schedule_referenced == true) {
68 8545adde k-paulius
			$savemsg = sprintf(gettext("Cannot delete schedule. Currently in use by %s."), $referenced_by);
69 615b27bc Scott Dale
		} else {
70 e3947e77 Steve Beaver
			unset($a_schedules[$_POST['id']]);
71 d398221a doktornotor
			write_config(gettext("Firewall schedule deleted."));
72 615b27bc Scott Dale
			header("Location: firewall_schedule.php");
73
			exit;
74
		}
75
	}
76
}
77
78
include("head.inc");
79 416cbf3c sbeaver
80 67c2baf1 Phil Davis
if ($savemsg) {
81 416cbf3c sbeaver
	print_info_box($savemsg, 'success');
82 67c2baf1 Phil Davis
}
83 615b27bc Scott Dale
?>
84
85 416b6a09 sbeaver
<div class="panel panel-default">
86 f17594c7 Sjon Hortensius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
87 416b6a09 sbeaver
	<div class="panel-body table-responsive">
88 54691fc6 PiBa-NL
		<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
89 416b6a09 sbeaver
			<thead>
90
				<tr>
91
					<th><!--"Active" indicator--></th>
92
					<th><?=gettext("Name")?></th>
93
					<th><?=gettext("Range: Date / Times / Name")?></th>
94
					<th><?=gettext("Description")?></th>
95 70dc5cd6 Phil Davis
					<th><?=gettext("Actions")?></th>
96 416b6a09 sbeaver
				</tr>
97
			</thead>
98
			<tbody>
99 416cbf3c sbeaver
<?php
100
$i = 0;
101
foreach ($a_schedules as $schedule):
102
	$schedstatus = filter_get_time_based_rule_status($schedule);
103
?>
104 416b6a09 sbeaver
				<tr>
105
					<td>
106 10fe1eb5 Stephen Beaver
						<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
107 416b6a09 sbeaver
					</td>
108
					<td>
109
						 <?=htmlspecialchars($schedule['name'])?>
110
					</td>
111
					<td>
112 416cbf3c sbeaver
<?php
113
	$first = true;
114 e6f34d22 Phil Davis
	foreach ($schedule['timerange'] as $timerange) {
115 416cbf3c sbeaver
		$tempFriendlyTime = "";
116
		$tempID = "";
117
		$firstprint = false;
118
119
		if ($timerange) {
120
			$dayFriendly = "";
121
			$tempFriendlyTime = "";
122
123
			//get hours
124
			$temptimerange = $timerange['hour'];
125
			$temptimeseparator = strrpos($temptimerange, "-");
126
127
			$starttime = substr ($temptimerange, 0, $temptimeseparator);
128
			$stoptime = substr ($temptimerange, $temptimeseparator+1);
129
130
			if ($timerange['month']) {
131
				$tempmontharray = explode(",", $timerange['month']);
132 e6f34d22 Phil Davis
				$tempdayarray = explode(",", $timerange['day']);
133 416cbf3c sbeaver
				$arraycounter = 0;
134
				$firstDayFound = false;
135
				$firstPrint = false;
136 e6f34d22 Phil Davis
				foreach ($tempmontharray as $monthtmp) {
137 416cbf3c sbeaver
					$month = $tempmontharray[$arraycounter];
138
					$day = $tempdayarray[$arraycounter];
139
140
					if (!$firstDayFound) {
141
						$firstDay = $day;
142
						$firstmonth = $month;
143
						$firstDayFound = true;
144
					}
145
146
					$currentDay = $day;
147
					$nextDay = $tempdayarray[$arraycounter+1];
148
					$currentDay++;
149
150 e6f34d22 Phil Davis
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
151 67c2baf1 Phil Davis
						if ($firstPrint) {
152 416cbf3c sbeaver
							$dayFriendly .= "<br />";
153 67c2baf1 Phil Davis
						}
154 416cbf3c sbeaver
155
						$currentDay--;
156
157 67c2baf1 Phil Davis
						if ($currentDay != $firstDay) {
158 416cbf3c sbeaver
							$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
159 67c2baf1 Phil Davis
						} else {
160 416cbf3c sbeaver
							$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
161 67c2baf1 Phil Davis
						}
162 416cbf3c sbeaver
163
						$firstDayFound = false;
164
						$firstPrint = true;
165
					}
166
					$arraycounter++;
167
				}
168 67c2baf1 Phil Davis
			} else {
169 416cbf3c sbeaver
				$tempdayFriendly = $timerange['position'];
170
				$firstDayFound = false;
171
				$tempFriendlyDayArray = explode(",", $tempdayFriendly);
172
				$currentDay = "";
173
				$firstDay = "";
174
				$nextDay = "";
175
				$counter = 0;
176
177 e6f34d22 Phil Davis
				foreach ($tempFriendlyDayArray as $day) {
178
					if ($day != "") {
179 67c2baf1 Phil Davis
						if (!$firstDayFound) {
180 416cbf3c sbeaver
							$firstDay = $tempFriendlyDayArray[$counter];
181
							$firstDayFound = true;
182
						}
183
184
						$currentDay =$tempFriendlyDayArray[$counter];
185
						//get next day
186
						$nextDay = $tempFriendlyDayArray[$counter+1];
187
						$currentDay++;
188
189 e6f34d22 Phil Davis
						if ($currentDay != $nextDay) {
190 67c2baf1 Phil Davis
							if ($firstprint) {
191 416cbf3c sbeaver
								$dayFriendly .= "<br />";
192 67c2baf1 Phil Davis
							}
193 416cbf3c sbeaver
194
							$currentDay--;
195
196 67c2baf1 Phil Davis
							if ($currentDay != $firstDay) {
197 416cbf3c sbeaver
								$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
198 67c2baf1 Phil Davis
							} else {
199 416cbf3c sbeaver
								$dayFriendly .= $dayArray[$firstDay-1];
200 67c2baf1 Phil Davis
							}
201 416cbf3c sbeaver
202
							$firstDayFound = false;
203
							$firstprint = true;
204 615b27bc Scott Dale
						}
205 416cbf3c sbeaver
						$counter++;
206
					}
207
				}
208
			}
209
210
			$timeFriendly = $starttime . "-" . $stoptime;
211 2f7d3a1f jim-p
			$description = htmlspecialchars($timerange['rangedescr']);
212 416cbf3c sbeaver
213
			print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
214
		}
215
	$first = false;
216
	}
217
?>
218 416b6a09 sbeaver
					</td>
219 416cbf3c sbeaver
220 416b6a09 sbeaver
					<td>
221
						<?=htmlspecialchars($schedule['descr'])?>&nbsp;
222
					</td>
223 416cbf3c sbeaver
224 416b6a09 sbeaver
					<td>
225 84147b7b Steve Beaver
						<a class="fa fa-pencil" title="<?=gettext("Edit schedule"); ?>" href="firewall_schedule_edit.php?id=<?=$i?>"></a>
226 e3947e77 Steve Beaver
						<a class="fa fa-trash" title="<?=gettext("Delete schedule")?>" href="firewall_schedule.php?act=del&amp;id=<?=$i?>" usepost></a>
227 416cbf3c sbeaver
228 416b6a09 sbeaver
					</td>
229
				</tr>
230 416cbf3c sbeaver
<?php
231
	$i++;
232
endforeach;
233
?>
234 416b6a09 sbeaver
			</tbody>
235
		</table>
236 416cbf3c sbeaver
	</div>
237 416b6a09 sbeaver
</div>
238 416cbf3c sbeaver
239 b96cb0a5 Stephen Beaver
<?=($i > 0) ? CLOCK . gettext(' Indicates that the schedule is currently active.'):''?>
240 416cbf3c sbeaver
241 c10cb196 Stephen Beaver
<nav class="action-buttons">
242 84147b7b Steve Beaver
	<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success">
243 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
244 2ec8f0ba Stephen Beaver
		<?=gettext("Add")?>
245
	</a>
246 416b6a09 sbeaver
</nav>
247 416cbf3c sbeaver
248 35681930 Stephen Beaver
<div class="infoblock">
249 f6aebbcc NewEraCracker
	<?php print_info_box(gettext('Schedules act as placeholders for time ranges to be used in firewall rules.'), 'info', false); ?>
250 2ec8f0ba Stephen Beaver
</div>
251 416cbf3c sbeaver
252 2ec8f0ba Stephen Beaver
<?php
253 416cbf3c sbeaver
254 2de1c196 heper
include("foot.inc");