Project

General

Profile

Download (45 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-2024 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-solid 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-solid 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-solid 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-solid 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-solid 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-solid 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
global $user_settings;
575
$show_system_alias_popup = (array_key_exists('webgui', $user_settings) && !$user_settings['webgui']['disablealiaspopupdetail']);
576
$system_alias_specialnet = get_specialnet('', [SPECIALNET_IFNET, SPECIALNET_GROUP]);
577
foreach ($a_filter as $filteri => $filterent):
578

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

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

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

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

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

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

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

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

    
666
							//get hours
667
							$temptimerange = $timerange['hour'];
668
							$temptimeseparator = strrpos($temptimerange, "-");
669

    
670
							$starttime = substr ($temptimerange, 0, $temptimeseparator);
671
							$stoptime = substr ($temptimerange, $temptimeseparator+1);
672

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

    
683
									if (!$firstDayFound) {
684
										$firstDay = $day;
685
										$firstmonth = $month;
686
										$firstDayFound = true;
687
									}
688

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

    
867
		if (isset($filterent['protocol'])) {
868
			echo strtoupper($filterent['protocol']);
869

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

    
1008
// There can be separator(s) after the last rule listed.
1009
foreach ($seprows as $idx => $sep) {
1010
	if ($idx >= $nrules) {
1011
		display_separator($separators, $idx, $columns_in_table);
1012
	}
1013
}
1014
?>
1015
				</tbody>
1016
			</table>
1017
		</div>
1018
	</div>
1019

    
1020
<?php if ($nrules == 0): ?>
1021
	<div class="alert alert-warning" role="alert">
1022
		<p>
1023
		<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
1024
			<?=gettext("No floating rules are currently defined.");?>
1025
		<?php else: ?>
1026
			<?=gettext("No rules are currently defined for this interface");?><br />
1027
			<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
1028
		<?php endif;?>
1029
			<?=gettext("Click the button to add a new rule.");?>
1030
		</p>
1031
	</div>
1032
<?php endif;?>
1033

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

    
1106
else: ?>
1107
	<div class="alert alert-warning" role="alert">
1108
		<p>
1109
			<?= gettext("Select an interface to view firewall rules.") ?>
1110
			<br />
1111
			<?php
1112
				echo sprintf(gettext("See %sSystem > General Setup%s, %sRequire Firewall Interface%s."),
1113
				'<a href="/system.php">',
1114
				'</a>',
1115
				'<strong>',
1116
				'</strong>');
1117
			?>
1118
		</p>
1119
	</div>
1120

    
1121
<?php endif; ?>
1122

    
1123
<div class="infoblock">
1124
	<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
1125
		<dl class="dl-horizontal responsive">
1126
		<!-- Legend -->
1127
			<dt><?=gettext('Legend')?></dt>				<dd></dd>
1128
			<dt><i class="fa-solid fa-check text-success"></i></dt>		<dd><?=gettext("Pass");?></dd>
1129
			<dt><i class="fa-solid fa-filter"></i></dt>	<dd><?=gettext("Match");?></dd>
1130
			<dt><i class="fa-solid fa-times text-danger"></i></dt>	<dd><?=gettext("Block");?></dd>
1131
			<dt><i class="fa-regular fa-hand text-warning"></i></dt>		<dd><?=gettext("Reject");?></dd>
1132
			<dt><i class="fa-solid fa-tasks"></i></dt>	<dd> <?=gettext("Log");?></dd>
1133
			<dt><i class="fa-solid fa-cog"></i></dt>		<dd> <?=gettext("Advanced filter");?></dd>
1134
			<dt><i class="fa-solid fa-forward text-success"></i></dt><dd> <?=gettext("&quot;Quick&quot; rule. Applied immediately on match.")?></dd>
1135
		</dl>
1136

    
1137
<?php
1138
	if ("FloatingRules" != $if) {
1139
		print(gettext("Rules are evaluated on a first-match basis (i.e. " .
1140
			"the action of the first rule to match a packet will be executed). ") . '<br />' .
1141
			gettext("This means that if block rules are used, it is important to pay attention " .
1142
			"to the rule order. Everything that isn't explicitly passed is blocked " .
1143
			"by default. "));
1144
	} else {
1145
		print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
1146
			"the action of the first rule to match a packet will be executed) only " .
1147
			"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
1148
			"other rules match. Pay close attention to the rule order and options " .
1149
			"chosen. If no rule here matches, the per-interface or default rules are used. "));
1150
	}
1151

    
1152
	printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
1153
			'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa-solid fa-anchor"></i>');
1154
?>
1155
	</div>
1156
	</div>
