Project

General

Profile

Download (32.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * firewall_rules.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2018 Rubicon Communications, LLC (Netgate)
7
 * All rights reserved.
8
 *
9
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12
 *
13
 * Licensed under the Apache License, Version 2.0 (the "License");
14
 * you may not use this file except in compliance with the License.
15
 * You may obtain a copy of the License at
16
 *
17
 * http://www.apache.org/licenses/LICENSE-2.0
18
 *
19
 * Unless required by applicable law or agreed to in writing, software
20
 * distributed under the License is distributed on an "AS IS" BASIS,
21
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
 * See the License for the specific language governing permissions and
23
 * limitations under the License.
24
 */
25

    
26
##|+PRIV
27
##|*IDENT=page-firewall-rules
28
##|*NAME=Firewall: Rules
29
##|*DESCR=Allow access to the 'Firewall: Rules' page.
30
##|*MATCH=firewall_rules.php*
31
##|-PRIV
32

    
33
require_once("guiconfig.inc");
34
require_once("functions.inc");
35
require_once("filter.inc");
36
require_once("ipsec.inc");
37
require_once("shaper.inc");
38

    
39
$XmoveTitle = gettext("Move checked rules above this one. Shift+Click to move checked rules below.");
40
$ShXmoveTitle = gettext("Move checked rules below this one. Release shift to move checked rules above.");
41

    
42
$shortcut_section = "firewall";
43

    
44
function get_pf_rules($rules, $tracker) {
45

    
46
	if ($rules == NULL || !is_array($rules))
47
		return (NULL);
48

    
49
	$arr = array();
50
	foreach ($rules as $rule) {
51
		if ($rule['tracker'] === $tracker) {
52
			$arr[] = $rule;
53
		}
54
	}
55

    
56
	if (count($arr) == 0)
57
		return (NULL);
58

    
59
	return ($arr);
60
}
61

    
62
function print_states($tracker) {
63
	global $rulescnt;
64

    
65
	$rulesid = "";
66
	$bytes = 0;
67
	$states = 0;
68
	$packets = 0;
69
	$evaluations = 0;
70
	$stcreations = 0;
71
	$rules = get_pf_rules($rulescnt, $tracker);
72
	if (is_array($rules)) {
73
		foreach ($rules as $rule) {
74
			$bytes += $rule['bytes'];
75
			$states += $rule['states'];
76
			$packets += $rule['packets'];
77
			$evaluations += $rule['evaluations'];
78
			$stcreations += $rule['state creations'];
79
			if (strlen($rulesid) > 0) {
80
				$rulesid .= ",";
81
			}
82
			$rulesid .= "{$rule['id']}";
83
		}
84
	}
85

    
86
	$trackertext = !empty($tracker) ? "Tracking ID: {$tracker}<br>" : "";
87
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" data-toggle=\"popover\" data-trigger=\"hover focus\" title=\"%s\" ",
88
	    $rulesid, gettext("States details"));
89
	printf("data-content=\"{$trackertext}evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\" usepost>",
90
	    format_number($evaluations), format_number($packets), format_bytes($bytes),
91
	    format_number($states), format_number($stcreations));
92
	printf("%s/%s</a><br>", format_number($states), format_bytes($bytes));
93
}
94

    
95
function delete_nat_association($id) {
96
	global $config;
97

    
98
	if (!$id || !is_array($config['nat']['rule'])) {
99
		return;
100
	}
101

    
102
	$a_nat = &$config['nat']['rule'];
103

    
104
	foreach ($a_nat as &$natent) {
105
		if ($natent['associated-rule-id'] == $id) {
106
			$natent['associated-rule-id'] = '';
107
		}
108
	}
109
}
110

    
111
if (!is_array($config['filter']['rule'])) {
112
	$config['filter']['rule'] = array();
113
}
114

    
115
filter_rules_sort();
116
$a_filter = &$config['filter']['rule'];
117

    
118
if ($_REQUEST['if']) {
119
	$if = $_REQUEST['if'];
120
}
121

    
122
$ifdescs = get_configured_interface_with_descr();
123

    
124
$iflist = create_interface_list();
125

    
126
if (!$if || !isset($iflist[$if])) {
127
	if ($if != "any" && $if != "FloatingRules" && isset($iflist['wan'])) {
128
		$if = "wan";
129
	} else {
130
		$if = "FloatingRules";
131
	}
132
}
133

    
134
if ($_POST['apply']) {
135
	$retval = 0;
136
	$retval |= filter_configure();
137

    
138
	clear_subsystem_dirty('filter');
139
}
140

    
141
if ($_POST['act'] == "del") {
142
	if ($a_filter[$_POST['id']]) {
143
		if (!empty($a_filter[$_POST['id']]['associated-rule-id'])) {
144
			delete_nat_association($a_filter[$_POST['id']]['associated-rule-id']);
145
		}
146
		unset($a_filter[$_POST['id']]);
147

    
148
		// Update the separators
149
		$a_separators = &$config['filter']['separator'][strtolower($if)];
150
		$ridx = ifridx($if, $_POST['id']);	// get rule index within interface
151
		$mvnrows = -1;
152
		move_separators($a_separators, $ridx, $mvnrows);
153

    
154
		if (write_config(gettext("Firewall: Rules - deleted a firewall rule."))) {
155
			mark_subsystem_dirty('filter');
156
		}
157

    
158
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
159
		exit;
160
	}
161
}
162

    
163
// Handle save msg if defined
164
if ($_REQUEST['savemsg']) {
165
	$savemsg = htmlentities($_REQUEST['savemsg']);
166
}
167

    
168
if (isset($_POST['del_x'])) {
169
	/* delete selected rules */
170
	$deleted = false;
171

    
172
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
173
		$a_separators = &$config['filter']['separator'][strtolower($if)];
174
		$num_deleted = 0;
175

    
176
		foreach ($_POST['rule'] as $rulei) {
177
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
178
			unset($a_filter[$rulei]);
179
			$deleted = true;
180

    
181
			// Update the separators
182
			// As rules are deleted, $ridx has to be decremented or separator position will break
183
			$ridx = ifridx($if, $rulei) - $num_deleted;	// get rule index within interface
184
			$mvnrows = -1;
185
			move_separators($a_separators, $ridx, $mvnrows);
186
			$num_deleted++;
187
		}
188

    
189
		if ($deleted) {
190
			if (write_config(gettext("Firewall: Rules - deleted selected firewall rules."))) {
191
				mark_subsystem_dirty('filter');
192
			}
193
		}
194

    
195
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
196
		exit;
197
	}
