Project

General

Profile

Download (7 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 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 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 650d95d1 jim-p
init_config_arr(array('schedules', 'schedule'));
45 615b27bc Scott Dale
$a_schedules = &$config['schedules']['schedule'];
46
47 e3947e77 Steve Beaver
if ($_POST['act'] == "del") {
48
	if ($a_schedules[$_POST['id']]) {
49 615b27bc Scott Dale
		/* make sure rule is not being referenced by any nat or filter rules */
50
		$is_schedule_referenced = false;
51
		$referenced_by = false;
52 e3947e77 Steve Beaver
		$schedule_name = $a_schedules[$_POST['id']]['name'];
53 615b27bc Scott Dale
54 bedc00c8 Phil Davis
		if (is_array($config['filter']['rule'])) {
55
			foreach ($config['filter']['rule'] as $rule) {
56 615b27bc Scott Dale
				//check for this later once this is established
57 bedc00c8 Phil Davis
				if ($rule['sched'] == $schedule_name) {
58 615b27bc Scott Dale
					$referenced_by = $rule['descr'];
59
					$is_schedule_referenced = true;
60 273c8b1c Scott Dale
					break;
61 615b27bc Scott Dale
				}
62
			}
63
		}
64
65 bedc00c8 Phil Davis
		if ($is_schedule_referenced == true) {
66 8545adde k-paulius
			$savemsg = sprintf(gettext("Cannot delete schedule. Currently in use by %s."), $referenced_by);
67 615b27bc Scott Dale
		} else {
68 e3947e77 Steve Beaver
			unset($a_schedules[$_POST['id']]);
69 d398221a doktornotor
			write_config(gettext("Firewall schedule deleted."));
70 615b27bc Scott Dale
			header("Location: firewall_schedule.php");
71
			exit;
72
		}
73
	}
74
}
75
76
include("head.inc");
77 416cbf3c sbeaver
78 67c2baf1 Phil Davis
if ($savemsg) {
79 416cbf3c sbeaver
	print_info_box($savemsg, 'success');
80 67c2baf1 Phil Davis
}
81 615b27bc Scott Dale
?>
82
83 416b6a09 sbeaver
<div class="panel panel-default">
84 f17594c7 Sjon Hortensius
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
85 416b6a09 sbeaver
	<div class="panel-body table-responsive">
86 54691fc6 PiBa-NL
		<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
87 416b6a09 sbeaver
			<thead>
88
				<tr>
89
					<th><!--"Active" indicator--></th>
90
					<th><?=gettext("Name")?></th>
91
					<th><?=gettext("Range: Date / Times / Name")?></th>
92
					<th><?=gettext("Description")?></th>
93 70dc5cd6 Phil Davis
					<th><?=gettext("Actions")?></th>
94 416b6a09 sbeaver
				</tr>
95
			</thead>
96
			<tbody>
97 416cbf3c sbeaver
<?php
98
$i = 0;
99
foreach ($a_schedules as $schedule):
100
	$schedstatus = filter_get_time_based_rule_status($schedule);
101
?>
102 416b6a09 sbeaver
				<tr>
103
					<td>
104 10fe1eb5 Stephen Beaver
						<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
105 416b6a09 sbeaver
					</td>
106
					<td>
107
						 <?=htmlspecialchars($schedule['name'])?>
108
					</td>
109
					<td>
110 416cbf3c sbeaver
<?php
111
	$first = true;
112 e6f34d22 Phil Davis
	foreach ($schedule['timerange'] as $timerange) {
113 416cbf3c sbeaver
		$tempFriendlyTime = "";
114
		$tempID = "";
115
		$firstprint = false;
116
117
		if ($timerange) {
118
			$dayFriendly = "";
119
			$tempFriendlyTime = "";
120
121
			//get hours
122
			$temptimerange = $timerange['hour'];
123
			$temptimeseparator = strrpos($temptimerange, "-");
124
125
			$starttime = substr ($temptimerange, 0, $temptimeseparator);
126
			$stoptime = substr ($temptimerange, $temptimeseparator+1);
127
128
			if ($timerange['month']) {
129
				$tempmontharray = explode(",", $timerange['month']);
130 e6f34d22 Phil Davis
				$tempdayarray = explode(",", $timerange['day']);
131 416cbf3c sbeaver
				$arraycounter = 0;
132
				$firstDayFound = false;
133
				$firstPrint = false;
134 e6f34d22 Phil Davis
				foreach ($tempmontharray as $monthtmp) {
135 416cbf3c sbeaver
					$month = $tempmontharray[$arraycounter];
136
					$day = $tempdayarray[$arraycounter];
137
138
					if (!$firstDayFound) {
139
						$firstDay = $day;
140
						$firstmonth = $month;
141
						$firstDayFound = true;
142
					}
143
144
					$currentDay = $day;
145
					$nextDay = $tempdayarray[$arraycounter+1];
146
					$currentDay++;
147
148 e6f34d22 Phil Davis
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
149 67c2baf1 Phil Davis
						if ($firstPrint) {
150 416cbf3c sbeaver
							$dayFriendly .= "<br />";
151 67c2baf1 Phil Davis
						}
152 416cbf3c sbeaver
153
						$currentDay--;
154
155 67c2baf1 Phil Davis
						if ($currentDay != $firstDay) {
156 416cbf3c sbeaver
							$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
157 67c2baf1 Phil Davis
						} else {
158 416cbf3c sbeaver
							$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
159 67c2baf1 Phil Davis
						}
160 416cbf3c sbeaver
161
						$firstDayFound = false;
162
						$firstPrint = true;
163
					}
164
					$arraycounter++;
165
				}
166 67c2baf1 Phil Davis
			} else {
167 416cbf3c sbeaver
				$tempdayFriendly = $timerange['position'];
168
				$firstDayFound = false;
169
				$tempFriendlyDayArray = explode(",", $tempdayFriendly);
170
				$currentDay = "";
171
				$firstDay = "";
172
				$nextDay = "";
173
				$counter = 0;
174
175 e6f34d22 Phil Davis
				foreach ($tempFriendlyDayArray as $day) {
176
					if ($day != "") {
177 67c2baf1 Phil Davis
						if (!$firstDayFound) {
178 416cbf3c sbeaver
							$firstDay = $tempFriendlyDayArray[$counter];
179
							$firstDayFound = true;
180
						}
181
182
						$currentDay =$tempFriendlyDayArray[$counter];
183
						//get next day
184
						$nextDay = $tempFriendlyDayArray[$counter+1];
185
						$currentDay++;
186
187 e6f34d22 Phil Davis
						if ($currentDay != $nextDay) {
188 67c2baf1 Phil Davis
							if ($firstprint) {
189 416cbf3c sbeaver
								$dayFriendly .= "<br />";
190 67c2baf1 Phil Davis
							}
191 416cbf3c sbeaver
192
							$currentDay--;
193
194 67c2baf1 Phil Davis
							if ($currentDay != $firstDay) {
195 416cbf3c sbeaver
								$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
196 67c2baf1 Phil Davis
							} else {
197 416cbf3c sbeaver
								$dayFriendly .= $dayArray[$firstDay-1];
198 67c2baf1 Phil Davis
							}
199 416cbf3c sbeaver
200
							$firstDayFound = false;
201
							$firstprint = true;
202 615b27bc Scott Dale
						}
203 416cbf3c sbeaver
						$counter++;
204
					}
205
				}
206
			}
207
208
			$timeFriendly = $starttime . "-" . $stoptime;
209 2f7d3a1f jim-p
			$description = htmlspecialchars($timerange['rangedescr']);
210 416cbf3c sbeaver
211
			print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
212
		}
213
	$first = false;
214
	}
