Project

General

Profile

Download (27.3 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 delete_nat_association($id) {
76
	global $config;
77

    
78
	if (!$id || !is_array($config['nat']['rule'])) {
79
		return;
80
	}
81

    
82
	$a_nat = &$config['nat']['rule'];
83

    
84
	foreach ($a_nat as &$natent) {
85
		if ($natent['associated-rule-id'] == $id) {
86
			$natent['associated-rule-id'] = '';
87
		}
88
	}
89
}
90

    
91
if (!is_array($config['filter']['rule'])) {
92
	$config['filter']['rule'] = array();
93
}
94

    
95
filter_rules_sort();
96
$a_filter = &$config['filter']['rule'];
97

    
98
$if = $_GET['if'];
99

    
100
if ($_POST['if']) {
101
	$if = $_POST['if'];
102
}
103

    
104
$ifdescs = get_configured_interface_with_descr();
105

    
106
/* add group interfaces */
107
if (is_array($config['ifgroups']['ifgroupentry'])) {
108
	foreach ($config['ifgroups']['ifgroupentry'] as $ifgen) {
109
		if (have_ruleint_access($ifgen['ifname'])) {
110
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
111
		}
112
	}
113
}
114

    
115
foreach ($ifdescs as $ifent => $ifdesc) {
116
	if (have_ruleint_access($ifent)) {
117
		$iflist[$ifent] = $ifdesc;
118
	}
119
}
120

    
121
if ($config['l2tp']['mode'] == "server") {
122
	if (have_ruleint_access("l2tp")) {
123
		$iflist['l2tp'] = "L2TP VPN";
124
	}
125
}
126

    
127
if (is_array($config['pppoes']['pppoe'])) {
128
	foreach ($config['pppoes']['pppoe'] as $pppoes) {
129
		if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe")) {
130
			$iflist['pppoe'] = "PPPoE Server";
131
		}
132
	}
133
}
134

    
135
/* add ipsec interfaces */
136
if (ipsec_enabled() && have_ruleint_access("enc0")) {
137
	$iflist["enc0"] = "IPsec";
138
}
139

    
140
/* add openvpn/tun interfaces */
141
if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) {
142
	$iflist["openvpn"] = "OpenVPN";
143
}
144

    
145
if (!$if || !isset($iflist[$if])) {
146
	if ("any" == $if) {
147
		$if = "FloatingRules";
148
	} else if ("FloatingRules" != $if) {
149
		if (isset($iflist['wan'])) {
150
			$if = "wan";
151
		} else {
152
			$if = "FloatingRules";
153
		}
154
	}
155
}
156

    
157
if ($_POST) {
158
	$pconfig = $_POST;
159

    
160
	if ($_POST['apply']) {
161
		$retval = 0;
162
		$retval = filter_configure();
163

    
164
		clear_subsystem_dirty('filter');
165

    
166
		$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"),
167
									"<a href='status_filter_reload.php'>", "</a>");
168
	}
169
}
170

    
171
if ($_GET['act'] == "del") {
172
	if ($a_filter[$_GET['id']]) {
173
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
174
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
175
		}
176
		unset($a_filter[$_GET['id']]);
177
		if (write_config()) {
178
			mark_subsystem_dirty('filter');
179
		}
180

    
181
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
182
		exit;
183
	}
184
}
185

    
186
// Handle save msg if defined
187
if ($_REQUEST['savemsg']) {
188
	$savemsg = htmlentities($_REQUEST['savemsg']);
189
}
190

    
191
if (isset($_POST['del_x'])) {
192
	/* delete selected rules */
193
	$deleted = false;
194

    
195
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
196
		foreach ($_POST['rule'] as $rulei) {
197
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
198
			unset($a_filter[$rulei]);
199
			$deleted = true;
200
		}
201

    
202
		if ($deleted) {
203
			if (write_config()) {
204
				mark_subsystem_dirty('filter');
205
			}
206
		}
207

    
208
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
209
		exit;
210
	}