198
} else if ($_POST['act'] == "toggle") {
199
	if ($a_filter[$_POST['id']]) {
200
		if (isset($a_filter[$_POST['id']]['disabled'])) {
201
			unset($a_filter[$_POST['id']]['disabled']);
202
			$wc_msg = gettext('Firewall: Rules - enabled a firewall rule.');
203
		} else {
204
			$a_filter[$_POST['id']]['disabled'] = true;
205
			$wc_msg = gettext('Firewall: Rules - disabled a firewall rule.');
206
		}
207
		if (write_config($wc_msg)) {
208
			mark_subsystem_dirty('filter');
209
		}
210

    
211
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
212
		exit;
213
	}
214
} else if ($_POST['order-store']) {
215

    
216
	/* update rule order, POST[rule] is an array of ordered IDs */
217
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
218
		$a_filter_new = array();
219

    
220
		// Include the rules of other interfaces listed in config before this (the selected) interface.
221
		foreach ($a_filter as $filteri_before => $filterent) {
222
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
223
				break;
224
			} else {
225
				$a_filter_new[] = $filterent;
226
			}
227
		}
228

    
229
		// Include the rules of this (the selected) interface.
230
		// If a rule is not in POST[rule], it has been deleted by the user
231
		foreach ($_POST['rule'] as $id) {
232
			$a_filter_new[] = $a_filter[$id];
233
		}
234

    
235
		// Include the rules of other interfaces listed in config after this (the selected) interface.
236
		foreach ($a_filter as $filteri_after => $filterent) {
237
			if ($filteri_before > $filteri_after) {
238
				continue;
239
			}
240
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
241
				continue;
242
			} else {
243
				$a_filter_new[] = $filterent;
244
			}
245
		}
246

    
247
		$a_filter = $a_filter_new;
248

    
249
		$config['filter']['separator'][strtolower($if)] = "";
250

    
251
		if ($_POST['separator']) {
252
			$idx = 0;
253
			foreach ($_POST['separator'] as $separator) {
254
				$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
255
			}
256
		}
257

    
258
		if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
259
			mark_subsystem_dirty('filter');
260
		}
