Project

General

Profile

Download (43.5 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-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

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

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

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

    
44
$shortcut_section = "firewall";
45

    
46
$filter_srcdsttype_flags = [
47
	SPECIALNET_ANY, SPECIALNET_COMPAT_ADDRAL, SPECIALNET_NET, SPECIALNET_SELF,
48
	SPECIALNET_CLIENTS, SPECIALNET_IFADDR, SPECIALNET_IFNET, SPECIALNET_GROUP
49
];
50

    
51
function get_pf_rules($rules, $tracker_start, $tracker_end) {
52

    
53
	if ($rules == NULL || !is_array($rules)) {
54
		return (NULL);
55
	}
56

    
57
	$arr = array();
58
	foreach ($rules as $key => $rule) {
59
		/* key 'error' indicates a call to pfctl_get_rule() returned
60
		 * nonzero. We may have a partial list of rules if that is the case */
61
		if ($key != 'error' &&
62
			$rule['tracker'] >= $tracker_start &&
63
		    $rule['tracker'] <= $tracker_end) {
64
			$arr[] = $rule;
65
		}
66
	}
67

    
68
	if (count($arr) == 0)
69
		return (NULL);
70

    
71
	return ($arr);
72
}
73

    
74
function print_states($tracker_start, $tracker_end = -1) {
75
	global $rulescnt;
76

    
77
	if (empty($tracker_start)) {
78
		return;
79
	}
80

    
81
	if ($tracker_end === -1) {
82
		$tracker_end = $tracker_start;
83
	} elseif ($tracker_end < $tracker_start) {
84
		return;
85
	}
86

    
87
	$rulesid = "";
88
	$bytes = 0;
89
	$states = 0;
90
	$packets = 0;
91
	$evaluations = 0;
92
	$stcreations = 0;
93
	$rules = get_pf_rules($rulescnt, $tracker_start, $tracker_end);
94
	if (is_array($rules)) {
95
		foreach ($rules as $rule) {
96
			$bytes += $rule['bytes'];
97
			$states += $rule['states'];
98
			$packets += $rule['packets'];
99
			$evaluations += $rule['evaluations'];
100
			$stcreations += $rule['state creations'];
101
			if (strlen($rulesid) > 0) {
102
				$rulesid .= ",";
103
			}
104
			$rulesid .= "{$rule['id']}";
105
		}
106
	}
107

    
108
	$trackertext = "Tracking ID: {$tracker_start}";
109
	if ($tracker_end != $tracker_start) {
110
		$trackertext .= '-' . $tracker_end;
111
	}
112
	$trackertext .= "<br />";
113

    
114
	printf("<a href=\"diag_dump_states.php?ruleid=%s\" " .
115
	    "data-toggle=\"popover\" data-trigger=\"hover focus\" " .
116
	    "title=\"%s\" ", $rulesid, gettext("States details"));
117
	printf("data-content=\"{$trackertext}evaluations: %s<br />packets: " .
118
	    "%s<br />bytes: %s<br />states: %s<br />state creations: " .
119
	    "%s\" data-html=\"true\" usepost>",
120
	    format_number($evaluations), format_number($packets),
121
	    format_bytes($bytes), format_number($states),
122
	    format_number($stcreations));
123
	printf("%s/%s</a><br />", format_number($states), format_bytes($bytes));
124
}
125

    
126
function delete_nat_association($id) {
127
	global $config;
128

    
129
	if (!$id || !is_array($config['nat']['rule'])) {
130
		return;
131
	}
132

    
133
	$a_nat = &$config['nat']['rule'];
134

    
135
	foreach ($a_nat as &$natent) {
136
		if ($natent['associated-rule-id'] == $id) {
137
			$natent['associated-rule-id'] = '';
138
		}
139
	}
140
}
141

    
142
init_config_arr(array('filter', 'rule'));
143
filter_rules_sort();
144
$a_filter = &$config['filter']['rule'];
145

    
146
if ($_REQUEST['if']) {
147
	$if = $_REQUEST['if'];
148
}
149

    
150
$ifdescs = get_configured_interface_with_descr();
151

    
152
$iflist = filter_get_interface_list();
153

    
154
if (!$if || !isset($iflist[$if])) {
155
	if ($if != 'any' &&
156
	    $if != 'EthernetRules' &&
157
	    $if != 'FloatingRules' &&
158
	    !config_path_enabled('system/webgui', 'requirefirewallinterface')) {
159
		/* default to the first configured interface */
160
		$if = array_key_first($ifdescs);
161
	}
162
}
163

    
164
if ($_POST['apply']) {
165
	$retval = 0;
166
	$retval |= filter_configure();
167

    
168
	clear_subsystem_dirty('filter');
169
}
170

    
171
if ($_POST['act'] == "del") {
172
	if ($a_filter[$_POST['id']]) {
173
		// separators must be updated before the rule is removed
174
		$ridx = get_interface_ruleindex($if, $_POST['id']);
175
		$a_separators = config_get_path('filter/separator/' . strtolower($if), []);
176
		shift_separators($a_separators, $ridx['index'], true);
177
		config_set_path('filter/separator/' . strtolower($if), $a_separators);
178

    
179
		// remove the rule
180
		if (!empty($a_filter[$_POST['id']]['associated-rule-id'])) {
181
			delete_nat_association($a_filter[$_POST['id']]['associated-rule-id']);
182
		}
183
		unset($a_filter[$_POST['id']]);
184

    
185
		if (write_config(gettext("Firewall: Rules - deleted a firewall rule."))) {
186
			mark_subsystem_dirty('filter');
187
		}
188

    
189
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
190
		exit;
191
	}
192
}
193

    
194
if (($_POST['act'] == 'killid') &&
195
    (!empty($_POST['tracker'])) &&
196
    (!empty($if))) {
197
	mwexec("/sbin/pfctl -k label -k " . escapeshellarg("id:{$_POST['tracker']}"));
198
	header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
199
	exit;
200
}
201

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

    
207
if (isset($_POST['del_x'])) {
208
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
209
		$removed = false;
210
		$a_separators = config_get_path('filter/separator/' . strtolower($if), []);
211
		foreach ($_POST['rule'] as $rulei) {
212
			// separators must be updated before the rule is removed
213
			$ridx = get_interface_ruleindex($if, $rulei);
214
			shift_separators($a_separators, $ridx['index'], true);
215

    
216
			// remove the rule
217
			delete_nat_association($a_filter[$rulei]['associated-rule-id']);
218
			unset($a_filter[$rulei]);
219
			$removed = true;
220
		}
221
		config_set_path('filter/separator/' . strtolower($if), $a_separators);
222

    
223
		if ($removed) {
224
			if (write_config(gettext("Firewall: Rules - deleted selected firewall rules."))) {
225
				mark_subsystem_dirty('filter');
226
			}
227
		}
228

    
229
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
230
		exit;
231
	}
232
} elseif (isset($_POST['toggle_x'])) {
233
	if (is_array($_POST['rule']) && count($_POST['rule'])) {
234
		foreach ($_POST['rule'] as $rulei) {
235
			if (isset($a_filter[$rulei]['disabled'])) {
236
				unset($a_filter[$rulei]['disabled']);
237
			} else {
238
				$a_filter[$rulei]['disabled'] = true;
239
			}
240
		}
241
		if (write_config(gettext("Firewall: Rules - toggle selected firewall rules."))) {
242
			mark_subsystem_dirty('filter');
243
		}
244

    
245
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
246
		exit;
247
	}
248
} else if ($_POST['act'] == "toggle") {
249
	if ($a_filter[$_POST['id']]) {
250
		if (isset($a_filter[$_POST['id']]['disabled'])) {
251
			unset($a_filter[$_POST['id']]['disabled']);
252
			$wc_msg = gettext('Firewall: Rules - enabled a firewall rule.');
253
		} else {
254
			$a_filter[$_POST['id']]['disabled'] = true;
255
			$wc_msg = gettext('Firewall: Rules - disabled a firewall rule.');
256
		}
257
		if (write_config($wc_msg)) {
258
			mark_subsystem_dirty('filter');
259
		}
260

    
261
		header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
262
		exit;
263
	}
264
} else if ($_POST['order-store']) {
265
	$updated = false;
266
	$dirty = false;
267

    
268
	/* update rule order, POST[rule] is an array of ordered IDs */
269
	if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
270
		$a_filter_new = array();
271

    
272
		// Include the rules of other interfaces listed in config before this (the selected) interface.
273
		$filteri_before = null;
274
		foreach ($a_filter as $idx => $filterent) {
275
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
276
				$filteri_before = $idx;
277
				break;
278
			} else {
279
				$a_filter_new[] = $filterent;
280
			}
281
		}
