1
|
<?php
|
2
|
/*
|
3
|
* firewall_aliases.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
* Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
|
9
|
* All rights reserved.
|
10
|
*
|
11
|
* originally based on m0n0wall (http://m0n0.ch/wall)
|
12
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
13
|
* All rights reserved.
|
14
|
*
|
15
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
16
|
* you may not use this file except in compliance with the License.
|
17
|
* You may obtain a copy of the License at
|
18
|
*
|
19
|
* http://www.apache.org/licenses/LICENSE-2.0
|
20
|
*
|
21
|
* Unless required by applicable law or agreed to in writing, software
|
22
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
23
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
24
|
* See the License for the specific language governing permissions and
|
25
|
* limitations under the License.
|
26
|
*/
|
27
|
|
28
|
##|+PRIV
|
29
|
##|*IDENT=page-firewall-aliases
|
30
|
##|*NAME=Firewall: Aliases
|
31
|
##|*DESCR=Allow access to the 'Firewall: Aliases' page.
|
32
|
##|*MATCH=firewall_aliases.php*
|
33
|
##|-PRIV
|
34
|
|
35
|
require_once("guiconfig.inc");
|
36
|
require_once("functions.inc");
|
37
|
require_once("filter.inc");
|
38
|
require_once("shaper.inc");
|
39
|
require_once("alias-utils.inc");
|
40
|
|
41
|
$tab = ($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/", "", $_REQUEST['tab']));
|
42
|
|
43
|
if ($_POST['apply']) {
|
44
|
$retval = 0;
|
45
|
|
46
|
/* reload all components that use aliases */
|
47
|
$retval |= filter_configure();
|
48
|
|
49
|
if ($retval == 0) {
|
50
|
clear_subsystem_dirty('aliases');
|
51
|
}
|
52
|
}
|
53
|
|
54
|
|
55
|
if ($_POST['act'] == "del") {
|
56
|
$delete_error = deleteAlias($_POST['id']);
|
57
|
|
58
|
if (strlen($delete_error) == 0) {
|
59
|
header("Location: firewall_aliases.php?tab=" . $tab);
|
60
|
exit;
|
61
|
}
|
62
|
}
|
63
|
|
64
|
$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
|
if ($dtab[1] == true) {
|
72
|
$bctab = $dtab[0];
|
73
|
break;
|
74
|
}
|
75
|
}
|
76
|
|
77
|
$pgtitle = array(gettext("Firewall"), gettext("Aliases"), $bctab);
|
78
|
$pglinks = array("", "firewall_aliases.php", "@self");
|
79
|
$shortcut_section = "aliases";
|
80
|
|
81
|
include("head.inc");
|
82
|
|
83
|
if ($delete_error) {
|
84
|
print_info_box($delete_error, 'danger');
|
85
|
}
|
86
|
if ($_POST['apply']) {
|
87
|
print_apply_result_box($retval);
|
88
|
}
|
89
|
|
90
|
if (is_subsystem_dirty('aliases')) {
|
91
|
print_apply_box(gettext("The alias list has been changed.") . "<br />" . gettext("The changes must be applied for them to take effect."));
|
92
|
}
|
93
|
|
94
|
display_top_tabs($tab_array);
|
95
|
|
96
|
/* Show system aliases. */
|
97
|
if ($tab == 'all'):
|
98
|
?>
|
99
|
<div class="panel panel-default">
|
100
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext('System Aliases')?></h2></div>
|
101
|
<div class="panel-body"><div class="table-responsive">
|
102
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
103
|
<thead>
|
104
|
<tr>
|
105
|
<th><?=gettext("Name")?></th>
|
106
|
<th><?=gettext("Type")?></th>
|
107
|
<th><?=gettext("Description")?></th>
|
108
|
<th><?=gettext("Values")?></th>
|
109
|
</tr>
|
110
|
</thead>
|
111
|
<tbody>
|
112
|
<?php
|
113
|
$system_aliases = get_reserved_table_names();
|
114
|
foreach ($system_aliases as $alias):
|
115
|
?>
|
116
|
<tr>
|
117
|
<td>
|
118
|
<?=htmlspecialchars($alias['name'])?>
|
119
|
</td>
|
120
|
<td>
|
121
|
<?=htmlspecialchars($alias_types[$alias['type']])?>
|
122
|
</td>
|
123
|
<td>
|
124
|
<?=htmlspecialchars($alias['descr'])?>
|
125
|
</td>
|
126
|
<td>
|
127
|
<?php
|
128
|
if ($alias["url"]) {
|
129
|
echo htmlspecialchars($alias["url"]);
|
130
|
} elseif (is_array($alias["aliasurl"])) {
|
131
|
$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
|
132
|
echo htmlspecialchars($aliasurls);
|
133
|
if (is_array($aliasurls) && (count($aliasurls) > 10)) {
|
134
|
echo "…";
|
135
|
}
|
136
|
} elseif (!empty($alias['address'])) {
|
137
|
$tmpaddr = explode(" ", $alias['address']);
|
138
|
if ($alias['type'] == 'host') {
|
139
|
$tmpaddr = array_map('alias_idn_to_utf8', $tmpaddr);
|
140
|
}
|
141
|
echo htmlspecialchars(implode(", ", array_slice($tmpaddr, 0, 10)));
|
142
|
if (count($tmpaddr) > 10) {
|
143
|
echo '…';
|
144
|
}
|
145
|
} else {
|
146
|
?>
|
147
|
<span style="font-style:italic;"><?=gettext('Values set dynamically.')?>
|
148
|
<?php
|
149
|
}
|
150
|
?>
|
151
|
</td>
|
152
|
</tr>
|
153
|
<?php
|
154
|
endforeach;
|
155
|
?>
|
156
|
</tbody>
|
157
|
</table>
|
158
|
</div></div>
|
159
|
</div>
|
160
|
<?php
|
161
|
endif;
|
162
|
?>
|
163
|
|
164
|
<div class="panel panel-default">
|
165
|
<div class="panel-heading"><h2 class="panel-title"><?=sprintf(gettext('Firewall Aliases %s'), $bctab)?></h2></div>
|
166
|
<div class="panel-body">
|
167
|
|
168
|
<div class="table-responsive">
|
169
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" data-sortable>
|
170
|
<thead>
|
171
|
<tr>
|
172
|
<th><?=gettext("Name")?></th>
|
173
|
<th><?=gettext("Type")?></th>
|
174
|
<th><?=gettext("Values")?></th>
|
175
|
<th><?=gettext("Description")?></th>
|
176
|
<th><?=gettext("Actions")?></th>
|
177
|
</tr>
|
178
|
</thead>
|
179
|
<tbody>
|
180
|
<?php
|
181
|
/* Ensure aliases are presented in natural sort order so they are easier to locate.
|
182
|
* and preserve keys so that the IDs match in the config and the list.
|
183
|
* https://redmine.pfsense.org/issues/14015 */
|
184
|
$aliases = get_sorted_aliases();
|
185
|
|
186
|
foreach ($aliases as $i => $alias):
|
187
|
unset($show_alias);
|
188
|
switch ($tab) {
|
189
|
case "all":
|
190
|
$show_alias= true;
|
191
|
break;
|
192
|
case "ip":
|
193
|
case "host":
|
194
|
case "network":
|
195
|
if (preg_match("/(host|network)/", $alias["type"])) {
|
196
|
$show_alias= true;
|
197
|
}
|
198
|
break;
|
199
|
case "url":
|
200
|
if (preg_match("/(url)/i", $alias["type"])) {
|
201
|
$show_alias= true;
|
202
|
}
|
203
|
break;
|
204
|
case "port":
|
205
|
if ($alias["type"] == "port") {
|
206
|
$show_alias= true;
|
207
|
}
|
208
|
break;
|
209
|
}
|
210
|
if ($show_alias):
|
211
|
?>
|
212
|
<tr>
|
213
|
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
214
|
<?=htmlspecialchars($alias['name'])?>
|
215
|
</td>
|
216
|
<td nowrap ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
217
|
<?=htmlspecialchars($alias_types[$alias['type']])?>
|
218
|
</td>
|
219
|
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
220
|
<?php
|
221
|
if ($alias["url"]) {
|
222
|
echo htmlspecialchars($alias["url"]) . "<br />";
|
223
|
} else {
|
224
|
if (is_array($alias["aliasurl"])) {
|
225
|
$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
|
226
|
echo htmlspecialchars($aliasurls);
|
227
|
if (is_array($aliasurls) && (count($aliasurls) > 10)) {
|
228
|
echo "…<br />";
|
229
|
}
|
230
|
echo "<br />\n";
|
231
|
}
|
232
|
$tmpaddr = explode(" ", $alias['address']);
|
233
|
if ($alias['type'] == 'host') {
|
234
|
$tmpaddr = array_map('alias_idn_to_utf8', $tmpaddr);
|
235
|
}
|
236
|
$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
|
237
|
echo htmlspecialchars($addresses);
|
238
|
if (count($tmpaddr) > 10) {
|
239
|
echo '…';
|
240
|
}
|
241
|
}
|
242
|
?>
|
243
|
</td>
|
244
|
<td ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
245
|
<?=htmlspecialchars($alias['descr'])?>
|
246
|
</td>
|
247
|
<td>
|
248
|
<a class="fa-solid fa-pencil" title="<?=gettext("Edit alias"); ?>" href="firewall_aliases_edit.php?id=<?=$i?>"></a>
|
249
|
<a class="fa-regular fa-clone" title="<?=gettext('Copy alias')?>" href="firewall_aliases_edit.php?dup=<?=$i;?>" ></a>
|
250
|
<a class="fa-solid fa-trash-can" title="<?=gettext("Delete alias")?>" href="?act=del&tab=<?=$tab?>&id=<?=$i?>" usepost></a>
|
251
|
</td>
|
252
|
</tr>
|
253
|
<?php endif?>
|
254
|
<?php endforeach?>
|
255
|
</tbody>
|
256
|
</table>
|
257
|
</div>
|
258
|
|
259
|
</div>
|
260
|
</div>
|
261
|
|
262
|
<nav class="action-buttons">
|
263
|
<a href="firewall_aliases_edit.php?tab=<?=$tab?>" role="button" class="btn btn-success btn-sm">
|
264
|
<i class="fa-solid fa-plus icon-embed-btn"></i>
|
265
|
<?=gettext("Add");?>
|
266
|
</a>
|
267
|
<?php
|
268
|
if (($tab == "ip") || ($tab == "port") || ($tab == "all")):
|
269
|
?>
|
270
|
<a href="firewall_aliases_import.php?tab=<?=$tab?>" role="button" class="btn btn-primary btn-sm">
|
271
|
<i class="fa-solid fa-upload icon-embed-btn"></i>
|
272
|
<?=gettext("Import");?>
|
273
|
</a>
|
274
|
<?php
|
275
|
endif
|
276
|
?>
|
277
|
</nav>
|
278
|
|
279
|
<!-- Information section. Icon ID must be "showinfo" and the information <div> ID must be "infoblock".
|
280
|
That way jQuery (in pfenseHelpers.js) will automatically take care of the display. -->
|
281
|
<div>
|
282
|
<div class="infoblock">
|
283
|
<?php print_info_box(gettext('Aliases act as placeholders for real hosts, networks or ports. They can be used to minimize the number ' .
|
284
|
'of changes that have to be made if a host, network or port changes.') . '<br />' .
|
285
|
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 />' .
|
286
|
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); ?>
|
287
|
</div>
|
288
|
</div>
|
289
|
|
290
|
<?php
|
291
|
include("foot.inc");
|