Project

General

Profile

Download (24.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_rules.php
5
	part of pfSense (https://www.pfsense.org)
6
	Copyright (C) 2005 Scott Ullrich (sullrich@gmail.com)
7
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
8

    
9
	originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18

    
19
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22

    
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34
/*
35
	pfSense_MODULE:	filter
36
*/
37

    
38
##|+PRIV
39
##|*IDENT=page-firewall-rules
40
##|*NAME=Firewall: Rules page
41
##|*DESCR=Allow access to the 'Firewall: Rules' page.
42
##|*MATCH=firewall_rules.php*
43
##|-PRIV
44

    
45
require("guiconfig.inc");
46
require_once("functions.inc");
47
require_once("filter.inc");
48
require_once("shaper.inc");
49

    
50
$pgtitle = array(gettext("Firewall"),gettext("Rules"));
51
$shortcut_section = "firewall";
52

    
53
function delete_nat_association($id) {
54
	global $config;
55

    
56
	if (!$id || !is_array($config['nat']['rule']))
57
		return;
58

    
59
	$a_nat = &$config['nat']['rule'];
60

    
61
	foreach ($a_nat as &$natent)
62
		if ($natent['associated-rule-id'] == $id)
63
			$natent['associated-rule-id'] = '';
64
}
65

    
66
if (!is_array($config['filter']['rule'])) {
67
	$config['filter']['rule'] = array();
68
}
69
filter_rules_sort();
70
$a_filter = &$config['filter']['rule'];
71

    
72
$if = $_GET['if'];
73
if ($_POST['if'])
74
	$if = $_POST['if'];
75

    
76
$ifdescs = get_configured_interface_with_descr();
77

    
78
// Drag and drop reordering
79
if($_REQUEST['dragdroporder']) {
80
	// First create a new ruleset array and tmp arrays
81
	$a_filter_before = array();
82
	$a_filter_order = array();
83
	$a_filter_order_tmp = array();
84
	$a_filter_after = array();
85
	$found = false;
86
	$drag_order = $_REQUEST['dragtable'];
87
	// Next traverse through rules building a new order for interface
88
	for ($i = 0; isset($a_filter[$i]); $i++) {
89
		if(( $_REQUEST['if'] == "FloatingRules" && isset($a_filter[$i]['floating']) ) || ( $a_filter[$i]['interface'] == $_REQUEST['if'] && !isset($a_filter[$i]['floating']) )) {
90
			$a_filter_order_tmp[] = $a_filter[$i];
91
			$found = true;
92
		} else if (!$found)
93
			$a_filter_before[] = $a_filter[$i];
94
		else
95
			$a_filter_after[] = $a_filter[$i];
96
	}
97
	// Reorder rules with the posted order
98
	for ($i = 0; $i<count($drag_order); $i++)
99
		$a_filter_order[] = $a_filter_order_tmp[$drag_order[$i]];
100
	// In case $drag_order didn't account for some rules, make sure we don't lose them
101
	if(count($a_filter_order) < count($a_filter_order_tmp)) {
102
		for ($i = 0; $i<count($a_filter_order_tmp); $i++)
103
			if(!in_array($i, $drag_order))
104
				$a_filter_order[] = $a_filter_order_tmp[$i];
105
	}
106
	// Overwrite filter rules with newly created items
107
	$config['filter']['rule'] = array_merge($a_filter_before, $a_filter_order, $a_filter_after);
108
	// Write configuration
109
	$config = write_config(gettext("Drag and drop firewall rules ordering update."));
110
	// Redirect back to page
111
	mark_subsystem_dirty('filter');
112
	$undo = array();
113
	foreach($_REQUEST['dragtable'] as $dt)
114
		$undo[] = "";
115
	$counter = 0;
116
	foreach($_REQUEST['dragtable'] as $dt) {
117
		$undo[$dt] = $counter;
118
		$counter++;
119
	}
120
	foreach($undo as $dt)
121
		$undotxt .= "&dragtable[]={$dt}";
122
	header("Location: firewall_rules.php?if=" . $_REQUEST['if'] . "&undodrag=true" . $undotxt);
123
	exit;
124
}
125

    
126
/* add group interfaces */
127
if (is_array($config['ifgroups']['ifgroupentry']))
128
	foreach($config['ifgroups']['ifgroupentry'] as $ifgen)
129
		if (have_ruleint_access($ifgen['ifname']))
130
			$iflist[$ifgen['ifname']] = $ifgen['ifname'];
131

    
132
foreach ($ifdescs as $ifent => $ifdesc)
133
	if(have_ruleint_access($ifent))
134
		$iflist[$ifent] = $ifdesc;
135

    
136
if ($config['l2tp']['mode'] == "server")
137
	if(have_ruleint_access("l2tp"))
138
		$iflist['l2tp'] = "L2TP VPN";
139

    
140
if ($config['pptpd']['mode'] == "server")
141
	if(have_ruleint_access("pptp"))
142
		$iflist['pptp'] = "PPTP VPN";
143

    
144
if (is_array($config['pppoes']['pppoe'])) {
145
	foreach ($config['pppoes']['pppoe'] as $pppoes)
146
		if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe"))
147
			$iflist['pppoe'] = "PPPoE Server";
148
}
149

    
150
/* add ipsec interfaces */
151
if (isset($config['ipsec']['enable']) || isset($config['ipsec']['client']['enable']))
152
	if(have_ruleint_access("enc0"))
153
		$iflist["enc0"] = "IPsec";
154

    
155
/* add openvpn/tun interfaces */
156
if  ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"])
157
	$iflist["openvpn"] = "OpenVPN";
158

    
159
pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/interfaces_override");
160

    
161
if (!$if || !isset($iflist[$if])) {
162
	if ("any" == $if)
163
		$if = "FloatingRules";
164
	else if ("FloatingRules" != $if) {
165
		if (isset($iflist['wan']))
166
			$if = "wan";
167
		else
168
			$if = "FloatingRules";
169
	}
170
}
171

    
172
if ($_POST) {
173

    
174
	$pconfig = $_POST;
175

    
176
	if ($_POST['apply']) {
177
		$retval = 0;
178
		$retval = filter_configure();
179

    
180
		clear_subsystem_dirty('filter');
181

    
182
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/apply");
183

    
184
		$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"),"<a href='status_filter_reload.php'>","</a>");
185
	}
186
}
187

    
188
if ($_GET['act'] == "del") {
189
	if ($a_filter[$_GET['id']]) {
190
		if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
191
			delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
192
		}
193
		unset($a_filter[$_GET['id']]);
194
		if (write_config())
195
			mark_subsystem_dirty('filter');
196
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
197
		exit;
198
	}
199
}
200

    
201
// Handle save msg if defined
202
if($_REQUEST['savemsg'])
203
	$savemsg = htmlentities($_REQUEST['savemsg']);
204

    
205
if (isset($_POST['del_x'])) {
206
	/* delete selected rules */
207
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
208
		foreach ($_POST['rule'] as $rulei) {
209
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
210
			unset($a_filter[$rulei]);
211
		}
212
		if (write_config())
213
			mark_subsystem_dirty('filter');
214
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
215
		exit;
216
	}
217
} else if ($_GET['act'] == "toggle") {
218
	if ($a_filter[$_GET['id']]) {
219
		if(isset($a_filter[$_GET['id']]['disabled']))
220
			unset($a_filter[$_GET['id']]['disabled']);
221
		else
222
			$a_filter[$_GET['id']]['disabled'] = true;
223
		if (write_config())
224
			mark_subsystem_dirty('filter');
225
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
226
		exit;
227
	}
228
} else {
229
	/* yuck - IE won't send value attributes for image buttons, while Mozilla does -
230
	   so we use .x/.y to fine move button clicks instead... */
231
	unset($movebtn);
232
	foreach ($_POST as $pn => $pd) {
233
		if (preg_match("/move_(\d+)_x/", $pn, $matches)) {
234
			$movebtn = $matches[1];
235
			break;
236
		}
237
	}
238
	/* move selected rules before this rule */
239
	if (isset($movebtn) && is_array($_POST['rule']) && count($_POST['rule'])) {
240
		$a_filter_new = array();
241

    
242
		/* copy all rules < $movebtn and not selected */
243
		for ($i = 0; $i < $movebtn; $i++) {
244
			if (!in_array($i, $_POST['rule']))
245
				$a_filter_new[] = $a_filter[$i];
246
		}
247

    
248
		/* copy all selected rules */
249
		for ($i = 0; $i < count($a_filter); $i++) {
250
			if ($i == $movebtn)
251
				continue;
252
			if (in_array($i, $_POST['rule']))
253
				$a_filter_new[] = $a_filter[$i];
254
		}
255

    
256
		/* copy $movebtn rule */
257
		if ($movebtn < count($a_filter))
258
			$a_filter_new[] = $a_filter[$movebtn];
259

    
260
		/* copy all rules > $movebtn and not selected */
261
		for ($i = $movebtn+1; $i < count($a_filter); $i++) {
262
			if (!in_array($i, $_POST['rule']))
263
				$a_filter_new[] = $a_filter[$i];
264
		}
265

    
266
		$a_filter = $a_filter_new;
267
		if (write_config())
268
			mark_subsystem_dirty('filter');
269
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
270
		exit;
271
	}
272
}
273

    
274
include("head.inc");
275
$nrules = 0;
276

    
277
?>
278
<form action="firewall_rules.php" method="post">
279

    
280
<?php if ($savemsg) print_info_box($savemsg);?>
281
<?php if (is_subsystem_dirty('filter')): ?><p>
282
<?php
283
if($_REQUEST['undodrag']) {
284
	foreach($_REQUEST['dragtable'] as $dt)
285
		$dragtable .= "&dragtable[]={$dt}";
286
	print_info_box_np_undo(gettext("The firewall rule configuration has been changed.<br />You must apply the changes in order for them to take effect."), "apply" , gettext("Apply changes") , "firewall_rules.php?if={$_REQUEST['if']}&dragdroporder=true&{$dragtable}");
287
} else {
288
	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);
