Project

General

Profile

Download (32.4 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'] = gettext("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'] = gettext("PPPoE Server");
131
		}
132
	}
133
}
134

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

    
140
/* add openvpn/tun interfaces */
141
if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) {
142
	$iflist["openvpn"] = gettext("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

    
159
	$pconfig = $_POST;
160

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

    
165
		clear_subsystem_dirty('filter');
166

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

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

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

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

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

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

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

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

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

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

    
236
		$a_filter = $a_filter_new;
237

    
238
		$config['filter']['separator'][strtolower($if)] = "";
239

    
240
		if ($_POST['separator']) {
241
			$idx = 0;
242
			foreach ($_POST['separator'] as $separator) {
243
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
244
			}
245
		}
246

    
247
		if (write_config()) {
248
			mark_subsystem_dirty('filter');
249
		}
250

    
251
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
252
		exit;
253
	}
254
}
255

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

    
258
foreach ($iflist as $ifent => $ifname) {
259
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
260
}
261

    
262
foreach ($tab_array as $dtab) {
263
	if ($dtab[1]) {
264
		$bctab = $dtab[0];
265
		break;
266
	}
267
}
268

    
269
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
270
$shortcut_section = "firewall";
271

    
272
include("head.inc");
273
$nrules = 0;
274

    
275
if ($savemsg) {
276
	print_info_box($savemsg, 'success');
277
}
278

    
279
if (is_subsystem_dirty('filter')) {
280
	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."));
281
}
282

    
283
display_top_tabs($tab_array);
284

    
285
$showantilockout = false;
286
$showprivate = false;
287
$showblockbogons = false;
288

    
289
if (!isset($config['system']['webgui']['noantilockout']) &&
290
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
291
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
292
	$showantilockout = true;
293
}
294

    
295
if (isset($config['interfaces'][$if]['blockpriv'])) {
296
	$showprivate = true;
297
}
298

    
299
if (isset($config['interfaces'][$if]['blockbogons'])) {
300
	$showblockbogons = true;
301
}
302

    
303
?>
304
<form method="post">
305
	<div class="panel panel-default">
306
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to change order)")?></h2></div>
307
		<div id="mainarea" class="table-responsive panel-body">
308
			<table id="ruletable" class="table table-hover table-striped table-condensed">
309
				<thead>
310
					<tr>
311
						<th><!-- checkbox --></th>
312
						<th><!-- status icons --></th>
313
						<th><?=gettext("Protocol")?></th>
314
						<th><?=gettext("Source")?></th>
315
						<th><?=gettext("Port")?></th>
316
						<th><?=gettext("Destination")?></th>
317
						<th><?=gettext("Port")?></th>
318
						<th><?=gettext("Gateway")?></th>
319
						<th><?=gettext("Queue")?></th>
320
						<th><?=gettext("Schedule")?></th>
321
						<th><?=gettext("Description")?></th>
322
						<th><?=gettext("Actions")?></th>
323
					</tr>
324
				</thead>
325

    
326
<?php if ($showblockbogons || $showantilockout || $showprivate) :
327
?>
328
				<tbody>
329
<?php
330
		// 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.
331
		if ($showantilockout):
332
			$alports = implode('<br />', filter_get_antilockout_ports(true));
333
?>
334
					<tr id="antilockout">
335
						<td></td>
336
						<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
337
						<td>*</td>
338
						<td>*</td>
339
						<td>*</td>
340
						<td><?=$iflist[$if];?> Address</td>
341
						<td><?=$alports?></td>
342
						<td>*</td>
343
						<td>*</td>
344
						<td></td>
345
						<td><?=gettext("Anti-Lockout Rule");?></td>
346
						<td>
347
							<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
348
						</td>
349
					</tr>
350
<?php 	endif;?>
351
<?php 	if ($showprivate): ?>
352
					<tr id="frrfc1918">
353
						<td></td>
354
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
355
						<td>*</td>
356
						<td><?=gettext("RFC 1918 networks");?></td>
357
						<td>*</td>
358
						<td>*</td>
359
						<td>*</td>
360
						<td>*</td>
361
						<td>*</td>
362
						<td></td>
363
						<td><?=gettext("Block private networks");?></td>
364
						<td>
