Project

General

Profile

Download (7.03 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-2016 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']['schedule'])) {
45
	$config['schedules']['schedule'] = array();
46
}
47

    
48
$a_schedules = &$config['schedules']['schedule'];
49

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

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

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

    
79
include("head.inc");
80

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

    
86
<div class="panel panel-default">
87
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
88
	<div class="panel-body table-responsive">
89
		<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
90
			<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
					<th><?=gettext("Actions")?></th>
97
				</tr>
98
			</thead>
99
			<tbody>
100
<?php
101
$i = 0;
102
foreach ($a_schedules as $schedule):
103
	$schedstatus = filter_get_time_based_rule_status($schedule);
104
?>
105
				<tr>
106
					<td>
107
						<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
108
					</td>
109
					<td>
110
						 <?=htmlspecialchars($schedule['name'])?>
111
					</td>
112
					<td>
113
<?php
114
	$first = true;
115
	foreach ($schedule['timerange'] as $timerange) {
116
		$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
				$tempdayarray = explode(",", $timerange['day']);
134
				$arraycounter = 0;
135
				$firstDayFound = false;
136
				$firstPrint = false;
137
				foreach ($tempmontharray as $monthtmp) {
138
					$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
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
152
						if ($firstPrint) {
153
							$dayFriendly .= "<br />";
154
						}
155

    
156
						$currentDay--;
157

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

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

    
178
				foreach ($tempFriendlyDayArray as $day) {
179
					if ($day != "") {
180
						if (!$firstDayFound) {
181
							$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
						if ($currentDay != $nextDay) {
191
							if ($firstprint) {
192
								$dayFriendly .= "<br />";
193
							}
194

    
195
							$currentDay--;
196

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

    
203
							$firstDayFound = false;
204
							$firstprint = true;
205
						}
206
						$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
					</td>
220

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

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

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

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

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

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

    
253
<?php
254

    
255
include("foot.inc");
(53-53/231)