289
}
290
?>
291
<br />
292
<?php endif;?>
293
<?php
294
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/before_table");
295
?>
296

    
297
<?php
298
/* active tabs */
299
$tab_array = array(array(gettext("Floating"), ("FloatingRules" == $if), "firewall_rules.php?if=FloatingRules"));
300

    
301
foreach ($iflist as $ifent => $ifname) {
302
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
303
}
304

    
305
display_top_tabs($tab_array);
306
?>
307
<div class="table-responsive">
308
<table class="table table-striped">
309
<?php
310
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/before_first_tr");
311
?>
312
	<thead>
313
	<tr>
314
		<th colspan="2"></th>
315
		<th><?=gettext("ID");?></th>
316
<?php
317
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_id_tablehead");
318
?>
319
		<th><?=gettext("Proto");?></th>
320
		<th><?=gettext("Source");?></th>
321
		<th><?=gettext("Port");?></th>
322
		<th><?=gettext("Destination");?></th>
323
		<th><?=gettext("Port");?></th>
324
		<th><?=gettext("Gateway");?></th>
325
		<th><?=gettext("Queue");?></th>
326
		<th><?=gettext("Schedule");?></th>
327
<?php
328
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_desc_tablehead");
329
?>
330
		<th><?=gettext("Description");?></th>
