Project

General

Profile

Download (8.68 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
 *
8
 *	Some or all of this file is based on the m0n0wall project which is
9
 *	Copyright (c)  2004 Manuel Kasper (BSD 2 clause)
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
##|+PRIV
60
##|*IDENT=page-firewall-schedules
61
##|*NAME=Firewall: Schedules
62
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
63
##|*MATCH=firewall_schedule.php*
64
##|-PRIV
65

    
66
define('CLOCK', '<i class="fa fa-clock-o icon-black"></i>');
67

    
68
$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
69
$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'));
70

    
71
require("guiconfig.inc");
72
require_once("filter.inc");
73
require("shaper.inc");
74

    
75
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
76

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

    
81
$a_schedules = &$config['schedules']['schedule'];
82

    
83
if ($_GET['act'] == "del") {
84
	if ($a_schedules[$_GET['id']]) {
85
		/* make sure rule is not being referenced by any nat or filter rules */
86
		$is_schedule_referenced = false;
87
		$referenced_by = false;
88
		$schedule_name = $a_schedules[$_GET['id']]['name'];
89

    
90
		if (is_array($config['filter']['rule'])) {
91
			foreach ($config['filter']['rule'] as $rule) {
92
				//check for this later once this is established
93
				if ($rule['sched'] == $schedule_name) {
94
					$referenced_by = $rule['descr'];
95
					$is_schedule_referenced = true;
96
					break;
97
				}
98
			}
99
		}
100

    
101
		if ($is_schedule_referenced == true) {
102
			$savemsg = sprintf(gettext("Cannot delete schedule. Currently in use by %s."), $referenced_by);
103
		} else {
104
			unset($a_schedules[$_GET['id']]);
105
			write_config();
106
			header("Location: firewall_schedule.php");
107
			exit;
108
		}
109
	}
110
}
111

    
112
include("head.inc");
113

    
114
if ($savemsg) {
115
	print_info_box($savemsg, 'success');
116
}
117
?>
118

    
119
<div class="panel panel-default">
120
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
121
	<div class="panel-body table-responsive">
122
		<table class="table table-striped table-hover table-condensed">
123
			<thead>
124
				<tr>
125
					<th><!--"Active" indicator--></th>
126
					<th><?=gettext("Name")?></th>
127
					<th><?=gettext("Range: Date / Times / Name")?></th>
128
					<th><?=gettext("Description")?></th>
129
					<th><?=gettext("Actions")?></th>
130
				</tr>
131
			</thead>
132
			<tbody>
133
<?php
134
$i = 0;
135
foreach ($a_schedules as $schedule):
136
	$schedstatus = filter_get_time_based_rule_status($schedule);
137
?>
138
				<tr>
139
					<td>
140
						<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
141
					</td>
142
					<td>
143
						 <?=htmlspecialchars($schedule['name'])?>
144
					</td>
145
					<td>
146
<?php
147
	$first = true;
148
	foreach ($schedule['timerange'] as $timerange) {
149
		$tempFriendlyTime = "";
150
		$tempID = "";
151
		$firstprint = false;
152

    
153
		if ($timerange) {
154
			$dayFriendly = "";
155
			$tempFriendlyTime = "";
156

    
157
			//get hours
158
			$temptimerange = $timerange['hour'];
159
			$temptimeseparator = strrpos($temptimerange, "-");
160

    
161
			$starttime = substr ($temptimerange, 0, $temptimeseparator);
162
			$stoptime = substr ($temptimerange, $temptimeseparator+1);
163

    
164
			if ($timerange['month']) {
165
				$tempmontharray = explode(",", $timerange['month']);
166
				$tempdayarray = explode(",", $timerange['day']);
167
				$arraycounter = 0;
168
				$firstDayFound = false;
169
				$firstPrint = false;
170
				foreach ($tempmontharray as $monthtmp) {
171
					$month = $tempmontharray[$arraycounter];
172
					$day = $tempdayarray[$arraycounter];
173

    
174
					if (!$firstDayFound) {
175
						$firstDay = $day;
176
						$firstmonth = $month;
177
						$firstDayFound = true;
178
					}
179

    
180
					$currentDay = $day;
181
					$nextDay = $tempdayarray[$arraycounter+1];
182
					$currentDay++;
183

    
184
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
185
						if ($firstPrint) {
186
							$dayFriendly .= "<br />";
187
						}
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

    
197
						$firstDayFound = false;
198
						$firstPrint = true;
199
					}
200
					$arraycounter++;
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
							$firstDay = $tempFriendlyDayArray[$counter];
215
							$firstDayFound = true;
216
						}
217

    
218
						$currentDay =$tempFriendlyDayArray[$counter];
219
						//get next day
220
						$nextDay = $tempFriendlyDayArray[$counter+1];
221
						$currentDay++;
222

    
223
						if ($currentDay != $nextDay) {
224
							if ($firstprint) {
225
								$dayFriendly .= "<br />";
226
							}
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

    
236
							$firstDayFound = false;
237
							$firstprint = true;
238
						}
239
						$counter++;
240
					}
241
				}
242
			}
243

    
244
			$timeFriendly = $starttime . "-" . $stoptime;
245
			$description = $timerange['rangedescr'];
246

    
247
			print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
248
		}
249
	$first = false;
250
	}
251
?>
252
					</td>
253

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

    
258
					<td>
259
						<a class="fa fa-pencil" title="<?=gettext("Edit schedule"); ?>" href="firewall_schedule_edit.php?id=<?=$i?>"></a>
260
						<a class="fa fa-trash" title="<?=gettext("Delete schedule")?>" href="firewall_schedule.php?act=del&amp;id=<?=$i?>"></a>
261

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

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

    
275
<nav class="action-buttons">
276
	<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success">
277
		<i class="fa fa-plus icon-embed-btn"></i>
278
		<?=gettext("Add")?>
279
	</a>
280
</nav>
281

    
282
<div class="infoblock">
283
	<?php print_info_box(gettext('Schedules act as placeholders for time ranges to be used in firewall rules.'), 'info', false); ?>
284
</div>
285

    
286
<?php
287

    
288
include("foot.inc");
(51-51/225)