Project

General

Profile

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

    
59
##|+PRIV
60
##|*IDENT=page-firewall-rules
61
##|*NAME=Firewall: Rules
62
##|*DESCR=Allow access to the 'Firewall: Rules' page.
63
##|*MATCH=firewall_rules.php*
64
##|-PRIV
65

    
66
require("guiconfig.inc");
67
require_once("functions.inc");
68
require_once("filter.inc");
69
require_once("ipsec.inc");
70
require_once("shaper.inc");
71

    
72
$pgtitle = array(gettext("Firewall"), gettext("Rules"));
73
$shortcut_section = "firewall";
74

    
75
function get_pf_rules($rules, $tracker) {
76

    
77
	if ($rules == NULL || !is_array($rules))
78
		return (NULL);
79

    
80
	$arr = array();
81
	foreach ($rules as $rule) {
82
		if ($rule['tracker'] === $tracker) {
83
			$arr[] = $rule;
84
		}
85
	}
86

    
87
	if (count($arr) == 0)
88
		return (NULL);
89

    
90
	return ($arr);
91
}
92

    
93
function print_states($tracker) {
94
	global $rulescnt;
95

    
96
	$rulesid = "";
97
	$bytes = 0;
98
	$states = 0;
99
	$packets = 0;
100
	$evaluations = 0;
101
	$stcreations = 0;
102
	$rules = get_pf_rules($rulescnt, $tracker);
103
	if (is_array($rules)) {
104
		foreach ($rules as $rule) {
105
			$bytes += $rule['bytes'];
106
			$states += $rule['states'];
107
			$packets += $rule['packets'];
108
			$evaluations += $rule['evaluations'];
109
			$stcreations += $rule['state creations'];
110
			if (strlen($rulesid) > 0) {
111
				$rulesid .= ",";
112
			}
113
			$rulesid .= "{$rule['id']}";
114
		}
115
	}
116

    
117
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" data-toggle=\"popover\" data-trigger=\"hover focus\" title=\"%s\" ",
118
	    $rulesid, gettext("States details"));
119
	printf("data-content=\"evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\">",
120
	    format_number($evaluations), format_number($packets), format_bytes($bytes),
121
	    format_number($states), format_number($stcreations));
122
	printf("%d/%s</a><br>", format_number($states), format_bytes($bytes));
123
}
124

    
125
function delete_nat_association($id) {
126
	global $config;
127

    
128
	if (!$id || !is_array($config['nat']['rule'])) {
129
		return;
130
	}
131

    
132
	$a_nat = &$config['nat']['rule'];
133

    
134
	foreach ($a_nat as &$natent) {
135
		if ($natent['associated-rule-id'] == $id) {
136
			$natent['associated-rule-id'] = '';
137
		}
138
	}
139
}
140

    
141
if (!is_array($config['filter']['rule'])) {
142
	$config['filter']['rule'] = array();
143
}
144

    
145
filter_rules_sort();
146
$a_filter = &$config['filter']['rule'];
147

    
148
$if = $_GET['if'];
149

    
150
if ($_POST['if']) {
151
	$if = $_POST['if'];
152
}
153

    
154
$ifdescs = get_configured_interface_with_descr();
155

    
156
/* add group interfaces */
157
if (is_array($config['ifgroups']['ifgroupentry'])) {
158
	foreach ($config['ifgroups']['ifgroupentry'] as $ifgen) {
159
		if (have_ruleint_access($ifgen['ifname'])) {
160
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
161
		}
162
	}
163
}
164

    
165
foreach ($ifdescs as $ifent => $ifdesc) {
166
	if (have_ruleint_access($ifent)) {
167
		$iflist[$ifent] = $ifdesc;
168
	}
169
}
170

    
171
if ($config['l2tp']['mode'] == "server") {
172
	if (have_ruleint_access("l2tp")) {
173
		$iflist['l2tp'] = gettext("L2TP VPN");
174
	}
175
}
176

    
177
if (is_array($config['pppoes']['pppoe'])) {
178
	foreach ($config['pppoes']['pppoe'] as $pppoes) {
179
		if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe")) {
180
			$iflist['pppoe'] = gettext("PPPoE Server");
181
		}
182
	}