331
		<th></th>
332
	</tr>
333
	</thead>
334
	<tbody>
335
	<?php   // 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.
336
		if (!isset($config['system']['webgui']['noantilockout']) &&
337
			(((count($config['interfaces']) > 1) && ($if == 'lan'))
338
			|| ((count($config['interfaces']) == 1) && ($if == 'wan')))):
339

    
340
			$alports = implode('<br />', filter_get_antilockout_ports(true));
341
	?>
342
	<tr id="antilockout">
343
		<td></td>
344
		<td title="<?=gettext("traffic is passed")?>"><i class="icon icon-ok"></i></td>
345
		<td></td>
346
		<?php
347
			pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_id_tr_antilockout");
348
		?>
349
		<td>*</td>
350
		<td>*</td>
351
		<td>*</td>
352
		<td><?=$iflist[$if];?> Address</td>
353
		<td><?=$alports?></td>
354
		<td>*</td>
355
		<td>*</td>
356
		<td></td>
357
		<td><?=gettext("Anti-Lockout Rule");?></td>
358
		<td>
359
			<a href="system_advanced_admin.php" class="btn btn-xs btn-primary">edit</a>
360
		</td>
361
	</tr>
362
<?php endif;?>
363

    
364
<?php if (isset($config['interfaces'][$if]['blockpriv'])): ?>
365
	<tr id="frrfc1918">