1157
</div>
1158

    
1159
<script type="text/javascript">
1160
//<![CDATA[
1161

    
1162
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
1163
iface = "<?=strtolower($if)?>";
1164
cncltxt = '<?=gettext("Cancel")?>';
1165
svtxt = '<?=gettext("Save")?>';
1166
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
1167
configsection = "filter";
1168

    
1169
events.push(function() {
1170

    
1171
	// "Move to here" (anchor) action
1172
	$('[id^=Xmove_]').click(function (event) {
1173

    
1174
		// Prevent click from toggling row
1175
		event.stopImmediatePropagation();
1176

    
1177
		// Save the target rule position
1178
		var anchor_row = $(this).parents("tr:first");
1179

    
1180
		if (event.shiftKey) {
1181
			$($('#ruletable > tbody  > tr').get().reverse()).each(function() {
1182
				ruleid = this.id.slice(2);
1183

    
1184
				if (ruleid && !isNaN(ruleid)) {
1185
					if ($('#frc' + ruleid).prop('checked')) {
1186
						// Move the selected rows, un-select them and add highlight class
1187
						$(this).insertAfter(anchor_row);
1188
						fr_toggle(ruleid, "fr");
1189
						$('#fr' + ruleid).addClass("highlight");
1190
					}
1191
				}
1192
			});
1193
		} else {
1194
			$('#ruletable > tbody  > tr').each(function() {
1195
				ruleid = this.id.slice(2);
1196

    
1197
				if (ruleid && !isNaN(ruleid)) {
1198
					if ($('#frc' + ruleid).prop('checked')) {
1199
						// Move the selected rows, un-select them and add highlight class
1200
						$(this).insertBefore(anchor_row);
1201
						fr_toggle(ruleid, "fr");
1202
						$('#fr' + ruleid).addClass("highlight");
1203
					}
1204
				}
1205
			});
1206
		}
1207

    
1208
		// Temporarily set background color so user can more easily see the moved rules, then fade
1209
		$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
1210
		$('#ruletable tr').removeClass("highlight");
1211
		$('#order-store').removeAttr('disabled');
1212
		reindex_rules($(anchor_row).parent('tbody'));
1213
		dirty = true;
1214
	}).mouseover(function(e) {
1215
		var ruleselected = false;
1216

    
1217
		$(this).css("cursor", "default");
1218

    
1219
		// Are any rules currently selected?
1220
		$('[id^=frc]').each(function () {
1221
			if ($(this).prop("checked")) {
1222
				ruleselected = true;
1223
			}
1224
		});
1225

    
1226
		// If so, change the icon to show the insertion point
1227
		if (ruleselected) {
1228
			if (e.shiftKey) {
1229
				$(this).removeClass().addClass("fa-solid fa-lg fa-arrow-down text-danger");
1230
			} else {
1231
				$(this).removeClass().addClass("fa-solid fa-lg fa-arrow-up text-danger");
1232
			}
1233
		}
1234
	}).mouseout(function(e) {
1235
		$(this).removeClass().addClass("fa-solid fa-anchor");
1236
	});
1237

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

    
1243
	$('table tbody.user-entries').sortable({
1244
		cursor: 'grabbing',
1245
		scroll: true,
1246
		overflow: 'scroll',
1247
		scrollSensitivity: 100,
1248
		update: function(event, ui) {
1249
			$('#order-store').removeAttr('disabled');
1250
			reindex_rules(ui.item.parent('tbody'));
1251
			dirty = true;
1252
		}
1253
	});
1254

    
1255
	$('table tbody.user-entries').show();
1256
<?php endif; ?>
1257

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

    
1262
		// Save the separator bar configuration
1263
		save_separators();
1264

    
1265
		// Suppress the "Do you really want to leave the page" message
1266
		saving = true;
1267
	});
1268

    
1269
	$('[id^=fr]').click(function () {
1270
		buttonsmode('frc', ['del_x', 'toggle_x', 'copy_x']);
1271
	});
1272

    
1273
	// Provide a warning message if the user tries to change page before saving
1274
	$(window).bind('beforeunload', function(){
1275
		if ((!saving && dirty) || newSeparator) {
1276
			return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
1277
		} else {
1278
			return undefined;
1279
		}
1280
	});
1281

    
1282
	$(document).on('keyup keydown', function(e){
1283
		if (e.shiftKey) {
1284
			$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
1285
		} else {
1286
			$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
1287
		}
1288
	});
1289

    
1290
	$('#selectAll').click(function() {
1291
		var checkedStatus = this.checked;
1292
		$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
1293
		$(this).prop('checked', checkedStatus);
1294
		});
1295
		buttonsmode('frc', ['del_x', 'toggle_x', 'copy_x']);
1296
	});
1297

    
1298
	$("#copyr").click(function() {
1299
		$("#rulescopy").modal('hide');
1300
		$("#dstif").val($("#copyr_dstif").val());
1301
		$("#convertif").val($("#copyr_convertif").prop('checked'));
1302
		document.getElementById('mainform').submit();
1303
	});
1304

    
1305
	$("#cancel_copyr").click(function() {
1306
		$("#rulescopy").modal('hide');
1307
	});
1308

    
1309
});
1310
//]]>
1311
</script>
1312

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