1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
|
|
/*
|
3 |
c5d81585
|
Renato Botelho
|
* firewall_aliases.php
|
4 |
9da2cf1c
|
Stephen Beaver
|
*
|
5 |
c5d81585
|
Renato Botelho
|
* part of pfSense (https://www.pfsense.org)
|
6 |
38809d47
|
Renato Botelho do Couto
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7 |
|
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8 |
402c98a2
|
Reid Linnemann
|
* Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
|
9 |
c5d81585
|
Renato Botelho
|
* All rights reserved.
|
10 |
fd9ebcd5
|
Stephen Beaver
|
*
|
11 |
c5d81585
|
Renato Botelho
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
12 |
|
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
13 |
|
|
* All rights reserved.
|
14 |
fd9ebcd5
|
Stephen Beaver
|
*
|
15 |
b12ea3fb
|
Renato Botelho
|
* 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 |
fd9ebcd5
|
Stephen Beaver
|
*
|
19 |
b12ea3fb
|
Renato Botelho
|
* http://www.apache.org/licenses/LICENSE-2.0
|
20 |
fd9ebcd5
|
Stephen Beaver
|
*
|
21 |
b12ea3fb
|
Renato Botelho
|
* 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 |
fd9ebcd5
|
Stephen Beaver
|
*/
|
27 |
5b237745
|
Scott Ullrich
|
|
28 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
29 |
|
|
##|*IDENT=page-firewall-aliases
|
30 |
5230f468
|
jim-p
|
##|*NAME=Firewall: Aliases
|
31 |
6b07c15a
|
Matthew Grooms
|
##|*DESCR=Allow access to the 'Firewall: Aliases' page.
|
32 |
|
|
##|*MATCH=firewall_aliases.php*
|
33 |
|
|
##|-PRIV
|
34 |
|
|
|
35 |
c81ef6e2
|
Phil Davis
|
require_once("guiconfig.inc");
|
36 |
7a927e67
|
Scott Ullrich
|
require_once("functions.inc");
|
37 |
|
|
require_once("filter.inc");
|
38 |
|
|
require_once("shaper.inc");
|
39 |
be14a369
|
Steve Beaver
|
require_once("alias-utils.inc");
|
40 |
5b237745
|
Scott Ullrich
|
|
41 |
6c07db48
|
Phil Davis
|
$tab = ($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/", "", $_REQUEST['tab']));
|
42 |
5b237745
|
Scott Ullrich
|
|
43 |
d1fd8c3b
|
Steve Beaver
|
if ($_POST['apply']) {
|
44 |
|
|
$retval = 0;
|
45 |
920b3bb0
|
Scott Ullrich
|
|
46 |
d1fd8c3b
|
Steve Beaver
|
/* reload all components that use aliases */
|
47 |
|
|
$retval |= filter_configure();
|
48 |
920b3bb0
|
Scott Ullrich
|
|
49 |
d1fd8c3b
|
Steve Beaver
|
if ($retval == 0) {
|
50 |
|
|
clear_subsystem_dirty('aliases');
|
51 |
5b237745
|
Scott Ullrich
|
}
|
52 |
|
|
}
|
53 |
|
|
|
54 |
d1fd8c3b
|
Steve Beaver
|
|
55 |
|
|
if ($_POST['act'] == "del") {
|
56 |
a903e9a6
|
Steve Beaver
|
$delete_error = deleteAlias($_POST['id']);
|
57 |
c769f983
|
Erik Fonnesbeck
|
|
58 |
a903e9a6
|
Steve Beaver
|
if (strlen($delete_error) == 0) {
|
59 |
|
|
header("Location: firewall_aliases.php?tab=" . $tab);
|
60 |
|
|
exit;
|
61 |
c769f983
|
Erik Fonnesbeck
|
}
|
62 |
|
|
}
|
63 |
|
|
|
64 |
e1515be9
|
Stephen Beaver
|
$tab_array = array();
|
65 |
|
|
$tab_array[] = array(gettext("IP"), ($tab == "ip" ? true : ($tab == "host" ? true : ($tab == "network" ? true : false))), "/firewall_aliases.php?tab=ip");
|
66 |
|
|
$tab_array[] = array(gettext("Ports"), ($tab == "port"? true : false), "/firewall_aliases.php?tab=port");
|
67 |
|
|
$tab_array[] = array(gettext("URLs"), ($tab == "url"? true : false), "/firewall_aliases.php?tab=url");
|
68 |
|
|
$tab_array[] = array(gettext("All"), ($tab == "all"? true : false), "/firewall_aliases.php?tab=all");
|
69 |
|
|
|
70 |
|
|
foreach ($tab_array as $dtab) {
|
71 |
67c2baf1
|
Phil Davis
|
if ($dtab[1] == true) {
|
72 |
e1515be9
|
Stephen Beaver
|
$bctab = $dtab[0];
|
73 |
|
|
break;
|
74 |
|
|
}
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
$pgtitle = array(gettext("Firewall"), gettext("Aliases"), $bctab);
|
78 |
edcd7535
|
Phil Davis
|
$pglinks = array("", "firewall_aliases.php", "@self");
|
79 |
d71fc5d3
|
jim-p
|
$shortcut_section = "aliases";
|
80 |
|
|
|
81 |
b63695db
|
Scott Ullrich
|
include("head.inc");
|
82 |
|
|
|
83 |
44c42356
|
Phil Davis
|
if ($delete_error) {
|
84 |
|
|
print_info_box($delete_error, 'danger');
|
85 |
|
|
}
|
86 |
|
|
if ($_POST['apply']) {
|
87 |
|
|
print_apply_result_box($retval);
|
88 |
67c2baf1
|
Phil Davis
|
}
|
89 |
6cb366de
|
Stephen Beaver
|
|
90 |
67c2baf1
|
Phil Davis
|
if (is_subsystem_dirty('aliases')) {
|
91 |
381ad9f3
|
NOYB
|
print_apply_box(gettext("The alias list has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
|
92 |
67c2baf1
|
Phil Davis
|
}
|
93 |
14726356
|
Sjon Hortensius
|
|
94 |
|
|
display_top_tabs($tab_array);
|
95 |
|
|
|
96 |
5b237745
|
Scott Ullrich
|
?>
|
97 |
b40fb789
|
Colin Fleming
|
|
98 |
|
|
<div class="panel panel-default">
|
99 |
7d95365e
|
Phil Davis
|
<div class="panel-heading"><h2 class="panel-title"><?=sprintf(gettext('Firewall Aliases %s'), $bctab)?></h2></div>
|
100 |
b40fb789
|
Colin Fleming
|
<div class="panel-body">
|
101 |
|
|
|
102 |
0ce45fdf
|
Sander van Leeuwen
|
<div class="table-responsive">
|
103 |
250061b0
|
Stephen Beaver
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
104 |
14726356
|
Sjon Hortensius
|
<thead>
|
105 |
|
|
<tr>
|
106 |
0ce45fdf
|
Sander van Leeuwen
|
<th><?=gettext("Name")?></th>
|
107 |
33cd2690
|
jim-p
|
<th><?=gettext("Type")?></th>
|
108 |
0ce45fdf
|
Sander van Leeuwen
|
<th><?=gettext("Values")?></th>
|
109 |
|
|
<th><?=gettext("Description")?></th>
|
110 |
af5e730b
|
Stephen Beaver
|
<th><?=gettext("Actions")?></th>
|
111 |
14726356
|
Sjon Hortensius
|
</tr>
|
112 |
|
|
</thead>
|
113 |
|
|
<tbody>
|
114 |
|
|
<?php
|
115 |
5c4a6ada
|
jim-p
|
/* Ensure aliases are presented in natural sort order so they are easier to locate.
|
116 |
|
|
* and preserve keys so that the IDs match in the config and the list.
|
117 |
|
|
* https://redmine.pfsense.org/issues/14015 */
|
118 |
|
|
$aliases = get_sorted_aliases();
|
119 |
|
|
|
120 |
29cd08ea
|
Christian McDonald
|
foreach ($aliases as $i => $alias):
|
121 |
|
|
unset($show_alias);
|
122 |
e6f34d22
|
Phil Davis
|
switch ($tab) {
|
123 |
14726356
|
Sjon Hortensius
|
case "all":
|
124 |
|
|
$show_alias= true;
|
125 |
|
|
break;
|
126 |
|
|
case "ip":
|
127 |
|
|
case "host":
|
128 |
|
|
case "network":
|
129 |
67c2baf1
|
Phil Davis
|
if (preg_match("/(host|network)/", $alias["type"])) {
|
130 |
14726356
|
Sjon Hortensius
|
$show_alias= true;
|
131 |
67c2baf1
|
Phil Davis
|
}
|
132 |
14726356
|
Sjon Hortensius
|
break;
|
133 |
|
|
case "url":
|
134 |
67c2baf1
|
Phil Davis
|
if (preg_match("/(url)/i", $alias["type"])) {
|
135 |
14726356
|
Sjon Hortensius
|
$show_alias= true;
|
136 |
67c2baf1
|
Phil Davis
|
}
|
137 |
14726356
|
Sjon Hortensius
|
break;
|
138 |
|
|
case "port":
|
139 |
67c2baf1
|
Phil Davis
|
if ($alias["type"] == "port") {
|
140 |
14726356
|
Sjon Hortensius
|
$show_alias= true;
|
141 |
67c2baf1
|
Phil Davis
|
}
|
142 |
14726356
|
Sjon Hortensius
|
break;
|
143 |
|
|
}
|
144 |
|
|
if ($show_alias):
|
145 |
|
|
?>
|
146 |
|
|
<tr>
|
147 |
f9a2b76d
|
Stephen Beaver
|
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
148 |
14726356
|
Sjon Hortensius
|
<?=htmlspecialchars($alias['name'])?>
|
149 |
|
|
</td>
|
150 |
33cd2690
|
jim-p
|
<td nowrap ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
151 |
|
|
<?=htmlspecialchars($alias_types[$alias['type']])?>
|
152 |
|
|
</td>
|
153 |
f9a2b76d
|
Stephen Beaver
|
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
154 |
14726356
|
Sjon Hortensius
|
<?php
|
155 |
|
|
if ($alias["url"]) {
|
156 |
ac6e07b5
|
jim-p
|
echo htmlspecialchars($alias["url"]) . "<br />";
|
157 |
14726356
|
Sjon Hortensius
|
} else {
|
158 |
e6f34d22
|
Phil Davis
|
if (is_array($alias["aliasurl"])) {
|
159 |
14726356
|
Sjon Hortensius
|
$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
|
160 |
ac6e07b5
|
jim-p
|
echo htmlspecialchars($aliasurls);
|
161 |
d6d46650
|
Steve Beaver
|
if (is_array($aliasurls) && (count($aliasurls) > 10)) {
|
162 |
14726356
|
Sjon Hortensius
|
echo "…<br />";
|
163 |
|
|
}
|
164 |
|
|
echo "<br />\n";
|
165 |
|
|
}
|
166 |
314f7804
|
Viktor G
|
$tmpaddr = explode(" ", $alias['address']);
|
167 |
|
|
if ($alias['type'] == 'host') {
|
168 |
|
|
$tmpaddr = array_map('alias_idn_to_utf8', $tmpaddr);
|
169 |
|
|
}
|
170 |
14726356
|
Sjon Hortensius
|
$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
|
171 |
ac6e07b5
|
jim-p
|
echo htmlspecialchars($addresses);
|
172 |
e6f34d22
|
Phil Davis
|
if (count($tmpaddr) > 10) {
|
173 |
14726356
|
Sjon Hortensius
|
echo '…';
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
?>
|
177 |
|
|
</td>
|
178 |
f9a2b76d
|
Stephen Beaver
|
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
179 |
14726356
|
Sjon Hortensius
|
<?=htmlspecialchars($alias['descr'])?>
|
180 |
|
|
</td>
|
181 |
|
|
<td>
|
182 |
e0cb987c
|
Marcos Mendoza
|
<a class="fa-solid fa-pencil" title="<?=gettext("Edit alias"); ?>" href="firewall_aliases_edit.php?id=<?=$i?>"></a>
|
183 |
32be4696
|
Marcos Mendoza
|
<a class="fa-regular fa-clone" title="<?=gettext('Copy alias')?>" href="firewall_aliases_edit.php?dup=<?=$i;?>" ></a>
|
184 |
|
|
<a class="fa-solid fa-trash-can" title="<?=gettext("Delete alias")?>" href="?act=del&tab=<?=$tab?>&id=<?=$i?>" usepost></a>
|
185 |
df4957e4
|
Stephen Beaver
|
</td>
|
186 |
|
|
</tr>
|
187 |
14726356
|
Sjon Hortensius
|
<?php endif?>
|
188 |
|
|
<?php endforeach?>
|
189 |
|
|
</tbody>
|
190 |
|
|
</table>
|
191 |
0ce45fdf
|
Sander van Leeuwen
|
</div>
|
192 |
5b237745
|
Scott Ullrich
|
|
193 |
ac950976
|
Colin Fleming
|
</div>
|
194 |
|
|
</div>
|
195 |
b40fb789
|
Colin Fleming
|
|
196 |
c10cb196
|
Stephen Beaver
|
<nav class="action-buttons">
|
197 |
84147b7b
|
Steve Beaver
|
<a href="firewall_aliases_edit.php?tab=<?=$tab?>" role="button" class="btn btn-success btn-sm">
|
198 |
e0cb987c
|
Marcos Mendoza
|
<i class="fa-solid fa-plus icon-embed-btn"></i>
|
199 |
df4957e4
|
Stephen Beaver
|
<?=gettext("Add");?>
|
200 |
11486640
|
Sjon Hortensius
|
</a>
|
201 |
e4c784bf
|
Phil Davis
|
<?php
|
202 |
|
|
if (($tab == "ip") || ($tab == "port") || ($tab == "all")):
|
203 |
|
|
?>
|
204 |
84147b7b
|
Steve Beaver
|
<a href="firewall_aliases_import.php?tab=<?=$tab?>" role="button" class="btn btn-primary btn-sm">
|
205 |
e0cb987c
|
Marcos Mendoza
|
<i class="fa-solid fa-upload icon-embed-btn"></i>
|
206 |
df4957e4
|
Stephen Beaver
|
<?=gettext("Import");?>
|
207 |
11486640
|
Sjon Hortensius
|
</a>
|
208 |
e4c784bf
|
Phil Davis
|
<?php
|
209 |
|
|
endif
|
210 |
|
|
?>
|
211 |
11486640
|
Sjon Hortensius
|
</nav>
|
212 |
0f89c125
|
marcelloc
|
|
213 |
df4957e4
|
Stephen Beaver
|
<!-- Information section. Icon ID must be "showinfo" and the information <div> ID must be "infoblock".
|
214 |
|
|
That way jQuery (in pfenseHelpers.js) will automatically take care of the display. -->
|
215 |
|
|
<div>
|
216 |
35681930
|
Stephen Beaver
|
<div class="infoblock">
|
217 |
f6aebbcc
|
NewEraCracker
|
<?php print_info_box(gettext('Aliases act as placeholders for real hosts, networks or ports. They can be used to minimize the number ' .
|
218 |
1a147fcd
|
Phil Davis
|
'of changes that have to be made if a host, network or port changes.') . '<br />' .
|
219 |
|
|
gettext('The name of an alias can be entered instead of the host, network or port where indicated. The alias will be resolved according to the list above.') . '<br />' .
|
220 |
|
|
gettext('If an alias cannot be resolved (e.g. because it was deleted), the corresponding element (e.g. filter/NAT/shaper rule) will be considered invalid and skipped.'), 'info', false); ?>
|
221 |
df4957e4
|
Stephen Beaver
|
</div>
|
222 |
|
|
</div>
|
223 |
0f89c125
|
marcelloc
|
|
224 |
df4957e4
|
Stephen Beaver
|
<?php
|
225 |
5932fc6a
|
heper
|
include("foot.inc");
|