Project

General

Profile

Download (7.03 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 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 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 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16 c5d81585 Renato Botelho
 *
17 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
18 c5d81585 Renato Botelho
 *
19 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24 fd9ebcd5 Stephen Beaver
 */
25 6aa3723a Renato Botelho
26 6b07c15a Matthew Grooms
##|+PRIV
27
##|*IDENT=page-firewall-schedules
28 5230f468 jim-p
##|*NAME=Firewall: Schedules
29 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
30
##|*MATCH=firewall_schedule.php*
31
##|-PRIV
32
33 b96cb0a5 Stephen Beaver
define('CLOCK', '<i class="fa fa-clock-o icon-black"></i>');
34 615b27bc Scott Dale
35 6c07db48 Phil Davis
$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
36
$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'));
37 615b27bc Scott Dale
38 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
39 f6339216 jim-p
require_once("filter.inc");
40 c81ef6e2 Phil Davis
require_once("shaper.inc");
41 615b27bc Scott Dale
42 6c07db48 Phil Davis
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
43 7102bd3c Carlos Eduardo Ramos
44 bedc00c8 Phil Davis
if (!is_array($config['schedules']['schedule'])) {
45 615b27bc Scott Dale
	$config['schedules']['schedule'] = array();
46 bedc00c8 Phil Davis
}
47 615b27bc Scott Dale
48
$a_schedules = &$config['schedules']['schedule'];
49
50 e3947e77 Steve Beaver
if ($_POST['act'] == "del") {
51
	if ($a_schedules[$_POST['id']]) {
52 615b27bc Scott Dale
		/* make sure rule is not being referenced by any nat or filter rules */
53
		$is_schedule_referenced = false;
54
		$referenced_by = false;
55 e3947e77 Steve Beaver
		$schedule_name = $a_schedules[$_POST['id']]['name'];
56 615b27bc Scott Dale
57 bedc00c8 Phil Davis
		if (is_array($config['filter']['rule'])) {
58
			foreach ($config['filter']['rule'] as $rule) {
59 615b27bc Scott Dale
				//check for this later once this is established
60 bedc00c8 Phil Davis
				if ($rule['sched'] == $schedule_name) {
61 615b27bc Scott Dale
					$referenced_by = $rule['descr'];
62
					$is_schedule_referenced = true;
63 273c8b1c Scott Dale
					break;
64 615b27bc Scott Dale
				}
65
			}
66
		}
67
68 bedc00c8 Phil Davis
		if ($is_schedule_referenced == true) {
69 8545adde k-paulius
			$savemsg = sprintf(gettext("Cannot delete schedule. Currently in use by %s."), $referenced_by);
70 615b27bc Scott Dale
		} else {
71 e3947e77 Steve Beaver
			unset($a_schedules[$_POST['id']]);
72 d398221a doktornotor
			write_config(gettext("Firewall schedule deleted."));
73 615b27bc Scott Dale
			header("Location: firewall_schedule.php");
74
			exit;
75
		}
76
	}
77
}
78
79
include("head.inc");
80 416cbf3c sbeaver
81 67c2baf1 Phil Davis
if ($savemsg) {
82 416cbf3c sbeaver
	print_info_box($savemsg, 'success');
83 67c2baf1 Phil Davis
}
84 615b27bc Scott Dale
?>
85
86 416b6a09 sbeaver
<div class="panel panel-default">
87 f17594c7 Sjon Hortensius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
88 416b6a09 sbeaver
	<div class="panel-body table-responsive">
89 54691fc6 PiBa-NL
		<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
90 416b6a09 sbeaver
			<thead>
91
				<tr>
92
					<th><!--"Active" indicator--></th>
93
					<th><?=gettext("Name")?></th>
94
					<th><?=gettext("Range: Date / Times / Name")?></th>
95
					<th><?=gettext("Description")?></th>
96 70dc5cd6 Phil Davis
					<th><?=gettext("Actions")?></th>
97 416b6a09 sbeaver
				</tr>
98
			</thead>
99
			<tbody>
100 416cbf3c sbeaver
<?php
101
$i = 0;
102
foreach ($a_schedules as $schedule):
103
	$schedstatus = filter_get_time_based_rule_status($schedule);
104
?>
105 416b6a09 sbeaver
				<tr>
106
					<td>
107 10fe1eb5 Stephen Beaver
						<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
108 416b6a09 sbeaver
					</td>
109
					<td>
110
						 <?=htmlspecialchars($schedule['name'])?>
111
					</td>
112
					<td>
113 416cbf3c sbeaver
<?php
114
	$first = true;
115 e6f34d22 Phil Davis
	foreach ($schedule['timerange'] as $timerange) {
116 416cbf3c sbeaver
		$tempFriendlyTime = "";
117
		$tempID = "";
118
		$firstprint = false;
119
120
		if ($timerange) {
121
			$dayFriendly = "";
122
			$tempFriendlyTime = "";
123
124
			//get hours
125
			$temptimerange = $timerange['hour'];
126
			$temptimeseparator = strrpos($temptimerange, "-");
127
128
			$starttime = substr ($temptimerange, 0, $temptimeseparator);
129
			$stoptime = substr ($temptimerange, $temptimeseparator+1);
130
131
			if ($timerange['month']) {
132
				$tempmontharray = explode(",", $timerange['month']);
133 e6f34d22 Phil Davis
				$tempdayarray = explode(",", $timerange['day']);
134 416cbf3c sbeaver
				$arraycounter = 0;
135
				$firstDayFound = false;
136
				$firstPrint = false;
137 e6f34d22 Phil Davis
				foreach ($tempmontharray as $monthtmp) {
138 416cbf3c sbeaver
					$month = $tempmontharray[$arraycounter];
139
					$day = $tempdayarray[$arraycounter];
140
141
					if (!$firstDayFound) {
142
						$firstDay = $day;
143
						$firstmonth = $month;
144
						$firstDayFound = true;
145
					}
146
147
					$currentDay = $day;
148
					$nextDay = $tempdayarray[$arraycounter+1];
149
					$currentDay++;
150
151 e6f34d22 Phil Davis
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
152 67c2baf1 Phil Davis
						if ($firstPrint) {
153 416cbf3c sbeaver
							$dayFriendly .= "<br />";
154 67c2baf1 Phil Davis
						}
155 416cbf3c sbeaver
156
						$currentDay--;
157
158 67c2baf1 Phil Davis
						if ($currentDay != $firstDay) {
159 416cbf3c sbeaver
							$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
160 67c2baf1 Phil Davis
						} else {
161 416cbf3c sbeaver
							$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
162 67c2baf1 Phil Davis
						}
163 416cbf3c sbeaver
164
						$firstDayFound = false;
165
						$firstPrint = true;
166
					}
167
					$arraycounter++;
168
				}
169 67c2baf1 Phil Davis
			} else {
170 416cbf3c sbeaver
				$tempdayFriendly = $timerange['position'];
171
				$firstDayFound = false;
172
				$tempFriendlyDayArray = explode(",", $tempdayFriendly);
173
				$currentDay = "";
174
				$firstDay = "";
175
				$nextDay = "";
176
				$counter = 0;
177
178 e6f34d22 Phil Davis
				foreach ($tempFriendlyDayArray as $day) {
179
					if ($day != "") {
180 67c2baf1 Phil Davis
						if (!$firstDayFound) {
181 416cbf3c sbeaver
							$firstDay = $tempFriendlyDayArray[$counter];
182
							$firstDayFound = true;
183
						}
184
185
						$currentDay =$tempFriendlyDayArray[$counter];
186
						//get next day
187
						$nextDay = $tempFriendlyDayArray[$counter+1];
188
						$currentDay++;
189
190 e6f34d22 Phil Davis
						if ($currentDay != $nextDay) {
191 67c2baf1 Phil Davis
							if ($firstprint) {
192 416cbf3c sbeaver
								$dayFriendly .= "<br />";
193 67c2baf1 Phil Davis
							}
194 416cbf3c sbeaver
195
							$currentDay--;
196
197 67c2baf1 Phil Davis
							if ($currentDay != $firstDay) {
198 416cbf3c sbeaver
								$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
199 67c2baf1 Phil Davis
							} else {
200 416cbf3c sbeaver
								$dayFriendly .= $dayArray[$firstDay-1];
201 67c2baf1 Phil Davis
							}
202 416cbf3c sbeaver
203
							$firstDayFound = false;
204
							$firstprint = true;
205 615b27bc Scott Dale
						}
206 416cbf3c sbeaver
						$counter++;
207
					}
208
				}
209
			}
210
211
			$timeFriendly = $starttime . "-" . $stoptime;
212
			$description = $timerange['rangedescr'];
213
214
			print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
215
		}
216
	$first = false;
217
	}