365
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
366
						</td>
367
					</tr>
368
<?php 	endif;?>
369
<?php 	if ($showblockbogons): ?>
370
					<tr id="frrfc1918">
371
					<td></td>
372
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
373
						<td>*</td>
374
						<td><?=gettext("Reserved/not assigned by IANA");?></td>
375
						<td>*</td>
376
						<td>*</td>
377
						<td>*</td>
378
						<td>*</td>
379
						<td>*</td>
380
						<td></td>
381
						<td><?=gettext("Block bogon networks");?></td>
382
						<td>
383
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
384
						</td>
385
					</tr>
386
<?php 	endif;?>
387
			</tbody>
388
<?php endif;?>
389
			<tbody class="user-entries">
390
<?php
391
$nrules = 0;
392
$seps = 0;
393

    
394
// There can be a separator before any rules are listed
395
if ($config['filter']['separator'][strtolower($if)]['sep0']['row'][0] == "fr-1") {
396
	print('<tr class="ui-sortable-handle separator">' .
397
		'<td bgcolor="#cce5ff" colspan="11">' . '<font color="#002699">' . $config['filter']['separator'][strtolower($if)]['sep0']['text'] . '</font></td>' .
398
		'<td  bgcolor="#cce5ff"><a href="#"><i class="fa fa-trash no-confirm sepdel" title="delete this separator"></i></a></td>' .
399
		'</tr>' . "\n");
400
}
401

    
402
for ($i = 0; isset($a_filter[$i]); $i++):
403
	$filterent = $a_filter[$i];
404

    
405
	if (($filterent['interface'] != $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" != $if)) {
406
		$display = 'style="display: none;"';
407
	} else {
408
		$display = "";
409
	}
410

    
411
?>
412
					<tr id="fr<?=$nrules;?>" <?=$display?> onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
413
						<td>
414
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$i;?>"/>
415
						</td>
416

    
417
	<?php
418
		if ($filterent['type'] == "block") {
419
			$iconfn = "times text-danger";
420
			$title_text = gettext("traffic is blocked");
421
		} else if ($filterent['type'] == "reject") {
422
			$iconfn = "hand-stop-o text-warning";
423
			$title_text = gettext("traffic is rejected");
424
		} else if ($filterent['type'] == "match") {
425
			$iconfn = "filter";
426
			$title_text = gettext("traffic is matched");
427
		} else {
428
			$iconfn = "check text-success";
429
			$title_text = gettext("traffic is passed");
430
		}
431
	?>
432
						<td title="<?=$title_text?>">
433

    
434
							<i class="fa fa-<?=$iconfn?>"></i>
435
	<?php
436
		$isadvset = firewall_check_for_advanced_options($filterent);
437
		if ($isadvset) {
438
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
439
		}
440

    
441
		if (isset($filterent['log'])) {
442
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'"></i>';
443
		}
444
	?>
445
						</td>
446
	<?php
447
		$alias = rule_columns_with_alias(
448
			$filterent['source']['address'],
449
			pprint_port($filterent['source']['port']),
450
			$filterent['destination']['address'],
451
			pprint_port($filterent['destination']['port'])
452
		);
453

    
454
		//build Schedule popup box
455
		$a_schedules = &$config['schedules']['schedule'];
456
		$schedule_span_begin = "";
457
		$schedule_span_end = "";
458
		$sched_caption_escaped = "";
459
		$sched_content = "";
460
		$schedstatus = false;
461
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
462
		$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'));
463
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
464
			$idx = 0;
465
			foreach ($a_schedules as $schedule) {
466
				if ($schedule['name'] == $filterent['sched']) {
467
					$schedstatus = filter_get_time_based_rule_status($schedule);
468

    
469
					foreach ($schedule['timerange'] as $timerange) {
470
						$tempFriendlyTime = "";
471
						$tempID = "";
472
						$firstprint = false;
473
						if ($timerange) {
474
							$dayFriendly = "";
475
							$tempFriendlyTime = "";
476

    
477
							//get hours
478
							$temptimerange = $timerange['hour'];
479
							$temptimeseparator = strrpos($temptimerange, "-");
480

    
481
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
482
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
483

    
484
							if ($timerange['month']) {
485
								$tempmontharray = explode(",", $timerange['month']);
486
								$tempdayarray = explode(",", $timerange['day']);
487
								$arraycounter = 0;
488
								$firstDayFound = false;
489
								$firstPrint = false;
490
								foreach ($tempmontharray as $monthtmp) {
491
									$month = $tempmontharray[$arraycounter];
492
									$day = $tempdayarray[$arraycounter];
493

    
494
									if (!$firstDayFound) {
495
										$firstDay = $day;
496
										$firstmonth = $month;
497
										$firstDayFound = true;
498
									}
499

    
500
									$currentDay = $day;
501
									$nextDay = $tempdayarray[$arraycounter+1];
502
									$currentDay++;
503
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
504
										if ($firstPrint) {
505
											$dayFriendly .= ", ";
506
										}
507
										$currentDay--;
508
										if ($currentDay != $firstDay) {
509
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
510
										} else {
511
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
512
										}
513
										$firstDayFound = false;
514
										$firstPrint = true;
515
									}
516
									$arraycounter++;
517
								}
518
							} else {
519
								$tempdayFriendly = $timerange['position'];
520
								$firstDayFound = false;
521
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
522
								$currentDay = "";
523
								$firstDay = "";
524
								$nextDay = "";
525
								$counter = 0;
526
								foreach ($tempFriendlyDayArray as $day) {
527
									if ($day != "") {
528
										if (!$firstDayFound) {
529
											$firstDay = $tempFriendlyDayArray[$counter];
530
											$firstDayFound = true;
531
										}
532
										$currentDay =$tempFriendlyDayArray[$counter];
533
										//get next day
534
										$nextDay = $tempFriendlyDayArray[$counter+1];
535
										$currentDay++;
536
										if ($currentDay != $nextDay) {
537
											if ($firstprint) {
538
												$dayFriendly .= ", ";
539
											}
540
											$currentDay--;
541
											if ($currentDay != $firstDay) {
542
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
543
											} else {
544
												$dayFriendly .= $dayArray[$firstDay-1];
545
											}
546
											$firstDayFound = false;
547
											$firstprint = true;
548
										}
549
										$counter++;
550
									}
551
								}
552
							}
553
							$timeFriendly = $starttime . " - " . $stoptime;
554
							$description = $timerange['rangedescr'];
555
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
556
						}
557
					}
558
					#FIXME
559
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
560
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
561
						$sched_caption_escaped . '" data-html="true">';
562
					$schedule_span_end = "</a>";
563
				}
564
			}