183
}
184

    
185
/* add ipsec interfaces */
186
if (ipsec_enabled() && have_ruleint_access("enc0")) {
187
	$iflist["enc0"] = gettext("IPsec");
188
}
189

    
190
/* add openvpn/tun interfaces */
191
if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) {
192
	$iflist["openvpn"] = gettext("OpenVPN");
193
}
194

    
195
if (!$if || !isset($iflist[$if])) {
196
	if ("any" == $if) {
197
		$if = "FloatingRules";
198
	} else if ("FloatingRules" != $if) {
199
		if (isset($iflist['wan'])) {
200
			$if = "wan";
201
		} else {
202
			$if = "FloatingRules";
203
		}
204
	}
205
}
206

    
207
if ($_POST) {
208
	$pconfig = $_POST;
209

    
210
	if ($_POST['apply']) {
211
		$retval = 0;
212
		$retval = filter_configure();
213

    
214
		clear_subsystem_dirty('filter');
215

    
216
		$savemsg = sprintf(gettext("The settings have been applied. The firewall rules are now reloading in the background.<br />You can also %s monitor %s the reload progress."),
217
									"<a href='status_filter_reload.php'>", "</a>");
218
	}
219
}
220

    
221
if ($_GET['act'] == "del") {
222
	if ($a_filter[$_GET['id']]) {
223
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
224
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
225
		}
226
		unset($a_filter[$_GET['id']]);
227

    
228
		// Update the separators
229
		$a_separators = &$config['filter']['separator'][strtolower($if)];
230
		$ridx = ifridx($if, $_GET['id']);	// get rule index within interface
231
		$mvnrows = -1;
232
		move_separators($a_separators, $ridx, $mvnrows);
233

    
234
		if (write_config()) {
235
			mark_subsystem_dirty('filter');
236
		}
237

    
238
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
239
		exit;
240
	}
241
}
242

    
243
// Handle save msg if defined
244
if ($_REQUEST['savemsg']) {
245
	$savemsg = htmlentities($_REQUEST['savemsg']);
246
}
247

    
248
if (isset($_POST['del_x'])) {
249
	/* delete selected rules */
250
	$deleted = false;
251

    
252
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
253
		$a_separators = &$config['filter']['separator'][strtolower($if)];
254

    
255
		foreach ($_POST['rule'] as $rulei) {
256
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
257
			unset($a_filter[$rulei]);
258
			$deleted = true;
259

    
260
			// Update the separators
261
			$ridx = ifridx($if, $rulei);	// get rule index within interface
262
			$mvnrows = -1;
263
			move_separators($a_separators, $ridx, $mvnrows);
264
		}
265

    
266
		if ($deleted) {
267
			if (write_config()) {
268
				mark_subsystem_dirty('filter');
269
			}
270
		}
271

    
272
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
273
		exit;
274
	}
275
} else if ($_GET['act'] == "toggle") {
276
	if ($a_filter[$_GET['id']]) {
277
		if (isset($a_filter[$_GET['id']]['disabled'])) {
278
			unset($a_filter[$_GET['id']]['disabled']);
279
		} else {
280
			$a_filter[$_GET['id']]['disabled'] = true;
281
		}
282
		if (write_config()) {
283
			mark_subsystem_dirty('filter');
284
		}
285

    
286
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
287
		exit;
288
	}
289
} else if ($_POST['order-store']) {
290

    
291
	/* update rule order, POST[rule] is an array of ordered IDs */
292
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
293
		$a_filter_new = array();
294

    
295
		// get the rules of other interfaces listed in config before this interface.
296
		for ($i = 0; (isset($a_filter[$i]) && 
297
			(($a_filter[$i]['interface'] != $if && !isset($a_filter[$i]['floating'])) || (isset($a_filter[$i]['floating']) && "FloatingRules" != $if)) 
298
			); $i++) {
299
			$a_filter_new[] = $a_filter[$i];
300
		}
301

    
302
		// include the rules of this interface.
303
		// if a rule is not in POST[rule], it has been deleted by the user
304
		foreach ($_POST['rule'] as $id) {
305
			$a_filter_new[] = $a_filter[$id];
306
		}
307

    
308
		// get the rules of other interfaces listed in config after this interface.
309
		for ( ; (isset($a_filter[$i])); $i++) {
310
			if (($a_filter[$i]['interface'] != $if && !isset($a_filter[$i]['floating'])) || (isset($a_filter[$i]['floating']) && "FloatingRules" != $if)) {
311
				$a_filter_new[] = $a_filter[$i];
312
			}
313
		}
314

    
315
		$a_filter = $a_filter_new;
316

    
317
		$config['filter']['separator'][strtolower($if)] = "";
318

    
319
		if ($_POST['separator']) {
320
			$idx = 0;
321
			foreach ($_POST['separator'] as $separator) {
322
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
323
			}
324
		}
325

    
326
		if (write_config()) {
327
			mark_subsystem_dirty('filter');
328
		}
329

    
330
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
331
		exit;
332
	}
