Project

General

Profile

Download (8.54 KB) Statistics
| Branch: | Tag: | Revision:
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
 *	Copyright (c)  2004 Scott Ullrich
8
 *	Copyright (c)  2003-2004 Manuel Kasper <mk@neon1.net>
9 fd9ebcd5 Stephen Beaver
 *	Originally part of pfSense (https://www.pfsense.org)
10
 *
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 fd9ebcd5 Stephen Beaver
  *
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 7ac5a4cb Scott Ullrich
/*
59
	pfSense_MODULE: schedules
60
*/
61 6b07c15a Matthew Grooms
##|+PRIV
62
##|*IDENT=page-firewall-schedules
63
##|*NAME=Firewall: Schedules page
64
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
65
##|*MATCH=firewall_schedule.php*
66
##|-PRIV
67
68 416cbf3c sbeaver
define('CLOCK', '&#x1f550;');
69 615b27bc Scott Dale
70 6c07db48 Phil Davis
$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
71
$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'));
72 615b27bc Scott Dale
73
require("guiconfig.inc");
74 f6339216 jim-p
require_once("filter.inc");
75 1a03cf69 Scott Ullrich
require("shaper.inc");
76 615b27bc Scott Dale
77 6c07db48 Phil Davis
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
78 7102bd3c Carlos Eduardo Ramos
79 bedc00c8 Phil Davis
if (!is_array($config['schedules']['schedule'])) {
80 615b27bc Scott Dale
	$config['schedules']['schedule'] = array();
81 bedc00c8 Phil Davis
}
82 615b27bc Scott Dale
83
$a_schedules = &$config['schedules']['schedule'];
84
85
if ($_GET['act'] == "del") {
86
	if ($a_schedules[$_GET['id']]) {
87
		/* make sure rule is not being referenced by any nat or filter rules */
88
		$is_schedule_referenced = false;
89
		$referenced_by = false;
90
		$schedule_name = $a_schedules[$_GET['id']]['name'];
91
92 bedc00c8 Phil Davis
		if (is_array($config['filter']['rule'])) {
93
			foreach ($config['filter']['rule'] as $rule) {
94 615b27bc Scott Dale
				//check for this later once this is established
95 bedc00c8 Phil Davis
				if ($rule['sched'] == $schedule_name) {
96 615b27bc Scott Dale
					$referenced_by = $rule['descr'];
97
					$is_schedule_referenced = true;
98 273c8b1c Scott Dale
					break;
99 615b27bc Scott Dale
				}
100
			}
101
		}
102
103 bedc00c8 Phil Davis
		if ($is_schedule_referenced == true) {
104 e6f34d22 Phil Davis
			$savemsg = sprintf(gettext("Cannot delete Schedule. Currently in use by %s"), $referenced_by);
105 615b27bc Scott Dale
		} else {
106
			unset($a_schedules[$_GET['id']]);
107
			write_config();
108
			header("Location: firewall_schedule.php");
109
			exit;
110
		}
111
	}
112
}
113
114
include("head.inc");
115 416cbf3c sbeaver
116
if ($savemsg)
117
	print_info_box($savemsg, 'success');
118 615b27bc Scott Dale
?>
119
120 416b6a09 sbeaver
<div class="panel panel-default">
121 f17594c7 Sjon Hortensius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
122 416b6a09 sbeaver
	<div class="panel-body table-responsive">
123
		<table class="table table-striped table-hover table-condensed">
124
			<thead>
125
				<tr>
126
					<th><!--"Active" indicator--></th>
127
					<th><?=gettext("Name")?></th>
128
					<th><?=gettext("Range: Date / Times / Name")?></th>
129
					<th><?=gettext("Description")?></th>
130
					<th><!--Buttons--></th>
131
				</tr>
132
			</thead>
133
			<tbody>
134 416cbf3c sbeaver
<?php
135
$i = 0;
136
foreach ($a_schedules as $schedule):
137
	$schedstatus = filter_get_time_based_rule_status($schedule);
138
?>
139 416b6a09 sbeaver
				<tr>
140
					<td>
141
						<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
142
					</td>
143
					<td>
144
						 <?=htmlspecialchars($schedule['name'])?>
145
					</td>
146
					<td>
147 416cbf3c sbeaver
<?php
148
	$first = true;
149 e6f34d22 Phil Davis
	foreach ($schedule['timerange'] as $timerange) {
150 416cbf3c sbeaver
		$tempFriendlyTime = "";
151
		$tempID = "";
152
		$firstprint = false;
153
154
		if ($timerange) {
155
			$dayFriendly = "";
156
			$tempFriendlyTime = "";
157
158
			//get hours
159
			$temptimerange = $timerange['hour'];
160
			$temptimeseparator = strrpos($temptimerange, "-");
161
162
			$starttime = substr ($temptimerange, 0, $temptimeseparator);
163
			$stoptime = substr ($temptimerange, $temptimeseparator+1);
164
165
			if ($timerange['month']) {
166
				$tempmontharray = explode(",", $timerange['month']);
167 e6f34d22 Phil Davis
				$tempdayarray = explode(",", $timerange['day']);
168 416cbf3c sbeaver
				$arraycounter = 0;
169
				$firstDayFound = false;
170
				$firstPrint = false;
171 e6f34d22 Phil Davis
				foreach ($tempmontharray as $monthtmp) {
172 416cbf3c sbeaver
					$month = $tempmontharray[$arraycounter];
173
					$day = $tempdayarray[$arraycounter];
174
175
					if (!$firstDayFound) {
176
						$firstDay = $day;
177
						$firstmonth = $month;
178
						$firstDayFound = true;
179
					}
180
181
					$currentDay = $day;
182
					$nextDay = $tempdayarray[$arraycounter+1];
183
					$currentDay++;
184
185 e6f34d22 Phil Davis
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
186 416cbf3c sbeaver
						if ($firstPrint)
187
							$dayFriendly .= "<br />";
188
189
						$currentDay--;
190
191
						if ($currentDay != $firstDay)
192
							$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
193
						else
194
							$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
195
196
						$firstDayFound = false;
197
						$firstPrint = true;
198
					}
199
					$arraycounter++;
200
				}
201
			}
202
			else {
203
				$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 416cbf3c sbeaver
						if (!$firstDayFound)
214
						{
215
							$firstDay = $tempFriendlyDayArray[$counter];
216
							$firstDayFound = true;
217
						}
218
219
						$currentDay =$tempFriendlyDayArray[$counter];
220
						//get next day
221
						$nextDay = $tempFriendlyDayArray[$counter+1];
222
						$currentDay++;
223
224 e6f34d22 Phil Davis
						if ($currentDay != $nextDay) {
225 416cbf3c sbeaver
							if ($firstprint)
226
								$dayFriendly .= "<br />";
227
228
							$currentDay--;
229
230
							if ($currentDay != $firstDay)
231
								$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
232 273c8b1c Scott Dale
							else
233 416cbf3c sbeaver
								$dayFriendly .= $dayArray[$firstDay-1];
234
235
							$firstDayFound = false;
236
							$firstprint = true;
237 615b27bc Scott Dale
						}
238 416cbf3c sbeaver
						$counter++;
239
					}
240
				}
241
			}