282

    
283
		// Include the rules of this (the selected) interface.
284
		// If a rule is not in POST[rule], it has been deleted by the user
285
		foreach ($_POST['rule'] as $id) {
286
			$a_filter_new[] = $a_filter[$id];
287
		}
288

    
289
		// Include the rules of other interfaces listed in config after this (the selected) interface.
290
		foreach ($a_filter as $filteri_after => $filterent) {
291
			if ($filteri_before > $filteri_after) {
292
				continue;
293
			}
294
			if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
295
				continue;
296
			} else {
297
				$a_filter_new[] = $filterent;
298
			}
299
		}
300

    
301
		if ($a_filter !== $a_filter_new) {
302
			$a_filter = $a_filter_new;
303
			$dirty = true;
304
		}
305
	}
306

    
307
	$a_separators = config_get_path('filter/separator/' . strtolower($if), []);
308

    
309
	/* update separator order, POST[separator] is an array of ordered IDs */
310
	if (is_array($_POST['separator']) && !empty($_POST['separator'])) {
311
		$new_separator = array();
312
		$idx = 0;
313

    
314
		foreach ($_POST['separator'] as $separator) {
315
			$new_separator['sep' . $idx++] = $separator;
316
		}
317

    
318
		if ($a_separators !== $new_separator) {
319
			$a_separators = $new_separator;
320
			$updated = true;
321
		}
322
	} else if (!empty($a_separators)) {
323
		$a_separators = "";
324
		$updated = true;
325
	}
326

    
327
	if ($updated || $dirty) {
328
		config_set_path('filter/separator/' . strtolower($if), $a_separators);
329
		if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
330
			if ($dirty) {
331
				mark_subsystem_dirty('filter');
332
			}
333
		}
334
	}
335

    
336
	header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
337
	exit;