211
} else if ($_GET['act'] == "toggle") {
212
	if ($a_filter[$_GET['id']]) {
213
		if (isset($a_filter[$_GET['id']]['disabled'])) {
214
			unset($a_filter[$_GET['id']]['disabled']);
215
		} else {
216
			$a_filter[$_GET['id']]['disabled'] = true;
217
		}
218
		if (write_config()) {
219
			mark_subsystem_dirty('filter');
220
		}
221

    
222
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
223
		exit;
224
	}
225
} else if ($_POST['order-store']) {
226
	/* update rule order, POST[rule] is an array of ordered IDs */
227
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
228
		$a_filter_new = array();
229

    
230
		// if a rule is not in POST[rule], it has been deleted by the user
231
		foreach ($_POST['rule'] as $id) {
232
			$a_filter_new[] = $a_filter[$id];
233
		}
234

    
235
		$a_filter = $a_filter_new;
236
		if (write_config()) {
237
			mark_subsystem_dirty('filter');
238
		}
239

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

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

    
247
foreach ($iflist as $ifent => $ifname) {
248
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
249
}
250

    
251
foreach ($tab_array as $dtab) {
252
	if ($dtab[1]) {
253
		$bctab = $dtab[0];
254
		break;
255
	}
256
}
257

    
258
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
259
$shortcut_section = "firewall";
260

    
261
include("head.inc");
262
$nrules = 0;
263

    
264
if ($savemsg) {
265
	print_info_box($savemsg, 'success');
266
}
267

    
268
if (is_subsystem_dirty('filter')) {
269
	print_info_box_np(gettext("The firewall rule configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."), "apply", "", true);
270
}
271

    
272
display_top_tabs($tab_array);
273

    
274
?>
275
<form method="post">
276
	<div class="panel panel-default">
277
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to change order)")?></h2></div>
278
		<div id="mainarea" class="table-responsive panel-body">
279
			<table id="ruletable" class="table table-hover table-striped table-condensed">
280
				<thead>
281
					<tr>
282
						<th><!-- checkbox --></th>
283
						<th><!-- status icons --></th>
284
						<th><?=gettext("Protocol")?></th>
285
						<th><?=gettext("Source")?></th>
286
						<th><?=gettext("Port")?></th>
287
						<th><?=gettext("Destination")?></th>
288
						<th><?=gettext("Port")?></th>
289
						<th><?=gettext("Gateway")?></th>
290
						<th><?=gettext("Queue")?></th>
291
						<th><?=gettext("Schedule")?></th>
292
						<th><?=gettext("Description")?></th>
293
						<th><?=gettext("Actions")?></th>
294
					</tr>
295
				</thead>
296
				<tbody>
297
<?php
298
		// 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.
299
	if (!isset($config['system']['webgui']['noantilockout']) &&
300
	    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
301
	     ((count($config['interfaces']) == 1) && ($if == 'wan')))):
302
		$alports = implode('<br />', filter_get_antilockout_ports(true));
303
?>
304
					<tr id="antilockout">
305
						<td></td>
306
						<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
307
						<td>*</td>
308
						<td>*</td>
309
						<td>*</td>
310
						<td><?=$iflist[$if];?> Address</td>
311
						<td><?=$alports?></td>
312
						<td>*</td>
313
						<td>*</td>
314
						<td></td>
315
						<td><?=gettext("Anti-Lockout Rule");?></td>
316
						<td>
317
							<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
318
						</td>
319
					</tr>
320
<?php endif;?>
321
<?php if (isset($config['interfaces'][$if]['blockpriv'])): ?>
322
					<tr id="frrfc1918">
323
						<td></td>
324
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
325
						<td>*</td>
326
						<td><?=gettext("RFC 1918 networks");?></td>
327
						<td>*</td>
328
						<td>*</td>
329
						<td>*</td>
330
						<td>*</td>
331
						<td>*</td>
332
						<td></td>
333
						<td><?=gettext("Block private networks");?></td>
334
						<td>
335
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
336
						</td>
337
					</tr>