333
}
334

    
335
$tab_array = array(array(gettext("Floating"), ("FloatingRules" == $if), "firewall_rules.php?if=FloatingRules"));
336

    
337
foreach ($iflist as $ifent => $ifname) {
338
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
339
}
340

    
341
foreach ($tab_array as $dtab) {
342
	if ($dtab[1]) {
343
		$bctab = $dtab[0];
344
		break;
345
	}
346
}
347

    
348
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
349
$shortcut_section = "firewall";
350

    
351
include("head.inc");
352
$nrules = 0;
353

    
354
if ($savemsg) {
355
	print_info_box($savemsg, 'success');
356
}
357

    
358
if (is_subsystem_dirty('filter')) {
359
	print_apply_box(gettext("The firewall rule configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));
360
}
361

    
362
display_top_tabs($tab_array);
363

    
364
$showantilockout = false;
365
$showprivate = false;
366
$showblockbogons = false;
367

    
368
if (!isset($config['system']['webgui']['noantilockout']) &&
369
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
370
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
371
	$showantilockout = true;
372
}
373

    
374
if (isset($config['interfaces'][$if]['blockpriv'])) {
375
	$showprivate = true;
376
}
377

    
378
if (isset($config['interfaces'][$if]['blockbogons'])) {
379
	$showblockbogons = true;
380
}
381

    
382
/* Load the counter data of each pf rule. */
383
$rulescnt = pfSense_get_pf_rules();
384

    
385
// Update this if you add or remove columns!
386
$columns_in_table = 13;
387

    
388
?>
389
<form method="post">
390
	<div class="panel panel-default">
391
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to Change Order)")?></h2></div>
392
		<div id="mainarea" class="table-responsive panel-body">
393
			<table id="ruletable" class="table table-hover table-striped table-condensed">
394
				<thead>
395
					<tr>
396
						<th><!-- checkbox --></th>
397
						<th><!-- status icons --></th>
398
						<th><?=gettext("States")?></th>
399
						<th><?=gettext("Protocol")?></th>
400
						<th><?=gettext("Source")?></th>
401
						<th><?=gettext("Port")?></th>
402
						<th><?=gettext("Destination")?></th>
403
						<th><?=gettext("Port")?></th>
404
						<th><?=gettext("Gateway")?></th>
405
						<th><?=gettext("Queue")?></th>
406
						<th><?=gettext("Schedule")?></th>
407
						<th><?=gettext("Description")?></th>
408
						<th><?=gettext("Actions")?></th>
409
					</tr>
410
				</thead>
411

    
412
<?php if ($showblockbogons || $showantilockout || $showprivate) :
413
?>
414
				<tbody>
415
<?php
416
		// Show the anti-lockout rule if it's enabled, and we are on LAN with an if count > 1, or WAN with an if count of 1.
417
		if ($showantilockout):
418
			$alports = implode('<br />', filter_get_antilockout_ports(true));
419
?>
420
					<tr id="antilockout">
421
						<td></td>
422
						<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
423
						<td><?php print_states(intval(ANTILOCKOUT_TRACKER)); ?></td>
424
						<td>*</td>
425
						<td>*</td>
426
						<td>*</td>
427
						<td><?=$iflist[$if];?> Address</td>
428
						<td><?=$alports?></td>
429
						<td>*</td>
430
						<td>*</td>
431
						<td></td>
432
						<td><?=gettext("Anti-Lockout Rule");?></td>
433
						<td>
434
							<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
435
						</td>
436
					</tr>
437
<?php 	endif;?>
438
<?php 	if ($showprivate): ?>
439
					<tr id="frrfc1918">
440
						<td></td>
441
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
442
						<td><?php print_states(intval(RFC1918_TRACKER)); ?></td>
443
						<td>*</td>
444
						<td><?=gettext("RFC 1918 networks");?></td>
445
						<td>*</td>
446
						<td>*</td>
447
						<td>*</td>
448
						<td>*</td>
449
						<td>*</td>
450
						<td></td>
451
						<td><?=gettext("Block private networks");?></td>
452
						<td>
453
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
454
						</td>
455
					</tr>
456
<?php 	endif;?>
457
<?php 	if ($showblockbogons): ?>
458
					<tr id="frrfc1918">
459
						<td></td>
460
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
461
						<td><?php print_states(intval(BOGONS_TRACKER)); ?></td>
462
						<td>*</td>
463
						<td><?=sprintf(gettext("Reserved%sNot assigned by IANA"), "<br />");?></td>
464
						<td>*</td>
465
						<td>*</td>
466
						<td>*</td>
467
						<td>*</td>
468
						<td>*</td>
469
						<td></td>
470
						<td><?=gettext("Block bogon networks");?></td>
471
						<td>
472
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
473
						</td>
474
					</tr>
475
<?php 	endif;?>
476
			</tbody>
477
<?php endif;?>
478
			<tbody class="user-entries">
479
<?php
480
$nrules = 0;
481
$separators = $config['filter']['separator'][strtolower($if)];
482

    
483
// Get a list of separator rows and use it to call the display separator function only for rows which there are separator(s).
484
// More efficient than looping through the list of separators on every row.
485
$seprows = separator_rows($separators);
486

    
487
foreach ($a_filter as $filteri => $filterent):
488

    
489
	if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
490

    
491
		// Display separator(s) for section beginning at rule n
492
		if ($seprows[$nrules]) {
493
			display_separator($separators, $nrules, $columns_in_table);
494
		}
495
?>
496
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
497
						<td>
498
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
499
						</td>
500

    
501
	<?php
502
		if ($filterent['type'] == "block") {
503
			$iconfn = "times text-danger";
504
			$title_text = gettext("traffic is blocked");
505
		} else if ($filterent['type'] == "reject") {
506
			$iconfn = "hand-stop-o text-warning";
507
			$title_text = gettext("traffic is rejected");
508
		} else if ($filterent['type'] == "match") {
509
			$iconfn = "filter";
510
			$title_text = gettext("traffic is matched");
511
		} else {
512
			$iconfn = "check text-success";
513
			$title_text = gettext("traffic is passed");
514
		}
515
	?>
516
						<td title="<?=$title_text?>">
517
							<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$filteri;?>">
518
								<i class="fa fa-<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
519
							</a>
520
	<?php
521
		if ($filterent['quick'] == 'yes') {
522
			print '<i class="fa fa-forward text-success" title="'. gettext("&quot;Quick&quot; rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
523
		}
524

    
525
		$isadvset = firewall_check_for_advanced_options($filterent);
526
		if ($isadvset) {
527
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
528
		}
529

    
530
		if (isset($filterent['log'])) {
531
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
532
		}
533
	?>
534
						</td>
535
	<?php
536
		$alias = rule_columns_with_alias(
537
			$filterent['source']['address'],
538
			pprint_port($filterent['source']['port']),
539
			$filterent['destination']['address'],
540
			pprint_port($filterent['destination']['port'])
541
		);
542

    
543
		//build Schedule popup box
544
		$a_schedules = &$config['schedules']['schedule'];
545
		$schedule_span_begin = "";
546
		$schedule_span_end = "";
547
		$sched_caption_escaped = "";
548
		$sched_content = "";
549
		$schedstatus = false;
550
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
551
		$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'));
552
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
553
			$idx = 0;
554
			foreach ($a_schedules as $schedule) {
555
				if ($schedule['name'] == $filterent['sched']) {
556
					$schedstatus = filter_get_time_based_rule_status($schedule);
557

    
558
					foreach ($schedule['timerange'] as $timerange) {
559
						$tempFriendlyTime = "";
560
						$tempID = "";
561
						$firstprint = false;
562
						if ($timerange) {
563
							$dayFriendly = "";
564
							$tempFriendlyTime = "";
565

    
566
							//get hours
567
							$temptimerange = $timerange['hour'];
568
							$temptimeseparator = strrpos($temptimerange, "-");
569

    
570
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
571
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
572

    
573
							if ($timerange['month']) {
574
								$tempmontharray = explode(",", $timerange['month']);
575
								$tempdayarray = explode(",", $timerange['day']);
576
								$arraycounter = 0;
577
								$firstDayFound = false;
578
								$firstPrint = false;
579
								foreach ($tempmontharray as $monthtmp) {
580
									$month = $tempmontharray[$arraycounter];
581
									$day = $tempdayarray[$arraycounter];
582

    
583
									if (!$firstDayFound) {
584
										$firstDay = $day;
585
										$firstmonth = $month;
586
										$firstDayFound = true;
587
									}
588

    
589
									$currentDay = $day;
590
									$nextDay = $tempdayarray[$arraycounter+1];
591
									$currentDay++;
592
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
593
										if ($firstPrint) {
594
											$dayFriendly .= ", ";
595
										}
596
										$currentDay--;
597
										if ($currentDay != $firstDay) {
598
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
599
										} else {
600
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
601
										}
602
										$firstDayFound = false;
603
										$firstPrint = true;
604
									}
605
									$arraycounter++;
606
								}
607
							} else {
608
								$tempdayFriendly = $timerange['position'];
609
								$firstDayFound = false;
610
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
611
								$currentDay = "";
612
								$firstDay = "";
613
								$nextDay = "";
614
								$counter = 0;
615
								foreach ($tempFriendlyDayArray as $day) {
616
									if ($day != "") {
617
										if (!$firstDayFound) {
618
											$firstDay = $tempFriendlyDayArray[$counter];
619
											$firstDayFound = true;
620
										}
621
										$currentDay =$tempFriendlyDayArray[$counter];
622
										//get next day
623
										$nextDay = $tempFriendlyDayArray[$counter+1];
624
										$currentDay++;
625
										if ($currentDay != $nextDay) {
626
											if ($firstprint) {
627
												$dayFriendly .= ", ";
628
											}
629
											$currentDay--;
630
											if ($currentDay != $firstDay) {
631
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
632
											} else {
633
												$dayFriendly .= $dayArray[$firstDay-1];
634
											}
635
											$firstDayFound = false;
636
											$firstprint = true;
637
										}
638
										$counter++;
639
									}
640
								}
641
							}
642
							$timeFriendly = $starttime . " - " . $stoptime;
643
							$description = $timerange['rangedescr'];
644
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
645
						}
646
					}
647
					#FIXME
648
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
649
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
650
						$sched_caption_escaped . '" data-html="true">';
651
					$schedule_span_end = "</a>";
652
				}
653
			}
654
			$idx++;
655
		}