338
} elseif (isset($_POST['dstif']) && !empty($_POST['dstif']) &&
339
    isset($iflist[$_POST['dstif']]) && have_ruleint_access($_POST['dstif']) &&
340
    is_array($_POST['rule']) && count($_POST['rule'])) {
341
	$confiflist = get_configured_interface_list();
342
	/* Use this as a starting point and increase as we go, otherwise if the
343
	 * loop runs fast there can be duplicates.
344
	 * https://redmine.pfsense.org/issues/13507 */
345
	$tracker = (int)microtime(true);
346
	foreach ($_POST['rule'] as $rulei) {
347
		$filterent = $a_filter[$rulei];
348
		$filterent['tracker'] = $tracker++;
349
		$filterent['interface'] = $_POST['dstif'];
350
		if (($_POST['convertif'] == 'true') && ($if != $_POST['dstif']) &&
351
		    in_array($_POST['dstif'], $confiflist)) {
352
			if (isset($filterent['source']['network']) &&
353
			    ($filterent['source']['network'] == $if)) {
354
				$filterent['source']['network'] = $_POST['dstif'];
355
			}
356
			if (isset($filterent['destination']['network']) &&
357
			    ($filterent['destination']['network'] == $if)) {
358
				$filterent['destination']['network'] = $_POST['dstif'];
359
			}
360
			if (isset($filterent['source']['network']) &&
361
			    ($filterent['source']['network'] == ($if . 'ip'))) {
362
				$filterent['source']['network'] = $_POST['dstif'] . 'ip';
363
			}
364
			if (isset($filterent['destination']['network']) &&
365
			    ($filterent['destination']['network'] == ($if . 'ip'))) {
366
				$filterent['destination']['network'] = $_POST['dstif'] . 'ip';
367
			}
368
		}
369
		$a_filter[] = $filterent;
370
	}
371
	if (write_config(gettext("Firewall: Rules - copying selected firewall rules."))) {
372
		mark_subsystem_dirty('filter');
373
	}
374

    
375
	header("Location: firewall_rules.php?if=" . htmlspecialchars($_POST['dstif']));
376
	exit;
377
}
378

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

    
381
foreach ($iflist as $ifent => $ifname) {
382
	$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
383
}
384

    
385
foreach ($tab_array as $dtab) {
386
	if ($dtab[1]) {
387
		$bctab = $dtab[0];
388
		break;
389
	}
390
}
391

    
392
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
393
$pglinks = array("", "firewall_rules.php", "@self");
394
$shortcut_section = "firewall";
395

    
396
include("head.inc");
397
$nrules = 0;
398

    
399
if ($savemsg) {
400
	print_info_box($savemsg, 'success');
401
}
402

    
403
if ($_POST['apply']) {
404
	print_apply_result_box($retval);
405
}
406

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

    
411
display_top_tabs($tab_array, false, 'pills');
412

    
413
$showantilockout = false;
414
$showprivate = false;
415
$showblockbogons = false;
416

    
417
if (!isset($config['system']['webgui']['noantilockout']) &&
418
    (((count($config['interfaces']) > 1) && ($if == 'lan')) ||
419
    ((count($config['interfaces']) == 1) && ($if == 'wan')))) {
420
	$showantilockout = true;
421
}
422

    
423
if (isset($config['interfaces'][$if]['blockpriv'])) {
424
	$showprivate = true;
425
}
426

    
427
if (isset($config['interfaces'][$if]['blockbogons'])) {
428
	$showblockbogons = true;
429
}
430

    
431
if (isset($config['system']['webgui']['roworderdragging'])) {
432
	$rules_header_text = gettext("Rules");
433
} else {
434
	$rules_header_text = gettext("Rules (Drag to Change Order)");
435
}
436

    
437
/* Load the counter data of each pf rule. */
438
$rulescnt = pfSense_get_pf_rules();
439

    
440
// Update this if you add or remove columns!
441
$columns_in_table = 13;
442

    
443
/* Floating rules tab has one extra column
444
 * https://redmine.pfsense.org/issues/10667 */
445
if ($if == "FloatingRules") {
446
	$columns_in_table++;
447
}
448

    
449
// Only show rules table if interface is set.
450
if (isset($if)):
451

    
452
?>
453
<!-- Allow table to scroll when dragging outside of the display window -->
454
<style>
455
.table-responsive {
456
    clear: both;
457
    overflow-x: visible;
458
    margin-bottom: 0px;
459
}
460
</style>
461

    
462
<form id="mainform" method="post">
463
	<input name="if" id="if" type="hidden" value="<?=$if?>" />
464
	<input name="dstif" id="dstif" type="hidden" value="" />
465
	<input name="convertif" id="convertif" type="hidden" value="" />
466
	<div class="panel panel-default">
467
		<div class="panel-heading"><h2 class="panel-title"><?=$rules_header_text?></h2></div>
468
		<div id="mainarea" class="table-responsive panel-body">
469
			<table id="ruletable" class="table table-hover table-striped table-condensed" style="overflow-x: 'visible'">
470
				<thead>
471
					<tr>
472
						<th><input type="checkbox" id="selectAll" name="selectAll" /></th>
473
						<th><!-- status icons --></th>
474
						<th><?=gettext("States")?></th>
475
				<?php
476
					if ('FloatingRules' == $if) {
477
				?>
478
						<th><?=gettext("Interfaces")?></th>
479
				<?php
480
					}
481
				?>
482
						<th><?=gettext("Protocol")?></th>
483
						<th><?=gettext("Source")?></th>
484
						<th><?=gettext("Port")?></th>
485
						<th><?=gettext("Destination")?></th>
486
						<th><?=gettext("Port")?></th>
487
						<th><?=gettext("Gateway")?></th>
488
						<th><?=gettext("Queue")?></th>
489
						<th><?=gettext("Schedule")?></th>
490
						<th><?=gettext("Description")?></th>
491
						<th><?=gettext("Actions")?></th>
492
					</tr>
493
				</thead>
494

    
495
<?php if ($showblockbogons || $showantilockout || $showprivate) :
496
?>
497
				<tbody>
498
<?php
499
		// 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.
500
		if ($showantilockout):
501
			$alports = implode('<br />', filter_get_antilockout_ports(true));
502
?>
503
					<tr id="antilockout">
504
						<td></td>
505
						<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