338
<?php endif;?>
339
<?php if (isset($config['interfaces'][$if]['blockbogons'])): ?>
340
					<tr id="frrfc1918">
341
					<td></td>
342
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
343
						<td>*</td>
344
						<td><?=gettext("Reserved/not assigned by IANA");?></td>
345
						<td>*</td>
346
						<td>*</td>
347
						<td>*</td>
348
						<td>*</td>
349
						<td>*</td>
350
						<td></td>
351
						<td><?=gettext("Block bogon networks");?></td>
352
						<td>
353
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
354
						</td>
355
					</tr>
356
<?php endif;?>
357
			</tbody>
358

    
359
			<tbody class="user-entries">
360
<?php
361
$nrules = 0;
362
for ($i = 0; isset($a_filter[$i]); $i++):
363
	$filterent = $a_filter[$i];
364

    
365
	if (($filterent['interface'] != $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" != $if)) {
366
		$display = 'style="display: none;"';
367
	} else {
368
		$display = "";
369
	}
370
?>
371
					<tr id="fr<?=$nrules;?>" <?=$display?> onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
372
						<td >
373
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$i;?>"/>
374
						</td>
375

    
376
	<?php
377
		if ($filterent['type'] == "block") {
378
			$iconfn = "times text-danger";
379
			$title_text = gettext("traffic is blocked");
380
		} else if ($filterent['type'] == "reject") {
381
			$iconfn = "hand-stop-o text-warning";
382
			$title_text = gettext("traffic is rejected");
383
		} else if ($filterent['type'] == "match") {
384
			$iconfn = "filter";
385
			$title_text = gettext("traffic is matched");
386
		} else {
387
			$iconfn = "check text-success";
388
			$title_text = gettext("traffic is passed");
389
		}
390
	?>
391
						<td title="<?=$title_text?>">
392

    
393
							<i class="fa fa-<?=$iconfn?>"></i>
394
	<?php
395
		$isadvset = firewall_check_for_advanced_options($filterent);
396
		if ($isadvset) {
397
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
398
		}
399

    
400
		if (isset($filterent['log'])) {
401
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'"></i>';
402
		}
403
	?>
404
						</td>
405
	<?php
406
		$alias = rule_columns_with_alias(
407
			$filterent['source']['address'],
408
			pprint_port($filterent['source']['port']),
409
			$filterent['destination']['address'],
410
			pprint_port($filterent['destination']['port'])
411
		);
412

    
413
		//build Schedule popup box
414
		$a_schedules = &$config['schedules']['schedule'];
415
		$schedule_span_begin = "";
416
		$schedule_span_end = "";
417
		$sched_caption_escaped = "";
418
		$sched_content = "";
419
		$schedstatus = false;
420
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
421
		$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'));
422
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
423
			$idx = 0;
424
			foreach ($a_schedules as $schedule) {
425
				if ($schedule['name'] == $filterent['sched']) {
426
					$schedstatus = filter_get_time_based_rule_status($schedule);
427

    
428
					foreach ($schedule['timerange'] as $timerange) {
429
						$tempFriendlyTime = "";
430
						$tempID = "";
431
						$firstprint = false;
432
						if ($timerange) {
433
							$dayFriendly = "";
434
							$tempFriendlyTime = "";
435

    
436
							//get hours
437
							$temptimerange = $timerange['hour'];
438
							$temptimeseparator = strrpos($temptimerange, "-");
439

    
440
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
441
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
442

    
443
							if ($timerange['month']) {
444
								$tempmontharray = explode(",", $timerange['month']);
445
								$tempdayarray = explode(",", $timerange['day']);
446
								$arraycounter = 0;
447
								$firstDayFound = false;
448
								$firstPrint = false;
449
								foreach ($tempmontharray as $monthtmp) {
450
									$month = $tempmontharray[$arraycounter];
451
									$day = $tempdayarray[$arraycounter];
452

    
453
									if (!$firstDayFound) {
454
										$firstDay = $day;
455
										$firstmonth = $month;
456
										$firstDayFound = true;
457
									}
458

    
459
									$currentDay = $day;
460
									$nextDay = $tempdayarray[$arraycounter+1];
461
									$currentDay++;
462
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
463
										if ($firstPrint) {
464
											$dayFriendly .= ", ";
465
										}
466
										$currentDay--;
467
										if ($currentDay != $firstDay) {
468
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
469
										} else {
470
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
471
										}
472
										$firstDayFound = false;
473
										$firstPrint = true;
474
									}
475
									$arraycounter++;
476
								}
477
							} else {
478
								$tempdayFriendly = $timerange['position'];
479
								$firstDayFound = false;
480
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
481
								$currentDay = "";
482
								$firstDay = "";
483
								$nextDay = "";
484
								$counter = 0;
485
								foreach ($tempFriendlyDayArray as $day) {
486
									if ($day != "") {
487
										if (!$firstDayFound) {
488
											$firstDay = $tempFriendlyDayArray[$counter];
489
											$firstDayFound = true;
490
										}
491
										$currentDay =$tempFriendlyDayArray[$counter];
492
										//get next day
493
										$nextDay = $tempFriendlyDayArray[$counter+1];
494
										$currentDay++;
495
										if ($currentDay != $nextDay) {
496
											if ($firstprint) {
497
												$dayFriendly .= ", ";
498
											}
499
											$currentDay--;
500
											if ($currentDay != $firstDay) {
501
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
502
											} else {
503
												$dayFriendly .= $dayArray[$firstDay-1];
504
											}
505
											$firstDayFound = false;
506
											$firstprint = true;
507
										}
508
										$counter++;
509
									}
510
								}
511
							}
512
							$timeFriendly = $starttime . " - " . $stoptime;
513
							$description = $timerange['rangedescr'];
514
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
515
						}
516
					}
517
					#FIXME
518
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
519
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
520
					    $sched_caption_escaped . '" data-html="true">';
521
					$schedule_span_end = "";
522
				}
523
			}