565
			$idx++;
566
		}
567
		$printicon = false;
568
		$alttext = "";
569
		$image = "";
570
		if (!isset($filterent['disabled'])) {
571
			if ($schedstatus) {
572
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
573
					$image = "times-circle";
574
					$dispcolor = "text-danger";
575
					$alttext = gettext("Traffic matching this rule is currently being denied");
576
				} else {
577
					$image = "play-circle";
578
					$dispcolor = "text-success";
579
					$alttext = gettext("Traffic matching this rule is currently being allowed");
580
				}
581
				$printicon = true;
582
			} else if ($filterent['sched']) {
583
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
584
					$image = "times-circle";
585
				} else {
586
					$image = "play-circle";
587
				}
588
				$alttext = gettext("This rule is not currently active because its period has expired");
589
				$dispcolor = "text-warning";
590
				$printicon = true;
591
			}
592
		}
593
	?>
594
				<td>
595
	<?php
596
		if (isset($filterent['ipprotocol'])) {
597
			switch ($filterent['ipprotocol']) {
598
				case "inet":
599
					echo "IPv4 ";
600
					break;
601
				case "inet6":
602
					echo "IPv6 ";
603
					break;
604
				case "inet46":
605
					echo "IPv4+6 ";
606
					break;
607
			}
608
		} else {
609
			echo "IPv4 ";
610
		}
611

    
612
		if (isset($filterent['protocol'])) {
613
			echo strtoupper($filterent['protocol']);
614

    
615
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
616
				echo ' <span style="cursor: help;" title="' . gettext('ICMP type') . ': ' .
617
					($filterent['ipprotocol'] == "inet6" ? $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']]) .
618
					'"><u>';
619
				echo $filterent['icmptype'];
620
				echo '</u></span>';
621
			}
622
		} else echo "*";