366
		<td></td>
367
		<td title="<?=gettext("traffic is blocked")?>"><i class="icon icon-remove"></i></td>
368
		<td></td>
369
		<td>*</td>
370
		<td><?=gettext("RFC 1918 networks");?></td>
371
		<td>*</td>
372
		<td>*</td>
373
		<td>*</td>
374
		<td>*</td>
375
		<td>*</td>
376
		<td></td>
377
		<td><?=gettext("Block private networks");?></td>
378
		<td>
379
			<a href="system_advanced_admin.php" class="btn btn-xs btn-primary" title="<?=gettext("edit rule");?>">edit</a>
380
		</td>
381
	</tr>
382
<?php endif;?>
383
<?php if (isset($config['interfaces'][$if]['blockbogons'])): ?>
384
	<tr id="frrfc1918">
385
		<td></td>
386
		<td title="<?=gettext("traffic is blocked")?>"><i class="icon icon-remove"></i></td>
387
		<td></td>
388
		<td>*</td>
389
		<td><?=gettext("Reserved/not assigned by IANA");?></td>
390
		<td>*</td>
391
		<td>*</td>
392
		<td>*</td>
393
		<td>*</td>
394
		<td>*</td>
395
		<td>*</td>
396
		<td><?=gettext("Block bogon networks");?></td>
397
		<td>
398
			<a href="system_advanced_admin.php" class="btn btn-xs btn-primary">edit</a>
399
		</td>
400
	</tr>
401
<?php endif;?>
402

    
403
<?php for ($i = 0; isset($a_filter[$i]); $i++):
404
	pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/row_start");
405
	$filterent = $a_filter[$i];
406
	if ($filterent['interface'] != $if && !isset($filterent['floating']))
407
		continue;
408
	if (isset($filterent['floating']) && "FloatingRules" != $if)
409
		continue;
410

    
411
	$nrules++;
412
?>
413
	<tr id="fr<?=$i?>"<?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
414
	<td>
415
		<input type="checkbox" id="frc<?=$i?>" name="rule[]" value="<?=$i?>" />
416
	</td>
417
	<td title="<?=gettext("traffic is ").$filterent['type']."ed"?>">
418
	<?php
419
		if ($filterent['type'] == "block")
420
			$iconfn = "remove";
421
		else if ($filterent['type'] == "reject")
422
			$iconfn = "fire";
423
		else if ($filterent['type'] == "match")
424
			$iconfn = "filter";
425
		else
426
			$iconfn = "ok";
427
	?>
428
	<i class="icon icon-<?=$iconfn?>"></i>
429
	<?php
430
		$isadvset = firewall_check_for_advanced_options($filterent);
431
		if ($isadvset)
432
			print '<i class="icon icon-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
433

    
434
		if (isset($filterent['log']))
435
			print '<i class="icon icon-tasks" title="'. gettext("traffic is logged") .'"></i>';
436
	?>
437
	</td>
438
	<?php
439
		$alias = rule_columns_with_alias(
440
			$filterent['source']['address'],
441
			pprint_port($filterent['source']['port']),
442
			$filterent['destination']['address'],
443
			pprint_port($filterent['destination']['port'])
444
		);
