Project

General

Profile

Download (8.65 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
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15
 *
16
 * 1. Redistributions of source code must retain the above copyright notice,
17
 *    this list of conditions and the following disclaimer.
18
 *
19
 * 2. Redistributions in binary form must reproduce the above copyright
20
 *    notice, this list of conditions and the following disclaimer in
21
 *    the documentation and/or other materials provided with the
22
 *    distribution.
23
 *
24
 * 3. All advertising materials mentioning features or use of this software
25
 *    must display the following acknowledgment:
26
 *    "This product includes software developed by the pfSense Project
27
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
28
 *
29
 * 4. The names "pfSense" and "pfSense Project" must not be used to
30
 *    endorse or promote products derived from this software without
31
 *    prior written permission. For written permission, please contact
32
 *    coreteam@pfsense.org.
33
 *
34
 * 5. Products derived from this software may not be called "pfSense"
35
 *    nor may "pfSense" appear in their names without prior written
36
 *    permission of the Electric Sheep Fencing, LLC.
37
 *
38
 * 6. Redistributions of any form whatsoever must retain the following
39
 *    acknowledgment:
40
 *
41
 * "This product includes software developed by the pfSense Project
42
 * for use in the pfSense software distribution (http://www.pfsense.org/).
43
 *
44
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
 * OF THE POSSIBILITY OF SUCH DAMAGE.
56
 */
57

    
58
##|+PRIV
59
##|*IDENT=page-firewall-schedules
60
##|*NAME=Firewall: Schedules
61
##|*DESCR=Allow access to the 'Firewall: Schedules' page.
62
##|*MATCH=firewall_schedule.php*
63
##|-PRIV
64

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

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

    
70
require_once("guiconfig.inc");
71
require_once("filter.inc");
72
require_once("shaper.inc");
73

    
74
$pgtitle = array(gettext("Firewall"), gettext("Schedules"));
75

    
76
if (!is_array($config['schedules']['schedule'])) {
77
	$config['schedules']['schedule'] = array();
78
}
79

    
80
$a_schedules = &$config['schedules']['schedule'];
81

    
82
if ($_GET['act'] == "del") {
83
	if ($a_schedules[$_GET['id']]) {
84
		/* make sure rule is not being referenced by any nat or filter rules */
85
		$is_schedule_referenced = false;
86
		$referenced_by = false;
87
		$schedule_name = $a_schedules[$_GET['id']]['name'];
88

    
89
		if (is_array($config['filter']['rule'])) {
90
			foreach ($config['filter']['rule'] as $rule) {
91
				//check for this later once this is established
92
				if ($rule['sched'] == $schedule_name) {
93
					$referenced_by = $rule['descr'];
94
					$is_schedule_referenced = true;
95
					break;
96
				}
97
			}
98
		}
99

    
100
		if ($is_schedule_referenced == true) {
101
			$savemsg = sprintf(gettext("Cannot delete schedule. Currently in use by %s."), $referenced_by);
102
		} else {
103
			unset($a_schedules[$_GET['id']]);
104
			write_config();
105
			header("Location: firewall_schedule.php");
106
			exit;
107
		}
108
	}
109
}
110

    
111
include("head.inc");
112

    
113
if ($savemsg) {
114
	print_info_box($savemsg, 'success');
115
}
116
?>
117

    
118
<div class="panel panel-default">
119
	<div class="panel-heading"><h2 class="panel-title"><?=gettext('Schedules')?></h2></div>
120
	<div class="panel-body table-responsive">
121
		<table class="table table-striped table-hover table-condensed table-rowdblclickedit">
122
			<thead>
123
				<tr>
124
					<th><!--"Active" indicator--></th>
125
					<th><?=gettext("Name")?></th>
126
					<th><?=gettext("Range: Date / Times / Name")?></th>
127
					<th><?=gettext("Description")?></th>
128
					<th><?=gettext("Actions")?></th>
129
				</tr>
130
			</thead>
131
			<tbody>
132
<?php
133
$i = 0;
134
foreach ($a_schedules as $schedule):
135
	$schedstatus = filter_get_time_based_rule_status($schedule);
136
?>
137
				<tr>
138
					<td>
139
						<?=($schedstatus) ? '<a title="' . gettext("Schedule is currently active") . '">' . CLOCK . '</a>':''?>
140
					</td>
141
					<td>
142
						 <?=htmlspecialchars($schedule['name'])?>
143
					</td>
144
					<td>
145
<?php
146
	$first = true;
147
	foreach ($schedule['timerange'] as $timerange) {
148
		$tempFriendlyTime = "";
149
		$tempID = "";
150
		$firstprint = false;
151

    
152
		if ($timerange) {
153
			$dayFriendly = "";
154
			$tempFriendlyTime = "";
155

    
156
			//get hours
157
			$temptimerange = $timerange['hour'];
158
			$temptimeseparator = strrpos($temptimerange, "-");
159

    
160
			$starttime = substr ($temptimerange, 0, $temptimeseparator);
161
			$stoptime = substr ($temptimerange, $temptimeseparator+1);
162

    
163
			if ($timerange['month']) {
164
				$tempmontharray = explode(",", $timerange['month']);
165
				$tempdayarray = explode(",", $timerange['day']);
166
				$arraycounter = 0;
167
				$firstDayFound = false;
168
				$firstPrint = false;
169
				foreach ($tempmontharray as $monthtmp) {
170
					$month = $tempmontharray[$arraycounter];
171
					$day = $tempdayarray[$arraycounter];
172

    
173
					if (!$firstDayFound) {
174
						$firstDay = $day;
175
						$firstmonth = $month;
176
						$firstDayFound = true;
177
					}
178

    
179
					$currentDay = $day;
180
					$nextDay = $tempdayarray[$arraycounter+1];
181
					$currentDay++;
182

    
183
					if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
184
						if ($firstPrint) {
185
							$dayFriendly .= "<br />";
186
						}
187

    
188
						$currentDay--;
189

    
190
						if ($currentDay != $firstDay) {
191
							$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
192
						} else {
193
							$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
194
						}
195

    
196
						$firstDayFound = false;
197
						$firstPrint = true;
198
					}
199
					$arraycounter++;
200
				}
201
			} else {
202
				$tempdayFriendly = $timerange['position'];
203
				$firstDayFound = false;
204
				$tempFriendlyDayArray = explode(",", $tempdayFriendly);
205
				$currentDay = "";
206
				$firstDay = "";
207
				$nextDay = "";
208
				$counter = 0;
209

    
210
				foreach ($tempFriendlyDayArray as $day) {
211
					if ($day != "") {
212
						if (!$firstDayFound) {
213
							$firstDay = $tempFriendlyDayArray[$counter];
214
							$firstDayFound = true;
215
						}
216

    
217
						$currentDay =$tempFriendlyDayArray[$counter];
218
						//get next day
219
						$nextDay = $tempFriendlyDayArray[$counter+1];
220
						$currentDay++;
221

    
222
						if ($currentDay != $nextDay) {
223
							if ($firstprint) {
224
								$dayFriendly .= "<br />";
225
							}
226

    
227
							$currentDay--;
228

    
229
							if ($currentDay != $firstDay) {
230
								$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
231
							} else {
232
								$dayFriendly .= $dayArray[$firstDay-1];
233
							}
234

    
235
							$firstDayFound = false;
236
							$firstprint = true;
237
						}
238
						$counter++;
239
					}
240
				}
241
			}
242

    
243
			$timeFriendly = $starttime . "-" . $stoptime;
244
			$description = $timerange['rangedescr'];
245

    
246
			print(($first ? '':'<br />') . $dayFriendly . ' / ' . $timeFriendly . ' / ' . $description);
247
		}
248
	$first = false;
249
	}
250
?>
251
					</td>
252

    
253
					<td>
254
						<?=htmlspecialchars($schedule['descr'])?>&nbsp;
255
					</td>
256

    
257
					<td>
258
						<a class="fa fa-pencil" title="<?=gettext("Edit schedule"); ?>" href="firewall_schedule_edit.php?id=<?=$i?>"></a>
259
						<a class="fa fa-trash" title="<?=gettext("Delete schedule")?>" href="firewall_schedule.php?act=del&amp;id=<?=$i?>"></a>
260

    
261
					</td>
262
				</tr>
263
<?php
264
	$i++;
265
endforeach;
266
?>
267
			</tbody>
268
		</table>
269
	</div>
270
</div>
271

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

    
274
<nav class="action-buttons">
275
	<a href="firewall_schedule_edit.php" class="btn btn-sm btn-success">
276
		<i class="fa fa-plus icon-embed-btn"></i>
277
		<?=gettext("Add")?>
278
	</a>
279
</nav>
280

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

    
285
<?php
286

    
287
include("foot.inc");
(50-50/227)