1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
firewall_aliases_edit.php
|
6
|
Copyright (C) 2004 Scott Ullrich
|
7
|
All rights reserved.
|
8
|
|
9
|
originially part of m0n0wall (http://m0n0.ch/wall)
|
10
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11
|
All rights reserved.
|
12
|
|
13
|
Redistribution and use in source and binary forms, with or without
|
14
|
modification, are permitted provided that the following conditions are met:
|
15
|
|
16
|
1. Redistributions of source code must retain the above copyright notice,
|
17
|
this list of conditions and the following disclaimer.
|
18
|
|
19
|
2. Redistributions in binary form must reproduce the above copyright
|
20
|
notice, this list of conditions and the following disclaimer in the
|
21
|
documentation and/or other materials provided with the distribution.
|
22
|
|
23
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
24
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
25
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
26
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
27
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
POSSIBILITY OF SUCH DAMAGE.
|
33
|
*/
|
34
|
|
35
|
require("guiconfig.inc");
|
36
|
|
37
|
if (!is_array($config['aliases']['alias']))
|
38
|
$config['aliases']['alias'] = array();
|
39
|
|
40
|
aliases_sort();
|
41
|
$a_aliases = &$config['aliases']['alias'];
|
42
|
|
43
|
$id = $_GET['id'];
|
44
|
if (isset($_POST['id']))
|
45
|
$id = $_POST['id'];
|
46
|
|
47
|
if (isset($id) && $a_aliases[$id]) {
|
48
|
$pconfig['name'] = $a_aliases[$id]['name'];
|
49
|
$addresses = explode(' ', $a_aliases[$id]['address']);
|
50
|
if (is_array($addresses))
|
51
|
$address = $addresses[0];
|
52
|
else
|
53
|
$address = $addresses;
|
54
|
list($pconfig['address'],$pconfig['address_subnet']) =
|
55
|
explode('/', $address);
|
56
|
if ($pconfig['address_subnet'])
|
57
|
$pconfig['type'] = "network";
|
58
|
else
|
59
|
if (is_ipaddr($pconfig['address']))
|
60
|
$pconfig['type'] = "host";
|
61
|
else
|
62
|
$pconfig['type'] = "port";
|
63
|
|
64
|
$pconfig['descr'] = $a_aliases[$id]['descr'];
|
65
|
}
|
66
|
|
67
|
if ($_POST) {
|
68
|
|
69
|
unset($input_errors);
|
70
|
$pconfig = $_POST;
|
71
|
|
72
|
/* input validation */
|
73
|
$reqdfields = explode(" ", "name address");
|
74
|
$reqdfieldsn = explode(",", "Name,Address");
|
75
|
|
76
|
if ($_POST['type'] == "network") {
|
77
|
$reqdfields[] = "address_subnet";
|
78
|
$reqdfieldsn[] = "Subnet bit count";
|
79
|
}
|
80
|
|
81
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
82
|
|
83
|
if (($_POST['name'] && (is_validaliasname($_POST['name']) == false))) {
|
84
|
$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9.";
|
85
|
}
|
86
|
if (($_POST['name'] && (is_validaliasname($_POST['name']) == -1))) {
|
87
|
$input_errors[] = "Reserved word used for alias name.";
|
88
|
}
|
89
|
if ($_POST['type'] == "host")
|
90
|
if (!is_ipaddr($_POST['address'])) {
|
91
|
$input_errors[] = "A valid address must be specified.";
|
92
|
}
|
93
|
if ($_POST['type'] == "network") {
|
94
|
if (!is_ipaddr($_POST['address'])) {
|
95
|
$input_errors[] = "A valid address must be specified.";
|
96
|
}
|
97
|
if (!is_numeric($_POST['address_subnet'])) {
|
98
|
$input_errors[] = "A valid subnet bit count must be specified.";
|
99
|
}
|
100
|
}
|
101
|
if ($_POST['type'] == "port")
|
102
|
if (!is_port($_POST['address']))
|
103
|
$input_errors[] = "The port must be an integer between 1 and 65535.";
|
104
|
|
105
|
/* check for name conflicts */
|
106
|
foreach ($a_aliases as $alias) {
|
107
|
if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
|
108
|
continue;
|
109
|
|
110
|
if ($alias['name'] == $_POST['name']) {
|
111
|
$input_errors[] = "An alias with this name already exists.";
|
112
|
break;
|
113
|
}
|
114
|
}
|
115
|
|
116
|
if (!$input_errors) {
|
117
|
$alias = array();
|
118
|
$alias['name'] = $_POST['name'];
|
119
|
if ($_POST['type'] == "network")
|
120
|
$alias['address'] = $_POST['address'] . "/" . $_POST['address_subnet'];
|
121
|
|
122
|
else
|
123
|
$alias['address'] = $_POST['address'];
|
124
|
|
125
|
$address = $alias['address'];
|
126
|
$isfirst = 0;
|
127
|
for($x=0; $x<99; $x++) {
|
128
|
$comd = "\$subnet = \$_POST['address" . $x . "'];";
|
129
|
eval($comd);
|
130
|
$comd = "\$subnet_address = \$_POST['address_subnet" . $x . "'];";
|
131
|
eval($comd);
|
132
|
if($subnet <> "") {
|
133
|
$address .= " ";
|
134
|
$address .= $subnet;
|
135
|
if($subnet_address <> "") $address .= "/" . $subnet_address;
|
136
|
}
|
137
|
}
|
138
|
|
139
|
$alias['address'] = $address;
|
140
|
$alias['descr'] = $_POST['descr'];
|
141
|
|
142
|
if (isset($id) && $a_aliases[$id])
|
143
|
$a_aliases[$id] = $alias;
|
144
|
else
|
145
|
$a_aliases[] = $alias;
|
146
|
|
147
|
filter_configure();
|
148
|
|
149
|
write_config();
|
150
|
|
151
|
header("Location: firewall_aliases.php");
|
152
|
exit;
|
153
|
}
|
154
|
}
|
155
|
|
156
|
$pgtitle = "System: Firewall: Aliases: Edit";
|
157
|
include("head.inc");
|
158
|
|
159
|
?>
|
160
|
|
161
|
<script language="JavaScript">
|
162
|
<!--
|
163
|
function typesel_change() {
|
164
|
switch (document.iform.type.selectedIndex) {
|
165
|
case 0: /* host */
|
166
|
var cmd;
|
167
|
document.iform.address_subnet.disabled = 1;
|
168
|
document.iform.address_subnet.value = "";
|
169
|
document.iform.address_subnet.selected = 0;
|
170
|
newrows = totalrows+1;
|
171
|
for(i=2; i<newrows; i++) {
|
172
|
comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
|
173
|
eval(comd);
|
174
|
comd = 'document.iform.address_subnet' + i + '.value = "";';
|
175
|
eval(comd);
|
176
|
}
|
177
|
break;
|
178
|
case 1: /* network */
|
179
|
var cmd;
|
180
|
document.iform.address_subnet.disabled = 0;
|
181
|
// document.iform.address_subnet.value = "";
|
182
|
newrows = totalrows+1;
|
183
|
for(i=2; i<newrows; i++) {
|
184
|
comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
|
185
|
eval(comd);
|
186
|
// comd = 'document.iform.address_subnet' + i + '.value = "32";';
|
187
|
// eval(comd);
|
188
|
}
|
189
|
break;
|
190
|
case 2: /* port */
|
191
|
var cmd;
|
192
|
document.iform.address_subnet.disabled = 1;
|
193
|
document.iform.address_subnet.value = "";
|
194
|
newrows = totalrows+1;
|
195
|
for(i=2; i<newrows; i++) {
|
196
|
comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
|
197
|
eval(comd);
|
198
|
comd = 'document.iform.address_subnet' + i + '.value = "32";';
|
199
|
eval(comd);
|
200
|
}
|
201
|
break;
|
202
|
}
|
203
|
}
|
204
|
|
205
|
function update_box_type() {
|
206
|
var indexNum = document.forms[0].type.selectedIndex;
|
207
|
var selected = document.forms[0].type.options[indexNum].text;
|
208
|
if(selected == 'Network(s)') {
|
209
|
document.getElementById ("addressnetworkport").firstChild.data = "Network(s)";
|
210
|
document.getElementById ("address_subnet").visible = true;
|
211
|
document.getElementById ("address_subnet").disabled = false;
|
212
|
} else if(selected == 'Host(s)') {
|
213
|
document.getElementById ("addressnetworkport").firstChild.data = "Host(s)";
|
214
|
document.getElementById ("address_subnet").visible = false;
|
215
|
document.getElementById ("address_subnet").disabled = true;
|
216
|
} else if(selected == 'Port(s)') {
|
217
|
document.getElementById ("addressnetworkport").firstChild.data = "Port(s)";
|
218
|
document.getElementById ("address_subnet").visible = false;
|
219
|
document.getElementById ("address_subnet").disabled = true;
|
220
|
}
|
221
|
}
|
222
|
|
223
|
-->
|
224
|
</script>
|
225
|
|
226
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
227
|
<?php include("fbegin.inc"); ?>
|
228
|
|
229
|
<script type="text/javascript" language="javascript" src="row_helper.js">
|
230
|
</script>
|
231
|
|
232
|
<input type='hidden' name='address_type' value='textbox'></input>
|
233
|
<input type='hidden' name='address_subnet_type' value='select'></input>
|
234
|
|
235
|
<script type="text/javascript" language='javascript'>
|
236
|
<!--
|
237
|
|
238
|
rowname[0] = "address";
|
239
|
rowtype[0] = "textbox";
|
240
|
|
241
|
rowname[1] = "address_subnet";
|
242
|
rowtype[1] = "select";
|
243
|
|
244
|
rowname[2] = "address_subnet";
|
245
|
rowtype[2] = "select";
|
246
|
-->
|
247
|
</script>
|
248
|
|
249
|
<p class="pgtitle"><?=$pgtitle?></p>
|
250
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
251
|
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
|
252
|
<?display_topbar()?>
|
253
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
254
|
<tr>
|
255
|
<td valign="top" class="vncellreq">Name</td>
|
256
|
<td class="vtable"> <input name="name" type="text" class="formfld" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>">
|
257
|
<br> <span class="vexpl">The name of the alias may only consist
|
258
|
of the characters a-z, A-Z and 0-9.</span></td>
|
259
|
</tr>
|
260
|
<tr>
|
261
|
<td width="22%" valign="top" class="vncell">Description</td>
|
262
|
<td width="78%" class="vtable"> <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
|
263
|
<br> <span class="vexpl">You may enter a description here
|
264
|
for your reference (not parsed).</span></td>
|
265
|
</tr>
|
266
|
<tr>
|
267
|
<td valign="top" class="vncellreq">Type</td>
|
268
|
<td class="vtable">
|
269
|
<select name="type" class="formfld" id="type" onChange="update_box_type(); typesel_change();">
|
270
|
<option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
|
271
|
<option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
|
272
|
<option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
|
273
|
</select>
|
274
|
</td>
|
275
|
</tr>
|
276
|
<tr>
|
277
|
<td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport" name="addressnetworkport">Host(s)</div></td>
|
278
|
<td width="78%" class="vtable">
|
279
|
|
280
|
|
281
|
<table name="maintable" id="maintable">
|
282
|
<tbody>
|
283
|
|
284
|
<?php
|
285
|
$counter = 0;
|
286
|
$address = $a_aliases[$id]['address'];
|
287
|
$item = explode(" ", $address);
|
288
|
foreach($item as $ww) {
|
289
|
$address = $item[$counter];
|
290
|
$address_subnet = "";
|
291
|
$item2 = explode("/", $address);
|
292
|
foreach($item2 as $current) {
|
293
|
if($item2[1] <> "") {
|
294
|
$address = $item2[0];
|
295
|
$address_subnet = $item2[1];
|
296
|
}
|
297
|
}
|
298
|
if($counter > 0) $tracker = $counter + 1;
|
299
|
?>
|
300
|
<tr><td> <input name="address<?php echo $tracker; ?>" type="text" class="formfld" id="address<?php echo $tracker; ?>" size="20" value="<?=htmlspecialchars($address);?>"></td><td>
|
301
|
<select name="address_subnet<?php echo $tracker; ?>" class="formfld" id="address_subnet<?php echo $tracker; ?>">
|
302
|
<option></option>
|
303
|
<?php for ($i = 32; $i >= 1; $i--): ?>
|
304
|
<option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
|
305
|
<?php endfor; ?>
|
306
|
</select>
|
307
|
<?php
|
308
|
if($counter > 0)
|
309
|
echo "<input type=\"image\" src=\"/themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\">";
|
310
|
?>
|
311
|
|
312
|
</td></tr>
|
313
|
<?php $counter++; } ?>
|
314
|
|
315
|
</tbody>
|
316
|
</table>
|
317
|
<a onClick="javascript:addRowTo('maintable'); typesel_change(); return false;" href="#"><img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add another entry"></a>
|
318
|
</td>
|
319
|
</tr>
|
320
|
<tr>
|
321
|
<td width="22%" valign="top"> </td>
|
322
|
<td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
|
323
|
<?php if (isset($id) && $a_aliases[$id]): ?>
|
324
|
<input name="id" type="hidden" value="<?=$id;?>">
|
325
|
<?php endif; ?>
|
326
|
</td>
|
327
|
</tr>
|
328
|
</table>
|
329
|
</form>
|
330
|
<script language="JavaScript">
|
331
|
<!--
|
332
|
field_counter_js = 2;
|
333
|
rows = 1;
|
334
|
totalrows = <?php echo $counter; ?>;
|
335
|
loaded = <?php echo $counter; ?>;
|
336
|
typesel_change();
|
337
|
update_box_type();
|
338
|
|
339
|
//-->
|
340
|
</script>
|
341
|
<?php include("fend.inc"); ?>
|
342
|
</body>
|
343
|
</html>
|