524
			$idx++;
525
		}
526
		$printicon = false;
527
		$alttext = "";
528
		$image = "";
529
		if (!isset($filterent['disabled'])) {
530
			if ($schedstatus) {
531
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
532
					$image = "times-circle";
533
					$dispcolor = "text-danger";
534
					$alttext = gettext("Traffic matching this rule is currently being denied");
535
				} else {
536
					$image = "play-circle";
537
					$dispcolor = "text-success";
538
					$alttext = gettext("Traffic matching this rule is currently being allowed");
539
				}
540
				$printicon = true;
541
			} else if ($filterent['sched']) {
542
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
543
					$image = "times-circle";
544
				} else {
545
					$image = "play-circle";
546
				}
547
				$alttext = gettext("This rule is not currently active because its period has expired");
548
				$dispcolor = "text-warning";
549
				$printicon = true;
550
			}
551
		}
552
	?>
553
				<td>
554
	<?php
555
		if (isset($filterent['ipprotocol'])) {
556
			switch ($filterent['ipprotocol']) {
557
				case "inet":
558
					echo "IPv4 ";
559
					break;
560
				case "inet6":
561
					echo "IPv6 ";
562
					break;
563
				case "inet46":
564
					echo "IPv4+6 ";
565
					break;
566
			}
567
		} else {
568
			echo "IPv4 ";
569
		}
570

    
571
		if (isset($filterent['protocol'])) {
572
			echo strtoupper($filterent['protocol']);
573

    
574
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
575
				echo ' <span style="cursor: help;" title="ICMP type: ' .
576
					($filterent['ipprotocol'] == "inet6" ? $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']]) .
577
					'"><u>';
578
				echo $filterent['icmptype'];
579
				echo '</u></span>';
580
			}
581
		} else echo "*";
582

    
583
	?>
584
						</td>
585
						<td>
586
							<?php if (isset($alias['src'])): ?>
587
								<a href="/firewall_aliases_edit.php?id=<?=$alias['src']?>" data-toggle="popover" data-trigger="hover focus" title="Alias details" data-content="<?=alias_info_popup($alias['src'])?>" data-html="true">