261

    
262
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
263
		exit;
264
	}
265
}
266

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

    
269
foreach ($iflist as $ifent => $ifname) {
270
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
271
}
272

    
273
foreach ($tab_array as $dtab) {
274
	if ($dtab[1]) {
275
		$bctab = $dtab[0];
276
		break;
277
	}
278
}
279

    
280
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
281
$pglinks = array("", "firewall_rules.php", "@self");
282
$shortcut_section = "firewall";
283

    
284
include("head.inc");
285
$nrules = 0;
286

    
287
if ($savemsg) {
288
	print_info_box($savemsg, 'success');
289
}
290

    
291
if ($_POST['apply']) {
292
	print_apply_result_box($retval);
293
}
294

    
295
if (is_subsystem_dirty('filter')) {
296
	print_apply_box(gettext("The firewall rule configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
297
}
298

    
299
display_top_tabs($tab_array, false, 'pills');
300

    
301
$showantilockout = false;
302
$showprivate = false;
303
$showblockbogons = false;
304

    
305
if (!isset($config['system']['webgui']['noantilockout']) &&
306
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
307
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
308
	$showantilockout = true;
309
}
310

    
311
if (isset($config['interfaces'][$if]['blockpriv'])) {
312
	$showprivate = true;
313
}
314

    
315
if (isset($config['interfaces'][$if]['blockbogons'])) {
316
	$showblockbogons = true;
317
}
318

    
319
/* Load the counter data of each pf rule. */
320
$rulescnt = pfSense_get_pf_rules();
321

    
322
// Update this if you add or remove columns!
323
$columns_in_table = 13;
324

    
325
?>
326
<!-- Allow table to scroll when dragging outside of the display window -->
327
<style>
328
.table-responsive {
329
    clear: both;
330
    overflow-x: visible;
331
    margin-bottom: 0px;
332
}
333
</style>
334

    
335
<form method="post">
336
	<input name="if" id="if" type="hidden" value="<?=$if?>" />
337
	<div class="panel panel-default">
338
		<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to Change Order)")?></h2></div>
339
		<div id="mainarea" class="table-responsive panel-body">
340
			<table id="ruletable" class="table table-hover table-striped table-condensed" style="overflow-x: 'visible'">
341
				<thead>
342
					<tr>
343
						<th><!-- checkbox --></th>
344
						<th><!-- status icons --></th>
345
						<th><?=gettext("States")?></th>
346
						<th><?=gettext("Protocol")?></th>
347
						<th><?=gettext("Source")?></th>
348
						<th><?=gettext("Port")?></th>
349
						<th><?=gettext("Destination")?></th>
350
						<th><?=gettext("Port")?></th>
351
						<th><?=gettext("Gateway")?></th>
352
						<th><?=gettext("Queue")?></th>
353
						<th><?=gettext("Schedule")?></th>
354
						<th><?=gettext("Description")?></th>
355
						<th><?=gettext("Actions")?></th>
356
					</tr>
357
				</thead>
358

    
359
<?php if ($showblockbogons || $showantilockout || $showprivate) :
360
?>
361
				<tbody>
362
<?php
363
		// 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.
364
		if ($showantilockout):
365
			$alports = implode('<br />', filter_get_antilockout_ports(true));
366
?>
367
					<tr id="antilockout">
368
						<td></td>
369
						<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
370
						<td><?php print_states(intval(ANTILOCKOUT_TRACKER)); ?></td>
371
						<td>*</td>
372
						<td>*</td>
373
						<td>*</td>
374
						<td><?=$iflist[$if];?> Address</td>
375
						<td><?=$alports?></td>
376
						<td>*</td>
377
						<td>*</td>
378
						<td></td>
379
						<td><?=gettext("Anti-Lockout Rule");?></td>
380
						<td>
381
							<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
382
						</td>
383
					</tr>
384
<?php 	endif;?>
385
<?php 	if ($showprivate): ?>
386
					<tr id="private">
387
						<td></td>
388
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
389
						<td><?php print_states(intval(RFC1918_TRACKER)); ?></td>
390
						<td>*</td>
391
						<td><?=gettext("RFC 1918 networks");?></td>
392
						<td>*</td>
393
						<td>*</td>
394
						<td>*</td>
395
						<td>*</td>
396
						<td>*</td>
397
						<td></td>
398
						<td><?=gettext("Block private networks");?></td>
399
						<td>
400
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa fa-cog"></i></a>
401
						</td>
402
					</tr>
403
<?php 	endif;?>
404
<?php 	if ($showblockbogons): ?>
405
					<tr id="bogons">
406
						<td></td>
407
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
408
						<td><?php print_states(intval(BOGONS_TRACKER)); ?></td>
409
						<td>*</td>
410
						<td><?=sprintf(gettext("Reserved%sNot assigned by IANA"), "<br />");?></td>
411
						<td>*</td>
412
						<td>*</td>
413
						<td>*</td>
414
						<td>*</td>
415
						<td>*</td>
416
						<td></td>
417
						<td><?=gettext("Block bogon networks");?></td>
418
						<td>
419
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa fa-cog"></i></a>
420
						</td>
421
					</tr>
422
<?php 	endif;?>
423
			</tbody>
424
<?php endif;?>
425
			<tbody class="user-entries">
426
<?php
427
$nrules = 0;
428
$separators = $config['filter']['separator'][strtolower($if)];
429

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

    
434
foreach ($a_filter as $filteri => $filterent):
435

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

    
438
		// Display separator(s) for section beginning at rule n
439
		if ($seprows[$nrules]) {
440
			display_separator($separators, $nrules, $columns_in_table);
441
		}
442
?>
443
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
444
						<td>
445
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
446
						</td>
447

    
448
	<?php
449
		if ($filterent['type'] == "block") {
450
			$iconfn = "times text-danger";
451
			$title_text = gettext("traffic is blocked");
452
		} else if ($filterent['type'] == "reject") {
453
			$iconfn = "hand-stop-o text-warning";
454
			$title_text = gettext("traffic is rejected");
455
		} else if ($filterent['type'] == "match") {
456
			$iconfn = "filter";
457
			$title_text = gettext("traffic is matched");
458
		} else {
459
			$iconfn = "check text-success";
460
			$title_text = gettext("traffic is passed");
461
		}
462
	?>
463
						<td title="<?=$title_text?>">
464
							<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$filteri;?>" usepost>
465
								<i class="fa fa-<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
466
							</a>
467
	<?php
468
		if ($filterent['quick'] == 'yes') {
469
			print '<i class="fa fa-forward text-success" title="'. gettext("&quot;Quick&quot; rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
470
		}
471

    
472
		$isadvset = firewall_check_for_advanced_options($filterent);
473
		if ($isadvset) {
474
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
475
		}
476

    
477
		if (isset($filterent['log'])) {
478
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
479
		}
480
	?>
481
						</td>
482
	<?php
483
		$alias = rule_columns_with_alias(
484
			$filterent['source']['address'],
485
			pprint_port($filterent['source']['port']),
486
			$filterent['destination']['address'],
487
			pprint_port($filterent['destination']['port'])
488
		);
489

    
490
		//build Schedule popup box
491
		$a_schedules = &$config['schedules']['schedule'];
492
		$schedule_span_begin = "";
493
		$schedule_span_end = "";
494
		$sched_caption_escaped = "";
495
		$sched_content = "";
496
		$schedstatus = false;
497
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
498
		$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'));
499
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
500
			$idx = 0;
501
			foreach ($a_schedules as $schedule) {
502
				if ($schedule['name'] == $filterent['sched']) {
503
					$schedstatus = filter_get_time_based_rule_status($schedule);
504

    
505
					foreach ($schedule['timerange'] as $timerange) {
506
						$tempFriendlyTime = "";
507
						$tempID = "";
508
						$firstprint = false;
509
						if ($timerange) {
510
							$dayFriendly = "";
511
							$tempFriendlyTime = "";
512

    
513
							//get hours
514
							$temptimerange = $timerange['hour'];
515
							$temptimeseparator = strrpos($temptimerange, "-");
516

    
517
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
518
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
519

    
520
							if ($timerange['month']) {
521
								$tempmontharray = explode(",", $timerange['month']);
522
								$tempdayarray = explode(",", $timerange['day']);
523
								$arraycounter = 0;
524
								$firstDayFound = false;
525
								$firstPrint = false;
526
								foreach ($tempmontharray as $monthtmp) {
527
									$month = $tempmontharray[$arraycounter];
528
									$day = $tempdayarray[$arraycounter];
529

    
530
									if (!$firstDayFound) {
531
										$firstDay = $day;
532
										$firstmonth = $month;
533
										$firstDayFound = true;
534
									}
535

    
536
									$currentDay = $day;
537
									$nextDay = $tempdayarray[$arraycounter+1];
538
									$currentDay++;
539
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
540
										if ($firstPrint) {
541
											$dayFriendly .= ", ";
542
										}
543
										$currentDay--;
544
										if ($currentDay != $firstDay) {
545
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
546
										} else {
547
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
548
										}
549
										$firstDayFound = false;
550
										$firstPrint = true;
551
									}
552
									$arraycounter++;
553
								}
554
							} else {
555
								$tempdayFriendly = $timerange['position'];
556
								$firstDayFound = false;
557
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
558
								$currentDay = "";
559
								$firstDay = "";
560
								$nextDay = "";
561
								$counter = 0;
562
								foreach ($tempFriendlyDayArray as $day) {
563
									if ($day != "") {
564
										if (!$firstDayFound) {
565
											$firstDay = $tempFriendlyDayArray[$counter];
566
											$firstDayFound = true;
567
										}
568
										$currentDay =$tempFriendlyDayArray[$counter];
569
										//get next day
570
										$nextDay = $tempFriendlyDayArray[$counter+1];
571
										$currentDay++;
572
										if ($currentDay != $nextDay) {
573
											if ($firstprint) {
574
												$dayFriendly .= ", ";
575
											}
576
											$currentDay--;
577
											if ($currentDay != $firstDay) {
578
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
579
											} else {
580
												$dayFriendly .= $dayArray[$firstDay-1];
581
											}
582
											$firstDayFound = false;
583
											$firstprint = true;
584
										}
585
										$counter++;
586
									}
587
								}
588
							}
589
							$timeFriendly = $starttime . " - " . $stoptime;
590
							$description = $timerange['rangedescr'];
591
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
592
						}
593
					}
594
					#FIXME
595
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
596
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
597
						$sched_caption_escaped . '" data-html="true">';
598
					$schedule_span_end = "</a>";
599
				}
600
				$idx++;
601
			}
602
		}