623

    
624
	?>
625
						</td>
626
						<td>
627
							<?php if (isset($alias['src'])): ?>
628
								<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">
629
									<?=htmlspecialchars(pprint_address($filterent['source']))?>
630
								</a>
631
							<?php else: ?>
632
								<?=htmlspecialchars(pprint_address($filterent['source']))?>
633
							<?php endif; ?>
634
						</td>
635
						<td>
636
							<?php if (isset($alias['srcport'])): ?>
637
								<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">
638
									<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
639
								</a>
640
							<?php else: ?>
641
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
642
							<?php endif; ?>
643
						</td>
644
						<td>
645
							<?php if (isset($alias['dst'])): ?>
646
								<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">
647
									<?=htmlspecialchars(pprint_address($filterent['destination']))?>
648
								</a>
649
							<?php else :?>
650
								<?=htmlspecialchars(pprint_address($filterent['destination']))?>
651
							<?php endif; ?>
652
						</td>
653
						<td>
654
							<?php if (isset($alias['dstport'])): ?>
655
								<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">
656
									<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
657
								</a>
658
							<?php else: ?>
659
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
660
							<?php endif; ?>
661
						</td>
662
						<td>
663
							<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
664
								<?=htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr'])?>
665
							<?php else: ?>
666
								<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
667
							<?php endif; ?>
668
						</td>
669
						<td>
670
							<?php
671
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
672
									$desc = $filterent['ackqueue'] ;
673
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
674
									$desc = $filterent['defaultqueue'];
675
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
676
								} else if (isset($filterent['defaultqueue'])) {
677
									$desc = $filterent['defaultqueue'];
678
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
679
								} else {
680
									echo gettext("none");
681
								}
682
							?>
683
						</td>
684
						<td>
685
							<?php if ($printicon) { ?>
686
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
687
							<?php } ?>
688
							<?=$schedule_span_begin;?><?=htmlspecialchars($filterent['sched']);?>&nbsp;<?=$schedule_span_end;?>
689
						</td>
690
						<td>
691
							<?=htmlspecialchars($filterent['descr']);?>
692
						</td>
693
						<td class="action-icons">
694
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
695
							<a href="firewall_rules_edit.php?id=<?=$i;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
696
							<a href="firewall_rules_edit.php?dup=<?=$i;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
697
<?php if (isset($filterent['disabled'])) {
698
?>
699
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
700
<?php } else {
701
?>
702
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
703
<?php }
704
?>
705
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" class="fa fa-trash" title="<?=gettext('Delete')?>"></a>
706
						</td>
707
					</tr>
708
<?php
709
		if (isset($config['filter']['separator'][strtolower($if)]['sep0'])) {
710
			foreach ($config['filter']['separator'][strtolower($if)] as $rulesep) {
711
				if ($rulesep['row']['0'] == "fr" . $nrules) {
712
					$cellcolor = $rulesep['color'];
713
					print('<tr class="ui-sortable-handle separator">' .
714
						'<td class="' . $cellcolor . '" colspan="11">' . '<span class="' . $cellcolor . '">' . $rulesep['text'] . '</span></td>' .
715
						'<td  class="' . $cellcolor . '"><a href="#"><i class="fa fa-trash no-confirm sepdel" title="delete this separator"></i></a></td>' .
716
						'</tr>' . "\n");
717
				}
718
			}
719
		}
720

    
721
		$nrules++;
722
		endfor;
723
?>
724
				</tbody>
725
			</table>
726
		</div>
727
	</div>
728

    
729
<?php if ($nrules == 0): ?>
730
	<div class="alert alert-warning" role="alert">
731
		<p>
732
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
733
			<?=gettext("No floating rules are currently defined.");?>
734
		<?php else: ?>
735
			<?=gettext("No rules are currently defined for this interface");?><br />
736
			<?=gettext("All incoming connections on this interface will be blocked until you add pass rules.");?>
737
		<?php endif;?>
738
			<?=gettext("Click the button to add a new rule.");?>
739
		</p>
740
	</div>
741
<?php endif;?>
742

    
743
	<nav class="action-buttons">
744
		<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')?>">