588
							<?php endif; ?>
589
							<?=htmlspecialchars(pprint_address($filterent['source']))?>
590
						</td>
591
						<td>
592
							<?php if (isset($alias['srcport'])): ?>
593
								<a href="/firewall_aliases_edit.php?id=<?=$alias['srcport']?>" data-toggle="popover" data-trigger="hover focus" title="Alias details" data-content="<?=alias_info_popup($alias['srcport'])?>" data-html="true">
594
							<?php endif; ?>
595
							<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
596
						</td>
597
						<td>
598
							<?php if (isset($alias['dst'])): ?>
599
								<a href="/firewall_aliases_edit.php?id=<?=$alias['dst']?>" data-toggle="popover" data-trigger="hover focus" title="Alias details" data-content="<?=alias_info_popup($alias['dst'])?>" data-html="true">
600
							<?php endif; ?>
601
							<?=htmlspecialchars(pprint_address($filterent['destination']))?>
602
						</td>
603
						<td>
604
							<?php if (isset($alias['dstport'])): ?>
605
								<a href="/firewall_aliases_edit.php?id=<?=$alias['dstport']?>" data-toggle="popover" data-trigger="hover focus" title="Alias details" data-content="<?=alias_info_popup($alias['dstport'])?>" data-html="true">
606
							<?php endif; ?>
607
							<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
608
						</td>
609
						<td>
610
							<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
611
								<?=htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr'])?>
612
							<?php else: ?>
613
								<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
614
							<?php endif; ?>
615
						</td>
616
						<td>
617
							<?php
618
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
619
									$desc = $filterent['ackqueue'] ;
620
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
621
									$desc = $filterent['defaultqueue'];
622
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
623
								} else if (isset($filterent['defaultqueue'])) {
624
									$desc = $filterent['defaultqueue'];
625
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
626
								} else {
627
									echo gettext("none");
628
								}
629
							?>
630
						</td>
631
						<td>
632
							<?php if ($printicon) { ?>
633
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>" alt="icon"></i>
634
							<?php } ?>
635
							<?=$schedule_span_begin;?><?=htmlspecialchars($filterent['sched']);?>&nbsp;<?=$schedule_span_end;?>
636
						</td>
637
						<td>
638
							<?=htmlspecialchars($filterent['descr']);?>
639
						</td>
640
						<td class="action-icons">
641
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
642
							<a href="firewall_rules_edit.php?id=<?=$i;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
643
							<a href="firewall_rules_edit.php?dup=<?=$i;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
644
<?php if (isset($filterent['disabled'])) {
645
?>
646
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
647
<?php } else {
648
?>
649
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
650
<?php }
651
?>
652
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" class="fa fa-trash" title="<?=gettext('Delete')?>"></a>
653
						</td>
654
					</tr>
655
<?php
656
		$nrules++;
657
		endfor;
658
?>
659
				</tbody>
660
			</table>
661
		</div>
662
	</div>
663

    
664
<?php if ($nrules == 0): ?>
665
	<div class="alert alert-warning" role="alert">
666
		<p>
667
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
668
			<?=gettext("No floating rules are currently defined.");?>
669
		<?php else: ?>
670
			<?=gettext("No rules are currently defined for this interface");?><br />
671
			<?=gettext("All incoming connections on this interface will be blocked until you add pass rules.");?>
672
		<?php endif;?>
673
			<?=gettext("Click the button to add a new rule.");?>
674
		</p>
675
	</div>
676
<?php endif;?>
677

    
678
	<nav class="action-buttons">
679
		<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')?>">
680
			<i class="fa fa-level-up icon-embed-btn"></i>
681
			<?=gettext("Add");?>
682
		</a>
683
		<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')?>">
684
			<i class="fa fa-level-down icon-embed-btn"></i>
685
			<?=gettext("Add");?>
686
		</a>
687
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
688
			<i class="fa fa-trash icon-embed-btn"></i>
