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