218
?>
219 416b6a09 sbeaver
					</td>
220 416cbf3c sbeaver
221 416b6a09 sbeaver
					<td>
222
						<?=htmlspecialchars($schedule['descr'])?>&nbsp;
223
					</td>
224 416cbf3c sbeaver
225 416b6a09 sbeaver
					<td>
226 84147b7b Steve Beaver
						<a class="fa fa-pencil" title="<?=gettext("Edit schedule"); ?>" href="firewall_schedule_edit.php?id=<?=$i?>"></a>
227 e3947e77 Steve Beaver
						<a class="fa fa-trash" title="<?=gettext("Delete schedule")?>" href="firewall_schedule.php?act=del&amp;id=<?=$i?>" usepost></a>
228 416cbf3c sbeaver
229 416b6a09 sbeaver
					</td>
230
				</tr>
231 416cbf3c sbeaver
<?php
232
	$i++;
233
endforeach;
234
?>
235 416b6a09 sbeaver
			</tbody>
236
		</table>
237 416cbf3c sbeaver
	</div>
238 416b6a09 sbeaver
</div>
239 416cbf3c sbeaver
240 b96cb0a5 Stephen Beaver
<?=($i > 0) ? CLOCK . gettext(' Indicates that the schedule is currently active.'):''?>
241 416cbf3c sbeaver
242 c10cb196 Stephen Beaver
<nav class="action-buttons">
243 84147b7b Steve Beaver
	<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success">
244 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
245 2ec8f0ba Stephen Beaver
		<?=gettext("Add")?>
246
	</a>
247 416b6a09 sbeaver
</nav>
248 416cbf3c sbeaver
249 35681930 Stephen Beaver
<div class="infoblock">
250 f6aebbcc NewEraCracker
	<?php print_info_box(gettext('Schedules act as placeholders for time ranges to be used in firewall rules.'), 'info', false); ?>
251 2ec8f0ba Stephen Beaver
</div>
252 416cbf3c sbeaver
253 2ec8f0ba Stephen Beaver
<?php
254 416cbf3c sbeaver
255 2de1c196 heper
include("foot.inc");