445

    
446
		//build Schedule popup box
447
		$a_schedules = &$config['schedules']['schedule'];
448
		$schedule_span_begin = "";
449
		$schedule_span_end = "";
450
		$sched_caption_escaped = "";
451
		$sched_content = "";
452
		$schedstatus = false;
453
		$dayArray = array (gettext('Mon'),gettext('Tues'),gettext('Wed'),gettext('Thur'),gettext('Fri'),gettext('Sat'),gettext('Sun'));
454
		$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'));
455
		if($config['schedules']['schedule'] <> "" and is_array($config['schedules']['schedule'])) {
456
			foreach ($a_schedules as $schedule)
457
			{
458
				if ($schedule['name'] == $filterent['sched'] ){
459
					$schedstatus = filter_get_time_based_rule_status($schedule);
460

    
461
					foreach($schedule['timerange'] as $timerange) {
462
						$tempFriendlyTime = "";
463
						$tempID = "";
464
						$firstprint = false;
465
						if ($timerange){
466
							$dayFriendly = "";
467
							$tempFriendlyTime = "";
468

    
469
							//get hours
470
							$temptimerange = $timerange['hour'];
471
							$temptimeseparator = strrpos($temptimerange, "-");
472

    
473
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
474
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
475

    
476
							if ($timerange['month']){
477
								$tempmontharray = explode(",", $timerange['month']);
478
								$tempdayarray = explode(",",$timerange['day']);
479
								$arraycounter = 0;
480
								$firstDayFound = false;
481
								$firstPrint = false;
482
								foreach ($tempmontharray as $monthtmp){
483
									$month = $tempmontharray[$arraycounter];
484
									$day = $tempdayarray[$arraycounter];
485

    
486
									if (!$firstDayFound)
487
									{
488
										$firstDay = $day;
489
										$firstmonth = $month;
490
										$firstDayFound = true;
491
									}
492

    
493
									$currentDay = $day;
494
									$nextDay = $tempdayarray[$arraycounter+1];
495
									$currentDay++;
496
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])){
497
										if ($firstPrint)
498
											$dayFriendly .= ", ";
499
										$currentDay--;
500
										if ($currentDay != $firstDay)
501
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
502
										else
503
											$dayFriendly .=  $monthArray[$month-1] . " " . $day;
504
										$firstDayFound = false;
505
										$firstPrint = true;
506
									}
507
									$arraycounter++;
508
								}
509
							}
510
							else
511
							{
512
								$tempdayFriendly = $timerange['position'];
513
								$firstDayFound = false;
514
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
515
								$currentDay = "";
516
								$firstDay = "";
517
								$nextDay = "";
518
								$counter = 0;
519
								foreach ($tempFriendlyDayArray as $day){
520
									if ($day != ""){
521
										if (!$firstDayFound)
522
										{
523
											$firstDay = $tempFriendlyDayArray[$counter];
524
											$firstDayFound = true;
525
										}
526
										$currentDay =$tempFriendlyDayArray[$counter];
527
										//get next day
528
										$nextDay = $tempFriendlyDayArray[$counter+1];
529
										$currentDay++;
530
										if ($currentDay != $nextDay){
531
											if ($firstprint)
532
												$dayFriendly .= ", ";
533
											$currentDay--;
534
											if ($currentDay != $firstDay)
535
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
536
											else
537
												$dayFriendly .= $dayArray[$firstDay-1];
538
											$firstDayFound = false;
539
											$firstprint = true;
540
										}
541
										$counter++;
542
									}
543
								}
544
							}
545
							$timeFriendly = $starttime . " - " . $stoptime;
546
							$description = $timerange['rangedescr'];
547
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
548
						}
549
					}
550
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
551
					$schedule_span_begin = "<span style=\"cursor: help;\" onmouseover=\"domTT_activate(this, event, 'content', '<h1>{$sched_caption_escaped}</h1><p>{$sched_content}</p>', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'styleClass', 'niceTitle');\" onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\"><u>";