506
						<td><?php print_states(intval(ANTILOCKOUT_TRACKER_START), intval(ANTILOCKOUT_TRACKER_END)); ?></td>
507
						<td>*</td>
508
						<td>*</td>
509
						<td>*</td>
510
						<td><?=$iflist[$if];?> Address</td>
511
						<td><?=$alports?></td>
512
						<td>*</td>
513
						<td>*</td>
514
						<td></td>
515
						<td><?=gettext("Anti-Lockout Rule");?></td>
516
						<td>
517
							<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
518
						</td>
519
					</tr>
520
<?php 	endif;?>
521
<?php 	if ($showprivate): ?>
522
					<tr id="private">
523
						<td></td>
524
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
525
						<td><?php print_states(intval(RFC1918_TRACKER_START), intval(RFC1918_TRACKER_END)); ?></td>
526
						<td>*</td>
527
						<td><?=gettext("RFC 1918 networks");?></td>
528
						<td>*</td>
529
						<td>*</td>
530
						<td>*</td>
531
						<td>*</td>
532
						<td>*</td>
533
						<td></td>
534
						<td><?=gettext("Block private networks");?></td>
535
						<td>
536
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa fa-cog"></i></a>
537
						</td>
538
					</tr>
539
<?php 	endif;?>
540
<?php 	if ($showblockbogons): ?>
541
					<tr id="bogons">
542
						<td></td>
543
						<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
544
						<td><?php print_states(intval(BOGONS_TRACKER_START), intval(BOGONS_TRACKER_END)); ?></td>
545
						<td>*</td>
546
						<td><?=sprintf(gettext("Reserved%sNot assigned by IANA"), "<br />");?></td>
547
						<td>*</td>
548
						<td>*</td>
549
						<td>*</td>
550
						<td>*</td>
551
						<td>*</td>
552
						<td></td>
553
						<td><?=gettext("Block bogon networks");?></td>
554
						<td>
555
							<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa fa-cog"></i></a>
556
						</td>
557
					</tr>
558
<?php 	endif;?>
559
			</tbody>
560
<?php endif;?>
561
			<tbody class="user-entries">
562
<?php
563
$nrules = 0;
564
$separators = config_get_path('filter/separator/'.strtolower($if));
565

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

    
570
/* Cache gateway status for this page load.
571
 * See https://redmine.pfsense.org/issues/12174 */
572
$gateways_status = return_gateways_status(true);
573

    
574
foreach ($a_filter as $filteri => $filterent):
575

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

    
578
		// Display separator(s) for section beginning at rule n
579
		if ($seprows[$nrules]) {
580
			display_separator($separators, $nrules, $columns_in_table);
581
		}
582
?>
583
					<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
584
						<td>
585
							<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
586
						</td>
587

    
588
	<?php
589
		if ($filterent['type'] == "block") {
590
			$iconfn = "times text-danger";
591
			$title_text = gettext("traffic is blocked");
592
		} else if ($filterent['type'] == "reject") {
593
			$iconfn = "hand-stop-o text-warning";
594
			$title_text = gettext("traffic is rejected");
595
		} else if ($filterent['type'] == "match") {
596
			$iconfn = "filter";
597
			$title_text = gettext("traffic is matched");
598
		} else {
599
			$iconfn = "check text-success";
600
			$title_text = gettext("traffic is passed");
601
		}
602
	?>
603
						<td title="<?=$title_text?>">
604
							<a href="?if=<?=htmlspecialchars($if);?>&amp;act=toggle&amp;id=<?=$filteri;?>" usepost>
605
								<i class="fa fa-<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
606
							</a>
607
	<?php
