Project

General

Profile

Download (8.54 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	firewall_schedule.php
4
*/
5
/* ====================================================================
6
 *	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
 *	Originally part of pfSense (https://www.pfsense.org)
10
 *
11
 *	Redistribution and use in source and binary forms, with or without modification,
12
 *	are permitted provided that the following conditions are met:
13
 *
14
 *	1. Redistributions of source code must retain the above copyright notice,
15
 *		this list of conditions and the following disclaimer.
16
 *
17
 *	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
 *
22
 *	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
 *
27
 *	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
 *
32
 *	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
 *
36
 *	6. Redistributions of any form whatsoever must retain the following
37
 *		acknowledgment:
38
 *
39
 *	"This product includes software developed by the pfSense Project
40
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
41
  *
42
 *	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
 *
55
 *	====================================================================
56
 *
57
 */
58
/*
59
	pfSense_MODULE: schedules
60
*/
61
##|+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
define('CLOCK', '&#x1f550;');
69

    
70
$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

    
73
require("guiconfig.inc");
74
require_once("filter.inc");
75
require("shaper.inc");
76

    
77
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
78

    
79
if (!is_array($config['schedules']['schedule'])) {
80
	$config['schedules']['schedule'] = array();
81
}
82

    
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
		if (is_array($config['filter']['rule'])) {
93
			foreach ($config['filter']['rule'] as $rule) {
94
				//check for this later once this is established
95
				if ($rule['sched'] == $schedule_name) {
96
					$referenced_by = $rule['descr'];
97
					$is_schedule_referenced = true;
98
					break;
99
				}
100
			}
101
		}
102

    
103
		if ($is_schedule_referenced == true) {
104
			$savemsg = sprintf(gettext("Cannot delete Schedule. Currently in use by %s"), $referenced_by);
105
		} 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

    
116
if ($savemsg)
117
	print_info_box($savemsg, 'success');
118
?>
119

    
120
<div class="panel panel-default">
121
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
122
	<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
<?php
135
$i = 0;
136
foreach ($a_schedules as $schedule):
137
	$schedstatus = filter_get_time_based_rule_status($schedule);
138
?>
139
				<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
<?php
148
	$first = true;
149
	foreach ($schedule['timerange'] as $timerange) {
150
		$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
				$tempdayarray = explode(",", $timerange['day']);
168
				$arraycounter = 0;
169
				$firstDayFound = false;
170
				$firstPrint = false;
171
				foreach ($tempmontharray as $monthtmp) {
172
					$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
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
186
						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
				foreach ($tempFriendlyDayArray as $day) {
212
					if ($day != "") {
213
						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
						if ($currentDay != $nextDay) {
225
							if ($firstprint)
226
								$dayFriendly .= "<br />";
227

    
228
							$currentDay--;
229

    
230
							if ($currentDay != $firstDay)
231
								$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
232
							else
233
								$dayFriendly .= $dayArray[$firstDay-1];
234

    
235
							$firstDayFound = false;
236
							$firstprint = true;
237
						}
238
						$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
					</td>
252

    
253
					<td>
254
						<?=htmlspecialchars($schedule['descr'])?>&nbsp;
255
					</td>
256

    
257
					<td>
258
						<a href="firewall_schedule_edit.php?id=<?=$i?>" class="btn btn-xs btn-info"><?=gettext("Edit")?></a>
259
						<a href="firewall_schedule.php?act=del&amp;id=<?=$i?>" class="btn btn-xs btn-danger"><?=gettext("Delete")?></a>
260

    
261
					</td>
262
				</tr>
263
<?php
264
	$i++;
265
endforeach;
266
?>
267
			</tbody>
268
		</table>
269
	</div>
270
</div>
271

    
272
<?=($i > 0) ? gettext(CLOCK . ' Indicates that the schedule is currently active.'):''?>
273

    
274
<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

    
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");
(63-63/237)