656
		$printicon = false;
657
		$alttext = "";
658
		$image = "";
659
		if (!isset($filterent['disabled'])) {
660
			if ($schedstatus) {
661
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
662
					$image = "times-circle";
663
					$dispcolor = "text-danger";
664
					$alttext = gettext("Traffic matching this rule is currently being denied");
665
				} else {
666
					$image = "play-circle";
667
					$dispcolor = "text-success";
668
					$alttext = gettext("Traffic matching this rule is currently being allowed");
669
				}
670
				$printicon = true;
671
			} else if ($filterent['sched']) {
672
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
673
					$image = "times-circle";
674
				} else {
675
					$image = "play-circle";
676
				}
677
				$alttext = gettext("This rule is not currently active because its period has expired");
678
				$dispcolor = "text-warning";
679
				$printicon = true;
680
			}
681
		}
682
	?>
683
				<td><?php print_states(intval($filterent['tracker'])); ?></td>
684
				<td>
685
	<?php
686
		if (isset($filterent['ipprotocol'])) {
687
			switch ($filterent['ipprotocol']) {
688
				case "inet":
689
					echo "IPv4 ";
690
					break;
691
				case "inet6":
692
					echo "IPv6 ";
693
					break;
694
				case "inet46":
695
					echo "IPv4+6 ";
696
					break;
697
			}
698
		} else {
699
			echo "IPv4 ";
700
		}