608
		if ($filterent['quick'] == 'yes') {
609
			print '<i class="fa fa-forward text-success" title="'. gettext("&quot;Quick&quot; rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
610
		}
611

    
612
		$isadvset = firewall_check_for_advanced_options($filterent);
613
		if ($isadvset) {
614
			print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'" style="cursor: pointer;"></i>';
615
		}
616

    
617
		if (isset($filterent['log'])) {
618
			print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
619
		}
620

    
621
		if (isset($filterent['direction']) && ($if == "FloatingRules")) {
622
			if ($filterent['direction'] == 'in') {
623
				print '<i class="fa fa-arrow-circle-o-left" title="'. gettext("direction is in") .'" style="cursor: pointer;"></i>';
624
			} elseif ($filterent['direction'] == 'out') {
625
				print '<i class="fa fa-arrow-circle-o-right" title="'. gettext("direction is out") .'" style="cursor: pointer;"></i>';
626
			}
627
		}
628
	?>
629
						</td>
630
	<?php
631
		$alias = rule_columns_with_alias(
632
			$filterent['source']['address'],
633
			pprint_port($filterent['source']['port']),
634
			$filterent['destination']['address'],
635
			pprint_port($filterent['destination']['port'])
636
		);
637

    
638
		//build Schedule popup box
639
		init_config_arr(array('schedules', 'schedule'));
640
		$a_schedules = &$config['schedules']['schedule'];
641
		$schedule_span_begin = "";
642
		$schedule_span_end = "";
643
		$sched_caption_escaped = "";
644
		$sched_content = "";
645
		$schedstatus = false;
646
		$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
647
		$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'));
648
		if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
649
			$idx = 0;
650
			foreach ($a_schedules as $schedule) {
651
				if (!empty($schedule['name']) &&
652
				    $schedule['name'] == $filterent['sched']) {
653
					$schedstatus = filter_get_time_based_rule_status($schedule);
654

    
655
					foreach ($schedule['timerange'] as $timerange) {
656
						$tempFriendlyTime = "";
657
						$tempID = "";
658
						$firstprint = false;
659
						if ($timerange) {
660
							$dayFriendly = "";
661
							$tempFriendlyTime = "";
662

    
663
							//get hours
664
							$temptimerange = $timerange['hour'];
665
							$temptimeseparator = strrpos($temptimerange, "-");
666

    
667
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
668
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
669

    
670
							if ($timerange['month']) {
671
								$tempmontharray = explode(",", $timerange['month']);
672
								$tempdayarray = explode(",", $timerange['day']);
673
								$arraycounter = 0;
674
								$firstDayFound = false;
675
								$firstPrint = false;
676
								foreach ($tempmontharray as $monthtmp) {
677
									$month = $tempmontharray[$arraycounter];
678
									$day = $tempdayarray[$arraycounter];
679

    
680
									if (!$firstDayFound) {
681
										$firstDay = $day;
682
										$firstmonth = $month;
683
										$firstDayFound = true;
684
									}
685

    
686
									$currentDay = $day;
687
									$nextDay = $tempdayarray[$arraycounter+1];
688
									$currentDay++;
689
									if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
690
										if ($firstPrint) {
691
											$dayFriendly .= ", ";
692
										}
693
										$currentDay--;
694
										if ($currentDay != $firstDay) {
695
											$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
696
										} else {
697
											$dayFriendly .=	 $monthArray[$month-1] . " " . $day;
698
										}
699
										$firstDayFound = false;
700
										$firstPrint = true;
701
									}
702
									$arraycounter++;
703
								}
704
							} else {
705
								$tempdayFriendly = $timerange['position'];
706
								$firstDayFound = false;
707
								$tempFriendlyDayArray = explode(",", $tempdayFriendly);
708
								$currentDay = "";
709
								$firstDay = "";
710
								$nextDay = "";
711
								$counter = 0;
712
								foreach ($tempFriendlyDayArray as $day) {
713
									if ($day != "") {
714
										if (!$firstDayFound) {
715
											$firstDay = $tempFriendlyDayArray[$counter];
716
											$firstDayFound = true;
717
										}
718
										$currentDay =$tempFriendlyDayArray[$counter];
719
										//get next day
720
										$nextDay = $tempFriendlyDayArray[$counter+1];
721
										$currentDay++;
722
										if ($currentDay != $nextDay) {
723
											if ($firstprint) {
724
												$dayFriendly .= ", ";
725
											}
726
											$currentDay--;
727
											if ($currentDay != $firstDay) {
728
												$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
729
											} else {
730
												$dayFriendly .= $dayArray[$firstDay-1];
731
											}
732
											$firstDayFound = false;
733
											$firstprint = true;
734
										}
735
										$counter++;
736
									}
737
								}
738
							}
739
							$timeFriendly = $starttime . " - " . $stoptime;
740
							$description = $timerange['rangedescr'];
741
							$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
742
						}
743
					}
744
					#FIXME
745
					$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
746
					$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
747
						$sched_caption_escaped . '" data-html="true">';
748
					$schedule_span_end = "</a>";
749
				}
750
				$idx++;
751
			}
752
		}
753
		$printicon = false;
754
		$alttext = "";
755
		$image = "";
756
		if (!isset($filterent['disabled'])) {
757
			if ($schedstatus) {
758
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
759
					$image = "times-circle";
760
					$dispcolor = "text-danger";
761
					$alttext = gettext("Traffic matching this rule is currently being denied");
762
				} else {
763
					$image = "play-circle";
764
					$dispcolor = "text-success";
765
					$alttext = gettext("Traffic matching this rule is currently being allowed");
766
				}
767
				$printicon = true;
768
			} else if ($filterent['sched']) {
769
				if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
770
					$image = "times-circle";
771
				} else {
772
					$image = "play-circle";
773
				}
774
				$alttext = gettext("This rule is not currently active because its period has expired");
775
				$dispcolor = "text-warning";
776
				$printicon = true;
777
			}
778
		}
779
	?>
780
				<td><?php print_states(intval($filterent['tracker'])); ?></td>
781
	<?php
782
		if ($if == 'FloatingRules') {
783
	?>
784
			<td onclick="fr_toggle(<?=$nrules;?>)" id="frd<?=$nrules;?>" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';">
785
	<?php
786
			if (isset($filterent['interface'])) {
787
				$selected_interfaces = explode(',', $filterent['interface']);
788
				unset($selected_descs);
789
				foreach ($selected_interfaces as $interface) {
790
					if (isset($ifdescs[$interface])) {
791
						$selected_descs[] = $ifdescs[$interface];
792
					} else {
793
						switch ($interface) {
794
						case 'l2tp':
795
							if (config_get_path('l2tp/mode') == 'server') {
796
								$selected_descs[] = 'L2TP VPN';
797
							}
798
							break;
799
						case 'pppoe':
800
							if (is_pppoe_server_enabled()) {
801
								$selected_descs[] = 'PPPoE Server';
802
							}
803
							break;
804
						case 'enc0':
805
							if (ipsec_enabled()) {
806
								$selected_descs[] = 'IPsec';
807
							}
808
							break;
809
						case 'openvpn':
810
							if (!empty(config_get_path('openvpn/openvpn-server', [])) ||
811
							    !empty(config_get_path('openvpn/openvpn-client', []))) {
812
								$selected_descs[] = 'OpenVPN';
813
							}
814
							break;
815
						case 'any':
816
							$selected_descs[] = 'Any';
817
							break;
818
						default:
819
							$selected_descs[] = $interface;
820
							break;
821
						}
822
					}
823
				}
824
				if (!empty($selected_descs)) {
825
					$desclist = '';
826
					$desclength = 0;
827
					foreach ($selected_descs as $desc) {
828
						$desclength += strlen($desc);
829
						if ($desclength > 18) {
830
							$desclist .= ',<br/>';
831
							$desclength = 0;
832
						} elseif ($desclist) {
833
							$desclist .= ', ';
834
							$desclength += 2;
835
						}
836
						$desclist .= $desc;
837
					}
838
					echo $desclist;
839
				}
840
			}
841
	?>
842
			</td>
843
	<?php
844
		}