745
			<i class="fa fa-level-up icon-embed-btn"></i>
746
			<?=gettext("Add");?>
747
		</a>
748
		<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')?>">
749
			<i class="fa fa-level-down icon-embed-btn"></i>
750
			<?=gettext("Add");?>
751
		</a>
752
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
753
			<i class="fa fa-trash icon-embed-btn"></i>
754
			<?=gettext("Delete"); ?>
755
		</button>
756
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
757
			<i class="fa fa-save icon-embed-btn"></i>
758
			<?=gettext("Save")?>
759
		</button>
760
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
761
			<i class="fa fa-plus icon-embed-btn"></i>
762
			<?=gettext("Separator")?>
763
		</button>
764
	</nav>
765
</form>
766

    
767
<div class="infoblock">
768
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
769
		<dl class="dl-horizontal responsive">
770
		<!-- Legend -->
771
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
772
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
773
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
774
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
775
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
776
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
777
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
778
		</dl>
779

    
780
<?php
781
	if ("FloatingRules" != $if) {
782
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
783
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
784
			gettext("This means that if you use block rules, you'll have to pay attention " .
785
			"to the rule order. Everything that isn't explicitly passed is blocked " .
786
			"by default. "));
787
	} else {
788
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
789
			"the action of the first rule to match a packet will be executed) only " .
790
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
791
			"other rules match. Pay close attention to the rule order and options " .
792
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
793
	}
794
?>
795
	</div>
796
	</div>
797
</div>
798

    
799
<script type="text/javascript">
800
//<![CDATA[
801
events.push(function() {
802

    
803
	// Make rules sortable
804
	$('table tbody.user-entries').sortable({
805
		cursor: 'grabbing',
806
		update: function(event, ui) {
807
			$('#order-store').removeAttr('disabled');
808
			dirty = true;
809
		}
810
	});
811

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

    
816
		// Save the separator bar configuration
817
		save_separators();
818

    
819
		// Suppress the "Do you really want to leave the page" message
820
		saving = true;
821
	});
822

    
823
	// Separator bar stuff ------------------------------------------------------------------------
824

    
825
	// Globals
826
	gColor = 'bg-info';
827
	newSeperator = false;
828
	saving = false;
829
	dirty = false;
830

    
831
	$("#addsep").prop('type' ,'button');
832

    
833
	$("#addsep").click(function() {
834
		if (newSeperator) {
835
			return(false);
836
		}
837

    
838
		gColor = 'bg-info';
839
		// Inset a temporary bar in which the user can enter some optional text
840
		$('#ruletable > tbody:last').append('<tr>' +
841
			'<td class="' + gColor + '" colspan="10"><input id="newsep" placeholder="<?=gettext("Enter a description, Save, then drag to final location.")?>" class="col-md-12" type="text" /></td>' +
842
			'<td class="' + gColor + '" colspan="2"><button class="btn btn-default btn-sm" id="btnnewsep"><?=gettext("Save")?></button>' +
843
			'<button class="btn btn-default btn-sm" id="btncncsep"><?=gettext("Cancel")?></button>' +
844
			'&nbsp;&nbsp;&nbsp;&nbsp;' +
845
			'&nbsp;&nbsp;<a href="#" id="sepclrblue" value="bg-info"><i class="fa fa-circle text-info"></i></a>' +
846
			'&nbsp;&nbsp;<a href="#" id="sepclrred" value="bg-danger"><i class="fa fa-circle text-danger"></i></a>' +
847
			'&nbsp;&nbsp;<a href="#" id="sepclrgreen" value="bg-success"><i class="fa fa-circle text-success"></i></a>' +
848
			'&nbsp;&nbsp;<a href="#" id="sepclrorange" value="bg-warning"><i class="fa fa-circle text-warning"></i></a>' +
849
			'</td></tr>');
850

    
851
		$('#newsep').focus();
852
		newSeperator = true;
853

    
854
		$("#btnnewsep").prop('type' ,'button');
855

    
856
		// Watch escape and enter keys
857
		$('#newsep').keyup(function(e) {
858
			if(e.which == 27) {
859
				$('#btncncsep').trigger('click');
860
			}
861
		});
862

    
863
		$('#newsep').keypress(function(e) {
864
			if(e.which == 13) {
865
				$('#btnnewsep').trigger('click');
866
			}
867
		});
868

    
869
		handle_colors();
870

    
871
		// Remove the temporary separator bar and replace it with the final version containing the
872
		// user's text and a delete icon
873
		$("#btnnewsep").click(function() {
874
			var septext = escapeHtml($('#newsep').val());
875
			$('#ruletable > tbody:last >tr:last').remove();
876
			$('#ruletable > tbody:last').append('<tr class="ui-sortable-handle separator">' +
877
				'<td class="' + gColor + '" colspan="11">' + '<span class="' + gColor + '">' + septext + '</span></td>' +
878
				'<td class="' + gColor + '"><a href="#"><i class="fa fa-trash sepdel"></i></a>' +
879
				'</td></tr>');
880

    
881
			$('#order-store').removeAttr('disabled');
882
			newSeperator = false;
883
			dirty = true;
884
		});
885

    
886
		// Cancel button
887
		$('#btncncsep').click(function(e) {
888
			e.preventDefault();
889
			$(this).parents('tr').remove();
890
			newSeperator = false;
891
		});
892
	});
