1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
3 |
5b237745
|
Scott Ullrich
|
/*
|
4 |
|
|
firewall_aliases.php
|
5 |
4d875b4f
|
Scott Ullrich
|
Copyright (C) 2004 Scott Ullrich
|
6 |
|
|
All rights reserved.
|
7 |
f0fe3d30
|
Scott Ullrich
|
|
8 |
4d875b4f
|
Scott Ullrich
|
originially part of m0n0wall (http://m0n0.ch/wall)
|
9 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
10 |
|
|
All rights reserved.
|
11 |
f0fe3d30
|
Scott Ullrich
|
|
12 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
13 |
|
|
modification, are permitted provided that the following conditions are met:
|
14 |
f0fe3d30
|
Scott Ullrich
|
|
15 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
16 |
|
|
this list of conditions and the following disclaimer.
|
17 |
f0fe3d30
|
Scott Ullrich
|
|
18 |
5b237745
|
Scott Ullrich
|
2. Redistributions in binary form must reproduce the above copyright
|
19 |
|
|
notice, this list of conditions and the following disclaimer in the
|
20 |
|
|
documentation and/or other materials provided with the distribution.
|
21 |
f0fe3d30
|
Scott Ullrich
|
|
22 |
5b237745
|
Scott Ullrich
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
32 |
|
|
*/
|
33 |
7ac5a4cb
|
Scott Ullrich
|
/*
|
34 |
|
|
pfSense_MODULE: aliases
|
35 |
|
|
*/
|
36 |
5b237745
|
Scott Ullrich
|
|
37 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
38 |
|
|
##|*IDENT=page-firewall-aliases
|
39 |
|
|
##|*NAME=Firewall: Aliases page
|
40 |
|
|
##|*DESCR=Allow access to the 'Firewall: Aliases' page.
|
41 |
|
|
##|*MATCH=firewall_aliases.php*
|
42 |
|
|
##|-PRIV
|
43 |
|
|
|
44 |
5b237745
|
Scott Ullrich
|
require("guiconfig.inc");
|
45 |
7a927e67
|
Scott Ullrich
|
require_once("functions.inc");
|
46 |
|
|
require_once("filter.inc");
|
47 |
|
|
require_once("shaper.inc");
|
48 |
5b237745
|
Scott Ullrich
|
|
49 |
|
|
if (!is_array($config['aliases']['alias']))
|
50 |
|
|
$config['aliases']['alias'] = array();
|
51 |
|
|
$a_aliases = &$config['aliases']['alias'];
|
52 |
|
|
|
53 |
ac7f1763
|
Renato Botelho
|
$tab = ($_REQUEST['tab'] == "" ? "ip" : preg_replace("/\W/","",$_REQUEST['tab']));
|
54 |
5b237745
|
Scott Ullrich
|
|
55 |
ac7f1763
|
Renato Botelho
|
if ($_POST) {
|
56 |
5b237745
|
Scott Ullrich
|
|
57 |
|
|
if ($_POST['apply']) {
|
58 |
|
|
$retval = 0;
|
59 |
920b3bb0
|
Scott Ullrich
|
|
60 |
|
|
/* reload all components that use aliases */
|
61 |
|
|
$retval = filter_configure();
|
62 |
|
|
|
63 |
b2774343
|
Scott Ullrich
|
if(stristr($retval, "error") <> true)
|
64 |
|
|
$savemsg = get_std_save_message($retval);
|
65 |
|
|
else
|
66 |
|
|
$savemsg = $retval;
|
67 |
a368a026
|
Ermal Lu?i
|
if ($retval == 0)
|
68 |
|
|
clear_subsystem_dirty('aliases');
|
69 |
5b237745
|
Scott Ullrich
|
}
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
if ($_GET['act'] == "del") {
|
73 |
|
|
if ($a_aliases[$_GET['id']]) {
|
74 |
58c32a28
|
Scott Ullrich
|
/* make sure rule is not being referenced by any nat or filter rules */
|
75 |
|
|
$is_alias_referenced = false;
|
76 |
|
|
$referenced_by = false;
|
77 |
|
|
$alias_name = $a_aliases[$_GET['id']]['name'];
|
78 |
c769f983
|
Erik Fonnesbeck
|
// Firewall rules
|
79 |
|
|
find_alias_reference(array('filter', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
80 |
|
|
find_alias_reference(array('filter', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
81 |
|
|
find_alias_reference(array('filter', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
|
82 |
|
|
find_alias_reference(array('filter', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
|
83 |
|
|
// NAT Rules
|
84 |
|
|
find_alias_reference(array('nat', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
85 |
|
|
find_alias_reference(array('nat', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
|
86 |
|
|
find_alias_reference(array('nat', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
87 |
|
|
find_alias_reference(array('nat', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
|
88 |
|
|
find_alias_reference(array('nat', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
|
89 |
|
|
find_alias_reference(array('nat', 'rule'), array('local-port'), $alias_name, $is_alias_referenced, $referenced_by);
|
90 |
b43b7613
|
Erik Fonnesbeck
|
// NAT 1:1 Rules
|
91 |
|
|
//find_alias_reference(array('nat', 'onetoone'), array('external'), $alias_name, $is_alias_referenced, $referenced_by);
|
92 |
|
|
//find_alias_reference(array('nat', 'onetoone'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
93 |
|
|
find_alias_reference(array('nat', 'onetoone'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
94 |
|
|
// NAT Outbound Rules
|
95 |
|
|
find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $alias_name, $is_alias_referenced, $referenced_by);
|
96 |
ca640261
|
Erik Fonnesbeck
|
find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $alias_name, $is_alias_referenced, $referenced_by);
|
97 |
b43b7613
|
Erik Fonnesbeck
|
find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
|
98 |
ca640261
|
Erik Fonnesbeck
|
find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $alias_name, $is_alias_referenced, $referenced_by);
|
99 |
b43b7613
|
Erik Fonnesbeck
|
find_alias_reference(array('nat', 'advancedoutbound', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
|
100 |
c769f983
|
Erik Fonnesbeck
|
// Alias in an alias
|
101 |
|
|
find_alias_reference(array('aliases', 'alias'), array('address'), $alias_name, $is_alias_referenced, $referenced_by);
|
102 |
3df59bab
|
Darren Embry
|
// Load Balancer
|
103 |
|
|
find_alias_reference(array('load_balancer', 'lbpool'), array('port'), $alias_name, $is_alias_referenced, $referenced_by);
|
104 |
|
|
find_alias_reference(array('load_balancer', 'virtual_server'), array('port'), $alias_name, $is_alias_referenced, $referenced_by);
|
105 |
cf96a1a9
|
Renato Botelho
|
// Static routes
|
106 |
|
|
find_alias_reference(array('staticroutes', 'route'), array('network'), $alias_name, $is_alias_referenced, $referenced_by);
|
107 |
58c32a28
|
Scott Ullrich
|
if($is_alias_referenced == true) {
|
108 |
4b4d550a
|
Chris Buechler
|
$savemsg = sprintf(gettext("Cannot delete alias. Currently in use by %s"), $referenced_by);
|
109 |
58c32a28
|
Scott Ullrich
|
} else {
|
110 |
|
|
unset($a_aliases[$_GET['id']]);
|
111 |
3a343d73
|
jim-p
|
if (write_config()) {
|
112 |
|
|
filter_configure();
|
113 |
|
|
mark_subsystem_dirty('aliases');
|
114 |
|
|
}
|
115 |
ac7f1763
|
Renato Botelho
|
header("Location: firewall_aliases.php?tab=" . $tab);
|
116 |
58c32a28
|
Scott Ullrich
|
exit;
|
117 |
|
|
}
|
118 |
5b237745
|
Scott Ullrich
|
}
|
119 |
|
|
}
|
120 |
b63695db
|
Scott Ullrich
|
|
121 |
c769f983
|
Erik Fonnesbeck
|
function find_alias_reference($section, $field, $origname, &$is_alias_referenced, &$referenced_by) {
|
122 |
|
|
global $config;
|
123 |
|
|
if(!$origname || $is_alias_referenced)
|
124 |
|
|
return;
|
125 |
|
|
|
126 |
|
|
$sectionref = &$config;
|
127 |
|
|
foreach($section as $sectionname) {
|
128 |
|
|
if(is_array($sectionref) && isset($sectionref[$sectionname]))
|
129 |
|
|
$sectionref = &$sectionref[$sectionname];
|
130 |
|
|
else
|
131 |
|
|
return;
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
if(is_array($sectionref)) {
|
135 |
|
|
foreach($sectionref as $itemkey => $item) {
|
136 |
|
|
$fieldfound = true;
|
137 |
|
|
$fieldref = &$sectionref[$itemkey];
|
138 |
|
|
foreach($field as $fieldname) {
|
139 |
|
|
if(is_array($fieldref) && isset($fieldref[$fieldname]))
|
140 |
|
|
$fieldref = &$fieldref[$fieldname];
|
141 |
|
|
else {
|
142 |
|
|
$fieldfound = false;
|
143 |
|
|
break;
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
|
|
if($fieldfound && $fieldref == $origname) {
|
147 |
|
|
$is_alias_referenced = true;
|
148 |
|
|
if(is_array($item))
|
149 |
|
|
$referenced_by = $item['descr'];
|
150 |
|
|
break;
|
151 |
|
|
}
|
152 |
|
|
}
|
153 |
|
|
}
|
154 |
|
|
}
|
155 |
|
|
|
156 |
9dc65295
|
Carlos Eduardo Ramos
|
$pgtitle = array(gettext("Firewall"),gettext("Aliases"));
|
157 |
d71fc5d3
|
jim-p
|
$shortcut_section = "aliases";
|
158 |
|
|
|
159 |
b63695db
|
Scott Ullrich
|
include("head.inc");
|
160 |
|
|
|
161 |
5b237745
|
Scott Ullrich
|
?>
|
162 |
|
|
|
163 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
164 |
|
|
<?php include("fbegin.inc"); ?>
|
165 |
|
|
<form action="firewall_aliases.php" method="post">
|
166 |
|
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
167 |
a368a026
|
Ermal Lu?i
|
<?php if (is_subsystem_dirty('aliases')): ?><p>
|
168 |
709e62f0
|
Colin Fleming
|
<?php 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."));?>
|
169 |
5b237745
|
Scott Ullrich
|
<?php endif; ?>
|
170 |
173d8e75
|
Scott Ullrich
|
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases/pre_table"); ?>
|
171 |
709e62f0
|
Colin Fleming
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firewall aliases">
|
172 |
a5416de2
|
Warren Baker
|
<tr>
|
173 |
|
|
<td class="tabnavtbl">
|
174 |
|
|
<?php
|
175 |
|
|
$tab_array = array();
|
176 |
983fb4d2
|
Warren Baker
|
$tab_array[] = array(gettext("IP"),($tab=="ip" ? true : ($tab=="host" ? true : ($tab == "network" ? true : false))), "/firewall_aliases.php?tab=ip");
|
177 |
a5416de2
|
Warren Baker
|
$tab_array[] = array(gettext("Ports"), ($tab=="port"? true : false), "/firewall_aliases.php?tab=port");
|
178 |
df1b3eb7
|
Chris Buechler
|
$tab_array[] = array(gettext("URLs"), ($tab=="url"? true : false), "/firewall_aliases.php?tab=url");
|
179 |
a5416de2
|
Warren Baker
|
$tab_array[] = array(gettext("All"), ($tab=="all"? true : false), "/firewall_aliases.php?tab=all");
|
180 |
|
|
display_top_tabs($tab_array);
|
181 |
|
|
?>
|
182 |
709e62f0
|
Colin Fleming
|
<input type="hidden" name="tab" value="<?=htmlspecialchars($tab);?>" />
|
183 |
a5416de2
|
Warren Baker
|
</td>
|
184 |
|
|
</tr>
|
185 |
9db1ff32
|
Renato Botelho
|
<tr>
|
186 |
|
|
<td>
|
187 |
|
|
<div id="mainarea">
|
188 |
709e62f0
|
Colin Fleming
|
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
|
189 |
9db1ff32
|
Renato Botelho
|
<tr>
|
190 |
|
|
<td width="20%" class="listhdrr"><?=gettext("Name"); ?></td>
|
191 |
|
|
<td width="43%" class="listhdrr"><?=gettext("Values"); ?></td>
|
192 |
|
|
<td width="30%" class="listhdr"><?=gettext("Description"); ?></td>
|
193 |
|
|
<td width="7%" class="list">
|
194 |
709e62f0
|
Colin Fleming
|
<table border="0" cellspacing="0" cellpadding="1" summary="add">
|
195 |
9db1ff32
|
Renato Botelho
|
<tr>
|
196 |
|
|
<td valign="middle" width="17"> </td>
|
197 |
709e62f0
|
Colin Fleming
|
<td valign="middle"><a href="firewall_aliases_edit.php?tab=<?=$tab?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" <?=dom_title(gettext("Add a new alias"));?> alt="add" /></a></td>
|
198 |
9db1ff32
|
Renato Botelho
|
</tr>
|
199 |
|
|
</table>
|
200 |
|
|
</td>
|
201 |
|
|
</tr>
|
202 |
|
|
<?php
|
203 |
|
|
asort($a_aliases);
|
204 |
|
|
foreach ($a_aliases as $i=> $alias){
|
205 |
|
|
unset ($show_alias);
|
206 |
|
|
switch ($tab){
|
207 |
|
|
case "all":
|
208 |
|
|
$show_alias= true;
|
209 |
|
|
break;
|
210 |
|
|
case "ip":
|
211 |
|
|
case "host":
|
212 |
|
|
case "network":
|
213 |
|
|
if (preg_match("/(host|network)/",$alias["type"]))
|
214 |
|
|
$show_alias= true;
|
215 |
|
|
break;
|
216 |
|
|
case "url":
|
217 |
|
|
if (preg_match("/(url)/i",$alias["type"]))
|
218 |
|
|
$show_alias= true;
|
219 |
|
|
break;
|
220 |
|
|
case "port":
|
221 |
|
|
if($alias["type"] == "port")
|
222 |
|
|
$show_alias= true;
|
223 |
|
|
break;
|
224 |
|
|
}
|
225 |
|
|
if ($show_alias) {
|
226 |
|
|
?>
|
227 |
|
|
<tr>
|
228 |
|
|
<td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
229 |
|
|
<?=htmlspecialchars($alias['name']);?>
|
230 |
|
|
</td>
|
231 |
|
|
<td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
232 |
|
|
<?php
|
233 |
|
|
if ($alias["url"]) {
|
234 |
|
|
echo $alias["url"] . "<br/>";
|
235 |
94597308
|
Renato Botelho
|
} else {
|
236 |
|
|
if(is_array($alias["aliasurl"])) {
|
237 |
|
|
$aliasurls = implode(", ", array_slice($alias["aliasurl"], 0, 10));
|
238 |
|
|
echo $aliasurls;
|
239 |
|
|
if(count($aliasurls) > 10) {
|
240 |
|
|
echo "...<br/>";
|
241 |
|
|
}
|
242 |
|
|
echo "<br/>\n";
|
243 |
|
|
}
|
244 |
|
|
$tmpaddr = explode(" ", $alias['address']);
|
245 |
|
|
$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
|
246 |
|
|
echo $addresses;
|
247 |
|
|
if(count($tmpaddr) > 10) {
|
248 |
|
|
echo "...";
|
249 |
9db1ff32
|
Renato Botelho
|
}
|
250 |
|
|
}
|
251 |
|
|
?>
|
252 |
|
|
</td>
|
253 |
|
|
<td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
254 |
|
|
<?=htmlspecialchars($alias['descr']);?>
|
255 |
|
|
</td>
|
256 |
709e62f0
|
Colin Fleming
|
<td valign="middle" class="list nowrap">
|
257 |
|
|
<table border="0" cellspacing="0" cellpadding="1" summary="icons">
|
258 |
9db1ff32
|
Renato Botelho
|
<tr>
|
259 |
709e62f0
|
Colin Fleming
|
<td valign="middle"><a href="firewall_aliases_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0" <?=dom_title(gettext("Edit alias")." {$alias['name']}");?> alt="edit" /></a></td>
|
260 |
|
|
<td><a href="firewall_aliases.php?act=del&tab=<?=$tab;?>&id=<?=$i;?>" onclick="return confirm('<?=gettext("Do you really want to delete this alias? All elements that still use it will become invalid (e.g. filter rules)!");?>')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0" <?=dom_title(gettext("Delete alias")." {$alias['name']}");?> alt="delete" /></a></td>
|
261 |
9db1ff32
|
Renato Botelho
|
</tr>
|
262 |
|
|
</table>
|
263 |
|
|
</td>
|
264 |
|
|
</tr>
|
265 |
|
|
<?php
|
266 |
|
|
} // if ($show_alias)
|
267 |
|
|
} // foreach
|
268 |
|
|
?>
|
269 |
0f89c125
|
marcelloc
|
|
270 |
9db1ff32
|
Renato Botelho
|
<tr>
|
271 |
709e62f0
|
Colin Fleming
|
<td colspan="3"> </td>
|
272 |
|
|
<td valign="middle" class="list nowrap">
|
273 |
|
|
<table border="0" cellspacing="0" cellpadding="1" summary="edit">
|
274 |
9db1ff32
|
Renato Botelho
|
<tbody>
|
275 |
|
|
<tr>
|
276 |
|
|
<td valign="middle">
|
277 |
709e62f0
|
Colin Fleming
|
<a href="firewall_aliases_edit.php?tab=<?=$tab?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" <?=dom_title(gettext("Add a new alias")); ?> alt="add" /></a>
|
278 |
9db1ff32
|
Renato Botelho
|
</td>
|
279 |
|
|
<td valign="middle">
|
280 |
709e62f0
|
Colin Fleming
|
<a href="firewall_aliases_import.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_import_alias.gif" width="17" height="17" border="0" <?=dom_title(gettext("Bulk import aliases from list"));?> alt="import" /></a>
|
281 |
9db1ff32
|
Renato Botelho
|
</td>
|
282 |
|
|
</tr>
|
283 |
|
|
</tbody>
|
284 |
|
|
</table>
|
285 |
|
|
</td>
|
286 |
|
|
</tr>
|
287 |
0f89c125
|
marcelloc
|
|
288 |
9db1ff32
|
Renato Botelho
|
<tr>
|
289 |
|
|
<td class="tabcont" colspan="3">
|
290 |
709e62f0
|
Colin Fleming
|
<p><span class="vexpl"><span class="red"><strong><?=gettext("Note:"); ?><br/></strong></span></span></p><div style="overflow:hidden; text-align:justify;"><p><span class="vexpl"><?=gettext("Aliases act as placeholders for real hosts, networks or ports. They can be used to minimize the number of changes that have to be made if a host, network or port changes. You can enter the name of an alias instead of the host, network or port in all fields that have a red background. The alias will be resolved according to the list above. 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."); ?></span></p></div>
|
291 |
9db1ff32
|
Renato Botelho
|
</td>
|
292 |
|
|
</tr>
|
293 |
|
|
</table>
|
294 |
|
|
</div>
|
295 |
|
|
</td>
|
296 |
|
|
</tr>
|
297 |
d2cfb7a4
|
Scott Ullrich
|
</table>
|
298 |
|
|
</form>
|
299 |
5b237745
|
Scott Ullrich
|
<?php include("fend.inc"); ?>
|
300 |
|
|
</body>
|
301 |
|
|
</html>
|