845
	?>
846
			<td>
847
	<?php
848
		if (isset($filterent['ipprotocol'])) {
849
			switch ($filterent['ipprotocol']) {
850
				case "inet":
851
					echo "IPv4 ";
852
					break;
853
				case "inet6":
854
					echo "IPv6 ";
855
					break;
856
				case "inet46":
857
					echo "IPv4+6 ";
858
					break;
859
			}
860
		} else {
861
			echo "IPv4 ";
862
		}
863

    
864
		if (isset($filterent['protocol'])) {
865
			echo strtoupper($filterent['protocol']);
866

    
867
			if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
868
				// replace each comma-separated icmptype item by its (localised) full description
869
				$t = 	implode(', ',
870
						array_map(
871
						        function($type) {
872
								global $icmptypes;
873
								return $icmptypes[$type]['descrip'];
874
							},
875
							explode(',', $filterent['icmptype'])
876
						)
877
					);
878
				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']));
879
			}
880
		} else {
881
			echo " *";
882
		}
883
	?>
884
						</td>
885
						<td>
886
							<?php if (isset($alias['src'])): ?>
887
								<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">
888
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['source'])))?>
889
								</a>
890
							<?php else: ?>
891
								<?=htmlspecialchars(pprint_address($filterent['source'], $filter_srcdsttype_flags))?>
892
							<?php endif; ?>
893
						</td>
894
						<td>
895
							<?php if (isset($alias['srcport'])): ?>
896
								<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">
897
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['source']['port'])))?>
898
								</a>
899
							<?php else: ?>
900
								<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
901
							<?php endif; ?>
902
						</td>
903
						<td>
904
							<?php if (isset($alias['dst'])): ?>
905
								<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">
906
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['destination'])))?>
907
								</a>
908
							<?php else: ?>
909
								<?=htmlspecialchars(pprint_address($filterent['destination'], $filter_srcdsttype_flags))?>
910
							<?php endif; ?>
911
						</td>
912
						<td>
913
							<?php if (isset($alias['dstport'])): ?>
914
								<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">
915
									<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['destination']['port'])))?>
916
								</a>
917
							<?php else: ?>
918
								<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
919
							<?php endif; ?>
920
						</td>
921
						<td>
922
							<?php if (isset($filterent['gateway'])): ?>
923
								<?php
924
									/* Cache gateway status for this page load.
925
									 * See https://redmine.pfsense.org/issues/12174 */
926
									if (!is_array($gw_info)) {
927
										$gw_info = array();
928
									}
929
									if (empty($gw_info[$filterent['gateway']])) {
930
										$gw_info[$filterent['gateway']] = gateway_info_popup($filterent['gateway'], $gateways_status);
931
									}
932
								?>
933
								<?php if (!empty($gw_info[$filterent['gateway']])): ?>
934
									<?=$gw_info[$filterent['gateway']]?>
935
								<?php else: ?>
936
									<span>
937
								<?php endif; ?>
938
							<?php else: ?>
939
								<span>
940
							<?php endif; ?>
941
								<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])): ?>
942
									<?=str_replace('_', '_<wbr>', htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr']))?>
943
								<?php else: ?>
944
									<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
945
								<?php endif; ?>
946
							</span>
947
						</td>
948
						<td>
949
							<?php
950
								if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
951
									$desc = str_replace('_', ' ', $filterent['ackqueue']);
952
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&amp;action=show\">{$desc}</a>";
953
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
954
									echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
955
								} else if (isset($filterent['defaultqueue'])) {
956
									$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
957
									echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&amp;action=show\">{$desc}</a>";
958
								} else {
959
									echo gettext("none");
960
								}
961
							?>
962
						</td>
963
						<td>
964
							<?php if ($printicon) { ?>
965
								<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
966
							<?php } ?>
967
							<?=$schedule_span_begin;?><?=str_replace('_', '_<wbr>', htmlspecialchars($filterent['sched']));?>&nbsp;<?=$schedule_span_end;?>
968
						</td>
969
						<td>
970
							<?=htmlspecialchars($filterent['descr']);?>
971
						</td>
972
						<td class="action-icons">
973
						<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
974
							<a	class="fa fa-anchor icon-pointer" id="Xmove_<?=$filteri?>" title="<?=$XmoveTitle?>"></a>
975
							<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
976
							<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
977
<?php if (isset($filterent['disabled'])) {
978
?>
979
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>" usepost></a>
980
<?php } else {
981
?>
982
							<a href="?act=toggle&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-ban" title="<?=gettext('Disable')?>" usepost></a>
983
<?php }
984
?>
985
							<a href="?act=del&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>" usepost></a>
986
<?php if (($filterent['type'] == 'pass') &&
987
	    !empty($filterent['tracker'])): ?>
988
							<a href="?act=killid&amp;if=<?=htmlspecialchars($if);?>&amp;id=<?=$filteri;?>&amp;tracker=<?=$filterent['tracker']?>" class="fa fa-times do-confirm" title="<?=gettext('Kill states on this interface created by this rule')?>" usepost></a>
989
<?php endif; ?>
990
						</td>
991
					</tr>
