Project

General

Profile

Download (8.65 KB) Statistics
| Branch: | Tag: | Revision:
1 615b27bc Scott Dale
<?php
2
/*
3 aaec5634 Renato Botelho
 * firewall_schedule.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 2a2396a6 Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 aaec5634 Renato Botelho
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15
 *
16
 * 1. Redistributions of source code must retain the above copyright notice,
17
 *    this list of conditions and the following disclaimer.
18
 *
19
 * 2. Redistributions in binary form must reproduce the above copyright
20
 *    notice, this list of conditions and the following disclaimer in
21
 *    the documentation and/or other materials provided with the
22
 *    distribution.
23
 *
24
 * 3. All advertising materials mentioning features or use of this software
25
 *    must display the following acknowledgment:
26
 *    "This product includes software developed by the pfSense Project
27
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
28
 *
29
 * 4. The names "pfSense" and "pfSense Project" must not be used to
30
 *    endorse or promote products derived from this software without
31
 *    prior written permission. For written permission, please contact
32
 *    coreteam@pfsense.org.
33
 *
34
 * 5. Products derived from this software may not be called "pfSense"
35
 *    nor may "pfSense" appear in their names without prior written
36
 *    permission of the Electric Sheep Fencing, LLC.
37
 *
38
 * 6. Redistributions of any form whatsoever must retain the following
39
 *    acknowledgment:
40
 *
41
 * "This product includes software developed by the pfSense Project
42
 * for use in the pfSense software distribution (http://www.pfsense.org/).
43
 *
44
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 fd9ebcd5 Stephen Beaver
 */
57 6aa3723a Renato Botelho
58 6b07c15a Matthew Grooms
##|+PRIV
59
##|*IDENT=page-firewall-schedules
60 5230f468 jim-p
##|*NAME=Firewall: Schedules
61 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
62
##|*MATCH=firewall_schedule.php*
63
##|-PRIV
64
65 b96cb0a5 Stephen Beaver
define('CLOCK', '<i class="fa fa-clock-o icon-black"></i>');
66 615b27bc Scott Dale
67 6c07db48 Phil Davis
$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
68
$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'));
69 615b27bc Scott Dale
70 aceaf18c Phil Davis
require_once("guiconfig.inc");
71 f6339216 jim-p
require_once("filter.inc");
72 aceaf18c Phil Davis
require_once("shaper.inc");
73 615b27bc Scott Dale
74 6c07db48 Phil Davis
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
75 7102bd3c Carlos Eduardo Ramos
76 bedc00c8 Phil Davis
if (!is_array($config['schedules']['schedule'])) {
77 615b27bc Scott Dale
	$config['schedules']['schedule'] = array();
78 bedc00c8 Phil Davis
}
79 615b27bc Scott Dale
80
$a_schedules = &$config['schedules']['schedule'];
81
82
if ($_GET['act'] == "del") {
83
	if ($a_schedules[$_GET['id']]) {
84
		/* make sure rule is not being referenced by any nat or filter rules */
85
		$is_schedule_referenced = false;
86
		$referenced_by = false;
87
		$schedule_name = $a_schedules[$_GET['id']]['name'];
88
89 bedc00c8 Phil Davis
		if (is_array($config['filter']['rule'])) {
90
			foreach ($config['filter']['rule'] as $rule) {
91 615b27bc Scott Dale
				//check for this later once this is established
92 bedc00c8 Phil Davis
				if ($rule['sched'] == $schedule_name) {
93 615b27bc Scott Dale
					$referenced_by = $rule['descr'];
94
					$is_schedule_referenced = true;
95 273c8b1c Scott Dale
					break;
96 615b27bc Scott Dale
				}
97
			}
98
		}
99
100 bedc00c8 Phil Davis
		if ($is_schedule_referenced == true) {
101 8545adde k-paulius
			$savemsg = sprintf(gettext("Cannot delete schedule. Currently in use by %s."), $referenced_by);
102 615b27bc Scott Dale
		} else {
103
			unset($a_schedules[$_GET['id']]);
104
			write_config();
105
			header("Location: firewall_schedule.php");
106
			exit;
107
		}
108
	}
109
}
110
111
include("head.inc");
112 416cbf3c sbeaver
113 67c2baf1 Phil Davis
if ($savemsg) {
114 416cbf3c sbeaver
	print_info_box($savemsg, 'success');
115 67c2baf1 Phil Davis
}
116 615b27bc Scott Dale
?>
117
118 416b6a09 sbeaver
<div class="panel panel-default">
119 f17594c7 Sjon Hortensius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
120 416b6a09 sbeaver
	<div class="panel-body table-responsive">
121 f8cb8d65 PiBa-NL
		<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
122 416b6a09 sbeaver
			<thead>
123
				<tr>
124
					<th><!--"Active" indicator--></th>
125
					<th><?=gettext("Name")?></th>
126
					<th><?=gettext("Range: Date / Times / Name")?></th>
127
					<th><?=gettext("Description")?></th>
128 70dc5cd6 Phil Davis
					<th><?=gettext("Actions")?></th>
129 416b6a09 sbeaver
				</tr>
130
			</thead>
131
			<tbody>
132 416cbf3c sbeaver
<?php
133
$i = 0;
134
foreach ($a_schedules as $schedule):
135
	$schedstatus = filter_get_time_based_rule_status($schedule);
136
?>
137 416b6a09 sbeaver
				<tr>
138
					<td>
139 10fe1eb5 Stephen Beaver
						<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