701

    
702
		if (isset($filterent['protocol'])) {
703
			echo strtoupper($filterent['protocol']);
704

    
705
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
706
				echo ' <span style="cursor: help;" title="' . gettext('ICMP type') . ': ' .
707
					($filterent['ipprotocol'] == "inet6" ? $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']]) .
708
					'"><u>';
709
				echo $filterent['icmptype'];
710
				echo '</u></span>';
711
			}
712
		} else echo "*";
713

    
714
	?>
715
						</td>
716
						<td>
717
							<?php if (isset($alias['src'])): ?>
718
								<a href="/firewall_aliases_edit.php?id=<?=$alias['src']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['src'])?>" data-html="true">
719
									<?=htmlspecialchars(pprint_address($filterent['source']))?>
720
								</a>
721
							<?php else: ?>
722
								<?=htmlspecialchars(pprint_address($filterent['source']))?>
723
							<?php endif; ?>
724
						</td>
725
						<td>
726
							<?php if (isset($alias['srcport'])): ?>
727
								<a href="/firewall_aliases_edit.php?id=<?=$alias['srcport']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['srcport'])?>" data-html="true">
728
									<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
729
								</a>
730
							<?php else: ?>
731
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
732
							<?php endif; ?>
733
						</td>
734
						<td>
735
							<?php if (isset($alias['dst'])): ?>