992
<?php
993
		$nrules++;
994
	}
995
endforeach;
996

    
997
// There can be separator(s) after the last rule listed.
998
foreach ($seprows as $idx => $sep) {
999
	if ($idx >= $nrules) {
1000
		display_separator($separators, $idx, $columns_in_table);
1001
	}
1002
}
1003
?>
1004
				</tbody>
1005
			</table>
1006
		</div>
1007
	</div>
1008

    
1009
<?php if ($nrules == 0): ?>
1010
	<div class="alert alert-warning" role="alert">
1011
		<p>
1012
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
1013
			<?=gettext("No floating rules are currently defined.");?>
1014
		<?php else: ?>
1015
			<?=gettext("No rules are currently defined for this interface");?><br />
1016
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
1017
		<?php endif;?>
1018
			<?=gettext("Click the button to add a new rule.");?>
1019
		</p>
1020
	</div>
1021
<?php endif;?>
1022

    
1023
	<nav class="action-buttons">
1024
		<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')?>">
1025
			<i class="fa fa-level-up icon-embed-btn"></i>
1026
			<?=gettext("Add");?>
1027
		</a>
1028
		<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')?>">
1029
			<i class="fa fa-level-down icon-embed-btn"></i>
1030
			<?=gettext("Add");?>
1031
		</a>
1032
		<button id="del_x" name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" disabled title="<?=gettext('Delete selected rules')?>">
1033
			<i class="fa fa-trash icon-embed-btn"></i>
1034
			<?=gettext("Delete"); ?>
1035
		</button>
1036
		<button id="toggle_x" name="toggle_x" type="submit" class="btn btn-primary btn-sm" value="<?=gettext("Toggle selected rules"); ?>" disabled title="<?=gettext('Toggle selected rules')?>">
1037
			<i class="fa fa-ban icon-embed-btn"></i>
1038
			<?=gettext("Toggle"); ?>
1039
		</button>
1040
		<?php if ($if != 'FloatingRules'):?>
1041
		<button id="copy_x" name="copy_x" type="button" class="btn btn-primary btn-sm" value="<?=gettext("Copy selected rules"); ?>" disabled title="<?=gettext('Copy selected rules')?>" data-toggle="modal" data-target="#rulescopy">
1042
			<i class="fa fa-clone icon-embed-btn"></i>
1043
			<?=gettext("Copy"); ?>
1044
		</button>
1045
		<?php endif;?>
1046
		<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
1047
			<i class="fa fa-save icon-embed-btn"></i>
1048
			<?=gettext("Save")?>
1049
		</button>
1050
		<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
1051
			<i class="fa fa-plus icon-embed-btn"></i>
1052
			<?=gettext("Separator")?>
1053
		</button>
1054
	</nav>
1055
</form>
1056
<?php
1057
// Create a Modal object to display Rules Copy window
1058
$form = new Form(false);
1059
$modal = new Modal('Copy selected rules', 'rulescopy', true);
1060
$modal->addInput(new Form_Select(
1061
	'copyr_dstif',
1062
	'*Destination Interface',
1063
	$if,
1064
	filter_get_interface_list()
1065
))->setHelp('Select the destination interface where the rules should be copied. Rules will be added after existing rules on that interface.');
1066
$modal->addInput(new Form_Checkbox(
1067
	'copyr_convertif',
1068
	'Convert interface definitions',
1069
	'Enable Interface Address/Net conversion',
1070
	false
1071
))->setHelp('Convert source Interface Address/Net definitions to the destination Interface Address/Net.%1$s' .
1072
	    'For example: LAN Address -> OPT1 Address, or LAN net -> OPT1 net.%1$s' .
1073
	    'Interface groups and some special interfaces (IPsec, OpenVPN), do not support this feature.', '<br />');
1074
$btncopyrules = new Form_Button(
1075
	'copyr',
1076
	'Paste',
1077
	null,
1078
	'fa-clone'
1079
);
1080
$btncopyrules->setAttribute('type','button')->addClass('btn-success');
1081
$btncancelcopyrules = new Form_Button(
1082
	'cancel_copyr',
1083
	'Cancel',
1084
	null,
1085
	'fa-undo'
1086
);
1087
$btncancelcopyrules->setAttribute('type','button')->addClass('btn-warning');
1088
$modal->addInput(new Form_StaticText(
1089
	null,
1090
	$btncopyrules . $btncancelcopyrules
1091
));
1092
$form->add($modal);
1093
print($form);
1094

    
1095
else: ?>
1096
	<div class="alert alert-warning" role="alert">
1097
		<p>
1098
			<?= gettext("Select an interface to view firewall rules.") ?>
1099
			<br />
1100
			<?php
1101
				echo sprintf(gettext("See %sSystem > General Setup%s, %sRequire Firewall Interface%s."),
1102
				'<a href="/system.php">',
1103
				'</a>',
1104
				'<strong>',
1105
				'</strong>');
1106
			?>
1107
		</p>
1108
	</div>
1109

    
1110
<?php endif; ?>
1111

    
1112
<div class="infoblock">
1113
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
1114
		<dl class="dl-horizontal responsive">
1115
		<!-- Legend -->
1116
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
1117
			<dt><i class="fa fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
1118
			<dt><i class="fa fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
1119
			<dt><i class="fa fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
1120
			<dt><i class="fa fa-hand-stop-o text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
1121
			<dt><i class="fa fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
1122
			<dt><i class="fa fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
1123
			<dt><i class="fa fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
1124
		</dl>
1125

    
1126
<?php
1127
	if ("FloatingRules" != $if) {
1128
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
1129
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
1130
			gettext("This means that if block rules are used, it is important to pay attention " .
1131
			"to the rule order. Everything that isn't explicitly passed is blocked " .
1132
			"by default. "));