140 416b6a09 sbeaver
					</td>
141
					<td>
142
						 <?=htmlspecialchars($schedule['name'])?>
143
					</td>
144
					<td>
145 416cbf3c sbeaver
<?php
146
	$first = true;
147 e6f34d22 Phil Davis
	foreach ($schedule['timerange'] as $timerange) {
148 416cbf3c sbeaver
		$tempFriendlyTime = "";
149
		$tempID = "";
150
		$firstprint = false;
151
152
		if ($timerange) {
153
			$dayFriendly = "";
154
			$tempFriendlyTime = "";
155
156
			//get hours
157
			$temptimerange = $timerange['hour'];
158
			$temptimeseparator = strrpos($temptimerange, "-");
159
160
			$starttime = substr ($temptimerange, 0, $temptimeseparator);
161
			$stoptime = substr ($temptimerange, $temptimeseparator+1);
162
163
			if ($timerange['month']) {
164
				$tempmontharray = explode(",", $timerange['month']);
165 e6f34d22 Phil Davis
				$tempdayarray = explode(",", $timerange['day']);
166 416cbf3c sbeaver
				$arraycounter = 0;
167
				$firstDayFound = false;
168
				$firstPrint = false;
169 e6f34d22 Phil Davis
				foreach ($tempmontharray as $monthtmp) {
170 416cbf3c sbeaver
					$month = $tempmontharray[$arraycounter];
171
					$day = $tempdayarray[$arraycounter];
172
173
					if (!$firstDayFound) {
174
						$firstDay = $day;
175
						$firstmonth = $month;
176
						$firstDayFound = true;
177
					}
178
179
					$currentDay = $day;
180
					$nextDay = $tempdayarray[$arraycounter+1];
181
					$currentDay++;
182
183 e6f34d22 Phil Davis
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
184 67c2baf1 Phil Davis
						if ($firstPrint) {
185 416cbf3c sbeaver
							$dayFriendly .= "<br />";
186 67c2baf1 Phil Davis
						}
187 416cbf3c sbeaver
188
						$currentDay--;
189
190 67c2baf1 Phil Davis
						if ($currentDay != $firstDay) {
191 416cbf3c sbeaver
							$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
192 67c2baf1 Phil Davis
						} else {
193 416cbf3c sbeaver
							$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
194 67c2baf1 Phil Davis
						}
195 416cbf3c sbeaver
196
						$firstDayFound = false;
197
						$firstPrint = true;
198
					}
199
					$arraycounter++;
200
				}
201 67c2baf1 Phil Davis
			} else {
202 416cbf3c sbeaver
				$tempdayFriendly = $timerange['position'];
203
				$firstDayFound = false;
204
				$tempFriendlyDayArray = explode(",", $tempdayFriendly);
205
				$currentDay = "";
206
				$firstDay = "";
207
				$nextDay = "";
208
				$counter = 0;
209
210 e6f34d22 Phil Davis
				foreach ($tempFriendlyDayArray as $day) {
211
					if ($day != "") {
212 67c2baf1 Phil Davis
						if (!$firstDayFound) {
213 416cbf3c sbeaver
							$firstDay = $tempFriendlyDayArray[$counter];
214
							$firstDayFound = true;
215
						}
216
217
						$currentDay =$tempFriendlyDayArray[$counter];
218
						//get next day
219
						$nextDay = $tempFriendlyDayArray[$counter+1];
220
						$currentDay++;
221
222 e6f34d22 Phil Davis
						if ($currentDay != $nextDay) {
223 67c2baf1 Phil Davis
							if ($firstprint) {
224 416cbf3c sbeaver
								$dayFriendly .= "<br />";
225 67c2baf1 Phil Davis
							}
226 416cbf3c sbeaver
227
							$currentDay--;
228
229 67c2baf1 Phil Davis
							if ($currentDay != $firstDay) {
230 416cbf3c sbeaver
								$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
231 67c2baf1 Phil Davis
							} else {
232 416cbf3c sbeaver
								$dayFriendly .= $dayArray[$firstDay-1];
233 67c2baf1 Phil Davis
							}
234 416cbf3c sbeaver
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 2de1c196 heper
						<a class="fa fa-pencil" title="<?=gettext("Edit schedule"); ?>" href="firewall_schedule_edit.php?id=<?=$i?>"></a>
259 33f0b0d5 Stephen Beaver
						<a class="fa fa-trash" title="<?=gettext("Delete schedule")?>" href="firewall_schedule.php?act=del&amp;id=<?=$i?>"></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 b96cb0a5 Stephen Beaver
<?=($i > 0) ? CLOCK . gettext(' Indicates that the schedule is currently active.'):''?>
273 416cbf3c sbeaver
274 c10cb196 Stephen Beaver
<nav class="action-buttons">
275 2ec8f0ba Stephen Beaver
	<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success">
276 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
277 2ec8f0ba Stephen Beaver
		<?=gettext("Add")?>
278
	</a>
279 416b6a09 sbeaver
</nav>
280 416cbf3c sbeaver
281 35681930 Stephen Beaver
<div class="infoblock">
282 f6aebbcc NewEraCracker
	<?php print_info_box(gettext('Schedules act as placeholders for time ranges to be used in firewall rules.'), 'info', false); ?>
283 2ec8f0ba Stephen Beaver
</div>
284 416cbf3c sbeaver
285 2ec8f0ba Stephen Beaver
<?php
286 416cbf3c sbeaver
287 2de1c196 heper
include("foot.inc");