Project

General

Profile

Download (7 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
init_config_arr(array('schedules', 'schedule'));
45
$a_schedules = &$config['schedules']['schedule'];
46

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

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

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

    
76
include("head.inc");
77

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

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

    
153
						$currentDay--;
154

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

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

    
175
				foreach ($tempFriendlyDayArray as $day) {
176
					if ($day != "") {
177
						if (!$firstDayFound) {
178
							$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
						if ($currentDay != $nextDay) {
188
							if ($firstprint) {
189
								$dayFriendly .= "<br />";
190
							}
191

    
192
							$currentDay--;
193

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

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

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

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

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

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

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

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

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

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

    
250
<?php
251

    
252
include("foot.inc");
(52-52/234)