1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
3 |
5b237745
|
Scott Ullrich
|
/*
|
4 |
|
|
firewall_aliases.php
|
5 |
|
|
*/
|
6 |
fd9ebcd5
|
Stephen Beaver
|
/* ====================================================================
|
7 |
|
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
8 |
|
|
* Copyright (c) 2004 Scott Ullrich
|
9 |
|
|
*
|
10 |
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
11 |
|
|
* are permitted provided that the following conditions are met:
|
12 |
|
|
*
|
13 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
14 |
|
|
* this list of conditions and the following disclaimer.
|
15 |
|
|
*
|
16 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
17 |
|
|
* notice, this list of conditions and the following disclaimer in
|
18 |
|
|
* the documentation and/or other materials provided with the
|
19 |
|
|
* distribution.
|
20 |
|
|
*
|
21 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
22 |
|
|
* must display the following acknowledgment:
|
23 |
|
|
* "This product includes software developed by the pfSense Project
|
24 |
|
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
25 |
|
|
*
|
26 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
27 |
|
|
* endorse or promote products derived from this software without
|
28 |
|
|
* prior written permission. For written permission, please contact
|
29 |
|
|
* coreteam@pfsense.org.
|
30 |
|
|
*
|
31 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
32 |
|
|
* nor may "pfSense" appear in their names without prior written
|
33 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
34 |
|
|
*
|
35 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
36 |
|
|
* acknowledgment:
|
37 |
|
|
*
|
38 |
|
|
* "This product includes software developed by the pfSense Project
|
39 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
40 |
|
|
*
|
41 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
42 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
43 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
44 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
45 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
46 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
47 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
48 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
49 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
50 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
51 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
52 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
53 |
|
|
*
|
54 |
|
|
* ====================================================================
|
55 |
|
|
*
|
56 |
|
|
*/
|
57 |
7ac5a4cb
|
Scott Ullrich
|
/*
|
58 |
|
|
pfSense_MODULE: aliases
|
59 |
|
|
*/
|
60 |
5b237745
|
Scott Ullrich
|
|
61 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
62 |
|
|
##|*IDENT=page-firewall-aliases
|
63 |
|
|
##|*NAME=Firewall: Aliases page
|
64 |
|
|
##|*DESCR=Allow access to the 'Firewall: Aliases' page.
|
65 |
|
|
##|*MATCH=firewall_aliases.php*
|
66 |
|
|
##|-PRIV
|
67 |
|
|
|
68 |
5b237745
|
Scott Ullrich
|
require("guiconfig.inc");
|
69 |
7a927e67
|
Scott Ullrich
|
require_once("functions.inc");
|
70 |
|
|
require_once("filter.inc");
|
71 |
|
|
require_once("shaper.inc");
|
72 |
5b237745
|
Scott Ullrich
|
|
73 |
95a40ac0
|
Phil Davis
|
if (!is_array($config['aliases']['alias'])) {
|
74 |
5b237745
|
Scott Ullrich
|
$config['aliases']['alias'] = array();
|
75 |
95a40ac0
|
Phil Davis
|
}
|
76 |
5b237745
|
Scott Ullrich
|
$a_aliases = &$config['aliases']['alias'];
|
77 |
|
|
|
78 |
6c07db48
|
Phil Davis
|
$tab = ($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/", "", $_REQUEST['tab']));
|
79 |
5b237745
|
Scott Ullrich
|
|
80 |
ac7f1763
|
Renato Botelho
|
if ($_POST) {
|
81 |
5b237745
|
Scott Ullrich
|
|
82 |
|
|
if ($_POST['apply']) {
|
83 |
|
|
$retval = 0;
|
84 |
920b3bb0
|
Scott Ullrich
|
|
85 |
|
|
/* reload all components that use aliases */
|
86 |
|
|
$retval = filter_configure();
|
87 |
|
|
|
88 |
95a40ac0
|
Phil Davis
|
if (stristr($retval, "error") <> true) {
|
89 |
14726356
|
Sjon Hortensius
|
$savemsg = get_std_save_message($retval);
|
90 |
95a40ac0
|
Phil Davis
|
} else {
|
91 |
14726356
|
Sjon Hortensius
|
$savemsg = $retval;
|
92 |
95a40ac0
|
Phil Davis
|
}
|
93 |
|
|
if ($retval == 0) {
|
94 |
a368a026
|
Ermal Lu?i
|
clear_subsystem_dirty('aliases');
|
95 |
95a40ac0
|
Phil Davis
|
}
|
96 |
5b237745
|
Scott Ullrich
|
}
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
if ($_GET['act'] == "del") {
|
100 |
|
|
if ($a_aliases[$_GET['id']]) {
|
101 |
58c32a28
|
Scott Ullrich
|
/* make sure rule is not being referenced by any nat or filter rules */
|
102 |
|
|
$is_alias_referenced = false;
|
103 |
|
|
$referenced_by = false;
|
104 |
|
|
$alias_name = $a_aliases[$_GET['id']]['name'];
|
105 |
c769f983
|
Erik Fonnesbeck
|
// Firewall rules
|
106 |
|
|
find_alias_reference(array('filter', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
107 |
|
|
find_alias_reference(array('filter', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
108 |
|
|
find_alias_reference(array('filter', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
|
109 |
|
|
find_alias_reference(array('filter', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
|
110 |
|
|
// NAT Rules
|
111 |
|
|
find_alias_reference(array('nat', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
112 |
|
|
find_alias_reference(array('nat', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
|
113 |
|
|
find_alias_reference(array('nat', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
114 |
|
|
find_alias_reference(array('nat', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
|
115 |
|
|
find_alias_reference(array('nat', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
|
116 |
|
|
find_alias_reference(array('nat', 'rule'), array('local-port'), $alias_name, $is_alias_referenced, $referenced_by);
|
117 |
b43b7613
|
Erik Fonnesbeck
|
// NAT 1:1 Rules
|
118 |
|
|
//find_alias_reference(array('nat', 'onetoone'), array('external'), $alias_name, $is_alias_referenced, $referenced_by);
|
119 |
|
|
//find_alias_reference(array('nat', 'onetoone'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
120 |
|
|
find_alias_reference(array('nat', 'onetoone'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
121 |
|
|
// NAT Outbound Rules
|
122 |
682b8f12
|
Phil Davis
|
find_alias_reference(array('nat', 'outbound', 'rule'), array('source', 'network'), $alias_name, $is_alias_referenced, $referenced_by);
|
123 |
|
|
find_alias_reference(array('nat', 'outbound', 'rule'), array('sourceport'), $alias_name, $is_alias_referenced, $referenced_by);
|
124 |
|
|
find_alias_reference(array('nat', 'outbound', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
125 |
|
|
find_alias_reference(array('nat', 'outbound', 'rule'), array('dstport'), $alias_name, $is_alias_referenced, $referenced_by);
|
126 |
|
|
find_alias_reference(array('nat', 'outbound', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
|
127 |
c769f983
|
Erik Fonnesbeck
|
// Alias in an alias
|
128 |
|
|
find_alias_reference(array('aliases', 'alias'), array('address'), $alias_name, $is_alias_referenced, $referenced_by);
|
129 |
3df59bab
|
Darren Embry
|
// Load Balancer
|
130 |
14726356
|
Sjon Hortensius
|
find_alias_reference(array('load_balancer', 'lbpool'), array('port'), $alias_name, $is_alias_referenced, $referenced_by);
|
131 |
3df59bab
|
Darren Embry
|
find_alias_reference(array('load_balancer', 'virtual_server'), array('port'), $alias_name, $is_alias_referenced, $referenced_by);
|
132 |
a161bfb8
|
Renato Botelho
|
// Static routes
|
133 |
|
|
find_alias_reference(array('staticroutes', 'route'), array('network'), $alias_name, $is_alias_referenced, $referenced_by);
|
134 |
95a40ac0
|
Phil Davis
|
if ($is_alias_referenced == true) {
|
135 |
4b4d550a
|
Chris Buechler
|
$savemsg = sprintf(gettext("Cannot delete alias. Currently in use by %s"), $referenced_by);
|
136 |
58c32a28
|
Scott Ullrich
|
} else {
|
137 |
|
|
unset($a_aliases[$_GET['id']]);
|
138 |
3a343d73
|
jim-p
|
if (write_config()) {
|
139 |
|
|
filter_configure();
|
140 |
|
|
mark_subsystem_dirty('aliases');
|
141 |
|
|
}
|
142 |
ac7f1763
|
Renato Botelho
|
header("Location: firewall_aliases.php?tab=" . $tab);
|
143 |
58c32a28
|
Scott Ullrich
|
exit;
|
144 |
|
|
}
|
145 |
5b237745
|
Scott Ullrich
|
}
|
146 |
|
|
}
|
147 |
b63695db
|
Scott Ullrich
|
|
148 |
c769f983
|
Erik Fonnesbeck
|
function find_alias_reference($section, $field, $origname, &$is_alias_referenced, &$referenced_by) {
|
149 |
|
|
global $config;
|
150 |
95a40ac0
|
Phil Davis
|
if (!$origname || $is_alias_referenced) {
|
151 |
c769f983
|
Erik Fonnesbeck
|
return;
|
152 |
95a40ac0
|
Phil Davis
|
}
|
153 |
c769f983
|
Erik Fonnesbeck
|
|
154 |
|
|
$sectionref = &$config;
|
155 |
95a40ac0
|
Phil Davis
|
foreach ($section as $sectionname) {
|
156 |
|
|
if (is_array($sectionref) && isset($sectionref[$sectionname])) {
|
157 |
c769f983
|
Erik Fonnesbeck
|
$sectionref = &$sectionref[$sectionname];
|
158 |
95a40ac0
|
Phil Davis
|
} else {
|
159 |
c769f983
|
Erik Fonnesbeck
|
return;
|
160 |
95a40ac0
|
Phil Davis
|
}
|
161 |
c769f983
|
Erik Fonnesbeck
|
}
|
162 |
|
|
|
163 |
95a40ac0
|
Phil Davis
|
if (is_array($sectionref)) {
|
164 |
|
|
foreach ($sectionref as $itemkey => $item) {
|
165 |
c769f983
|
Erik Fonnesbeck
|
$fieldfound = true;
|
166 |
|
|
$fieldref = &$sectionref[$itemkey];
|
167 |
95a40ac0
|
Phil Davis
|
foreach ($field as $fieldname) {
|
168 |
|
|
if (is_array($fieldref) && isset($fieldref[$fieldname])) {
|
169 |
c769f983
|
Erik Fonnesbeck
|
$fieldref = &$fieldref[$fieldname];
|
170 |
95a40ac0
|
Phil Davis
|
} else {
|
171 |
c769f983
|
Erik Fonnesbeck
|
$fieldfound = false;
|
172 |
|
|
break;
|
173 |
|
|
}
|
174 |
|
|
}
|
175 |
95a40ac0
|
Phil Davis
|
if ($fieldfound && $fieldref == $origname) {
|
176 |
c769f983
|
Erik Fonnesbeck
|
$is_alias_referenced = true;
|
177 |
95a40ac0
|
Phil Davis
|
if (is_array($item)) {
|
178 |
c769f983
|
Erik Fonnesbeck
|
$referenced_by = $item['descr'];
|
179 |
95a40ac0
|
Phil Davis
|
}
|
180 |
c769f983
|
Erik Fonnesbeck
|
break;
|
181 |
|
|
}
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
|
186 |
6c07db48
|
Phil Davis
|
$pgtitle = array(gettext("Firewall"), gettext("Aliases"));
|
187 |
d71fc5d3
|
jim-p
|
$shortcut_section = "aliases";
|
188 |
|
|
|
189 |
b63695db
|
Scott Ullrich
|
include("head.inc");
|
190 |
|
|
|
191 |
14726356
|
Sjon Hortensius
|
if ($savemsg)
|
192 |
|
|
print_info_box($savemsg);
|
193 |
|
|
if (is_subsystem_dirty('aliases'))
|
194 |
|
|
print_info_box_np(gettext("The alias list has been changed.") . "<br />" . gettext("You must apply the changes in order for them to take effect."));
|
195 |
|
|
|
196 |
|
|
$tab_array = array();
|
197 |
|
|
$tab_array[] = array(gettext("IP"),($tab=="ip" ? true : ($tab=="host" ? true : ($tab == "network" ? true : false))), "/firewall_aliases.php?tab=ip");
|
198 |
|
|
$tab_array[] = array(gettext("Ports"), ($tab=="port"? true : false), "/firewall_aliases.php?tab=port");
|
199 |
|
|
$tab_array[] = array(gettext("URLs"), ($tab=="url"? true : false), "/firewall_aliases.php?tab=url");
|
200 |
|
|
$tab_array[] = array(gettext("All"), ($tab=="all"? true : false), "/firewall_aliases.php?tab=all");
|
201 |
|
|
display_top_tabs($tab_array);
|
202 |
|
|
|
203 |
5b237745
|
Scott Ullrich
|
?>
|
204 |
0ce45fdf
|
Sander van Leeuwen
|
<div class="table-responsive">
|
205 |
|
|
<table class="table table-striped table-hover">
|
206 |
14726356
|
Sjon Hortensius
|
<thead>
|
207 |
|
|
<tr>
|
208 |
0ce45fdf
|
Sander van Leeuwen
|
<th><?=gettext("Name")?></th>
|
209 |
|
|
<th><?=gettext("Values")?></th>
|
210 |
|
|
<th><?=gettext("Description")?></th>
|
211 |
14726356
|
Sjon Hortensius
|
</tr>
|
212 |
|
|
</thead>
|
213 |
|
|
<tbody>
|
214 |
|
|
<?php
|
215 |
|
|
asort($a_aliases);
|
216 |
|
|
foreach ($a_aliases as $i=> $alias):
|
217 |
|
|
unset ($show_alias);
|
218 |
|
|
switch ($tab){
|
219 |
|
|
case "all":
|
220 |
|
|
$show_alias= true;
|
221 |
|
|
break;
|
222 |
|
|
case "ip":
|
223 |
|
|
case "host":
|
224 |
|
|
case "network":
|
225 |
|
|
if (preg_match("/(host|network)/",$alias["type"]))
|
226 |
|
|
$show_alias= true;
|
227 |
|
|
break;
|
228 |
|
|
case "url":
|
229 |
|
|
if (preg_match("/(url)/i",$alias["type"]))
|
230 |
|
|
$show_alias= true;
|
231 |
|
|
break;
|
232 |
|
|
case "port":
|
233 |
|
|
if($alias["type"] == "port")
|
234 |
|
|
$show_alias= true;
|
235 |
|
|
break;
|
236 |
|
|
}
|
237 |
|
|
if ($show_alias):
|
238 |
|
|
?>
|
239 |
|
|
<tr>
|
240 |
|
|
<td>
|
241 |
|
|
<?=htmlspecialchars($alias['name'])?>
|
242 |
|
|
</td>
|
243 |
|
|
<td>
|
244 |
|
|
<?php
|
245 |
|
|
if ($alias["url"]) {
|
246 |
|
|
echo $alias["url"] . "<br />";
|
247 |
|
|
} else {
|
248 |
|
|
if(is_array($alias["aliasurl"])) {
|
249 |
|
|
$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
|
250 |
|
|
echo $aliasurls;
|
251 |
|
|
if(count($aliasurls) > 10) {
|
252 |
|
|
echo "…<br />";
|
253 |
|
|
}
|
254 |
|
|
echo "<br />\n";
|
255 |
|
|
}
|
256 |
|
|
$tmpaddr = explode(" ", $alias['address']);
|
257 |
|
|
$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
|
258 |
|
|
echo $addresses;
|
259 |
|
|
if(count($tmpaddr) > 10) {
|
260 |
|
|
echo '…';
|
261 |
|
|
}
|
262 |
|
|
}
|
263 |
|
|
?>
|
264 |
|
|
</td>
|
265 |
|
|
<td>
|
266 |
|
|
<?=htmlspecialchars($alias['descr'])?>
|
267 |
|
|
</td>
|
268 |
|
|
<td>
|
269 |
|
|
<a href="firewall_aliases_edit.php?id=<?=$i?>" class="btn btn-xs btn-primary">edit</a>
|
270 |
|
|
<a href="?act=del&tab=<?=$tab?>&id=<?=$i?>" class="btn btn-xs btn-danger">delete</a>
|
271 |
|
|
</td>
|
272 |
|
|
</tr>
|
273 |
|
|
<?php endif?>
|
274 |
|
|
<?php endforeach?>
|
275 |
|
|
</tbody>
|
276 |
|
|
</table>
|
277 |
0ce45fdf
|
Sander van Leeuwen
|
</div>
|
278 |
5b237745
|
Scott Ullrich
|
|
279 |
11486640
|
Sjon Hortensius
|
<nav class="action-buttons">
|
280 |
|
|
<a href="firewall_aliases_edit.php?tab=<?=$tab?>" role="button" class="btn btn-success">
|
281 |
|
|
<?=gettext("add new alias");?>
|
282 |
|
|
</a>
|
283 |
|
|
<a href="firewall_aliases_import.php" role="button" class="btn btn-default">
|
284 |
|
|
<?=gettext("bulk import");?>
|
285 |
|
|
</a>
|
286 |
|
|
</nav>
|
287 |
0f89c125
|
marcelloc
|
|
288 |
7af44d47
|
Stephen Beaver
|
<?php
|
289 |
|
|
|
290 |
|
|
print_info_box(gettext('Aliases act as placeholders for real hosts, networks or ports. They can be used to minimize the number ' .
|
291 |
|
|
'of changes that have to be made if a host, network or port changes.' . '<br />' .
|
292 |
|
|
'You can enter the name of an alias instead of the host, network or port where indicated. The alias will be resolved according to the list above.' . '<br />' .
|
293 |
|
|
'If an alias cannot be resolved (e.g. because you deleted it), the corresponding element (e.g. filter/NAT/shaper rule) will be considered invalid and skipped.'));
|
294 |
0f89c125
|
marcelloc
|
|
295 |
7af44d47
|
Stephen Beaver
|
include("foot.inc");
|