1
|
<?php
|
2
|
/*
|
3
|
firewall_rules.php
|
4
|
*/
|
5
|
/* ====================================================================
|
6
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
7
|
*
|
8
|
* Some or all of this file is based on the m0n0wall project which is
|
9
|
* Copyright (c) 2004 Manuel Kasper (BSD 2 clause)
|
10
|
*
|
11
|
* Redistribution and use in source and binary forms, with or without modification,
|
12
|
* are permitted provided that the following conditions are met:
|
13
|
*
|
14
|
* 1. Redistributions of source code must retain the above copyright notice,
|
15
|
* this list of conditions and the following disclaimer.
|
16
|
*
|
17
|
* 2. Redistributions in binary form must reproduce the above copyright
|
18
|
* notice, this list of conditions and the following disclaimer in
|
19
|
* the documentation and/or other materials provided with the
|
20
|
* distribution.
|
21
|
*
|
22
|
* 3. All advertising materials mentioning features or use of this software
|
23
|
* must display the following acknowledgment:
|
24
|
* "This product includes software developed by the pfSense Project
|
25
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
26
|
*
|
27
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
28
|
* endorse or promote products derived from this software without
|
29
|
* prior written permission. For written permission, please contact
|
30
|
* coreteam@pfsense.org.
|
31
|
*
|
32
|
* 5. Products derived from this software may not be called "pfSense"
|
33
|
* nor may "pfSense" appear in their names without prior written
|
34
|
* permission of the Electric Sheep Fencing, LLC.
|
35
|
*
|
36
|
* 6. Redistributions of any form whatsoever must retain the following
|
37
|
* acknowledgment:
|
38
|
*
|
39
|
* "This product includes software developed by the pfSense Project
|
40
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
41
|
*
|
42
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
43
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
44
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
45
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
46
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
47
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
48
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
49
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
50
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
51
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
52
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
53
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
54
|
*
|
55
|
* ====================================================================
|
56
|
*
|
57
|
*/
|
58
|
|
59
|
##|+PRIV
|
60
|
##|*IDENT=page-firewall-rules
|
61
|
##|*NAME=Firewall: Rules
|
62
|
##|*DESCR=Allow access to the 'Firewall: Rules' page.
|
63
|
##|*MATCH=firewall_rules.php*
|
64
|
##|-PRIV
|
65
|
|
66
|
require("guiconfig.inc");
|
67
|
require_once("functions.inc");
|
68
|
require_once("filter.inc");
|
69
|
require_once("ipsec.inc");
|
70
|
require_once("shaper.inc");
|
71
|
|
72
|
$pgtitle = array(gettext("Firewall"), gettext("Rules"));
|
73
|
$shortcut_section = "firewall";
|
74
|
|
75
|
function get_pf_rules($rules, $tracker) {
|
76
|
|
77
|
if ($rules == NULL || !is_array($rules))
|
78
|
return (NULL);
|
79
|
|
80
|
$arr = array();
|
81
|
for ($i = 0; $i < count($rules); $i++) {
|
82
|
if ($rules[$i]['tracker'] === $tracker)
|
83
|
$arr[] = $rules[$i];
|
84
|
}
|
85
|
|
86
|
if (count($arr) == 0)
|
87
|
return (NULL);
|
88
|
|
89
|
return ($arr);
|
90
|
}
|
91
|
|
92
|
function print_states($tracker) {
|
93
|
global $rulescnt;
|
94
|
|
95
|
$rulesid = "";
|
96
|
$bytes = 0;
|
97
|
$states = 0;
|
98
|
$packets = 0;
|
99
|
$evaluations = 0;
|
100
|
$stcreations = 0;
|
101
|
$rules = get_pf_rules($rulescnt, $tracker);
|
102
|
for ($j = 0; is_array($rules) && $j < count($rules); $j++) {
|
103
|
$bytes += $rules[$j]['bytes'];
|
104
|
$states += $rules[$j]['states'];
|
105
|
$packets += $rules[$j]['packets'];
|
106
|
$evaluations += $rules[$j]['evaluations'];
|
107
|
$stcreations += $rules[$j]['state creations'];
|
108
|
if (strlen($rulesid) > 0)
|
109
|
$rulesid .= ",";
|
110
|
$rulesid .= "{$rules[$j]['id']}";
|
111
|
}
|
112
|
printf("<a href=\"diag_dump_states.php?ruleid=%s\" data-toggle=\"popover\" data-trigger=\"hover focus\" title=\"%s\" ",
|
113
|
$rulesid, gettext("States details"));
|
114
|
printf("data-content=\"evaluations: %s<br>packets: %s<br>bytes: %s<br>states: %s<br>state creations: %s\" data-html=\"true\">",
|
115
|
format_number($evaluations), format_number($packets), format_bytes($bytes),
|
116
|
format_number($states), format_number($stcreations));
|
117
|
printf("%d/%s</a><br>", format_number($states), format_bytes($bytes));
|
118
|
}
|
119
|
|
120
|
function delete_nat_association($id) {
|
121
|
global $config;
|
122
|
|
123
|
if (!$id || !is_array($config['nat']['rule'])) {
|
124
|
return;
|
125
|
}
|
126
|
|
127
|
$a_nat = &$config['nat']['rule'];
|
128
|
|
129
|
foreach ($a_nat as &$natent) {
|
130
|
if ($natent['associated-rule-id'] == $id) {
|
131
|
$natent['associated-rule-id'] = '';
|
132
|
}
|
133
|
}
|
134
|
}
|
135
|
|
136
|
if (!is_array($config['filter']['rule'])) {
|
137
|
$config['filter']['rule'] = array();
|
138
|
}
|
139
|
|
140
|
filter_rules_sort();
|
141
|
$a_filter = &$config['filter']['rule'];
|
142
|
|
143
|
$if = $_GET['if'];
|
144
|
|
145
|
if ($_POST['if']) {
|
146
|
$if = $_POST['if'];
|
147
|
}
|
148
|
|
149
|
$ifdescs = get_configured_interface_with_descr();
|
150
|
|
151
|
/* add group interfaces */
|
152
|
if (is_array($config['ifgroups']['ifgroupentry'])) {
|
153
|
foreach ($config['ifgroups']['ifgroupentry'] as $ifgen) {
|
154
|
if (have_ruleint_access($ifgen['ifname'])) {
|
155
|
$iflist[$ifgen['ifname']] = $ifgen['ifname'];
|
156
|
}
|
157
|
}
|
158
|
}
|
159
|
|
160
|
foreach ($ifdescs as $ifent => $ifdesc) {
|
161
|
if (have_ruleint_access($ifent)) {
|
162
|
$iflist[$ifent] = $ifdesc;
|
163
|
}
|
164
|
}
|
165
|
|
166
|
if ($config['l2tp']['mode'] == "server") {
|
167
|
if (have_ruleint_access("l2tp")) {
|
168
|
$iflist['l2tp'] = gettext("L2TP VPN");
|
169
|
}
|
170
|
}
|
171
|
|
172
|
if (is_array($config['pppoes']['pppoe'])) {
|
173
|
foreach ($config['pppoes']['pppoe'] as $pppoes) {
|
174
|
if (($pppoes['mode'] == 'server') && have_ruleint_access("pppoe")) {
|
175
|
$iflist['pppoe'] = gettext("PPPoE Server");
|
176
|
}
|
177
|
}
|
178
|
}
|
179
|
|
180
|
/* add ipsec interfaces */
|
181
|
if (ipsec_enabled() && have_ruleint_access("enc0")) {
|
182
|
$iflist["enc0"] = gettext("IPsec");
|
183
|
}
|
184
|
|
185
|
/* add openvpn/tun interfaces */
|
186
|
if ($config['openvpn']["openvpn-server"] || $config['openvpn']["openvpn-client"]) {
|
187
|
$iflist["openvpn"] = gettext("OpenVPN");
|
188
|
}
|
189
|
|
190
|
if (!$if || !isset($iflist[$if])) {
|
191
|
if ("any" == $if) {
|
192
|
$if = "FloatingRules";
|
193
|
} else if ("FloatingRules" != $if) {
|
194
|
if (isset($iflist['wan'])) {
|
195
|
$if = "wan";
|
196
|
} else {
|
197
|
$if = "FloatingRules";
|
198
|
}
|
199
|
}
|
200
|
}
|
201
|
|
202
|
if ($_POST) {
|
203
|
$pconfig = $_POST;
|
204
|
|
205
|
if ($_POST['apply']) {
|
206
|
$retval = 0;
|
207
|
$retval = filter_configure();
|
208
|
|
209
|
clear_subsystem_dirty('filter');
|
210
|
|
211
|
$savemsg = sprintf(gettext("The settings have been applied. The firewall rules are now reloading in the background.<br />You can also %s monitor %s the reload progress"),
|
212
|
"<a href='status_filter_reload.php'>", "</a>");
|
213
|
}
|
214
|
}
|
215
|
|
216
|
if ($_GET['act'] == "del") {
|
217
|
if ($a_filter[$_GET['id']]) {
|
218
|
if (!empty($a_filter[$_GET['id']]['associated-rule-id'])) {
|
219
|
delete_nat_association($a_filter[$_GET['id']]['associated-rule-id']);
|
220
|
}
|
221
|
unset($a_filter[$_GET['id']]);
|
222
|
|
223
|
// Update the separators
|
224
|
$a_separators = &$config['filter']['separator'][$if];
|
225
|
|
226
|
for ($idx=0; isset($a_separators['sep' . $idx]); $idx++ ) {
|
227
|
$seprow = substr($a_separators['sep' . $idx]['row']['0'], 2);
|
228
|
if ($seprow >= $_GET['id']) {
|
229
|
$a_separators['sep' . $idx]['row']['0'] = 'fr' . ($seprow - 1);
|
230
|
}
|
231
|
}
|
232
|
|
233
|
if (write_config()) {
|
234
|
mark_subsystem_dirty('filter');
|
235
|
}
|
236
|
|
237
|
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
|
238
|
exit;
|
239
|
}
|
240
|
}
|
241
|
|
242
|
// Handle save msg if defined
|
243
|
if ($_REQUEST['savemsg']) {
|
244
|
$savemsg = htmlentities($_REQUEST['savemsg']);
|
245
|
}
|
246
|
|
247
|
if (isset($_POST['del_x'])) {
|
248
|
/* delete selected rules */
|
249
|
$deleted = false;
|
250
|
|
251
|
if (is_array($_POST['rule']) && count($_POST['rule'])) {
|
252
|
$a_separators = &$config['filter']['separator'][$if];
|
253
|
|
254
|
foreach ($_POST['rule'] as $rulei) {
|
255
|
delete_nat_association($a_filter[$rulei]['associated-rule-id']);
|
256
|
unset($a_filter[$rulei]);
|
257
|
$deleted = true;
|
258
|
|
259
|
// Update the separators
|
260
|
for ($idx=0; isset($a_separators['sep' . $idx]); $idx++ ) {
|
261
|
$seprow = substr($a_separators['sep' . $idx]['row']['0'], 2);
|
262
|
if ($seprow >= $rulei) {
|
263
|
$a_separators['sep' . $idx]['row']['0'] = 'fr' . ($seprow - 1);
|
264
|
}
|
265
|
}
|
266
|
}
|
267
|
|
268
|
if ($deleted) {
|
269
|
if (write_config()) {
|
270
|
mark_subsystem_dirty('filter');
|
271
|
}
|
272
|
}
|
273
|
|
274
|
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
|
275
|
exit;
|
276
|
}
|
277
|
} else if ($_GET['act'] == "toggle") {
|
278
|
if ($a_filter[$_GET['id']]) {
|
279
|
if (isset($a_filter[$_GET['id']]['disabled'])) {
|
280
|
unset($a_filter[$_GET['id']]['disabled']);
|
281
|
} else {
|
282
|
$a_filter[$_GET['id']]['disabled'] = true;
|
283
|
}
|
284
|
if (write_config()) {
|
285
|
mark_subsystem_dirty('filter');
|
286
|
}
|
287
|
|
288
|
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
|
289
|
exit;
|
290
|
}
|
291
|
} else if ($_POST['order-store']) {
|
292
|
|
293
|
/* update rule order, POST[rule] is an array of ordered IDs */
|
294
|
if (is_array($_POST['rule']) && !empty($_POST['rule'])) {
|
295
|
$a_filter_new = array();
|
296
|
|
297
|
// if a rule is not in POST[rule], it has been deleted by the user
|
298
|
foreach ($_POST['rule'] as $id) {
|
299
|
$a_filter_new[] = $a_filter[$id];
|
300
|
}
|
301
|
|
302
|
$a_filter = $a_filter_new;
|
303
|
|
304
|
$config['filter']['separator'][strtolower($if)] = "";
|
305
|
|
306
|
if ($_POST['separator']) {
|
307
|
$idx = 0;
|
308
|
foreach ($_POST['separator'] as $separator) {
|
309
|
$config['filter']['separator'][strtolower($separator['if'])]['sep' . $idx++] = $separator;
|
310
|
}
|
311
|
}
|
312
|
|
313
|
if (write_config()) {
|
314
|
mark_subsystem_dirty('filter');
|
315
|
}
|
316
|
|
317
|
header("Location: firewall_rules.php?if=" . htmlspecialchars($if));
|
318
|
exit;
|
319
|
}
|
320
|
}
|
321
|
|
322
|
$tab_array = array(array(gettext("Floating"), ("FloatingRules" == $if), "firewall_rules.php?if=FloatingRules"));
|
323
|
|
324
|
foreach ($iflist as $ifent => $ifname) {
|
325
|
$tab_array[] = array($ifname, ($ifent == $if), "firewall_rules.php?if={$ifent}");
|
326
|
}
|
327
|
|
328
|
foreach ($tab_array as $dtab) {
|
329
|
if ($dtab[1]) {
|
330
|
$bctab = $dtab[0];
|
331
|
break;
|
332
|
}
|
333
|
}
|
334
|
|
335
|
$pgtitle = array(gettext("Firewall"), gettext("Rules"), $bctab);
|
336
|
$shortcut_section = "firewall";
|
337
|
|
338
|
include("head.inc");
|
339
|
$nrules = 0;
|
340
|
|
341
|
if ($savemsg) {
|
342
|
print_info_box($savemsg, 'success');
|
343
|
}
|
344
|
|
345
|
if (is_subsystem_dirty('filter')) {
|
346
|
print_apply_box(gettext("The firewall rule configuration has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));
|
347
|
}
|
348
|
|
349
|
display_top_tabs($tab_array);
|
350
|
|
351
|
$showantilockout = false;
|
352
|
$showprivate = false;
|
353
|
$showblockbogons = false;
|
354
|
|
355
|
if (!isset($config['system']['webgui']['noantilockout']) &&
|
356
|
(((count($config['interfaces']) > 1) && ($if == 'lan')) ||
|
357
|
((count($config['interfaces']) == 1) && ($if == 'wan')))) {
|
358
|
$showantilockout = true;
|
359
|
}
|
360
|
|
361
|
if (isset($config['interfaces'][$if]['blockpriv'])) {
|
362
|
$showprivate = true;
|
363
|
}
|
364
|
|
365
|
if (isset($config['interfaces'][$if]['blockbogons'])) {
|
366
|
$showblockbogons = true;
|
367
|
}
|
368
|
|
369
|
/* Load the counter data of each pf rule. */
|
370
|
$rulescnt = pfSense_get_pf_rules();
|
371
|
|
372
|
// Update this if you add or remove columns!
|
373
|
$columns_in_table = 13;
|
374
|
|
375
|
?>
|
376
|
<form method="post">
|
377
|
<div class="panel panel-default">
|
378
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Rules (Drag to change order)")?></h2></div>
|
379
|
<div id="mainarea" class="table-responsive panel-body">
|
380
|
<table id="ruletable" class="table table-hover table-striped table-condensed">
|
381
|
<thead>
|
382
|
<tr>
|
383
|
<th><!-- checkbox --></th>
|
384
|
<th><!-- status icons --></th>
|
385
|
<th><?=gettext("States")?></th>
|
386
|
<th><?=gettext("Protocol")?></th>
|
387
|
<th><?=gettext("Source")?></th>
|
388
|
<th><?=gettext("Port")?></th>
|
389
|
<th><?=gettext("Destination")?></th>
|
390
|
<th><?=gettext("Port")?></th>
|
391
|
<th><?=gettext("Gateway")?></th>
|
392
|
<th><?=gettext("Queue")?></th>
|
393
|
<th><?=gettext("Schedule")?></th>
|
394
|
<th><?=gettext("Description")?></th>
|
395
|
<th><?=gettext("Actions")?></th>
|
396
|
</tr>
|
397
|
</thead>
|
398
|
|
399
|
<?php if ($showblockbogons || $showantilockout || $showprivate) :
|
400
|
?>
|
401
|
<tbody>
|
402
|
<?php
|
403
|
// 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.
|
404
|
if ($showantilockout):
|
405
|
$alports = implode('<br />', filter_get_antilockout_ports(true));
|
406
|
?>
|
407
|
<tr id="antilockout">
|
408
|
<td></td>
|
409
|
<td title="<?=gettext("traffic is passed")?>"><i class="fa fa-check text-success"></i></td>
|
410
|
<td><?php print_states(intval(ANTILOCKOUT_TRACKER)); ?></td>
|
411
|
<td>*</td>
|
412
|
<td>*</td>
|
413
|
<td>*</td>
|
414
|
<td><?=$iflist[$if];?> Address</td>
|
415
|
<td><?=$alports?></td>
|
416
|
<td>*</td>
|
417
|
<td>*</td>
|
418
|
<td></td>
|
419
|
<td><?=gettext("Anti-Lockout Rule");?></td>
|
420
|
<td>
|
421
|
<a href="system_advanced_admin.php" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
|
422
|
</td>
|
423
|
</tr>
|
424
|
<?php endif;?>
|
425
|
<?php if ($showprivate): ?>
|
426
|
<tr id="frrfc1918">
|
427
|
<td></td>
|
428
|
<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
|
429
|
<td><?php print_states(intval(RFC1918_TRACKER)); ?></td>
|
430
|
<td>*</td>
|
431
|
<td><?=gettext("RFC 1918 networks");?></td>
|
432
|
<td>*</td>
|
433
|
<td>*</td>
|
434
|
<td>*</td>
|
435
|
<td>*</td>
|
436
|
<td>*</td>
|
437
|
<td></td>
|
438
|
<td><?=gettext("Block private networks");?></td>
|
439
|
<td>
|
440
|
<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
|
441
|
</td>
|
442
|
</tr>
|
443
|
<?php endif;?>
|
444
|
<?php if ($showblockbogons): ?>
|
445
|
<tr id="frrfc1918">
|
446
|
<td></td>
|
447
|
<td title="<?=gettext("traffic is blocked")?>"><i class="fa fa-times text-danger"></i></td>
|
448
|
<td><?php print_states(intval(BOGONS_TRACKER)); ?></td>
|
449
|
<td>*</td>
|
450
|
<td><?=sprintf(gettext("Reserved%sNot assigned by IANA"), "<br />");?></td>
|
451
|
<td>*</td>
|
452
|
<td>*</td>
|
453
|
<td>*</td>
|
454
|
<td>*</td>
|
455
|
<td>*</td>
|
456
|
<td></td>
|
457
|
<td><?=gettext("Block bogon networks");?></td>
|
458
|
<td>
|
459
|
<a href="interfaces.php?if=<?=htmlspecialchars($if)?>" title="<?=gettext("Settings");?>"><i class="fa fa-cog"></i></a>
|
460
|
</td>
|
461
|
</tr>
|
462
|
<?php endif;?>
|
463
|
</tbody>
|
464
|
<?php endif;?>
|
465
|
<tbody class="user-entries">
|
466
|
<?php
|
467
|
$nrules = 0;
|
468
|
$seps = 0;
|
469
|
|
470
|
// There can be a separator before any rules are listed
|
471
|
if ($config['filter']['separator'][strtolower($if)]['sep0']['row'][0] == "fr-1") {
|
472
|
$cellcolor = $config['filter']['separator'][strtolower($if)]['sep0']['color'];
|
473
|
print('<tr class="ui-sortable-handle separator">' .
|
474
|
'<td class="' . $cellcolor . '" colspan="' . ($columns_in_table -1) . '">' . '<span class="' . $cellcolor . '">' . $config['filter']['separator'][strtolower($if)]['sep0']['text'] . '</span></td>' .
|
475
|
'<td class="' . $cellcolor . '"><a href="#"><i class="fa fa-trash no-confirm sepdel" title="delete this separator"></i></a></td>' .
|
476
|
'</tr>' . "\n");
|
477
|
}
|
478
|
|
479
|
for ($i = 0; isset($a_filter[$i]); $i++):
|
480
|
$filterent = $a_filter[$i];
|
481
|
|
482
|
if (($filterent['interface'] != $if && !isset($filterent['floating'])) || (isset($filterent['floating']) && "FloatingRules" != $if)) {
|
483
|
$display = 'style="display: none;"';
|
484
|
} else {
|
485
|
$display = "";
|
486
|
}
|
487
|
|
488
|
?>
|
489
|
<tr id="fr<?=$nrules;?>" <?=$display?> onClick="fr_toggle(<?=$nrules;?>)" ondblclick="document.location='firewall_rules_edit.php?id=<?=$i;?>';" <?=(isset($filterent['disabled']) ? ' class="disabled"' : '')?>>
|
490
|
<td>
|
491
|
<input type="checkbox" id="frc<?=$nrules;?>" onClick="fr_toggle(<?=$nrules;?>)" name="rule[]" value="<?=$i;?>"/>
|
492
|
</td>
|
493
|
|
494
|
<?php
|
495
|
if ($filterent['type'] == "block") {
|
496
|
$iconfn = "times text-danger";
|
497
|
$title_text = gettext("traffic is blocked");
|
498
|
} else if ($filterent['type'] == "reject") {
|
499
|
$iconfn = "hand-stop-o text-warning";
|
500
|
$title_text = gettext("traffic is rejected");
|
501
|
} else if ($filterent['type'] == "match") {
|
502
|
$iconfn = "filter";
|
503
|
$title_text = gettext("traffic is matched");
|
504
|
} else {
|
505
|
$iconfn = "check text-success";
|
506
|
$title_text = gettext("traffic is passed");
|
507
|
}
|
508
|
?>
|
509
|
<td title="<?=$title_text?>">
|
510
|
|
511
|
<i class="fa fa-<?=$iconfn?>"></i>
|
512
|
<?php
|
513
|
$isadvset = firewall_check_for_advanced_options($filterent);
|
514
|
if ($isadvset) {
|
515
|
print '<i class="fa fa-cog" title="'. gettext("advanced setting") .': '. $isadvset .'"></i>';
|
516
|
}
|
517
|
|
518
|
if (isset($filterent['log'])) {
|
519
|
print '<i class="fa fa-tasks" title="'. gettext("traffic is logged") .'"></i>';
|
520
|
}
|
521
|
?>
|
522
|
</td>
|
523
|
<?php
|
524
|
$alias = rule_columns_with_alias(
|
525
|
$filterent['source']['address'],
|
526
|
pprint_port($filterent['source']['port']),
|
527
|
$filterent['destination']['address'],
|
528
|
pprint_port($filterent['destination']['port'])
|
529
|
);
|
530
|
|
531
|
//build Schedule popup box
|
532
|
$a_schedules = &$config['schedules']['schedule'];
|
533
|
$schedule_span_begin = "";
|
534
|
$schedule_span_end = "";
|
535
|
$sched_caption_escaped = "";
|
536
|
$sched_content = "";
|
537
|
$schedstatus = false;
|
538
|
$dayArray = array (gettext('Mon'), gettext('Tues'), gettext('Wed'), gettext('Thur'), gettext('Fri'), gettext('Sat'), gettext('Sun'));
|
539
|
$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'));
|
540
|
if ($config['schedules']['schedule'] != "" && is_array($config['schedules']['schedule'])) {
|
541
|
$idx = 0;
|
542
|
foreach ($a_schedules as $schedule) {
|
543
|
if ($schedule['name'] == $filterent['sched']) {
|
544
|
$schedstatus = filter_get_time_based_rule_status($schedule);
|
545
|
|
546
|
foreach ($schedule['timerange'] as $timerange) {
|
547
|
$tempFriendlyTime = "";
|
548
|
$tempID = "";
|
549
|
$firstprint = false;
|
550
|
if ($timerange) {
|
551
|
$dayFriendly = "";
|
552
|
$tempFriendlyTime = "";
|
553
|
|
554
|
//get hours
|
555
|
$temptimerange = $timerange['hour'];
|
556
|
$temptimeseparator = strrpos($temptimerange, "-");
|
557
|
|
558
|
$starttime = substr ($temptimerange, 0, $temptimeseparator);
|
559
|
$stoptime = substr ($temptimerange, $temptimeseparator+1);
|
560
|
|
561
|
if ($timerange['month']) {
|
562
|
$tempmontharray = explode(",", $timerange['month']);
|
563
|
$tempdayarray = explode(",", $timerange['day']);
|
564
|
$arraycounter = 0;
|
565
|
$firstDayFound = false;
|
566
|
$firstPrint = false;
|
567
|
foreach ($tempmontharray as $monthtmp) {
|
568
|
$month = $tempmontharray[$arraycounter];
|
569
|
$day = $tempdayarray[$arraycounter];
|
570
|
|
571
|
if (!$firstDayFound) {
|
572
|
$firstDay = $day;
|
573
|
$firstmonth = $month;
|
574
|
$firstDayFound = true;
|
575
|
}
|
576
|
|
577
|
$currentDay = $day;
|
578
|
$nextDay = $tempdayarray[$arraycounter+1];
|
579
|
$currentDay++;
|
580
|
if (($currentDay != $nextDay) || ($tempmontharray[$arraycounter] != $tempmontharray[$arraycounter+1])) {
|
581
|
if ($firstPrint) {
|
582
|
$dayFriendly .= ", ";
|
583
|
}
|
584
|
$currentDay--;
|
585
|
if ($currentDay != $firstDay) {
|
586
|
$dayFriendly .= $monthArray[$firstmonth-1] . " " . $firstDay . " - " . $currentDay ;
|
587
|
} else {
|
588
|
$dayFriendly .= $monthArray[$month-1] . " " . $day;
|
589
|
}
|
590
|
$firstDayFound = false;
|
591
|
$firstPrint = true;
|
592
|
}
|
593
|
$arraycounter++;
|
594
|
}
|
595
|
} else {
|
596
|
$tempdayFriendly = $timerange['position'];
|
597
|
$firstDayFound = false;
|
598
|
$tempFriendlyDayArray = explode(",", $tempdayFriendly);
|
599
|
$currentDay = "";
|
600
|
$firstDay = "";
|
601
|
$nextDay = "";
|
602
|
$counter = 0;
|
603
|
foreach ($tempFriendlyDayArray as $day) {
|
604
|
if ($day != "") {
|
605
|
if (!$firstDayFound) {
|
606
|
$firstDay = $tempFriendlyDayArray[$counter];
|
607
|
$firstDayFound = true;
|
608
|
}
|
609
|
$currentDay =$tempFriendlyDayArray[$counter];
|
610
|
//get next day
|
611
|
$nextDay = $tempFriendlyDayArray[$counter+1];
|
612
|
$currentDay++;
|
613
|
if ($currentDay != $nextDay) {
|
614
|
if ($firstprint) {
|
615
|
$dayFriendly .= ", ";
|
616
|
}
|
617
|
$currentDay--;
|
618
|
if ($currentDay != $firstDay) {
|
619
|
$dayFriendly .= $dayArray[$firstDay-1] . " - " . $dayArray[$currentDay-1];
|
620
|
} else {
|
621
|
$dayFriendly .= $dayArray[$firstDay-1];
|
622
|
}
|
623
|
$firstDayFound = false;
|
624
|
$firstprint = true;
|
625
|
}
|
626
|
$counter++;
|
627
|
}
|
628
|
}
|
629
|
}
|
630
|
$timeFriendly = $starttime . " - " . $stoptime;
|
631
|
$description = $timerange['rangedescr'];
|
632
|
$sched_content .= $dayFriendly . "; " . $timeFriendly . "<br />";
|
633
|
}
|
634
|
}
|
635
|
#FIXME
|
636
|
$sched_caption_escaped = str_replace("'", "\'", $schedule['descr']);
|
637
|
$schedule_span_begin = '<a href="/firewall_schedule_edit.php?id=' . $idx . '" data-toggle="popover" data-trigger="hover focus" title="' . $schedule['name'] . '" data-content="' .
|
638
|
$sched_caption_escaped . '" data-html="true">';
|
639
|
$schedule_span_end = "</a>";
|
640
|
}
|
641
|
}
|
642
|
$idx++;
|
643
|
}
|
644
|
$printicon = false;
|
645
|
$alttext = "";
|
646
|
$image = "";
|
647
|
if (!isset($filterent['disabled'])) {
|
648
|
if ($schedstatus) {
|
649
|
if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
|
650
|
$image = "times-circle";
|
651
|
$dispcolor = "text-danger";
|
652
|
$alttext = gettext("Traffic matching this rule is currently being denied");
|
653
|
} else {
|
654
|
$image = "play-circle";
|
655
|
$dispcolor = "text-success";
|
656
|
$alttext = gettext("Traffic matching this rule is currently being allowed");
|
657
|
}
|
658
|
$printicon = true;
|
659
|
} else if ($filterent['sched']) {
|
660
|
if ($filterent['type'] == "block" || $filterent['type'] == "reject") {
|
661
|
$image = "times-circle";
|
662
|
} else {
|
663
|
$image = "play-circle";
|
664
|
}
|
665
|
$alttext = gettext("This rule is not currently active because its period has expired");
|
666
|
$dispcolor = "text-warning";
|
667
|
$printicon = true;
|
668
|
}
|
669
|
}
|
670
|
?>
|
671
|
<td><?php print_states(intval($filterent['tracker'])); ?></td>
|
672
|
<td>
|
673
|
<?php
|
674
|
if (isset($filterent['ipprotocol'])) {
|
675
|
switch ($filterent['ipprotocol']) {
|
676
|
case "inet":
|
677
|
echo "IPv4 ";
|
678
|
break;
|
679
|
case "inet6":
|
680
|
echo "IPv6 ";
|
681
|
break;
|
682
|
case "inet46":
|
683
|
echo "IPv4+6 ";
|
684
|
break;
|
685
|
}
|
686
|
} else {
|
687
|
echo "IPv4 ";
|
688
|
}
|
689
|
|
690
|
if (isset($filterent['protocol'])) {
|
691
|
echo strtoupper($filterent['protocol']);
|
692
|
|
693
|
if (strtoupper($filterent['protocol']) == "ICMP" && !empty($filterent['icmptype'])) {
|
694
|
echo ' <span style="cursor: help;" title="' . gettext('ICMP type') . ': ' .
|
695
|
($filterent['ipprotocol'] == "inet6" ? $icmp6types[$filterent['icmptype']] : $icmptypes[$filterent['icmptype']]) .
|
696
|
'"><u>';
|
697
|
echo $filterent['icmptype'];
|
698
|
echo '</u></span>';
|
699
|
}
|
700
|
} else echo "*";
|
701
|
|
702
|
?>
|
703
|
</td>
|
704
|
<td>
|
705
|
<?php if (isset($alias['src'])): ?>
|
706
|
<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">
|
707
|
<?=htmlspecialchars(pprint_address($filterent['source']))?>
|
708
|
</a>
|
709
|
<?php else: ?>
|
710
|
<?=htmlspecialchars(pprint_address($filterent['source']))?>
|
711
|
<?php endif; ?>
|
712
|
</td>
|
713
|
<td>
|
714
|
<?php if (isset($alias['srcport'])): ?>
|
715
|
<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">
|
716
|
<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
|
717
|
</a>
|
718
|
<?php else: ?>
|
719
|
<?=htmlspecialchars(pprint_port($filterent['source']['port']))?>
|
720
|
<?php endif; ?>
|
721
|
</td>
|
722
|
<td>
|
723
|
<?php if (isset($alias['dst'])): ?>
|
724
|
<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">
|
725
|
<?=htmlspecialchars(pprint_address($filterent['destination']))?>
|
726
|
</a>
|
727
|
<?php else: ?>
|
728
|
<?=htmlspecialchars(pprint_address($filterent['destination']))?>
|
729
|
<?php endif; ?>
|
730
|
</td>
|
731
|
<td>
|
732
|
<?php if (isset($alias['dstport'])): ?>
|
733
|
<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">
|
734
|
<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
|
735
|
</a>
|
736
|
<?php else: ?>
|
737
|
<?=htmlspecialchars(pprint_port($filterent['destination']['port']))?>
|
738
|
<?php endif; ?>
|
739
|
</td>
|
740
|
<td>
|
741
|
<?php if (isset($config['interfaces'][$filterent['gateway']]['descr'])):?>
|
742
|
<?=htmlspecialchars($config['interfaces'][$filterent['gateway']]['descr'])?>
|
743
|
<?php else: ?>
|
744
|
<?=htmlspecialchars(pprint_port($filterent['gateway']))?>
|
745
|
<?php endif; ?>
|
746
|
</td>
|
747
|
<td>
|
748
|
<?php
|
749
|
if (isset($filterent['ackqueue']) && isset($filterent['defaultqueue'])) {
|
750
|
$desc = $filterent['ackqueue'] ;
|
751
|
echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['ackqueue']}&action=show\">{$desc}</a>";
|
752
|
$desc = $filterent['defaultqueue'];
|
753
|
echo "/<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&action=show\">{$desc}</a>";
|
754
|
} else if (isset($filterent['defaultqueue'])) {
|
755
|
$desc = $filterent['defaultqueue'];
|
756
|
echo "<a href=\"firewall_shaper_queues.php?queue={$filterent['defaultqueue']}&action=show\">{$desc}</a>";
|
757
|
} else {
|
758
|
echo gettext("none");
|
759
|
}
|
760
|
?>
|
761
|
</td>
|
762
|
<td>
|
763
|
<?php if ($printicon) { ?>
|
764
|
<i class="fa fa-<?=$image?> <?=$dispcolor?>" title="<?=$alttext;?>"></i>
|
765
|
<?php } ?>
|
766
|
<?=$schedule_span_begin;?><?=htmlspecialchars($filterent['sched']);?> <?=$schedule_span_end;?>
|
767
|
</td>
|
768
|
<td>
|
769
|
<?=htmlspecialchars($filterent['descr']);?>
|
770
|
</td>
|
771
|
<td class="action-icons">
|
772
|
<!-- <?=(isset($filterent['disabled']) ? 'enable' : 'disable')?> -->
|
773
|
<a href="firewall_rules_edit.php?id=<?=$i;?>" class="fa fa-pencil" title="<?=gettext('Edit')?>"></a>
|
774
|
<a href="firewall_rules_edit.php?dup=<?=$i;?>" class="fa fa-clone" title="<?=gettext('Copy')?>"></a>
|
775
|
<?php if (isset($filterent['disabled'])) {
|
776
|
?>
|
777
|
<a href="?act=toggle&if=<?=htmlspecialchars($if);?>&id=<?=$i;?>" class="fa fa-check-square-o" title="<?=gettext('Enable')?>"></a>
|
778
|
<?php } else {
|
779
|
?>
|
780
|
<a href="?act=toggle&if=<?=htmlspecialchars($if);?>&id=<?=$i;?>" class="fa fa-ban" title="<?=gettext('Disable')?>"></a>
|
781
|
<?php }
|
782
|
?>
|
783
|
<a href="?act=del&if=<?=htmlspecialchars($if);?>&id=<?=$i;?>" class="fa fa-trash" title="<?=gettext('Delete this rule')?>"></a>
|
784
|
</td>
|
785
|
</tr>
|
786
|
<?php
|
787
|
if (isset($config['filter']['separator'][strtolower($if)]['sep0'])) {
|
788
|
foreach ($config['filter']['separator'][strtolower($if)] as $rulesep) {
|
789
|
if ($rulesep['row']['0'] == "fr" . $nrules) {
|
790
|
$cellcolor = $rulesep['color'];
|
791
|
print('<tr class="ui-sortable-handle separator">' .
|
792
|
'<td class="' . $cellcolor . '" colspan="' . ($columns_in_table -1) . '">' . '<span class="' . $cellcolor . '">' . $rulesep['text'] . '</span></td>' .
|
793
|
'<td class="' . $cellcolor . '"><a href="#"><i class="fa fa-trash no-confirm sepdel" title="delete this separator"></i></a></td>' .
|
794
|
'</tr>' . "\n");
|
795
|
}
|
796
|
}
|
797
|
}
|
798
|
|
799
|
$nrules++;
|
800
|
endfor;
|
801
|
?>
|
802
|
</tbody>
|
803
|
</table>
|
804
|
</div>
|
805
|
</div>
|
806
|
|
807
|
<?php if ($nrules == 0): ?>
|
808
|
<div class="alert alert-warning" role="alert">
|
809
|
<p>
|
810
|
<?php if ($_REQUEST['if'] == "FloatingRules"): ?>
|
811
|
<?=gettext("No floating rules are currently defined.");?>
|
812
|
<?php else: ?>
|
813
|
<?=gettext("No rules are currently defined for this interface");?><br />
|
814
|
<?=gettext("All incoming connections on this interface will be blocked until you add pass rules.");?>
|
815
|
<?php endif;?>
|
816
|
<?=gettext("Click the button to add a new rule.");?>
|
817
|
</p>
|
818
|
</div>
|
819
|
<?php endif;?>
|
820
|
|
821
|
<nav class="action-buttons">
|
822
|
<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')?>">
|
823
|
<i class="fa fa-level-up icon-embed-btn"></i>
|
824
|
<?=gettext("Add");?>
|
825
|
</a>
|
826
|
<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')?>">
|
827
|
<i class="fa fa-level-down icon-embed-btn"></i>
|
828
|
<?=gettext("Add");?>
|
829
|
</a>
|
830
|
<button name="del_x" type="submit" class="btn btn-danger btn-sm" value="<?=gettext("Delete selected rules"); ?>" title="<?=gettext('Delete selected rules')?>">
|
831
|
<i class="fa fa-trash icon-embed-btn"></i>
|
832
|
<?=gettext("Delete"); ?>
|
833
|
</button>
|
834
|
<button type="submit" id="order-store" name="order-store" class="btn btn-sm btn-primary" value="store changes" disabled title="<?=gettext('Save rule order')?>">
|
835
|
<i class="fa fa-save icon-embed-btn"></i>
|
836
|
<?=gettext("Save")?>
|
837
|
</button>
|
838
|
<button type="submit" id="addsep" name="addsep" class="btn btn-sm btn-warning" title="<?=gettext('Add separator')?>">
|
839
|
<i class="fa fa-plus icon-embed-btn"></i>
|
840
|
<?=gettext("Separator")?>
|
841
|
</button>
|
842
|
</nav>
|
843
|
</form>
|
844
|
|
845
|
<div class="infoblock">
|
846
|
<div class="alert alert-info clearfix" role="alert"><div class="pull-left">
|
847
|
<dl class="dl-horizontal responsive">
|
848
|
<!-- Legend -->
|
849
|
<dt><?=gettext('Legend')?></dt> <dd></dd>
|
850
|
<dt><i class="fa fa-check text-success"></i></dt> <dd><?=gettext("Pass");?></dd>
|
851
|
<dt><i class="fa fa-filter"></i></dt> <dd><?=gettext("Match");?></dd>
|
852
|
<dt><i class="fa fa-times text-danger"></i></dt> <dd><?=gettext("Block");?></dd>
|
853
|
<dt><i class="fa fa-hand-stop-o text-warning"></i></dt> <dd><?=gettext("Reject");?></dd>
|
854
|
<dt><i class="fa fa-tasks"></i></dt> <dd> <?=gettext("Log");?></dd>
|
855
|
<dt><i class="fa fa-cog"></i></dt> <dd> <?=gettext("Advanced filter");?></dd>
|
856
|
</dl>
|
857
|
|
858
|
<?php
|
859
|
if ("FloatingRules" != $if) {
|
860
|
print(gettext("Rules are evaluated on a first-match basis (i.e. " .
|
861
|
"the action of the first rule to match a packet will be executed). ") . '<br />' .
|
862
|
gettext("This means that if you use block rules, you'll have to pay attention " .
|
863
|
"to the rule order. Everything that isn't explicitly passed is blocked " .
|
864
|
"by default. "));
|
865
|
} else {
|
866
|
print(gettext("Floating rules are evaluated on a first-match basis (i.e. " .
|
867
|
"the action of the first rule to match a packet will be executed) only " .
|
868
|
"if the 'quick' option is checked on a rule. Otherwise they will only match if no " .
|
869
|
"other rules match. Pay close attention to the rule order and options " .
|
870
|
"chosen. If no rule here matches, the per-interface or default rules are used. "));
|
871
|
}
|
872
|
?>
|
873
|
</div>
|
874
|
</div>
|
875
|
</div>
|
876
|
|
877
|
<script type="text/javascript">
|
878
|
//<![CDATA[
|
879
|
|
880
|
//Need to create some variables here so that jquery/pfSenseHelpers.js can read them
|
881
|
iface = "<?=strtolower($if)?>";
|
882
|
cncltxt = '<?=gettext("Cancel")?>';
|
883
|
svtxt = '<?=gettext("Save")?>';
|
884
|
svbtnplaceholder = '<?=gettext("Enter a description, Save, then drag to final location.")?>';
|
885
|
configsection = "filter";
|
886
|
|
887
|
events.push(function() {
|
888
|
|
889
|
// Make rules sortable. Hiding the table before applying sortable, then showing it again is
|
890
|
// a work-around for very slow sorting on FireFox
|
891
|
$('table tbody.user-entries').hide();
|
892
|
|
893
|
$('table tbody.user-entries').sortable({
|
894
|
cursor: 'grabbing',
|
895
|
update: function(event, ui) {
|
896
|
$('#order-store').removeAttr('disabled');
|
897
|
reindex_rules(ui.item.parent('tbody'));
|
898
|
dirty = true;
|
899
|
}
|
900
|
});
|
901
|
|
902
|
$('table tbody.user-entries').show();
|
903
|
|
904
|
// Check all of the rule checkboxes so that their values are posted
|
905
|
$('#order-store').click(function () {
|
906
|
$('[id^=frc]').prop('checked', true);
|
907
|
|
908
|
// Save the separator bar configuration
|
909
|
save_separators();
|
910
|
|
911
|
// Suppress the "Do you really want to leave the page" message
|
912
|
saving = true;
|
913
|
});
|
914
|
|
915
|
// provide a warning message if the user tries to change page before saving
|
916
|
$(window).bind('beforeunload', function(){
|
917
|
if ((!saving && dirty) || newSeperator) {
|
918
|
return ("<?=gettext('You have moved one or more rules but have not yet saved')?>");
|
919
|
} else {
|
920
|
return undefined;
|
921
|
}
|
922
|
});
|
923
|
|
924
|
});
|
925
|
//]]>
|
926
|
</script>
|
927
|
|
928
|
<?php include("foot.inc");?>
|