603
		$printicon = false;
604
		$alttext = "";
605
		$image = "";
606
		if (!isset($filterent['disabled'])) {
607
			if ($schedstatus) {
608
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
609
					$image = "times-circle";
610
					$dispcolor = "text-danger";
611
					$alttext = gettext("Traffic matching this rule is currently being denied");
612
				} else {
613
					$image = "play-circle";
614
					$dispcolor = "text-success";
615
					$alttext = gettext("Traffic matching this rule is currently being allowed");
616
				}
617
				$printicon = true;
618
			} else if ($filterent['sched']) {
619
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
620
					$image = "times-circle";
621
				} else {
622
					$image = "play-circle";
623
				}
624
				$alttext = gettext("This rule is not currently active because its period has expired");
625
				$dispcolor = "text-warning";
626
				$printicon = true;
627
			}
628
		}
629
	?>
630
				<td><?php print_states(intval($filterent['tracker'])); ?></td>
631
				<td>
632
	<?php
633
		if (isset($filterent['ipprotocol'])) {
634
			switch ($filterent['ipprotocol']) {
635
				case "inet":
636
					echo "IPv4 ";
637
					break;
638
				case "inet6":
639
					echo "IPv6 ";
640
					break;
641
				case "inet46":
642
					echo "IPv4+6 ";
643
					break;
644
			}
645
		} else {
646
			echo "IPv4 ";
647
		}