893

    
894
	// Delete a separator row
895
	$(function(){
896
		$('table').on('click','tr a .sepdel',function(e){
897
			e.preventDefault();
898
			$(this).parents('tr').remove();
899
			$('#order-store').removeAttr('disabled');
900
			dirty = true;
901
		});
902
	});
903

    
904
	// Compose an inout array containing the row #, color and text for each separator
905
	function save_separators() {
906
		var seprow = 0;
907
		var sepinput;
908
		var sepnum = 0;
909

    
910
		$('#ruletable > tbody > tr').each(function() {
911
			if ($(this).hasClass('separator')) {
912
				seprow = $(this).prev('tr').attr("id");
913
				if (seprow == undefined) {
914
					seprow = "fr-1";
915
				}
916

    
917
				sepinput = '<input type="hidden" name="separator[' + sepnum + '][row]" value="' + seprow + '"></input>';
918
				$('form').append(sepinput);
919
				sepinput = '<input type="hidden" name="separator[' + sepnum + '][text]" value="' + escapeHtml($(this).find('td').text()) + '"></input>';
920
				$('form').append(sepinput);
921
				sepinput = '<input type="hidden" name="separator[' + sepnum + '][color]" value="' + $(this).find('td').prop('class') + '"></input>';
922
				$('form').append(sepinput);
923
				sepinput = '<input type="hidden" name="separator[' + sepnum + '][if]" value="<?=strtolower($if)?>"></input>';
924
				$('form').append(sepinput);
925
				sepnum++;
926
			}
927

    
928
			if ($(this).parent('tbody').hasClass('user-entries')) {
929
				seprow++;
930
			}
931
		});
932
	}
933

    
934
	function handle_colors() {
935
		$('[id^=sepclr]').prop("type", "button");
936

    
937
		$('[id^=sepclr]').click(function () {
938
			var color =	 $(this).attr('value');
939
			// Clear all the color classes
940
			$(this).parent('td').prop('class', '');
941
			$(this).parent('td').prev('td').prop('class', '');
942
			// Install our new color class
943
			$(this).parent('td').addClass(color);
944
			$(this).parent('td').prev('td').addClass(color);
945
			// Set the global color
946
			gColor = color;
947
		});
948
	}
949

    
950
	// provide a warning message if the user tries to change page before saving
951
	$(window).bind('beforeunload', function(){
952
		if ((!saving && dirty) || newSeperator) {
953
			return ("<?=gettext('You have moved one or more rules but have not yet saved')?>");
954
		} else {
955
			return undefined;
956
		}
957
	});
958

    
959
	//JS equivalent to PHP htmlspecialchars()
960
	function escapeHtml(text) {
961
		var map = {
962
			'&': '&amp;',
963
			'<': '&lt;',
964
			'>': '&gt;',
965
			'"': '&quot;',
966
			"'": '&#039;'
967
		};
968

    
969
		return text.replace(/[&<>"']/g, function(m) { return map[m]; });
970
	}
971
	// --------------------------------------------------------------------------------------------
972
});
973
//]]>
974
</script>
975

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