736
								<a href="/firewall_aliases_edit.php?id=<?=$alias['dst']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['dst'])?>" data-html="true">
737
									<?=htmlspecialchars(pprint_address($filterent['destination']))?>
738
								</a>
739
							<?php else: ?>
740
								<?=htmlspecialchars(pprint_address($filterent['destination']))?>
741
							<?php endif; ?>
742
						</td>
743
						<td>
744
							<?php if (isset($alias['dstport'])): ?>
745
								<a href="/firewall_aliases_edit.php?id=<?=$alias['dstport']?>" data-toggle="popover" data-trigger="hover focus" title="<?=gettext('Alias details')?>" data-content="<?=alias_info_popup($alias['dstport'])?>" data-html="true">
746
									<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
747
								</a>
748
							<?php else: ?>
749
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
750
							<?php endif; ?>
751
						</td>
752
						<td>
753
							<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
754
								<?=htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr'])?>
755
							<?php else: ?>
756
								<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
757
							<?php endif; ?>
758
						</td>
759
						<td>
760
							<?php
761
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
762
									$desc = $filterent['ackqueue'] ;
763
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
764
									$desc = $filterent['defaultqueue'];
765
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
766
								} else if (isset($filterent['defaultqueue'])) {
767
									$desc = $filterent['defaultqueue'];
768
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
769
								} else {
770
									echo gettext("none");
771
								}
772
							?>
773
						</td>
774
						<td>
775
							<?php if ($printicon) { ?>
776
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
777
							<?php } ?>
778
							<?=$schedule_span_begin;?><?=htmlspecialchars($filterent['sched']);?>&nbsp;<?=$schedule_span_end;?>
779
						</td>
780
						<td>
781
							<?=htmlspecialchars($filterent['descr']);?>
782
						</td>
783
						<td class="action-icons">
784
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
785
							<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
786
							<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
787
<?php if (isset($filterent['disabled'])) {
788
?>
789
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
790
<?php } else {
791
?>
792
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
793
<?php }
794
?>
795
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>"></a>
796
						</td>
797
					</tr>
798
<?php
799
		$nrules++;
800
	}
