Project

General

Profile

Download (7.09 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * firewall_schedule.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2020 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-firewall-schedules
30
##|*NAME=Firewall: Schedules
31
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
32
##|*MATCH=firewall_schedule.php*
33
##|-PRIV
34

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

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

    
40
require_once("guiconfig.inc");
41
require_once("filter.inc");
42
require_once("shaper.inc");
43

    
44
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
45

    
46
init_config_arr(array('schedules', 'schedule'));
47
$a_schedules = &$config['schedules']['schedule'];
48

    
49
if ($_POST['act'] == "del") {
50
	if ($a_schedules[$_POST['id']]) {
51
		/* make sure rule is not being referenced by any nat or filter rules */
52
		$is_schedule_referenced = false;
53
		$referenced_by = false;
54
		$schedule_name = $a_schedules[$_POST['id']]['name'];
55

    
56
		if (is_array($config['filter']['rule'])) {
57
			foreach ($config['filter']['rule'] as $rule) {
58
				//check for this later once this is established
59
				if ($rule['sched'] == $schedule_name) {
60
					$referenced_by = $rule['descr'];
61
					$is_schedule_referenced = true;
62
					break;
63
				}
64
			}
65
		}
66

    
67
		if ($is_schedule_referenced == true) {
68
			$savemsg = sprintf(gettext("Cannot delete schedule. Currently in use by %s."), $referenced_by);
69
		} else {
70
			unset($a_schedules[$_POST['id']]);
71
			write_config(gettext("Firewall schedule deleted."));
72
			header("Location: firewall_schedule.php");
73
			exit;
74
		}
75
	}
76
}
77

    
78
include("head.inc");
79

    
80
if ($savemsg) {
81
	print_info_box($savemsg, 'success');
82
}
83
?>
84

    
85
<div class="panel panel-default">
86
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
87
	<div class="panel-body table-responsive">
88
		<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
89
			<thead>
90
				<tr>
91
					<th><!--"Active" indicator--></th>
92
					<th><?=gettext("Name")?></th>
93
					<th><?=gettext("Range: Date / Times / Name")?></th>
94
					<th><?=gettext("Description")?></th>
95
					<th><?=gettext("Actions")?></th>
96
				</tr>
97
			</thead>
98
			<tbody>
99
<?php
100
$i = 0;
101
foreach ($a_schedules as $schedule):
102
	$schedstatus = filter_get_time_based_rule_status($schedule);
103
?>
104
				<tr>
105
					<td>
106
						<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
107
					</td>
108
					<td>
109
						 <?=htmlspecialchars($schedule['name'])?>
110
					</td>
111
					<td>
112
<?php
113
	$first = true;
114
	foreach ($schedule['timerange'] as $timerange) {
115
		$tempFriendlyTime = "";
116
		$tempID = "";
117
		$firstprint = false;
118

    
119
		if ($timerange) {
120
			$dayFriendly = "";
121
			$tempFriendlyTime = "";
122

    
123
			//get hours
124
			$temptimerange = $timerange['hour'];
125
			$temptimeseparator = strrpos($temptimerange, "-");
126

    
127
			$starttime = substr ($temptimerange, 0, $temptimeseparator);
128
			$stoptime = substr ($temptimerange, $temptimeseparator+1);
129

    
130
			if ($timerange['month']) {
131
				$tempmontharray = explode(",", $timerange['month']);
132
				$tempdayarray = explode(",", $timerange['day']);
133
				$arraycounter = 0;
134
				$firstDayFound = false;
135
				$firstPrint = false;
136
				foreach ($tempmontharray as $monthtmp) {
137
					$month = $tempmontharray[$arraycounter];
138
					$day = $tempdayarray[$arraycounter];
139

    
140
					if (!$firstDayFound) {
141
						$firstDay = $day;
142
						$firstmonth = $month;
143
						$firstDayFound = true;
144
					}
145

    
146
					$currentDay = $day;
147
					$nextDay = $tempdayarray[$arraycounter+1];
148
					$currentDay++;
149

    
150
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
151
						if ($firstPrint) {
152
							$dayFriendly .= "<br />";
153
						}
154

    
155
						$currentDay--;
156

    
157
						if ($currentDay != $firstDay) {
158
							$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
159
						} else {
160
							$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
161
						}
162

    
163
						$firstDayFound = false;
164
						$firstPrint = true;
165
					}
166
					$arraycounter++;
167
				}
168
			} else {
169
				$tempdayFriendly = $timerange['position'];
170
				$firstDayFound = false;
171
				$tempFriendlyDayArray = explode(",", $tempdayFriendly);
172
				$currentDay = "";
173
				$firstDay = "";
174
				$nextDay = "";
175
				$counter = 0;
176

    
177
				foreach ($tempFriendlyDayArray as $day) {
178
					if ($day != "") {
179
						if (!$firstDayFound) {
180
							$firstDay = $tempFriendlyDayArray[$counter];
181
							$firstDayFound = true;
182
						}
183

    
184
						$currentDay =$tempFriendlyDayArray[$counter];
185
						//get next day
186
						$nextDay = $tempFriendlyDayArray[$counter+1];
187
						$currentDay++;
188

    
189
						if ($currentDay != $nextDay) {
190
							if ($firstprint) {
191
								$dayFriendly .= "<br />";
192
							}
193

    
194
							$currentDay--;
195

    
196
							if ($currentDay != $firstDay) {
197
								$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
198
							} else {
199
								$dayFriendly .= $dayArray[$firstDay-1];
200
							}
201

    
202
							$firstDayFound = false;
203
							$firstprint = true;
204
						}
205
						$counter++;
206
					}
207
				}
208
			}
209

    
210
			$timeFriendly = $starttime . "-" . $stoptime;
211
			$description = htmlspecialchars($timerange['rangedescr']);
212

    
213
			print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
214
		}
215
	$first = false;
216
	}
217
?>
218
					</td>
219

    
220
					<td>
221
						<?=htmlspecialchars($schedule['descr'])?>&nbsp;
222
					</td>
223

    
224
					<td>
225
						<a class="fa fa-pencil" title="<?=gettext("Edit schedule"); ?>" href="firewall_schedule_edit.php?id=<?=$i?>"></a>
226
						<a class="fa fa-trash" title="<?=gettext("Delete schedule")?>" href="firewall_schedule.php?act=del&amp;id=<?=$i?>" usepost></a>
227

    
228
					</td>
229
				</tr>
230
<?php
231
	$i++;
232
endforeach;
233
?>
234
			</tbody>
235
		</table>
236
	</div>
237
</div>
238

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

    
241
<nav class="action-buttons">
242
	<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success">
243
		<i class="fa fa-plus icon-embed-btn"></i>
244
		<?=gettext("Add")?>
245
	</a>
246
</nav>
247

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

    
252
<?php
253

    
254
include("foot.inc");
(52-52/229)