1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
firewall_aliases_edit.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
|
require("guiconfig.inc");
|
35
|
|
36
|
if (!is_array($config['aliases']['alias']))
|
37
|
$config['aliases']['alias'] = array();
|
38
|
|
39
|
aliases_sort();
|
40
|
$a_aliases = &$config['aliases']['alias'];
|
41
|
|
42
|
$id = $_GET['id'];
|
43
|
if (isset($_POST['id']))
|
44
|
$id = $_POST['id'];
|
45
|
|
46
|
if (isset($id) && $a_aliases[$id]) {
|
47
|
$pconfig['name'] = $a_aliases[$id]['name'];
|
48
|
list($pconfig['address'],$pconfig['address_subnet']) =
|
49
|
explode('/', $a_aliases[$id]['address']);
|
50
|
if ($pconfig['address_subnet'])
|
51
|
$pconfig['type'] = "network";
|
52
|
else
|
53
|
$pconfig['type'] = "host";
|
54
|
$pconfig['descr'] = $a_aliases[$id]['descr'];
|
55
|
}
|
56
|
|
57
|
if ($_POST) {
|
58
|
|
59
|
unset($input_errors);
|
60
|
$pconfig = $_POST;
|
61
|
|
62
|
/* input validation */
|
63
|
$reqdfields = explode(" ", "name address");
|
64
|
$reqdfieldsn = explode(",", "Name,Address");
|
65
|
|
66
|
if ($_POST['type'] == "network") {
|
67
|
$reqdfields[] = "address_subnet";
|
68
|
$reqdfieldsn[] = "Subnet bit count";
|
69
|
}
|
70
|
|
71
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
|
72
|
|
73
|
if (($_POST['name'] && !is_validaliasname($_POST['name']))) {
|
74
|
$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9.";
|
75
|
}
|
76
|
if (($_POST['address'] && !is_ipaddr($_POST['address']))) {
|
77
|
// XXX: fixup this to detect correct type of data that should be posted.
|
78
|
// $input_errors[] = "A valid address must be specified.";
|
79
|
}
|
80
|
if (($_POST['address_subnet'] && !is_numeric($_POST['address_subnet']))) {
|
81
|
$input_errors[] = "A valid subnet bit count must be specified.";
|
82
|
}
|
83
|
|
84
|
/* check for name conflicts */
|
85
|
foreach ($a_aliases as $alias) {
|
86
|
if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
|
87
|
continue;
|
88
|
|
89
|
if ($alias['name'] == $_POST['name']) {
|
90
|
$input_errors[] = "An alias with this name already exists.";
|
91
|
break;
|
92
|
}
|
93
|
}
|
94
|
|
95
|
if (!$input_errors) {
|
96
|
$alias = array();
|
97
|
$alias['name'] = $_POST['name'];
|
98
|
if ($_POST['type'] == "network")
|
99
|
$alias['address'] = $_POST['address'] . "/" . $_POST['address_subnet'];
|
100
|
|
101
|
else
|
102
|
$alias['address'] = $_POST['address'];
|
103
|
|
104
|
$address = $alias['address'];
|
105
|
$isfirst = 0;
|
106
|
for($x=0; $x<99; $x++) {
|
107
|
$comd = "\$subnet = \$_POST['address" . $x . "'];";
|
108
|
eval($comd);
|
109
|
$comd = "\$subnet_address = \$_POST['address_subnet" . $x . "'];";
|
110
|
eval($comd);
|
111
|
if($subnet <> "") {
|
112
|
$address .= " ";
|
113
|
$address .= $subnet;
|
114
|
if($subnet_address <> "") $address .= "/" . $subnet_address;
|
115
|
}
|
116
|
}
|
117
|
|
118
|
$alias['address'] = $address;
|
119
|
$alias['descr'] = $_POST['descr'];
|
120
|
|
121
|
if (isset($id) && $a_aliases[$id])
|
122
|
$a_aliases[$id] = $alias;
|
123
|
else
|
124
|
$a_aliases[] = $alias;
|
125
|
|
126
|
touch($d_aliasesdirty_path);
|
127
|
|
128
|
write_config();
|
129
|
|
130
|
header("Location: firewall_aliases.php");
|
131
|
exit;
|
132
|
}
|
133
|
}
|
134
|
?>
|
135
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
136
|
<html>
|
137
|
<head>
|
138
|
<title><?=gentitle("System: Firewall: Aliases: Edit alias");?></title>
|
139
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
140
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
141
|
<script language="JavaScript">
|
142
|
<!--
|
143
|
function typesel_change() {
|
144
|
switch (document.iform.type.selectedIndex) {
|
145
|
case 0: /* host */
|
146
|
var cmd;
|
147
|
document.iform.address_subnet.disabled = 1;
|
148
|
document.iform.address_subnet.value = "";
|
149
|
document.iform.address_subnet.selected = 0;
|
150
|
newrows = totalrows+1;
|
151
|
for(i=2; i<newrows; i++) {
|
152
|
comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
|
153
|
eval(comd);
|
154
|
comd = 'document.iform.address_subnet' + i + '.value = "";';
|
155
|
eval(comd);
|
156
|
}
|
157
|
break;
|
158
|
case 1: /* network */
|
159
|
var cmd;
|
160
|
document.iform.address_subnet.disabled = 0;
|
161
|
document.iform.address_subnet.value = "";
|
162
|
newrows = totalrows+1;
|
163
|
for(i=2; i<newrows; i++) {
|
164
|
comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
|
165
|
eval(comd);
|
166
|
comd = 'document.iform.address_subnet' + i + '.value = "32";';
|
167
|
eval(comd);
|
168
|
}
|
169
|
break;
|
170
|
case 2: /* port */
|
171
|
var cmd;
|
172
|
document.iform.address_subnet.disabled = 1;
|
173
|
document.iform.address_subnet.value = "";
|
174
|
newrows = totalrows+1;
|
175
|
for(i=2; i<newrows; i++) {
|
176
|
comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
|
177
|
eval(comd);
|
178
|
comd = 'document.iform.address_subnet' + i + '.value = "32";';
|
179
|
eval(comd);
|
180
|
}
|
181
|
break;
|
182
|
}
|
183
|
}
|
184
|
|
185
|
function update_box_type() {
|
186
|
var indexNum = document.forms[0].type.selectedIndex;
|
187
|
var selected = document.forms[0].type.options[indexNum].text;
|
188
|
if(selected == 'Network(s)') {
|
189
|
document.getElementById ("addressnetworkport").firstChild.data = "Network(s)";
|
190
|
document.getElementById ("address_subnet").visible = true;
|
191
|
document.getElementById ("address_subnet").disabled = true;
|
192
|
} else if(selected == 'Host(s)') {
|
193
|
document.getElementById ("addressnetworkport").firstChild.data = "Host(s)";
|
194
|
document.getElementById ("address_subnet").visible = false;
|
195
|
document.getElementById ("address_subnet").disabled = false;
|
196
|
} else if(selected == 'Port(s)') {
|
197
|
document.getElementById ("addressnetworkport").firstChild.data = "Port(s)";
|
198
|
document.getElementById ("address_subnet").visible = false;
|
199
|
document.getElementById ("address_subnet").disabled = true;
|
200
|
}
|
201
|
}
|
202
|
|
203
|
-->
|
204
|
</script>
|
205
|
</head>
|
206
|
|
207
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
208
|
<?php include("fbegin.inc"); ?>
|
209
|
|
210
|
<script type="text/javascript" language="javascript" src="row_helper.js">
|
211
|
</script>
|
212
|
|
213
|
<input type='hidden' name='address_type' value='textbox'></input>
|
214
|
<input type='hidden' name='address_subnet_type' value='select'></input>
|
215
|
|
216
|
<script type="text/javascript" language='javascript'>
|
217
|
<!--
|
218
|
|
219
|
rowname[0] = "address";
|
220
|
rowtype[0] = "textbox";
|
221
|
|
222
|
rowname[1] = "address_subnet";
|
223
|
rowtype[1] = "select";
|
224
|
|
225
|
rowname[2] = "address_subnet";
|
226
|
rowtype[2] = "select";
|
227
|
-->
|
228
|
</script>
|
229
|
|
230
|
<p class="pgtitle">Firewall: Aliases: Edit alias</p>
|
231
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
232
|
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
|
233
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
234
|
<tr>
|
235
|
<td valign="top" class="vncellreq">Name</td>
|
236
|
<td class="vtable"> <input name="name" type="text" class="formfld" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>">
|
237
|
<br> <span class="vexpl">The name of the alias may only consist
|
238
|
of the characters a-z, A-Z and 0-9.</span></td>
|
239
|
</tr>
|
240
|
<tr>
|
241
|
<td width="22%" valign="top" class="vncell">Description</td>
|
242
|
<td width="78%" class="vtable"> <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
|
243
|
<br> <span class="vexpl">You may enter a description here
|
244
|
for your reference (not parsed).</span></td>
|
245
|
</tr>
|
246
|
<tr>
|
247
|
<td valign="top" class="vncellreq">Type</td>
|
248
|
<td class="vtable">
|
249
|
<select name="type" class="formfld" id="type" onChange="update_box_type(); typesel_change();">
|
250
|
<option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
|
251
|
<option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
|
252
|
<option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
|
253
|
</select>
|
254
|
</td>
|
255
|
</tr>
|
256
|
<tr>
|
257
|
<td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport" name="addressnetworkport">Host(s)</div></td>
|
258
|
<td width="78%" class="vtable">
|
259
|
|
260
|
|
261
|
<table name="maintable" id="maintable">
|
262
|
<tbody>
|
263
|
|
264
|
<?php
|
265
|
$counter = 0;
|
266
|
$address = $a_aliases[$id]['address'];
|
267
|
$item = explode(" ", $address);
|
268
|
foreach($item as $ww) {
|
269
|
$address = $item[$counter];
|
270
|
$address_subnet = "";
|
271
|
$item2 = explode("/", $address);
|
272
|
foreach($item2 as $current) {
|
273
|
if($item2[1] <> "") {
|
274
|
$address = $item2[0];
|
275
|
$address_subnet = $item2[1];
|
276
|
}
|
277
|
}
|
278
|
if($counter > 0) $tracker = $counter + 1;
|
279
|
?>
|
280
|
<tr><td> <input name="address<?php echo $tracker; ?>" type="text" class="formfld" id="address<?php echo $tracker; ?>" size="20" value="<?=htmlspecialchars($address);?>"></td><td>
|
281
|
<select name="address_subnet<?php echo $tracker; ?>" class="formfld" id="address_subnet<?php echo $tracker; ?>">
|
282
|
<option></option>
|
283
|
<?php for ($i = 32; $i >= 1; $i--): ?>
|
284
|
<option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
|
285
|
<?php endfor; ?>
|
286
|
</select>
|
287
|
<?php
|
288
|
if($counter > 0)
|
289
|
echo "<input type=\"image\" src=\"/x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\">";
|
290
|
?>
|
291
|
|
292
|
</td></tr>
|
293
|
<?php $counter++; } ?>
|
294
|
|
295
|
</tbody>
|
296
|
</table>
|
297
|
<a onClick="javascript:addRowTo('maintable'); typesel_change(); return false;" href="#"><img border="0" src="/plus.gif"></a>
|
298
|
</td>
|
299
|
</tr>
|
300
|
<tr>
|
301
|
<td width="22%" valign="top"> </td>
|
302
|
<td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
|
303
|
<?php if (isset($id) && $a_aliases[$id]): ?>
|
304
|
<input name="id" type="hidden" value="<?=$id;?>">
|
305
|
<?php endif; ?>
|
306
|
</td>
|
307
|
</tr>
|
308
|
</table>
|
309
|
</form>
|
310
|
<script language="JavaScript">
|
311
|
<!--
|
312
|
field_counter_js = 2;
|
313
|
rows = 1;
|
314
|
totalrows = <?php echo $counter; ?>;
|
315
|
loaded = <?php echo $counter; ?>;
|
316
|
typesel_change();
|
317
|
|
318
|
//-->
|
319
|
</script>
|
320
|
<?php include("fend.inc"); ?>
|
321
|
</body>
|
322
|
</html>
|