552
					$schedule_span_end = "</u></span>";
553
				}
554
			}
555
		}
556
		$printicon = false;
557
		$alttext = "";
558
		$image = "";
559
		if (!isset($filterent['disabled'])) {
560
			if ($schedstatus) {
561
				if ($iconfn == "block" || $iconfn == "reject") {
562
					$image = "icon_block";
563
					$alttext = gettext("Traffic matching this rule is currently being denied");
564
				} else {
565
					$image = "icon_pass";
566
					$alttext = gettext("Traffic matching this rule is currently being allowed");
567
				}
568
				$printicon = true;
569
			} else if ($filterent['sched']) {
570
				if ($iconfn == "block" || $iconfn == "reject")
571
					$image = "icon_block_d";
572
				else
573
					$image = "icon_block";
574
				$alttext = gettext("This rule is not currently active because its period has expired");
575
				$printicon = true;
576
			}
577
		}
578
	?>
579
	<td><?=$filterent['id']?></td>
580
	<?php
581
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_id_tr");
582
	?>
583
	<td>
584
	<?php
585
		if (isset($filterent['ipprotocol'])) {
586
			switch($filterent['ipprotocol']) {
587
				case "inet":
588
					echo "IPv4 ";
589
					break;
590
				case "inet6":
591
					echo "IPv6 ";
592
					break;
593
				case "inet46":
594
					echo "IPv4+6 ";
595
					break;
596
			}
597
		} else {
598
			echo "IPv4 ";
599
		}
600

    
601
		if (isset($filterent['protocol'])) {
602
			echo strtoupper($filterent['protocol']);
603

    
604
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
605
				echo ' <span style="cursor: help;" title="ICMP type: ' .
606
					( $filterent['ipprotocol'] == "inet6" ?  $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']] ) .
607
					'"><u>';
608
				echo $filterent['icmptype'];
609
				echo '</u></span>';
610
			}
611
		} else echo "*";
612
	?>
613
	</td>
614
	<td>
615
		<?php if (isset($alias['src'])): ?>
616
			<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">
617
		<?php endif; ?>
618
		<?=htmlspecialchars(pprint_address($filterent['source']))?>
619
		<?php if (isset($alias['src'])): ?>
620
			<i class='icon icon-pencil'></i></a>
621
		<?php endif; ?>
622
	</td>
623
	<td>
624
		<?php if (isset($alias['srcport'])): ?>
625
			<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">
626
		<?php endif; ?>
627
		<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
628
		<?php if (isset($alias['srcport'])): ?>
629
			<i class='icon icon-pencil'></i></a>
630
		<?php endif; ?>
631
	</td>
632
	<td>
633
		<?php if (isset($alias['dst'])): ?>
634
			<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['dstport'])?>" data-html="true">
635
		<?php endif; ?>
636
		<?=htmlspecialchars(pprint_address($filterent['destination']['address']))?>
637
		<?php if (isset($alias['dst'])): ?>
638
			<i class='icon icon-pencil'></i></a>
639
		<?php endif; ?>
640
	</td>
641
	<td>
642
		<?php if (isset($alias['dstport'])): ?>
643
			<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">
644
		<?php endif; ?>
645
		<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
646
		<?php if (isset($alias['dstport'])): ?>
647
			<i class='icon icon-pencil'></i></a>
648
		<?php endif; ?>
649
	</td>
650
	<td>
651
		<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
652
			<?=htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr'])?>
653
		<?php else: ?>
654
			<?=htmlspecialchars(pprint_port($filterent['gateway']))?><a>
655
		<?php endif; ?>
656
	</td>
657
	<td>
658
	<?php
659
		if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
660
			$desc = $filterent['ackqueue'] ;
661
			echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
662
			$desc = $filterent['defaultqueue'];
663
			echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
664
		} else if (isset($filterent['defaultqueue'])) {
665
			$desc = $filterent['defaultqueue'];
666
			echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
667
		} else