242
243
			$timeFriendly = $starttime . "-" . $stoptime;
244
			$description = $timerange['rangedescr'];
245
246
			print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
247
		}
248
	$first = false;
249
	}
250
?>
251 416b6a09 sbeaver
					</td>
252 416cbf3c sbeaver
253 416b6a09 sbeaver
					<td>
254
						<?=htmlspecialchars($schedule['descr'])?>&nbsp;
255
					</td>
256 416cbf3c sbeaver
257 416b6a09 sbeaver
					<td>
258 016231d0 Stephen Beaver
						<a href="firewall_schedule_edit.php?id=<?=$i?>" class="btn btn-xs btn-info"><?=gettext("Edit")?></a>
259 416b6a09 sbeaver
						<a href="firewall_schedule.php?act=del&amp;id=<?=$i?>" class="btn btn-xs btn-danger"><?=gettext("Delete")?></a>
260 416cbf3c sbeaver
261 416b6a09 sbeaver
					</td>
262
				</tr>
263 416cbf3c sbeaver
<?php
264
	$i++;
265
endforeach;
266
?>
267 416b6a09 sbeaver
			</tbody>
268
		</table>
269 416cbf3c sbeaver
	</div>
270 416b6a09 sbeaver
</div>
271 416cbf3c sbeaver
272 e6f34d22 Phil Davis
<?=($i > 0) ? gettext(CLOCK . ' Indicates that the schedule is currently active.'):''?>
273 416cbf3c sbeaver
274 416b6a09 sbeaver
<nav class="action-buttons">
275
	<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success"><?=gettext("Add new schedule")?></a>
276
</nav>
277 416cbf3c sbeaver
278
<?php
279
280
print_info_box(gettext('Schedules act as placeholders for time ranges to be used in Firewall Rules.'));
281
282
include("foot.inc");