1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
firewall_aliases.php
|
5
|
Copyright (C) 2004 Scott Ullrich
|
6
|
All rights reserved.
|
7
|
|
8
|
originially part of m0n0wall (http://m0n0.ch/wall)
|
9
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
10
|
All rights reserved.
|
11
|
|
12
|
Redistribution and use in source and binary forms, with or without
|
13
|
modification, are permitted provided that the following conditions are met:
|
14
|
|
15
|
1. Redistributions of source code must retain the above copyright notice,
|
16
|
this list of conditions and the following disclaimer.
|
17
|
|
18
|
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
|
|
22
|
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
|
/*
|
34
|
pfSense_MODULE: aliases
|
35
|
*/
|
36
|
|
37
|
##|+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
|
require("guiconfig.inc");
|
45
|
require_once("functions.inc");
|
46
|
require_once("filter.inc");
|
47
|
require_once("shaper.inc");
|
48
|
|
49
|
if (!is_array($config['aliases']['alias']))
|
50
|
$config['aliases']['alias'] = array();
|
51
|
$a_aliases = &$config['aliases']['alias'];
|
52
|
|
53
|
if ($_POST) {
|
54
|
|
55
|
$pconfig = $_POST;
|
56
|
|
57
|
if ($_POST['apply']) {
|
58
|
$retval = 0;
|
59
|
|
60
|
/* reload all components that use aliases */
|
61
|
$retval = filter_configure();
|
62
|
|
63
|
if(stristr($retval, "error") <> true)
|
64
|
$savemsg = get_std_save_message($retval);
|
65
|
else
|
66
|
$savemsg = $retval;
|
67
|
if ($retval == 0)
|
68
|
clear_subsystem_dirty('aliases');
|
69
|
}
|
70
|
}
|
71
|
|
72
|
if ($_GET['act'] == "del") {
|
73
|
if ($a_aliases[$_GET['id']]) {
|
74
|
/* 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
|
if(is_array($config['nat']['rule'])) {
|
79
|
foreach($config['nat']['rule'] as $rule) {
|
80
|
if($rule['localip'] == $alias_name) {
|
81
|
$is_alias_referenced = true;
|
82
|
$referenced_by = $rule['descr'];
|
83
|
break;
|
84
|
}
|
85
|
}
|
86
|
}
|
87
|
if($is_alias_referenced == false) {
|
88
|
if(is_array($config['filter']['rule'])) {
|
89
|
foreach($config['filter']['rule'] as $rule) {
|
90
|
if($rule['source']) {
|
91
|
if($rule['source']['address'] && $rule['source']['address'] == $alias_name) {
|
92
|
$is_alias_referenced = true;
|
93
|
$referenced_by = $rule['descr'];
|
94
|
break;
|
95
|
}
|
96
|
if($rule['source']['port'] && $rule['source']['port'] == $alias_name) {
|
97
|
$is_alias_referenced = true;
|
98
|
$referenced_by = $rule['descr'];
|
99
|
break;
|
100
|
}
|
101
|
if($rule['destination']['address'] && $rule['destination']['address'] == $alias_name) {
|
102
|
$is_alias_referenced = true;
|
103
|
$referenced_by = $rule['descr'];
|
104
|
break;
|
105
|
}
|
106
|
}
|
107
|
if($rule['destination'])
|
108
|
if($rule['destination']['port'] && $rule['destination']['port'] == $alias_name) {
|
109
|
$is_alias_referenced = true;
|
110
|
$referenced_by = $rule['descr'];
|
111
|
break;
|
112
|
}
|
113
|
}
|
114
|
}
|
115
|
}
|
116
|
if($is_alias_referenced == false) {
|
117
|
if(is_array($config['nat']['rule'])) {
|
118
|
foreach($config['nat']['rule'] as $rule) {
|
119
|
if($rule['source']['address'] && $rule['source']['address'] == $alias_name) {
|
120
|
$is_alias_referenced = true;
|
121
|
$referenced_by = $rule['descr'];
|
122
|
break;
|
123
|
}
|
124
|
if($rule['source']['port'] && $rule['source']['port'] == $alias_name) {
|
125
|
$is_alias_referenced = true;
|
126
|
$referenced_by = $rule['descr'];
|
127
|
break;
|
128
|
}
|
129
|
if($rule['destination']['address'] && $rule['destination']['address'] == $alias_name) {
|
130
|
$is_alias_referenced = true;
|
131
|
$referenced_by = $rule['descr'];
|
132
|
break;
|
133
|
}
|
134
|
if($rule['destination']['port'] && $rule['destination']['port'] == $alias_name) {
|
135
|
$is_alias_referenced = true;
|
136
|
$referenced_by = $rule['descr'];
|
137
|
break;
|
138
|
}
|
139
|
if($rule['target'] && $rule['target'] == $alias_name) {
|
140
|
$is_alias_referenced = true;
|
141
|
$referenced_by = $rule['descr'];
|
142
|
break;
|
143
|
}
|
144
|
if($rule['local-port'] && $rule['local-port'] == $alias_name) {
|
145
|
$is_alias_referenced = true;
|
146
|
$referenced_by = $rule['descr'];
|
147
|
break;
|
148
|
}
|
149
|
}
|
150
|
}
|
151
|
}
|
152
|
if($is_alias_referenced == true) {
|
153
|
$savemsg = sprintf(gettext("Cannot delete alias. Currently in use by %s"), $referenced_by);
|
154
|
} else {
|
155
|
unset($a_aliases[$_GET['id']]);
|
156
|
write_config();
|
157
|
filter_configure();
|
158
|
mark_subsystem_dirty('aliases');
|
159
|
header("Location: firewall_aliases.php");
|
160
|
exit;
|
161
|
}
|
162
|
}
|
163
|
}
|
164
|
|
165
|
$pgtitle = array(gettext("Firewall"),gettext("Aliases"));
|
166
|
include("head.inc");
|
167
|
|
168
|
?>
|
169
|
|
170
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
171
|
<?php include("fbegin.inc"); ?>
|
172
|
<form action="firewall_aliases.php" method="post">
|
173
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
174
|
<?php if (is_subsystem_dirty('aliases')): ?><p>
|
175
|
<?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."));?>
|
176
|
<?php endif; ?>
|
177
|
|
178
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
179
|
<tr>
|
180
|
<td width="25%" class="listhdrr"><?=gettext("Name"); ?></td>
|
181
|
<td width="25%" class="listhdrr"><?=gettext("Values"); ?></td>
|
182
|
<td width="25%" class="listhdr"><?=gettext("Description"); ?></td>
|
183
|
<td width="10%" class="list">
|
184
|
<table border="0" cellspacing="0" cellpadding="1">
|
185
|
<tr>
|
186
|
<td valign="middle" width="17"> </td>
|
187
|
<td valign="middle"><a href="firewall_aliases_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add a new alias"); ?>"></a></td>
|
188
|
</tr>
|
189
|
</table>
|
190
|
</td>
|
191
|
</tr>
|
192
|
<?php $i = 0; foreach ($a_aliases as $alias): ?>
|
193
|
<tr>
|
194
|
<td class="listlr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
195
|
<?=htmlspecialchars($alias['name']);?>
|
196
|
</td>
|
197
|
<td class="listr" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
198
|
<?php
|
199
|
if ($alias["url"]) {
|
200
|
echo $alias["url"] . "<br/>";
|
201
|
}
|
202
|
if ($alias["aliasurl"]) {
|
203
|
echo $alias["aliasurl"] . "<br/>";
|
204
|
}
|
205
|
$tmpaddr = explode(" ", $alias['address']);
|
206
|
$addresses = implode(", ", array_slice($tmpaddr, 0, 10));
|
207
|
echo $addresses;
|
208
|
if(count($tmpaddr) > 10) {
|
209
|
echo "...";
|
210
|
}
|
211
|
?>
|
212
|
</td>
|
213
|
<td class="listbg" ondblclick="document.location='firewall_aliases_edit.php?id=<?=$i;?>';">
|
214
|
<?=htmlspecialchars($alias['descr']);?>
|
215
|
</td>
|
216
|
<td valign="middle" nowrap class="list">
|
217
|
<table border="0" cellspacing="0" cellpadding="1">
|
218
|
<tr>
|
219
|
<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" title="<?=gettext("edit alias"); ?>"></a></td>
|
220
|
<td><a href="firewall_aliases.php?act=del&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" title="<?=gettext("delete alias"); ?>"></a></td>
|
221
|
</tr>
|
222
|
</table>
|
223
|
</td>
|
224
|
</tr>
|
225
|
<?php $i++; endforeach; ?>
|
226
|
<tr>
|
227
|
<td class="list" colspan="3"></td>
|
228
|
<td class="list">
|
229
|
<table border="0" cellspacing="0" cellpadding="1">
|
230
|
<tr>
|
231
|
<td valign="middle" width="17"> </td>
|
232
|
<td valign="middle">
|
233
|
<a href="firewall_aliases_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0" title="<?=gettext("add a new alias"); ?>"></a></td>
|
234
|
</td>
|
235
|
<td valign="middle">
|
236
|
<a href="firewall_aliases_import.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_import_alias.gif" width="17" height="17" border="0" title="<?=gettext("Bulk import aliases from list"); ?>" alt="" /></a>
|
237
|
</td>
|
238
|
</tr>
|
239
|
</table>
|
240
|
</td>
|
241
|
</tr>
|
242
|
<tr>
|
243
|
<td class="tabcont" colspan="3">
|
244
|
<p><span class="vexpl"><span class="red"><strong><?=gettext("Note:"); ?><br></strong></span><?=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>
|
245
|
</td>
|
246
|
</tr>
|
247
|
</table>
|
248
|
</form>
|
249
|
<?php include("fend.inc"); ?>
|
250
|
</body>
|
251
|
</html>
|