1133
	} else {
1134
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
1135
			"the action of the first rule to match a packet will be executed) only " .
1136
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
1137
			"other rules match. Pay close attention to the rule order and options " .
1138
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
1139
	}
1140

    
1141
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
1142
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa fa-anchor"></i>');
1143
?>
1144
	</div>
1145
	</div>
1146
</div>
1147

    
1148
<script type="text/javascript">
1149
//<![CDATA[
1150

    
1151
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
1152
iface = "<?=strtolower($if)?>";
1153
cncltxt = '<?=gettext("Cancel")?>';
1154
svtxt = '<?=gettext("Save")?>';
1155
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
1156
configsection = "filter";
1157

    
1158
events.push(function() {
1159

    
1160
	// "Move to here" (anchor) action
1161
	$('[id^=Xmove_]').click(function (event) {
1162

    
1163
		// Prevent click from toggling row
1164
		event.stopImmediatePropagation();
1165

    
1166
		// Save the target rule position
1167
		var anchor_row = $(this).parents("tr:first");
1168

    
1169
		if (event.shiftKey) {
1170
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
1171
				ruleid = this.id.slice(2);
1172

    
1173
				if (ruleid && !isNaN(ruleid)) {
1174
					if ($('#frc' + ruleid).prop('checked')) {
1175
						// Move the selected rows, un-select them and add highlight class
1176
						$(this).insertAfter(anchor_row);
1177
						fr_toggle(ruleid, "fr");
1178
						$('#fr' + ruleid).addClass("highlight");
1179
					}
1180
				}
1181
			});
1182
		} else {
1183
			$('#ruletable > tbody  > tr').each(function() {
1184
				ruleid = this.id.slice(2);
1185

    
1186
				if (ruleid && !isNaN(ruleid)) {
1187
					if ($('#frc' + ruleid).prop('checked')) {
1188
						// Move the selected rows, un-select them and add highlight class
1189
						$(this).insertBefore(anchor_row);
1190
						fr_toggle(ruleid, "fr");
1191
						$('#fr' + ruleid).addClass("highlight");
1192
					}
1193
				}
1194
			});
1195
		}
1196

    
1197
		// Temporarily set background color so user can more easily see the moved rules, then fade
1198
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
1199
		$('#ruletable tr').removeClass("highlight");
1200
		$('#order-store').removeAttr('disabled');
1201
		reindex_rules($(anchor_row).parent('tbody'));
1202
		dirty = true;
1203
	}).mouseover(function(e) {
1204
		var ruleselected = false;
1205

    
1206
		$(this).css("cursor", "default");
1207

    
1208
		// Are any rules currently selected?
1209
		$('[id^=frc]').each(function () {
1210
			if ($(this).prop("checked")) {
1211
				ruleselected = true;
1212
			}
1213
		});
1214

    
1215
		// If so, change the icon to show the insertion point
1216
		if (ruleselected) {
1217
			if (e.shiftKey) {
1218
				$(this).removeClass().addClass("fa fa-lg fa-arrow-down text-danger");
1219
			} else {
1220
				$(this).removeClass().addClass("fa fa-lg fa-arrow-up text-danger");
1221
			}
1222
		}
1223
	}).mouseout(function(e) {
1224
		$(this).removeClass().addClass("fa fa-anchor");
1225
	});
1226

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

    
1232
	$('table tbody.user-entries').sortable({
1233
		cursor: 'grabbing',
1234
		scroll: true,
1235
		overflow: 'scroll',
1236
		scrollSensitivity: 100,
1237
		update: function(event, ui) {
1238
			$('#order-store').removeAttr('disabled');
1239
			reindex_rules(ui.item.parent('tbody'));
1240
			dirty = true;
1241
		}
1242
	});
1243

    
1244
	$('table tbody.user-entries').show();
1245
<?php endif; ?>
1246

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

    
1251
		// Save the separator bar configuration
1252
		save_separators();
1253

    
1254
		// Suppress the "Do you really want to leave the page" message
1255
		saving = true;
1256
	});
1257

    
1258
	$('[id^=fr]').click(function () {
1259
		buttonsmode('frc', ['del_x', 'toggle_x', 'copy_x']);
1260
	});
1261

    
1262
	// Provide a warning message if the user tries to change page before saving
1263
	$(window).bind('beforeunload', function(){
1264
		if ((!saving && dirty) || newSeparator) {
1265
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
1266
		} else {
1267
			return undefined;
1268
		}
1269
	});
1270

    
1271
	$(document).on('keyup keydown', function(e){
1272
		if (e.shiftKey) {
1273
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1274
		} else {
1275
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1276
		}
1277
	});
1278

    
1279
	$('#selectAll').click(function() {
1280
		var checkedStatus = this.checked;
1281
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
1282
		$(this).prop('checked', checkedStatus);
1283
		});
1284
		buttonsmode('frc', ['del_x', 'toggle_x', 'copy_x']);
1285
	});
1286

    
1287
	$("#copyr").click(function() {
1288
		$("#rulescopy").modal('hide');
1289
		$("#dstif").val($("#copyr_dstif").val());
1290
		$("#convertif").val($("#copyr_convertif").prop('checked'));
1291
		document.getElementById('mainform').submit();
1292
	});
1293

    
1294
	$("#cancel_copyr").click(function() {
1295
		$("#rulescopy").modal('hide');
1296
	});
1297

    
1298
});
1299
//]]>
1300
</script>
1301

    
1302
<?php include("foot.inc");?>
(50-50/228)