689
			<?=gettext("Delete"); ?>
690
		</button>
691
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
692
			<i class="fa fa-save icon-embed-btn"></i>
693
			<?=gettext("Save")?>
694
		</button>
695
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
696
			<i class="fa fa-plus icon-embed-btn"></i>
697
			<?=gettext("Separator")?>
698
		</button>
699
	</nav>
700
</form>
701

    
702
<div class="infoblock">
703
	<div class="alert alert-info clearfix" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><div class="pull-left">
704
		<dl class="dl-horizontal responsive">
705
		<!-- Legend -->
706
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
707
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
708
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
709
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
710
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
711
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
712
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
713
		</dl>
714

    
715
<?php
716
	if ("FloatingRules" != $if) {
717
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
718
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
719
			gettext("This means that if you use block rules, you'll have to pay attention " .
720
			"to the rule order. Everything that isn't explicitly passed is blocked " .
721
			"by default. "));
722
	} else {
723
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
724
			"the action of the first rule to match a packet will be executed) only " .
725
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
726
			"other rules match. Pay close attention to the rule order and options " .
727
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
728
	}
729
?>
730
	</div>
731
	</div>
732
</div>
733

    
734
<script type="text/javascript">
735
//<![CDATA[
736
events.push(function() {
737

    
738
	// Make rules sortable
739
	$('table tbody.user-entries').sortable({
740
		cursor: 'grabbing',
741
		update: function(event, ui) {
742
			$('#order-store').removeAttr('disabled');
743
		}
744
	});
745

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

    
750
		// Save the separator bar configuration
751
		save_separators();
752
	});
753

    
754
	// Separator bar stuff ------------------------------------------------------------------------
755
	$("#addsep").prop('type' ,'button');
756

    
757
    $("#addsep").click(function() {
758
        alert("This feature is not yet complete. (Nothing is saved)\nIncluded for review only.");
759
        // Inset a temporary bar in which hte user can enter some optional text
760
        $('#ruletable > tbody:last').append('<tr>' +
761
            '<td bgcolor="#cce5ff" colspan="10"><input id="newsep" placeholder="<?=gettext("Enter a description, Save, then drag to final location.")?>" class="col-md-12" type="text"></input></td>' +
762
            '<td bgcolor="#cce5ff" colspan="2"><button class="btn btn-default btn-sm" id="btnnewsep"><?=gettext("Save")?></button></td>' +
763
            '</tr>');
764

    
765
		$("#btnnewsep").prop('type' ,'button');
766

    
767
		// Remove the temporary separator bar and replace it with the final version containing the
768
		// user's text and a delete icon
769
		$("#btnnewsep").click(function() {
770
			var septext = escapeHtml($('#newsep').val());
771
			$('#ruletable > tbody:last >tr:last').remove();
772
			$('#ruletable > tbody:last').append('<tr class="ui-sortable-handle">' +
773
	            '<td bgcolor="#cce5ff" colspan="11">' + '<font color="#002699">' + septext + '</font></td>' +
774
	            '<td  bgcolor="#cce5ff"><a href="#"><i class="fa fa-trash sepdel"></i></a></td>' +
775
	            '</tr>');
776
		});
777
    });
778

    
779
	// Delete a sepaator row
780
	$(function(){
781
		$('table').on('click','tr a .sepdel',function(e){
782
			e.preventDefault();
783
			$(this).parents('tr').remove();
784
		});
785
	});
786

    
787
	function save_separators() {
788
		return(true);
789
	}
790

    
791
	//JS equivalent to PHP htmlspecialchars()
792
	function escapeHtml(text) {
793
		var map = {
794
			'&': '&amp;',
795
			'<': '&lt;',
796
			'>': '&gt;',
797
			'"': '&quot;',
798
			"'": '&#039;'
799
		};
800

    
801
		return text.replace(/[&<>"']/g, function(m) { return map[m]; });
802
	}
803
	// --------------------------------------------------------------------------------------------
804
});
805
//]]>
806
</script>
807

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