801
endforeach;
802

    
803
// There can be separator(s) after the last rule listed.
804
if ($seprows[$nrules]) {
805
	display_separator($separators, $nrules, $columns_in_table);
806
}
807
?>
808
				</tbody>
809
			</table>
810
		</div>
811
	</div>
812

    
813
<?php if ($nrules == 0): ?>
814
	<div class="alert alert-warning" role="alert">
815
		<p>
816
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
817
			<?=gettext("No floating rules are currently defined.");?>
818
		<?php else: ?>
819
			<?=gettext("No rules are currently defined for this interface");?><br />
820
			<?=gettext("All incoming connections on this interface will be blocked until you add pass rules.");?>
821
		<?php endif;?>
822
			<?=gettext("Click the button to add a new rule.");?>
823
		</p>
824
	</div>
825
<?php endif;?>
826

    
827
	<nav class="action-buttons">
828
		<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>&amp;after=-1" role="button" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the top of the list')?>">
829
			<i class="fa fa-level-up icon-embed-btn"></i>
830
			<?=gettext("Add");?>
831
		</a>
832
		<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>" role="button" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the end of the list')?>">
833
			<i class="fa fa-level-down icon-embed-btn"></i>
834
			<?=gettext("Add");?>
835
		</a>
836
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
837
			<i class="fa fa-trash icon-embed-btn"></i>
838
			<?=gettext("Delete"); ?>
839
		</button>
840
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
841
			<i class="fa fa-save icon-embed-btn"></i>
842
			<?=gettext("Save")?>
843
		</button>
844
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
845
			<i class="fa fa-plus icon-embed-btn"></i>
846
			<?=gettext("Separator")?>
847
		</button>
848
	</nav>
849
</form>
850

    
851
<div class="infoblock">
852
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
853
		<dl class="dl-horizontal responsive">
854
		<!-- Legend -->
855
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
856
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
857
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
858
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
859
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
860
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
861
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
862
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
863
		</dl>
864

    
865
<?php
866
	if ("FloatingRules" != $if) {
867
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
868
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
869
			gettext("This means that if you use block rules, you'll have to pay attention " .
870
			"to the rule order. Everything that isn't explicitly passed is blocked " .
871
			"by default. "));
872
	} else {
873
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
874
			"the action of the first rule to match a packet will be executed) only " .
875
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
876
			"other rules match. Pay close attention to the rule order and options " .
877
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
878
	}
879
?>
880
	</div>
881
	</div>
882
</div>
883

    
884
<script type="text/javascript">
885
//<![CDATA[
886

    
887
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
888
iface = "<?=strtolower($if)?>";
889
cncltxt = '<?=gettext("Cancel")?>';
890
svtxt = '<?=gettext("Save")?>';
891
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
892
configsection = "filter";
893

    
894
events.push(function() {
895

    
896
	// Make rules sortable. Hiding the table before applying sortable, then showing it again is
897
	// a work-around for very slow sorting on FireFox
898
	$('table tbody.user-entries').hide();
899

    
900
	$('table tbody.user-entries').sortable({
901
		cursor: 'grabbing',
902
		update: function(event, ui) {
903
			$('#order-store').removeAttr('disabled');
904
			reindex_rules(ui.item.parent('tbody'));
905
			dirty = true;
906
		}
907
	});
908

    
909
	$('table tbody.user-entries').show();
910

    
911
	// Check all of the rule checkboxes so that their values are posted
912
	$('#order-store').click(function () {
913
		$('[id^=frc]').prop('checked', true);
914

    
915
		// Save the separator bar configuration
916
		save_separators();
917

    
918
		// Suppress the "Do you really want to leave the page" message
919
		saving = true;
920
	});
921

    
922
	// provide a warning message if the user tries to change page before saving
923
	$(window).bind('beforeunload', function(){
924
		if ((!saving && dirty) || newSeperator) {
925
			return ("<?=gettext('You have moved one or more rules but have not yet saved')?>");
926
		} else {
927
			return undefined;
928
		}
929
	});
930

    
931
});
932
//]]>
933
</script>
934

    
935
<?php include("foot.inc");?>
(49-49/229)