668
			echo gettext("none");
669
	?>
670
	</td>
671
	<td>
672
		<?php if ($printicon) { ?><img src="./themes/<?= $g['theme'];?>/images/icons/<?=$image;?>.gif" title="<?=$alttext;?>" border="0" alt="icon" /><?php } ?>
673
		<?=$schedule_span_begin;?><?=htmlspecialchars($filterent['sched']);?>&nbsp;<?=$schedule_span_end;?>
674
	</td>
675
	<?php
676
		pfSense_handle_custom_code("/usr/local/pkg/firewall_rules/pre_descr_tr");
677
	?>
678
	<td>
679
		<?=htmlspecialchars($filterent['descr']);?>
680
	</td>
681
	<td>
682
		<a href="firewall_rules_edit.php?id=<?=$i;?>" class="btn btn-xs btn-primary">edit</a>
683
		<a href="firewall_rules_edit.php?dup=<?=$i;?>" class="btn btn-xs btn-default">copy</a>
684
		<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" class="btn btn-xs btn-warning"><?=(isset($filterent['disabled']) ? 'enable' : 'disable')?></a>
685
		<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$i;?>" class="btn btn-xs btn-danger">delete</a>
686
	</td>
687
	</tr>
688
	<?php endfor;?>
689
</tbody>
690
</table>
691
</div>
692

    
693
<?php if ($nrules == 0): ?>
694
	<div class="alert alert-warning" role="alert">
695
		<p>
696
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
697
			<?=gettext("No floating rules are currently defined.");?>
698
		<?php else: ?>
699
			<?=gettext("No rules are currently defined for this interface");?><br />
700
			<?=gettext("All incoming connections on this interface will be blocked until you add pass rules.");?>
701
		<?php endif;?>
702
			<?=gettext("Click the button to add a new rule.");?>
703
		</p>
704
	</div>
705
<?php endif;?>
706

    
707
<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>" role="button" class="btn btn-success">
708
	<?=gettext("add new");?>
709
</a>
710
<?php if ($i > 0): ?>
711
	<a href="#" role="button" class="btn btn-danger">
712
		<?=gettext("delete selected");?>
713
	</a>
714
	<!-- onclick="return confirm('<?=gettext('Do you really want to delete the selected rules?');?>')" />-->
715
<?php endif;?>
716

    
717
<h2>Legend</h2>
718
<ul>
719
	<li><i class="icon icon-ok"></i> <?=gettext("pass");?></li>
720
	<li><i class="icon icon-filter"></i> <?=gettext("match");?></li>
721
	<li><i class="icon icon-remove"></i> <?=gettext("block");?></li>
722
	<li><i class="icon icon-fire"></i> <?=gettext("reject");?></li>
723
	<li><i class="icon icon-tasks"></i> <?=gettext("log");?></li>
724
	<li><i class="icon icon-cog"></i> <?=gettext("advanced filter");?></li>
725
</ul>
726

    
727
<p>
728
<?php if ("FloatingRules" != $if): ?>
729
<?=gettext("Rules are evaluated on a first-match basis (i.e. " .
730
	"the action of the first rule to match a packet will be executed). " .
731
	"This means that if you use block rules, you'll have to pay attention " .
732
	"to the rule order. Everything that isn't explicitly passed is blocked " .
733
	"by default. ");?>
734
<?php else: ?>
735
<?=gettext("Floating rules are evaluated on a first-match basis (i.e. " .
736
	"the action of the first rule to match a packet will be executed) only " .
737
	"if the 'quick' option is checked on a rule. Otherwise they will only apply if no " .
738
	"other rules match. Pay close attention to the rule order and options " .
739
	"chosen. If no rule here matches, the per-interface or default rules are used. ");?>
740
<?php endif;?>
741
</p>
742
	<input type="hidden" name="if" value="<?=htmlspecialchars($if);?>" />
743
</form>
744
<?php include("foot.inc");?>
(71-71/252)