Project

General

Profile

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

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

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

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

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

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

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

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

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

    
471
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
472
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
473

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

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

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

    
599
		if (isset($filterent['protocol'])) {
600
			echo strtoupper($filterent['protocol']);
601

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

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

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

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

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