215
?>
216 416b6a09 sbeaver
					</td>
217 416cbf3c sbeaver
218 416b6a09 sbeaver
					<td>
219
						<?=htmlspecialchars($schedule['descr'])?>&nbsp;
220
					</td>
221 416cbf3c sbeaver
222 416b6a09 sbeaver
					<td>
223 84147b7b Steve Beaver
						<a class="fa fa-pencil" title="<?=gettext("Edit schedule"); ?>" href="firewall_schedule_edit.php?id=<?=$i?>"></a>
224 e3947e77 Steve Beaver
						<a class="fa fa-trash" title="<?=gettext("Delete schedule")?>" href="firewall_schedule.php?act=del&amp;id=<?=$i?>" usepost></a>
225 416cbf3c sbeaver
226 416b6a09 sbeaver
					</td>
227
				</tr>
228 416cbf3c sbeaver
<?php
229
	$i++;
230
endforeach;
231
?>
232 416b6a09 sbeaver
			</tbody>
233
		</table>
234 416cbf3c sbeaver
	</div>
235 416b6a09 sbeaver
</div>
236 416cbf3c sbeaver
237 b96cb0a5 Stephen Beaver
<?=($i > 0) ? CLOCK . gettext(' Indicates that the schedule is currently active.'):''?>
238 416cbf3c sbeaver
239 c10cb196 Stephen Beaver
<nav class="action-buttons">
240 84147b7b Steve Beaver
	<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success">
241 9d5a20cf heper
		<i class="fa fa-plus icon-embed-btn"></i>
242 2ec8f0ba Stephen Beaver
		<?=gettext("Add")?>
243
	</a>
244 416b6a09 sbeaver
</nav>
245 416cbf3c sbeaver
246 35681930 Stephen Beaver
<div class="infoblock">
247 f6aebbcc NewEraCracker
	<?php print_info_box(gettext('Schedules act as placeholders for time ranges to be used in firewall rules.'), 'info', false); ?>
248 2ec8f0ba Stephen Beaver
</div>
249 416cbf3c sbeaver
250 2ec8f0ba Stephen Beaver
<?php
251 416cbf3c sbeaver
252 2de1c196 heper
include("foot.inc");