648

    
649
		if (isset($filterent['protocol'])) {
650
			echo strtoupper($filterent['protocol']);
651

    
652
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
653
				// replace each comma-separated icmptype item by its (localised) full description
654
				$t = 	implode(', ',
655
						array_map(
656
						        function($type) {
657
								global $icmptypes;
658
								return $icmptypes[$type]['descrip'];
659
							},
660
							explode(',', $filterent['icmptype'])
661
						)
662
					);
663
				echo sprintf('<br /><div style="cursor:help;padding:1px;line-height:1.1em;max-height:2.5em;max-width:180px;overflow-y:auto;overflow-x:hidden" title="%s:%s%s"><small><u>%s</u></small></div>', gettext('ICMP subtypes'), chr(13), $t, str_replace(',', '</u>, <u>',$filterent['icmptype']));
664
			}
665
		} else {
666
			echo " *";
667
		}
668
	?>
669
						</td>
670
						<td>
671
							<?php if (isset($alias['src'])): ?>
672
								<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">
673
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['source'])))?>
674
								</a>
675
							<?php else: ?>
676
								<?=htmlspecialchars(pprint_address($filterent['source']))?>
677
							<?php endif; ?>
678
						</td>
679
						<td>
680
							<?php if (isset($alias['srcport'])): ?>
