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 <[email protected]>.
|
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
|
$evaluations += $rule['evaluations'];
|
97
|
$packets += $rule['packets'];
|
98
|
$bytes += $rule['bytes'];
|
99
|
$states += $rule['states'];
|
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
|
$title = (gettext('States details'));
|
115
|
$href = ('diag_dump_states.php?ruleid=' . $rulesid);
|
116
|
printf("<a href=\"%s\" " .
|
117
|
"data-toggle=\"popover\" data-trigger=\"hover focus\" " .
|
118
|
"title=\"%s\" ", $href, $title);
|
119
|
printf("data-content=\"{$trackertext}evaluations: %s<br />packets: " .
|
120
|
"%s<br />bytes: %s<br />", format_number($evaluations), format_number($packets),
|
121
|
format_bytes($bytes));
|
122
|
printf("states: %s<br />state creations: %s", format_number($states),
|
123
|
format_number($stcreations));
|
124
|
printf("\" data-html=\"true\" usepost>");
|
125
|
printf("%s/%s</a><br />", format_number($states), format_bytes($bytes));
|
126
|
}
|
127
|
|
128
|
function delete_nat_association($id) {
|
129
|
$a_nat = config_get_path('nat/rule');
|
130
|
if (!$id || !is_array($a_nat)) {
|
131
|
return;
|
132
|
}
|
133
|
|
134
|
foreach ($a_nat as &$natent) {
|
135
|
if ($natent['associated-rule-id'] == $id) {
|
136
|
$natent['associated-rule-id'] = '';
|
137
|
}
|
138
|
}
|
139
|
config_set_path('nat/rule', $a_nat);
|
140
|
}
|
141
|
|
142
|
config_init_path('filter/rule');
|
143
|
filter_rules_sort();
|
144
|
|
145
|
if ($_REQUEST['if']) {
|
146
|
$if = $_REQUEST['if'];
|
147
|
}
|
148
|
|
149
|
$ifdescs = get_configured_interface_with_descr();
|
150
|
|
151
|
$iflist = filter_get_interface_list();
|
152
|
|
153
|
if (!$if || !isset($iflist[$if])) {
|
154
|
if ($if != 'any' &&
|
155
|
$if != 'EthernetRules' &&
|
156
|
$if != 'FloatingRules' &&
|
157
|
!config_path_enabled('system/webgui', 'requirefirewallinterface')) {
|
158
|
/* default to the first configured interface */
|
159
|
$if = array_key_first($ifdescs);
|
160
|
}
|
161
|
}
|
162
|
|
163
|
if ($_POST['apply']) {
|
164
|
$retval = 0;
|
165
|
$retval |= filter_configure();
|
166
|
|
167
|
clear_subsystem_dirty('filter');
|
168
|
}
|
169
|
|
170
|
if ($_POST['act'] == "del") {
|
171
|
if (config_get_path("filter/rule/{$_POST['id']}")) {
|
172
|
// separators must be updated before the rule is removed
|
173
|
$ridx = get_interface_ruleindex($if, $_POST['id']);
|
174
|
$a_separators = config_get_path('filter/separator/' . strtolower($if), []);
|
175
|
shift_separators($a_separators, $ridx['index'], true);
|
176
|
config_set_path('filter/separator/' . strtolower($if), $a_separators);
|
177
|
|
178
|
// remove the rule
|
179
|
if (!empty(config_get_path("filter/rule/{$_POST['id']}/associated-rule-id"))) {
|
180
|
delete_nat_association(config_get_path("filter/rule/{$_POST['id']}/associated-rule-id"));
|
181
|
}
|
182
|
config_del_path("filter/rule/{$_POST['id']}");
|
183
|
|
184
|
if (write_config(gettext("Firewall: Rules - deleted a firewall rule."))) {
|
185
|
mark_subsystem_dirty('filter');
|
186
|
}
|
187
|
|
188
|
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
|
189
|
exit;
|
190
|
}
|
191
|
}
|
192
|
|
193
|
if (($_POST['act'] == 'killid') &&
|
194
|
(!empty($_POST['tracker'])) &&
|
195
|
(!empty($if))) {
|
196
|
mwexec("/sbin/pfctl -k label -k " . escapeshellarg("id:{$_POST['tracker']}"));
|
197
|
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
|
198
|
exit;
|
199
|
}
|
200
|
|
201
|
// Handle save msg if defined
|
202
|
if ($_REQUEST['savemsg']) {
|
203
|
$savemsg = htmlentities($_REQUEST['savemsg']);
|
204
|
}
|
205
|
|
206
|
if (isset($_POST['del_x'])) {
|
207
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
208
|
$removed = false;
|
209
|
$a_separators = config_get_path('filter/separator/' . strtolower($if), []);
|
210
|
foreach ($_POST['rule'] as $rulei) {
|
211
|
// separators must be updated before the rule is removed
|
212
|
$ridx = get_interface_ruleindex($if, $rulei);
|
213
|
shift_separators($a_separators, $ridx['index'], true);
|
214
|
|
215
|
// remove the rule
|
216
|
delete_nat_association(config_get_path("filter/rule/{$rulei}/associated-rule-id"));
|
217
|
config_del_path("filter/rule/{$rulei}");
|
218
|
$removed = true;
|
219
|
}
|
220
|
config_set_path('filter/separator/' . strtolower($if), $a_separators);
|
221
|
|
222
|
if ($removed) {
|
223
|
if (write_config(gettext("Firewall: Rules - deleted selected firewall rules."))) {
|
224
|
mark_subsystem_dirty('filter');
|
225
|
}
|
226
|
}
|
227
|
|
228
|
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
|
229
|
exit;
|
230
|
}
|
231
|
} elseif (isset($_POST['toggle_x'])) {
|
232
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
233
|
foreach ($_POST['rule'] as $rulei) {
|
234
|
if (config_path_enabled("filter/rule/{$rulei}", 'disabled')) {
|
235
|
config_del_path("filter/rule/{$rulei}/disabled");
|
236
|
} else {
|
237
|
config_set_path("filter/rule/{$rulei}/disabled", true);
|
238
|
}
|
239
|
}
|
240
|
if (write_config(gettext("Firewall: Rules - toggle selected firewall rules."))) {
|
241
|
mark_subsystem_dirty('filter');
|
242
|
}
|
243
|
|
244
|
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
|
245
|
exit;
|
246
|
}
|
247
|
} else if ($_POST['act'] == "toggle") {
|
248
|
if (config_get_path("filter/rule/{$_POST['id']}")) {
|
249
|
if (config_path_enabled("filter/rule/{$_POST['id']}", 'disabled')) {
|
250
|
config_del_path("filter/rule/{$_POST['id']}/disabled");
|
251
|
$wc_msg = gettext('Firewall: Rules - enabled a firewall rule.');
|
252
|
} else {
|
253
|
config_set_path("filter/rule/{$_POST['id']}/disabled", true);
|
254
|
$wc_msg = gettext('Firewall: Rules - disabled a firewall rule.');
|
255
|
}
|
256
|
if (write_config($wc_msg)) {
|
257
|
mark_subsystem_dirty('filter');
|
258
|
}
|
259
|
|
260
|
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
|
261
|
exit;
|
262
|
}
|
263
|
} else if ($_POST['order-store']) {
|
264
|
$updated = false;
|
265
|
$dirty = false;
|
266
|
/* update rule order, POST[rule] is an array of ordered IDs */
|
267
|
if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
|
268
|
$a_filter_new = array();
|
269
|
|
270
|
// Include the rules of other interfaces listed in config before this (the selected) interface.
|
271
|
$filteri_before = null;
|
272
|
foreach (config_get_path('filter/rule', []) as $idx => $filterent) {
|
273
|
if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
|
274
|
$filteri_before = $idx;
|
275
|
break;
|
276
|
} else {
|
277
|
$a_filter_new[] = $filterent;
|
278
|
}
|
279
|
}
|
280
|
|
281
|
// Include the rules of this (the selected) interface.
|
282
|
// If a rule is not in POST[rule], it has been deleted by the user
|
283
|
foreach ($_POST['rule'] as $id) {
|
284
|
$a_filter_new[] = config_get_path("filter/rule/{$id}");
|
285
|
}
|
286
|
|
287
|
// Include the rules of other interfaces listed in config after this (the selected) interface.
|
288
|
foreach (config_get_path('filter/rule', []) as $filteri_after => $filterent) {
|
289
|
if ($filteri_before > $filteri_after) {
|
290
|
continue;
|
291
|
}
|
292
|
if (($filterent['interface'] == $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" == $if)) {
|
293
|
continue;
|
294
|
} else {
|
295
|
$a_filter_new[] = $filterent;
|
296
|
}
|
297
|
}
|
298
|
|
299
|
if (config_get_path('filter/rule') !== $a_filter_new) {
|
300
|
config_set_path('filter/rule', $a_filter_new);
|
301
|
$dirty = true;
|
302
|
}
|
303
|
}
|
304
|
|
305
|
$a_separators = config_get_path('filter/separator/' . strtolower($if), []);
|
306
|
|
307
|
/* update separator order, POST[separator] is an array of ordered IDs */
|
308
|
if (is_array($_POST['separator']) && !empty($_POST['separator'])) {
|
309
|
$new_separator = array();
|
310
|
$idx = 0;
|
311
|
|
312
|
foreach ($_POST['separator'] as $separator) {
|
313
|
$new_separator['sep' . $idx++] = $separator;
|
314
|
}
|
315
|
|
316
|
if ($a_separators !== $new_separator) {
|
317
|
$a_separators = $new_separator;
|
318
|
$updated = true;
|
319
|
}
|
320
|
} else if (!empty($a_separators)) {
|
321
|
$a_separators = "";
|
322
|
$updated = true;
|
323
|
}
|
324
|
|
325
|
if ($updated || $dirty) {
|
326
|
config_set_path('filter/separator/' . strtolower($if), $a_separators);
|
327
|
if (write_config(gettext("Firewall: Rules - reordered firewall rules."))) {
|
328
|
if ($dirty) {
|
329
|
mark_subsystem_dirty('filter');
|
330
|
}
|
331
|
}
|
332
|
}
|
333
|
|
334
|
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
|
335
|
exit;
|
336
|
} elseif (isset($_POST['dstif']) && !empty($_POST['dstif']) &&
|
337
|
isset($iflist[$_POST['dstif']]) && have_ruleint_access($_POST['dstif']) &&
|
338
|
is_array($_POST['rule']) && count($_POST['rule'])) {
|
339
|
$confiflist = get_configured_interface_list();
|
340
|
/* Use this as a starting point and increase as we go, otherwise if the
|
341
|
* loop runs fast there can be duplicates.
|
342
|
* https://redmine.pfsense.org/issues/13507 */
|
343
|
$tracker = (int)microtime(true);
|
344
|
foreach ($_POST['rule'] as $rulei) {
|
345
|
$filterent = config_get_path("filter/rule/{$rulei}");
|
346
|
$filterent['tracker'] = $tracker++;
|
347
|
$filterent['interface'] = $_POST['dstif'];
|
348
|
if (($_POST['convertif'] == 'true') && ($if != $_POST['dstif']) &&
|
349
|
in_array($_POST['dstif'], $confiflist)) {
|
350
|
if (isset($filterent['source']['network']) &&
|
351
|
($filterent['source']['network'] == $if)) {
|
352
|
$filterent['source']['network'] = $_POST['dstif'];
|
353
|
}
|
354
|
if (isset($filterent['destination']['network']) &&
|
355
|
($filterent['destination']['network'] == $if)) {
|
356
|
$filterent['destination']['network'] = $_POST['dstif'];
|
357
|
}
|
358
|
if (isset($filterent['source']['network']) &&
|
359
|
($filterent['source']['network'] == ($if . 'ip'))) {
|
360
|
$filterent['source']['network'] = $_POST['dstif'] . 'ip';
|
361
|
}
|
362
|
if (isset($filterent['destination']['network']) &&
|
363
|
($filterent['destination']['network'] == ($if . 'ip'))) {
|
364
|
$filterent['destination']['network'] = $_POST['dstif'] . 'ip';
|
365
|
}
|
366
|
}
|
367
|
config_set_path('filter/rule/', $filterent);
|
368
|
}
|
369
|
if (write_config(gettext("Firewall: Rules - copying selected firewall rules."))) {
|
370
|
mark_subsystem_dirty('filter');
|
371
|
}
|
372
|
|
373
|
header("Location: firewall_rules.php?if=" . htmlspecialchars($_POST['dstif']));
|
374
|
exit;
|
375
|
}
|
376
|
|
377
|
$tab_array[] = [gettext('Floating'), ($if === 'FloatingRules'), 'firewall_rules.php?if=FloatingRules'];
|
378
|
|
379
|
foreach ($iflist as $ifent => $ifname) {
|
380
|
$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
|
381
|
}
|
382
|
|
383
|
foreach ($tab_array as $dtab) {
|
384
|
if ($dtab[1]) {
|
385
|
$bctab = $dtab[0];
|
386
|
break;
|
387
|
}
|
388
|
}
|
389
|
|
390
|
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
|
391
|
$pglinks = array("", "firewall_rules.php", "@self");
|
392
|
$shortcut_section = "firewall";
|
393
|
|
394
|
include("head.inc");
|
395
|
$nrules = 0;
|
396
|
|
397
|
if ($savemsg) {
|
398
|
print_info_box($savemsg, 'success');
|
399
|
}
|
400
|
|
401
|
if ($_POST['apply']) {
|
402
|
print_apply_result_box($retval);
|
403
|
}
|
404
|
|
405
|
if (is_subsystem_dirty('filter')) {
|
406
|
print_apply_box(gettext("The firewall rule configuration has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
|
407
|
}
|
408
|
|
409
|
display_top_tabs($tab_array, false, 'pills');
|
410
|
|
411
|
$showantilockout = false;
|
412
|
$showprivate = false;
|
413
|
$showblockbogons = false;
|
414
|
|
415
|
if (!config_path_enabled('system/webgui', 'noantilockout') &&
|
416
|
(((count(config_get_path('interfaces', [])) > 1) && ($if == 'lan')) ||
|
417
|
((count(config_get_path('interfaces', [])) == 1) && ($if == 'wan')))) {
|
418
|
$showantilockout = true;
|
419
|
}
|
420
|
|
421
|
if (config_path_enabled("interfaces/{$if}", "blockpriv")) {
|
422
|
$showprivate = true;
|
423
|
}
|
424
|
|
425
|
if (config_path_enabled("interfaces/{$if}", "blockbogons")) {
|
426
|
$showblockbogons = true;
|
427
|
}
|
428
|
|
429
|
if (config_path_enabled('system/webgui', 'roworderdragging')) {
|
430
|
$rules_header_text = gettext('Rules');
|
431
|
} else {
|
432
|
$rules_header_text = gettext('Rules (Drag to Change Order)');
|
433
|
}
|
434
|
|
435
|
/* Load the counter data of each pf rule. */
|
436
|
$rulescnt = pfSense_get_pf_rules();
|
437
|
|
438
|
// Update this if you add or remove columns!
|
439
|
$columns_in_table = 13;
|
440
|
|
441
|
/* Floating rules tab has one extra column
|
442
|
* https://redmine.pfsense.org/issues/10667 */
|
443
|
if ($if === 'FloatingRules') {
|
444
|
$columns_in_table++;
|
445
|
}
|
446
|
|
447
|
// Only show rules table if interface is set.
|
448
|
if (isset($if)):
|
449
|
|
450
|
?>
|
451
|
<!-- Allow table to scroll when dragging outside of the display window -->
|
452
|
<style>
|
453
|
.table-responsive {
|
454
|
clear: both;
|
455
|
overflow-x: visible;
|
456
|
margin-bottom: 0px;
|
457
|
}
|
458
|
</style>
|
459
|
|
460
|
<form id="mainform" method="post">
|
461
|
<input name="if" id="if" type="hidden" value="<?=$if?>" />
|
462
|
<input name="dstif" id="dstif" type="hidden" value="" />
|
463
|
<input name="convertif" id="convertif" type="hidden" value="" />
|
464
|
<div class="panel panel-default">
|
465
|
<div class="panel-heading"><h2 class="panel-title"><?=$rules_header_text?></h2></div>
|
466
|
<div id="mainarea" class="table-responsive panel-body">
|
467
|
<table id="ruletable" class="table table-hover table-striped table-condensed" style="overflow-x: 'visible'">
|
468
|
<thead>
|
469
|
<tr>
|
470
|
<th><input type="checkbox" id="selectAll" name="selectAll" /></th>
|
471
|
<th><!-- status icons --></th>
|
472
|
<th><?=gettext('States')?></th>
|
473
|
<?php if ($if === 'FloatingRules'): ?>
|
474
|
<th><?=gettext('Interfaces')?></th>
|
475
|
<?php endif; ?>
|
476
|
<th><?=gettext('Protocol')?></th>
|
477
|
<th><?=gettext('Source')?></th>
|
478
|
<th><?=gettext('Port')?></th>
|
479
|
<th><?=gettext('Destination')?></th>
|
480
|
<th><?=gettext('Port')?></th>
|
481
|
<th><?=gettext('Gateway')?></th>
|
482
|
<th><?=gettext('Queue')?></th>
|
483
|
<th><?=gettext('Schedule')?></th>
|
484
|
<th><?=gettext('Description')?></th>
|
485
|
<th><?=gettext('Actions')?></th>
|
486
|
</tr>
|
487
|
</thead>
|
488
|
|
489
|
<?php if ($showblockbogons || $showantilockout || $showprivate) :
|
490
|
?>
|
491
|
<tbody>
|
492
|
<?php
|
493
|
// 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.
|
494
|
if ($showantilockout):
|
495
|
$alports = implode('<br />', filter_get_antilockout_ports(true));
|
496
|
?>
|
497
|
<tr id="antilockout">
|
498
|
<td></td>
|
499
|
<td title="<?=gettext("traffic is passed")?>"><i class="fa-solid fa-check text-success"></i></td>
|
500
|
<td><?php print_states(intval(ANTILOCKOUT_TRACKER_START), intval(ANTILOCKOUT_TRACKER_END)); ?></td>
|
501
|
<td>*</td>
|
502
|
<td>*</td>
|
503
|
<td>*</td>
|
504
|
<td><?=$iflist[$if];?> Address</td>
|
505
|
<td><?=$alports?></td>
|
506
|
<td>*</td>
|
507
|
<td>*</td>
|
508
|
<td></td>
|
509
|
<td><?=gettext("Anti-Lockout Rule");?></td>
|
510
|
<td>
|
511
|
<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa-solid fa-cog"></i></a>
|
512
|
</td>
|
513
|
</tr>
|
514
|
<?php endif;?>
|
515
|
<?php if ($showprivate): ?>
|
516
|
<tr id="private">
|
517
|
<td></td>
|
518
|
<td title="<?=gettext("traffic is blocked")?>"><i class="fa-solid fa-times text-danger"></i></td>
|
519
|
<td><?php print_states(intval(RFC1918_TRACKER_START), intval(RFC1918_TRACKER_END)); ?></td>
|
520
|
<td>*</td>
|
521
|
<td><?=gettext("RFC 1918 networks");?></td>
|
522
|
<td>*</td>
|
523
|
<td>*</td>
|
524
|
<td>*</td>
|
525
|
<td>*</td>
|
526
|
<td>*</td>
|
527
|
<td></td>
|
528
|
<td><?=gettext("Block private networks");?></td>
|
529
|
<td>
|
530
|
<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa-solid fa-cog"></i></a>
|
531
|
</td>
|
532
|
</tr>
|
533
|
<?php endif;?>
|
534
|
<?php if ($showblockbogons): ?>
|
535
|
<tr id="bogons">
|
536
|
<td></td>
|
537
|
<td title="<?=gettext("traffic is blocked")?>"><i class="fa-solid fa-times text-danger"></i></td>
|
538
|
<td><?php print_states(intval(BOGONS_TRACKER_START), intval(BOGONS_TRACKER_END)); ?></td>
|
539
|
<td>*</td>
|
540
|
<td><?=sprintf(gettext("Reserved%sNot assigned by IANA"), "<br />");?></td>
|
541
|
<td>*</td>
|
542
|
<td>*</td>
|
543
|
<td>*</td>
|
544
|
<td>*</td>
|
545
|
<td>*</td>
|
546
|
<td></td>
|
547
|
<td><?=gettext("Block bogon networks");?></td>
|
548
|
<td>
|
549
|
<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>" usepost><i class="fa-solid fa-cog"></i></a>
|
550
|
</td>
|
551
|
</tr>
|
552
|
<?php endif;?>
|
553
|
</tbody>
|
554
|
<?php endif;?>
|
555
|
<tbody class="user-entries">
|
556
|
<?php
|
557
|
$nrules = 0;
|
558
|
$separators = config_get_path('filter/separator/'.strtolower($if));
|
559
|
|
560
|
// Get a list of separator rows and use it to call the display separator function only for rows which there are separator(s).
|
561
|
// More efficient than looping through the list of separators on every row.
|
562
|
$seprows = separator_rows($separators);
|
563
|
|
564
|
/* Cache gateway status for this page load.
|
565
|
* See https://redmine.pfsense.org/issues/12174 */
|
566
|
$gateways_status = return_gateways_status(true);
|
567
|
|
568
|
global $user_settings;
|
569
|
$show_system_alias_popup = (array_key_exists('webgui', $user_settings) && !$user_settings['webgui']['disablealiaspopupdetail']);
|
570
|
$system_alias_specialnet = get_specialnet('', [SPECIALNET_IFNET, SPECIALNET_GROUP]);
|
571
|
config_init_path('schedules/schedule');
|
572
|
$a_schedules = config_get_path('schedules/schedule');
|
573
|
$if_config = config_get_path('interfaces');
|
574
|
foreach (config_get_path('filter/rule', []) as $filteri => $filterent):
|
575
|
|
576
|
if (($filterent['interface'] == $if && !isset($filterent['floating'])) ||
|
577
|
(isset($filterent['floating']) && $if === 'FloatingRules')) {
|
578
|
|
579
|
// Display separator(s) for section beginning at rule n
|
580
|
if ($seprows[$nrules]) {
|
581
|
display_separator($separators, $nrules, $columns_in_table);
|
582
|
}
|
583
|
?>
|
584
|
<tr id="fr<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$filteri;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
|
585
|
<td>
|
586
|
<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$filteri;?>"/>
|
587
|
</td>
|
588
|
|
589
|
<?php
|
590
|
if ($filterent['type'] == "block") {
|
591
|
$iconfn = "fa-solid fa-times text-danger";
|
592
|
$title_text = gettext("traffic is blocked");
|
593
|
} else if ($filterent['type'] == "reject") {
|
594
|
$iconfn = "fa-regular fa-hand text-warning";
|
595
|
$title_text = gettext("traffic is rejected");
|
596
|
} else if ($filterent['type'] == "match") {
|
597
|
$iconfn = "fa-solid fa-filter";
|
598
|
$title_text = gettext("traffic is matched");
|
599
|
} else {
|
600
|
$iconfn = "fa-solid fa-check text-success";
|
601
|
$title_text = gettext("traffic is passed");
|
602
|
}
|
603
|
?>
|
604
|
<td title="<?=$title_text?>">
|
605
|
<a href="?if=<?=htmlspecialchars($if);?>&act=toggle&id=<?=$filteri;?>" usepost>
|
606
|
<i class="<?=$iconfn?>" title="<?=gettext("click to toggle enabled/disabled status");?>"></i>
|
607
|
</a>
|
608
|
<?php
|
609
|
if ($filterent['quick'] == 'yes') {
|
610
|
print '<i class="fa-solid fa-forward text-success" title="'. gettext(""Quick" rule. Applied immediately on match.") .'" style="cursor: pointer;"></i>';
|
611
|
}
|
612
|
|
613
|
$isadvset = firewall_check_for_advanced_options($filterent);
|
614
|
if ($isadvset) {
|
615
|
print '<i class="fa-solid fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'" style="cursor: pointer;"></i>';
|
616
|
}
|
617
|
|
618
|
if (isset($filterent['log'])) {
|
619
|
print '<i class="fa-solid fa-tasks" title="'. gettext("traffic is logged") .'" style="cursor: pointer;"></i>';
|
620
|
}
|
621
|
|
622
|
if (isset($filterent['direction']) &&
|
623
|
($if == "FloatingRules")) {
|
624
|
if ($filterent['direction'] == 'in') {
|
625
|
print '<i class="fa-regular fa-circle-left" title="'. gettext("direction is in") .'" style="cursor: pointer;"></i>';
|
626
|
} elseif ($filterent['direction'] == 'out') {
|
627
|
print '<i class="fa-regular fa-circle-right" title="'. gettext("direction is out") .'" style="cursor: pointer;"></i>';
|
628
|
}
|
629
|
}
|
630
|
?>
|
631
|
</td>
|
632
|
<?php
|
633
|
$alias = rule_columns_with_alias(
|
634
|
$filterent['source']['address'],
|
635
|
pprint_port($filterent['source']['port']),
|
636
|
$filterent['destination']['address'],
|
637
|
pprint_port($filterent['destination']['port'])
|
638
|
);
|
639
|
|
640
|
//build Schedule popup box
|
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 ($a_schedules != "" && is_array($a_schedules)) {
|
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 = "fa-solid fa-times-circle";
|
760
|
$dispcolor = "text-danger";
|
761
|
$alttext = gettext("Traffic matching this rule is currently being denied");
|
762
|
} else {
|
763
|
$image = "fa-solid fa-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 = "fa-solid fa-times-circle";
|
771
|
} else {
|
772
|
$image = "fa-solid fa-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']), -1); ?></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 elseif ($show_system_alias_popup && array_key_exists($filterent['source']['network'], $system_alias_specialnet)): ?>
|
891
|
<a data-toggle="popover" data-trigger="hover focus" title="<?=gettext('System alias details')?>" data-content="<?=system_alias_info_popup(strtoupper($filterent['source']['network']) . '__NETWORK')?>" data-html="true">
|
892
|
<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['source'], $filter_srcdsttype_flags)))?>
|
893
|
</a>
|
894
|
<?php else: ?>
|
895
|
<?=htmlspecialchars(pprint_address($filterent['source'], $filter_srcdsttype_flags))?>
|
896
|
<?php endif; ?>
|
897
|
</td>
|
898
|
<td>
|
899
|
<?php if (isset($alias['srcport'])): ?>
|
900
|
<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">
|
901
|
<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['source']['port'])))?>
|
902
|
</a>
|
903
|
<?php else: ?>
|
904
|
<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
|
905
|
<?php endif; ?>
|
906
|
</td>
|
907
|
<td>
|
908
|
<?php if (isset($alias['dst'])): ?>
|
909
|
<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">
|
910
|
<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['destination'])))?>
|
911
|
</a>
|
912
|
<?php elseif ($show_system_alias_popup && array_key_exists($filterent['destination']['network'], $system_alias_specialnet)): ?>
|
913
|
<a data-toggle="popover" data-trigger="hover focus" title="<?=gettext('System alias details')?>" data-content="<?=system_alias_info_popup(strtoupper($filterent['destination']['network']) . '__NETWORK')?>" data-html="true">
|
914
|
<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_address($filterent['destination'], $filter_srcdsttype_flags)))?>
|
915
|
</a>
|
916
|
<?php else: ?>
|
917
|
<?=htmlspecialchars(pprint_address($filterent['destination'], $filter_srcdsttype_flags))?>
|
918
|
<?php endif; ?>
|
919
|
</td>
|
920
|
<td>
|
921
|
<?php if (isset($alias['dstport'])): ?>
|
922
|
<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">
|
923
|
<?=str_replace('_', '_<wbr>', htmlspecialchars(pprint_port($filterent['destination']['port'])))?>
|
924
|
</a>
|
925
|
<?php else: ?>
|
926
|
<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
|
927
|
<?php endif; ?>
|
928
|
</td>
|
929
|
<td>
|
930
|
<?php if (isset($filterent['gateway'])): ?>
|
931
|
<?php
|
932
|
/* Cache gateway status for this page load.
|
933
|
* See https://redmine.pfsense.org/issues/12174 */
|
934
|
if (!is_array($gw_info)) {
|
935
|
$gw_info = array();
|
936
|
}
|
937
|
if (empty($gw_info[$filterent['gateway']])) {
|
938
|
$gw_info[$filterent['gateway']] = gateway_info_popup($filterent['gateway'], $gateways_status);
|
939
|
}
|
940
|
?>
|
941
|
<?php if (!empty($gw_info[$filterent['gateway']])): ?>
|
942
|
<?=$gw_info[$filterent['gateway']]?>
|
943
|
<?php else: ?>
|
944
|
<span>
|
945
|
<?php endif; ?>
|
946
|
<?php else: ?>
|
947
|
<span>
|
948
|
<?php endif; ?>
|
949
|
<?php if (isset($if_config[$filterent['gateway']]['descr'])): ?>
|
950
|
<?=str_replace('_', '_<wbr>', htmlspecialchars($if_config[$filterent['gateway']]['descr']))?>
|
951
|
<?php else: ?>
|
952
|
<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
|
953
|
<?php endif; ?>
|
954
|
</span>
|
955
|
</td>
|
956
|
<td>
|
957
|
<?php
|
958
|
if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
|
959
|
$desc = str_replace('_', ' ', $filterent['ackqueue']);
|
960
|
echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&action=show\">{$desc}</a>";
|
961
|
$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
|
962
|
echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&action=show\">{$desc}</a>";
|
963
|
} else if (isset($filterent['defaultqueue'])) {
|
964
|
$desc = str_replace('_', '_<wbr>', $filterent['defaultqueue']);
|
965
|
echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&action=show\">{$desc}</a>";
|
966
|
} else {
|
967
|
echo gettext("none");
|
968
|
}
|
969
|
?>
|
970
|
</td>
|
971
|
<td>
|
972
|
<?php if ($printicon) { ?>
|
973
|
<i class="<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
|
974
|
<?php } ?>
|
975
|
<?=$schedule_span_begin;?><?=str_replace('_', '_<wbr>', htmlspecialchars($filterent['sched']));?> <?=$schedule_span_end;?>
|
976
|
</td>
|
977
|
<td>
|
978
|
<?=htmlspecialchars($filterent['descr']);?>
|
979
|
</td>
|
980
|
<td class="action-icons">
|
981
|
<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
|
982
|
<a class="fa-solid fa-anchor icon-pointer" id="Xmove_<?=$filteri?>" title="<?=$XmoveTitle?>"></a>
|
983
|
<a href="firewall_rules_edit.php?id=<?=$filteri;?>" class="fa-solid fa-pencil" title="<?=gettext('Edit')?>"></a>
|
984
|
<a href="firewall_rules_edit.php?dup=<?=$filteri;?>" class="fa-regular fa-clone" title="<?=gettext('Copy')?>"></a>
|
985
|
<?php if (isset($filterent['disabled'])) {
|
986
|
?>
|
987
|
<a href="?act=toggle&if=<?=htmlspecialchars($if);?>&id=<?=$filteri;?>" class="fa-regular fa-square-check" title="<?=gettext('Enable')?>" usepost></a>
|
988
|
<?php } else {
|
989
|
?>
|
990
|
<a href="?act=toggle&if=<?=htmlspecialchars($if);?>&id=<?=$filteri;?>" class="fa-solid fa-ban" title="<?=gettext('Disable')?>" usepost></a>
|
991
|
<?php }
|
992
|
?>
|
993
|
<a href="?act=del&if=<?=htmlspecialchars($if);?>&id=<?=$filteri;?>" class="fa-solid fa-trash-can" title="<?=gettext('Delete this rule')?>" usepost></a>
|
994
|
<?php if (($filterent['type'] == 'pass') &&
|
995
|
!empty($filterent['tracker'])): ?>
|
996
|
<a href="?act=killid&if=<?=htmlspecialchars($if);?>&id=<?=$filteri;?>&tracker=<?=$filterent['tracker']?>" class="fa-solid fa-times do-confirm" title="<?=gettext('Kill states on this interface created by this rule')?>" usepost></a>
|
997
|
<?php endif; ?>
|
998
|
</td>
|
999
|
</tr>
|
1000
|
<?php
|
1001
|
$nrules++;
|
1002
|
}
|
1003
|
endforeach;
|
1004
|
|
1005
|
// There can be separator(s) after the last rule listed.
|
1006
|
foreach ($seprows as $idx => $sep) {
|
1007
|
if ($idx >= $nrules) {
|
1008
|
display_separator($separators, $idx, $columns_in_table);
|
1009
|
}
|
1010
|
}
|
1011
|
?>
|
1012
|
</tbody>
|
1013
|
</table>
|
1014
|
</div>
|
1015
|
</div>
|
1016
|
|
1017
|
<?php if ($nrules == 0): ?>
|
1018
|
<div class="alert alert-warning" role="alert">
|
1019
|
<p>
|
1020
|
<?php if ($if === 'FloatingRules'): ?>
|
1021
|
<?=gettext('No floating rules are currently defined.');?>
|
1022
|
<?php else: ?>
|
1023
|
<?=gettext("No rules are currently defined for this interface");?><br />
|
1024
|
<?=gettext("All incoming connections on this interface will be blocked until pass rules are added.");?>
|
1025
|
<?php endif;?>
|
1026
|
<?=gettext("Click the button to add a new rule.");?>
|
1027
|
</p>
|
1028
|
</div>
|
1029
|
<?php endif;?>
|
1030
|
|
1031
|
<nav class="action-buttons">
|
1032
|
<a href="firewall_rules_edit.php?if=<?=htmlspecialchars($if);?>&after=-1" role="button" class="btn btn-sm btn-success" title="<?=gettext('Add rule to the top of the list')?>">
|
1033
|
<i class="fa-solid fa-turn-up icon-embed-btn"></i>
|
1034
|
<?=gettext("Add");?>
|
1035
|
</a>
|
1036
|
<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')?>">
|
1037
|
<i class="fa-solid fa-turn-down icon-embed-btn"></i>
|
1038
|
<?=gettext("Add");?>
|
1039
|
</a>
|
1040
|
<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')?>">
|
1041
|
<i class="fa-solid fa-trash-can icon-embed-btn"></i>
|
1042
|
<?=gettext("Delete"); ?>
|
1043
|
</button>
|
1044
|
<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')?>">
|
1045
|
<i class="fa-solid fa-ban icon-embed-btn"></i>
|
1046
|
<?=gettext("Toggle"); ?>
|
1047
|
</button>
|
1048
|
<?php if ($if !== 'FloatingRules'):?>
|
1049
|
<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">
|
1050
|
<i class="fa-regular fa-clone icon-embed-btn"></i>
|
1051
|
<?=gettext("Copy"); ?>
|
1052
|
</button>
|
1053
|
<?php endif;?>
|
1054
|
<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
|
1055
|
<i class="fa-solid fa-save icon-embed-btn"></i>
|
1056
|
<?=gettext("Save")?>
|
1057
|
</button>
|
1058
|
<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
|
1059
|
<i class="fa-solid fa-plus icon-embed-btn"></i>
|
1060
|
<?=gettext("Separator")?>
|
1061
|
</button>
|
1062
|
</nav>
|
1063
|
</form>
|
1064
|
<?php
|
1065
|
// Create a Modal object to display Rules Copy window
|
1066
|
$form = new Form(false);
|
1067
|
$modal = new Modal('Copy selected rules', 'rulescopy', true);
|
1068
|
$modal->addInput(new Form_Select(
|
1069
|
'copyr_dstif',
|
1070
|
'*Destination Interface',
|
1071
|
$if,
|
1072
|
filter_get_interface_list()
|
1073
|
))->setHelp('Select the destination interface where the rules should be copied. Rules will be added after existing rules on that interface.');
|
1074
|
$modal->addInput(new Form_Checkbox(
|
1075
|
'copyr_convertif',
|
1076
|
'Convert interface definitions',
|
1077
|
'Enable Interface Address/Net conversion',
|
1078
|
false
|
1079
|
))->setHelp('Convert source Interface Address/Net definitions to the destination Interface Address/Net.%1$s' .
|
1080
|
'For example: LAN Address -> OPT1 Address, or LAN net -> OPT1 net.%1$s' .
|
1081
|
'Interface groups and some special interfaces (IPsec, OpenVPN), do not support this feature.', '<br />');
|
1082
|
$btncopyrules = new Form_Button(
|
1083
|
'copyr',
|
1084
|
'Paste',
|
1085
|
null,
|
1086
|
'fa-regular fa-clone'
|
1087
|
);
|
1088
|
$btncopyrules->setAttribute('type','button')->addClass('btn-success');
|
1089
|
$btncancelcopyrules = new Form_Button(
|
1090
|
'cancel_copyr',
|
1091
|
'Cancel',
|
1092
|
null,
|
1093
|
'fa-solid fa-undo'
|
1094
|
);
|
1095
|
$btncancelcopyrules->setAttribute('type','button')->addClass('btn-warning');
|
1096
|
$modal->addInput(new Form_StaticText(
|
1097
|
null,
|
1098
|
$btncopyrules . $btncancelcopyrules
|
1099
|
));
|
1100
|
$form->add($modal);
|
1101
|
print($form);
|
1102
|
|
1103
|
else: ?>
|
1104
|
<div class="alert alert-warning" role="alert">
|
1105
|
<p>
|
1106
|
<?= gettext("Select an interface to view firewall rules.") ?>
|
1107
|
<br />
|
1108
|
<?php
|
1109
|
echo sprintf(gettext("See %sSystem > General Setup%s, %sRequire Firewall Interface%s."),
|
1110
|
'<a href="/system.php">',
|
1111
|
'</a>',
|
1112
|
'<strong>',
|
1113
|
'</strong>');
|
1114
|
?>
|
1115
|
</p>
|
1116
|
</div>
|
1117
|
|
1118
|
<?php endif; ?>
|
1119
|
|
1120
|
<div class="infoblock">
|
1121
|
<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
|
1122
|
<dl class="dl-horizontal responsive">
|
1123
|
<!-- Legend -->
|
1124
|
<dt><?=gettext('Legend')?></dt> <dd></dd>
|
1125
|
<dt><i class="fa-solid fa-check text-success"></i></dt> <dd><?=gettext("Pass");?></dd>
|
1126
|
<dt><i class="fa-solid fa-filter"></i></dt> <dd><?=gettext("Match");?></dd>
|
1127
|
<dt><i class="fa-solid fa-times text-danger"></i></dt> <dd><?=gettext("Block");?></dd>
|
1128
|
<dt><i class="fa-regular fa-hand text-warning"></i></dt> <dd><?=gettext("Reject");?></dd>
|
1129
|
<dt><i class="fa-solid fa-tasks"></i></dt> <dd> <?=gettext("Log");?></dd>
|
1130
|
<dt><i class="fa-solid fa-cog"></i></dt> <dd> <?=gettext("Advanced filter");?></dd>
|
1131
|
<dt><i class="fa-solid fa-forward text-success"></i></dt><dd> <?=gettext(""Quick" rule. Applied immediately on match.")?></dd>
|
1132
|
</dl>
|
1133
|
|
1134
|
<?php
|
1135
|
if ("FloatingRules" != $if) {
|
1136
|
print(gettext("Rules are evaluated on a first-match basis (i.e. " .
|
1137
|
"the action of the first rule to match a packet will be executed). ") . '<br />' .
|
1138
|
gettext("This means that if block rules are used, it is important to pay attention " .
|
1139
|
"to the rule order. Everything that isn't explicitly passed is blocked " .
|
1140
|
"by default. "));
|
1141
|
} else {
|
1142
|
print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
|
1143
|
"the action of the first rule to match a packet will be executed) only " .
|
1144
|
"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
|
1145
|
"other rules match. Pay close attention to the rule order and options " .
|
1146
|
"chosen. If no rule here matches, the per-interface or default rules are used. "));
|
1147
|
}
|
1148
|
|
1149
|
printf(gettext('%1$sClick the anchor icon %2$s to move checked rules before the clicked row. Hold down ' .
|
1150
|
'the shift key and click to move the rules after the clicked row.'), '<br /><br />', '<i class="fa-solid fa-anchor"></i>');
|
1151
|
?>
|
1152
|
</div>
|
1153
|
</div>
|
1154
|
</div>
|
1155
|
|
1156
|
<script type="text/javascript">
|
1157
|
//<![CDATA[
|
1158
|
|
1159
|
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
|
1160
|
iface = "<?=strtolower($if)?>";
|
1161
|
cncltxt = '<?=gettext("Cancel")?>';
|
1162
|
svtxt = '<?=gettext("Save")?>';
|
1163
|
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
|
1164
|
configsection = "filter";
|
1165
|
|
1166
|
events.push(function() {
|
1167
|
|
1168
|
// "Move to here" (anchor) action
|
1169
|
$('[id^=Xmove_]').click(function (event) {
|
1170
|
|
1171
|
// Prevent click from toggling row
|
1172
|
event.stopImmediatePropagation();
|
1173
|
|
1174
|
// Save the target rule position
|
1175
|
var anchor_row = $(this).parents("tr:first");
|
1176
|
|
1177
|
if (event.shiftKey) {
|
1178
|
$($('#ruletable > tbody > tr').get().reverse()).each(function() {
|
1179
|
ruleid = this.id.slice(2);
|
1180
|
|
1181
|
if (ruleid && !isNaN(ruleid)) {
|
1182
|
if ($('#frc' + ruleid).prop('checked')) {
|
1183
|
// Move the selected rows, un-select them and add highlight class
|
1184
|
$(this).insertAfter(anchor_row);
|
1185
|
fr_toggle(ruleid, "fr");
|
1186
|
$('#fr' + ruleid).addClass("highlight");
|
1187
|
}
|
1188
|
}
|
1189
|
});
|
1190
|
} else {
|
1191
|
$('#ruletable > tbody > tr').each(function() {
|
1192
|
ruleid = this.id.slice(2);
|
1193
|
|
1194
|
if (ruleid && !isNaN(ruleid)) {
|
1195
|
if ($('#frc' + ruleid).prop('checked')) {
|
1196
|
// Move the selected rows, un-select them and add highlight class
|
1197
|
$(this).insertBefore(anchor_row);
|
1198
|
fr_toggle(ruleid, "fr");
|
1199
|
$('#fr' + ruleid).addClass("highlight");
|
1200
|
}
|
1201
|
}
|
1202
|
});
|
1203
|
}
|
1204
|
|
1205
|
// Temporarily set background color so user can more easily see the moved rules, then fade
|
1206
|
$('.highlight').effect("highlight", {color: "#739b4b;"}, 4000);
|
1207
|
$('#ruletable tr').removeClass("highlight");
|
1208
|
$('#order-store').removeAttr('disabled');
|
1209
|
reindex_rules($(anchor_row).parent('tbody'));
|
1210
|
dirty = true;
|
1211
|
}).mouseover(function(e) {
|
1212
|
var ruleselected = false;
|
1213
|
|
1214
|
$(this).css("cursor", "default");
|
1215
|
|
1216
|
// Are any rules currently selected?
|
1217
|
$('[id^=frc]').each(function () {
|
1218
|
if ($(this).prop("checked")) {
|
1219
|
ruleselected = true;
|
1220
|
}
|
1221
|
});
|
1222
|
|
1223
|
// If so, change the icon to show the insertion point
|
1224
|
if (ruleselected) {
|
1225
|
if (e.shiftKey) {
|
1226
|
$(this).removeClass().addClass("fa-solid fa-lg fa-arrow-down text-danger");
|
1227
|
} else {
|
1228
|
$(this).removeClass().addClass("fa-solid fa-lg fa-arrow-up text-danger");
|
1229
|
}
|
1230
|
}
|
1231
|
}).mouseout(function(e) {
|
1232
|
$(this).removeClass().addClass("fa-solid fa-anchor");
|
1233
|
});
|
1234
|
|
1235
|
<?php if(!config_path_enabled('system/webgui', 'roworderdragging')): ?>
|
1236
|
// Make rules sortable. Hiding the table before applying sortable, then showing it again is
|
1237
|
// a work-around for very slow sorting on FireFox
|
1238
|
$('table tbody.user-entries').hide();
|
1239
|
|
1240
|
$('table tbody.user-entries').sortable({
|
1241
|
cursor: 'grabbing',
|
1242
|
scroll: true,
|
1243
|
overflow: 'scroll',
|
1244
|
scrollSensitivity: 100,
|
1245
|
update: function(event, ui) {
|
1246
|
$('#order-store').removeAttr('disabled');
|
1247
|
reindex_rules(ui.item.parent('tbody'));
|
1248
|
dirty = true;
|
1249
|
}
|
1250
|
});
|
1251
|
|
1252
|
$('table tbody.user-entries').show();
|
1253
|
<?php endif; ?>
|
1254
|
|
1255
|
// Check all of the rule checkboxes so that their values are posted
|
1256
|
$('#order-store').click(function () {
|
1257
|
$('[id^=frc]').prop('checked', true);
|
1258
|
|
1259
|
// Save the separator bar configuration
|
1260
|
save_separators();
|
1261
|
|
1262
|
// Suppress the "Do you really want to leave the page" message
|
1263
|
saving = true;
|
1264
|
});
|
1265
|
|
1266
|
$('[id^=fr]').click(function () {
|
1267
|
buttonsmode('frc', ['del_x', 'toggle_x', 'copy_x']);
|
1268
|
});
|
1269
|
|
1270
|
// Provide a warning message if the user tries to change page before saving
|
1271
|
$(window).bind('beforeunload', function(){
|
1272
|
if ((!saving && dirty) || newSeparator) {
|
1273
|
return ("<?=gettext('One or more rules have been moved but have not yet been saved')?>");
|
1274
|
} else {
|
1275
|
return undefined;
|
1276
|
}
|
1277
|
});
|
1278
|
|
1279
|
$(document).on('keyup keydown', function(e){
|
1280
|
if (e.shiftKey) {
|
1281
|
$('[id^=Xmove_]').attr("title", "<?=$ShXmoveTitle?>");
|
1282
|
} else {
|
1283
|
$('[id^=Xmove_]').attr("title", "<?=$XmoveTitle?>");
|
1284
|
}
|
1285
|
});
|
1286
|
|
1287
|
$('#selectAll').click(function() {
|
1288
|
var checkedStatus = this.checked;
|
1289
|
$('#ruletable tbody tr').find('td:first :checkbox').each(function() {
|
1290
|
$(this).prop('checked', checkedStatus);
|
1291
|
});
|
1292
|
buttonsmode('frc', ['del_x', 'toggle_x', 'copy_x']);
|
1293
|
});
|
1294
|
|
1295
|
$("#copyr").click(function() {
|
1296
|
$("#rulescopy").modal('hide');
|
1297
|
$("#dstif").val($("#copyr_dstif").val());
|
1298
|
$("#convertif").val($("#copyr_convertif").prop('checked'));
|
1299
|
document.getElementById('mainform').submit();
|
1300
|
});
|
1301
|
|
1302
|
$("#cancel_copyr").click(function() {
|
1303
|
$("#rulescopy").modal('hide');
|
1304
|
});
|
1305
|
|
1306
|
});
|
1307
|
//]]>
|
1308
|
</script>
|
1309
|
|
1310
|
<?php include("foot.inc");?>
|