Project

General

Profile

Download (7.12 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-2018 Rubicon Communications, LLC (Netgate)
7
 * 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
 * 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
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * 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
 */
25

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

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

    
35
$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

    
38
require_once("guiconfig.inc");
39
require_once("filter.inc");
40
require_once("shaper.inc");
41

    
42
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
43

    
44
if (!is_array($config['schedules'])) {
45
	$config['schedules'] = array();
46
}
47
if (!is_array($config['schedules']['schedule'])) {
48
	$config['schedules']['schedule'] = array();
49
}
50

    
51
$a_schedules = &$config['schedules']['schedule'];
52

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

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

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

    
82
include("head.inc");
83

    
84
if ($savemsg) {
85
	print_info_box($savemsg, 'success');
86
}
87
?>
88

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

    
123
		if ($timerange) {
124
			$dayFriendly = "";
125
			$tempFriendlyTime = "";
126

    
127
			//get hours
128
			$temptimerange = $timerange['hour'];
129
			$temptimeseparator = strrpos($temptimerange, "-");
130

    
131
			$starttime = substr ($temptimerange, 0, $temptimeseparator);
132
			$stoptime = substr ($temptimerange, $temptimeseparator+1);
133

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

    
144
					if (!$firstDayFound) {
145
						$firstDay = $day;
146
						$firstmonth = $month;
147
						$firstDayFound = true;
148
					}
149

    
150
					$currentDay = $day;
151
					$nextDay = $tempdayarray[$arraycounter+1];
152
					$currentDay++;
153

    
154
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
155
						if ($firstPrint) {
156
							$dayFriendly .= "<br />";
157
						}
158

    
159
						$currentDay--;
160

    
161
						if ($currentDay != $firstDay) {
162
							$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
163
						} else {
164
							$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
165
						}
166

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

    
181
				foreach ($tempFriendlyDayArray as $day) {
182
					if ($day != "") {
183
						if (!$firstDayFound) {
184
							$firstDay = $tempFriendlyDayArray[$counter];
185
							$firstDayFound = true;
186
						}
187

    
188
						$currentDay =$tempFriendlyDayArray[$counter];
189
						//get next day
190
						$nextDay = $tempFriendlyDayArray[$counter+1];
191
						$currentDay++;
192

    
193
						if ($currentDay != $nextDay) {
194
							if ($firstprint) {
195
								$dayFriendly .= "<br />";
196
							}
197

    
198
							$currentDay--;
199

    
200
							if ($currentDay != $firstDay) {
201
								$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
202
							} else {
203
								$dayFriendly .= $dayArray[$firstDay-1];
204
							}
205

    
206
							$firstDayFound = false;
207
							$firstprint = true;
208
						}
209
						$counter++;
210
					}
211
				}
212
			}
213

    
214
			$timeFriendly = $starttime . "-" . $stoptime;
215
			$description = htmlspecialchars($timerange['rangedescr']);
216

    
217
			print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
218
		}
219
	$first = false;
220
	}
221
?>
222
					</td>
223

    
224
					<td>
225
						<?=htmlspecialchars($schedule['descr'])?>&nbsp;
226
					</td>
227

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

    
232
					</td>
233
				</tr>
234
<?php
235
	$i++;
236
endforeach;
237
?>
238
			</tbody>
239
		</table>
240
	</div>
241
</div>
242

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

    
245
<nav class="action-buttons">
246
	<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success">
247
		<i class="fa fa-plus icon-embed-btn"></i>
248
		<?=gettext("Add")?>
249
	</a>
250
</nav>
251

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

    
256
<?php
257

    
258
include("foot.inc");
(52-52/235)