681
								<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">
682
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['source']['port'])))?>
683
								</a>
684
							<?php else: ?>
685
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
686
							<?php endif; ?>
687
						</td>
688
						<td>
689
							<?php if (isset($alias['dst'])): ?>
690
								<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">
691
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['destination'])))?>
692
								</a>
693
							<?php else: ?>
694
								<?=htmlspecialchars(pprint_address($filterent['destination']))?>
695
							<?php endif; ?>
696
						</td>
697
						<td>
698
							<?php if (isset($alias['dstport'])): ?>
699
								<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">
700
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['destination']['port'])))?>
701
								</a>
702
							<?php else: ?>
703
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
704
							<?php endif; ?>
705
						</td>
706
						<td>
707
							<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
708
								<?=str_replace('_', '_<wbr>', htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']))?>
709
							<?php else: ?>
710
								<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
711
							<?php endif; ?>
712
						</td>
713
						<td>
714
							<?php
715
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
716
									$desc = str_replace('_', ' ', $filterent['ackqueue']);
717
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
718
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
719
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
720
								} else if (isset($filterent['defaultqueue'])) {
721
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
722
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
723
								} else {
724
									echo gettext("none");
725
								}
726
							?>
727
						</td>
728
						<td>
729
							<?php if ($printicon) { ?>
730
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
731
							<?php } ?>
732
							<?=$schedule_span_begin;?><?=str_replace('_', '_<wbr>', htmlspecialchars($filterent['sched']));?>&nbsp;<?=$schedule_span_end;?>
733
						</td>
734
						<td>
735
							<?=htmlspecialchars($filterent['descr']);?>
736
						</td>
737
						<td class="action-icons">
738
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
739
							<a	class="fa fa-anchor icon-pointer" id="Xmove_<?=$filteri?>" title="<?=$XmoveTitle?>"></a>
740
							<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
741
							<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
742
<?php if (isset($filterent['disabled'])) {
743
?>
744
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>" usepost></a>
745
<?php } else {
746
?>
747
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-ban" title="<?=gettext('Disable')?>" usepost></a>
748
<?php }
749
?>
750
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>" usepost></a>
751
						</td>
752
					</tr>
753
<?php
754
		$nrules++;
755
	}
756
endforeach;
757

    
758
// There can be separator(s) after the last rule listed.
759
if ($seprows[$nrules]) {
760
	display_separator($separators, $nrules, $columns_in_table);
761
}
762
?>
763
				</tbody>
764
			</table>
765
		</div>
766
	</div>
767

    
768
<?php if ($nrules == 0): ?>
769
	<div class="alert alert-warning" role="alert">
770
		<p>
771
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
772
			<?=gettext("No floating rules are currently defined.");?>
773
		<?php else: ?>
774
			<?=gettext("No rules are currently defined for this interface");?><br />
775
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
776
		<?php endif;?>
777
			<?=gettext("Click the button to add a new rule.");?>
778
		</p>
779
	</div>
780
<?php endif;?>
781

    
782
	<nav class="action-buttons">
783
		<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')?>">
784
			<i class="fa fa-level-up icon-embed-btn"></i>
785
			<?=gettext("Add");?>
786
		</a>
787
		<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')?>">
788
			<i class="fa fa-level-down icon-embed-btn"></i>
789
			<?=gettext("Add");?>
790
		</a>
791
		<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
792
			<i class="fa fa-trash icon-embed-btn"></i>
793
			<?=gettext("Delete"); ?>
794
		</button>
795
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
796
			<i class="fa fa-save icon-embed-btn"></i>
797
			<?=gettext("Save")?>
798
		</button>
799
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
800
			<i class="fa fa-plus icon-embed-btn"></i>
801
			<?=gettext("Separator")?>
802
		</button>
803
	</nav>
804
</form>
805

    
806
<div class="infoblock">
807
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
808
		<dl class="dl-horizontal responsive">
809
		<!-- Legend -->
810
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
811
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
812
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
813
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
814
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
815
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
816
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
817
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
818
		</dl>
819

    
820
<?php
821
	if ("FloatingRules" != $if) {
822
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
823
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
824
			gettext("This means that if block rules are used, it is important to pay attention " .
825
			"to the rule order. Everything that isn't explicitly passed is blocked " .
826
			"by default. "));
827
	} else {
828
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
829
			"the action of the first rule to match a packet will be executed) only " .
830
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
831
			"other rules match. Pay close attention to the rule order and options " .
832
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
833
	}
834

    
835
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
836
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>')
837
?>
838
	</div>
839
	</div>
840
</div>
841

    
842
<script type="text/javascript">
843
//<![CDATA[
844

    
845
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
846
iface = "<?=strtolower($if)?>";
847
cncltxt = '<?=gettext("Cancel")?>';
848
svtxt = '<?=gettext("Save")?>';
849
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
850
configsection = "filter";
851

    
852
events.push(function() {
853

    
854
	// "Move to here" (anchor) action
855
	$('[id^=Xmove_]').click(function (event) {
856

    
857
		// Prevent click from toggling row
858
		event.stopImmediatePropagation();
859

    
860
		// Save the target rule position
861
		var anchor_row = $(this).parents("tr:first");
862

    
863
		if (event.shiftKey) {
864
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
865
				ruleid = this.id.slice(2);
866

    
867
				if (ruleid && !isNaN(ruleid)) {
868
					if ($('#frc' + ruleid).prop('checked')) {
869
						// Move the selected rows, un-select them and add highlight class
870
						$(this).insertAfter(anchor_row);
871
						fr_toggle(ruleid, "fr");
872
						$('#fr' + ruleid).addClass("highlight");
873
					}
874
				}
875
			});
876
		} else {
877
			$('#ruletable > tbody  > tr').each(function() {
878
				ruleid = this.id.slice(2);
879

    
880
				if (ruleid && !isNaN(ruleid)) {
881
					if ($('#frc' + ruleid).prop('checked')) {
882
						// Move the selected rows, un-select them and add highlight class
883
						$(this).insertBefore(anchor_row);
884
						fr_toggle(ruleid, "fr");
885
						$('#fr' + ruleid).addClass("highlight");
886
					}
887
				}
888
			});
889
		}
890

    
891
		// Temporarily set background color so user can more easily see the moved rules, then fade
892
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
893
		$('#ruletable tr').removeClass("highlight");
894
		$('#order-store').removeAttr('disabled');
895
		reindex_rules($(anchor_row).parent('tbody'));
896
		dirty = true;
897
	}).mouseover(function(e) {
898
		var ruleselected = false;
899

    
900
		$(this).css("cursor", "default");
901

    
902
		// Are any rules currently selected?
903
		$('[id^=frc]').each(function () {
904
			if ($(this).prop("checked")) {
905
				ruleselected = true;
906
			}
907
		});
908

    
909
		// If so, change the icon to show the insertion point
910
		if (ruleselected) {
911
			if (e.shiftKey) {
912
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
913
			} else {
914
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
915
			}
916
		}
917
	}).mouseout(function(e) {
918
		$(this).removeClass().addClass("fa fa-anchor");
919
	});
920

    
921
<?php if(!isset($config['system']['webgui']['roworderdragging'])): ?>
922
	// Make rules sortable. Hiding the table before applying sortable, then showing it again is
923
	// a work-around for very slow sorting on FireFox
924
	$('table tbody.user-entries').hide();
925

    
926
	$('table tbody.user-entries').sortable({
927
		cursor: 'grabbing',
928
		scroll: true,
929
		overflow: 'scroll',
930
		scrollSensitivity: 100,
931
		update: function(event, ui) {
932
			$('#order-store').removeAttr('disabled');
933
			reindex_rules(ui.item.parent('tbody'));
934
			dirty = true;
935
		}
936
	});
937

    
938
	$('table tbody.user-entries').show();
939
<?php endif; ?>
940

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

    
945
		// Save the separator bar configuration
946
		save_separators();
947

    
948
		// Suppress the "Do you really want to leave the page" message
949
		saving = true;
950
	});
951

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

    
961
	$(document).on('keyup keydown', function(e){
962
		if (e.shiftKey) {
963
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
964
		} else {
965
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
966
		}
967
	});
968
});
969
//]]>
970
</script>
971

    
972
<?php include("foot.inc");?>
(50-50/232)