Project

General

Profile

Download (11.3 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 d2cfb7a4 Scott Ullrich
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5
	firewall_aliases_edit.php
6 2e9ab96b Scott Ullrich
	Copyright (C) 2004 Scott Ullrich
7
	All rights reserved.
8
9
	originially part of m0n0wall (http://m0n0.ch/wall)
10 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12 d2cfb7a4 Scott Ullrich
13 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 d2cfb7a4 Scott Ullrich
16 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 d2cfb7a4 Scott Ullrich
19 5b237745 Scott Ullrich
	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 d2cfb7a4 Scott Ullrich
23 5b237745 Scott Ullrich
	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 d89924da Bill Marquette
	$addresses = explode(' ', $a_aliases[$id]['address']);
50
	if (is_array($addresses))
51
		$address = $addresses[0];
52
	else
53
		$address = $addresses;
54 d2cfb7a4 Scott Ullrich
	list($pconfig['address'],$pconfig['address_subnet']) =
55 d89924da Bill Marquette
		explode('/', $address);
56 5b237745 Scott Ullrich
	if ($pconfig['address_subnet'])
57
		$pconfig['type'] = "network";
58
	else
59 d89924da Bill Marquette
		if (is_ipaddr($pconfig['address']))
60
			$pconfig['type'] = "host";
61
		else
62
			$pconfig['type'] = "port";
63
			
64 5b237745 Scott Ullrich
	$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 d2cfb7a4 Scott Ullrich
76 5b237745 Scott Ullrich
	if ($_POST['type'] == "network") {
77
		$reqdfields[] = "address_subnet";
78
		$reqdfieldsn[] = "Subnet bit count";
79
	}
80 d2cfb7a4 Scott Ullrich
81 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
82 d2cfb7a4 Scott Ullrich
83 0df6adf8 Bill Marquette
	$x = is_validaliasname($_POST['name']);
84
	if (!isset($x)) {
85
		$input_errors[] = "Reserved word used for alias name.";
86
	} else {
87
		if (is_validaliasname($_POST['name']) == false)
88
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9.";
89 beeef1f0 Bill Marquette
	}
90 93a48ed8 Bill Marquette
	if ($_POST['type'] == "host")
91
		if (!is_ipaddr($_POST['address'])) {
92
			$input_errors[] = "A valid address must be specified.";
93
		}
94
	if ($_POST['type'] == "network") {
95
		if (!is_ipaddr($_POST['address'])) {
96
			$input_errors[] = "A valid address must be specified.";
97
		}
98
		if (!is_numeric($_POST['address_subnet'])) {
99
			$input_errors[] = "A valid subnet bit count must be specified.";
100
		}
101 5b237745 Scott Ullrich
	}
102 93a48ed8 Bill Marquette
	if ($_POST['type'] == "port")
103
		if (!is_port($_POST['address']))
104
			$input_errors[] = "The port must be an integer between 1 and 65535.";
105 d2cfb7a4 Scott Ullrich
106 5b237745 Scott Ullrich
	/* check for name conflicts */
107
	foreach ($a_aliases as $alias) {
108
		if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
109
			continue;
110
111
		if ($alias['name'] == $_POST['name']) {
112
			$input_errors[] = "An alias with this name already exists.";
113
			break;
114
		}
115
	}
116
117
	if (!$input_errors) {
118
		$alias = array();
119
		$alias['name'] = $_POST['name'];
120
		if ($_POST['type'] == "network")
121
			$alias['address'] = $_POST['address'] . "/" . $_POST['address_subnet'];
122 d2cfb7a4 Scott Ullrich
123 5b237745 Scott Ullrich
		else
124
			$alias['address'] = $_POST['address'];
125 d2cfb7a4 Scott Ullrich
126
		$address = $alias['address'];
127
		$isfirst = 0;
128
		for($x=0; $x<99; $x++) {
129
			$comd = "\$subnet = \$_POST['address" . $x . "'];";
130
			eval($comd);
131
			$comd = "\$subnet_address = \$_POST['address_subnet" . $x . "'];";
132
			eval($comd);
133
			if($subnet <> "") {
134 19757279 Scott Ullrich
				$address .= " ";
135 d2cfb7a4 Scott Ullrich
				$address .= $subnet;
136
				if($subnet_address <> "") $address .= "/" . $subnet_address;
137
			}
138
		}
139
140
		$alias['address'] = $address;
141 5b237745 Scott Ullrich
		$alias['descr'] = $_POST['descr'];
142
143
		if (isset($id) && $a_aliases[$id])
144
			$a_aliases[$id] = $alias;
145
		else
146
			$a_aliases[] = $alias;
147 d2cfb7a4 Scott Ullrich
148 7c9c77f7 Scott Ullrich
		filter_configure();
149 d2cfb7a4 Scott Ullrich
150 5b237745 Scott Ullrich
		write_config();
151 d2cfb7a4 Scott Ullrich
152 5b237745 Scott Ullrich
		header("Location: firewall_aliases.php");
153
		exit;
154
	}
155
}
156 da7ae7ef Bill Marquette
157 183a4aae Bill Marquette
$pgtitle = "System: Firewall: Aliases: Edit";
158 da7ae7ef Bill Marquette
include("head.inc");
159
160 5b237745 Scott Ullrich
?>
161 da7ae7ef Bill Marquette
162 5b237745 Scott Ullrich
<script language="JavaScript">
163
<!--
164
function typesel_change() {
165
	switch (document.iform.type.selectedIndex) {
166
		case 0:	/* host */
167 d2cfb7a4 Scott Ullrich
			var cmd;
168 5b237745 Scott Ullrich
			document.iform.address_subnet.disabled = 1;
169
			document.iform.address_subnet.value = "";
170 8a1a87cc Scott Ullrich
			document.iform.address_subnet.selected = 0;
171 d2cfb7a4 Scott Ullrich
			newrows = totalrows+1;
172
			for(i=2; i<newrows; i++) {
173
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
174
				eval(comd);
175
				comd = 'document.iform.address_subnet' + i + '.value = "";';
176
				eval(comd);
177
			}
178 5b237745 Scott Ullrich
			break;
179
		case 1:	/* network */
180 d2cfb7a4 Scott Ullrich
			var cmd;
181 5b237745 Scott Ullrich
			document.iform.address_subnet.disabled = 0;
182 d89924da Bill Marquette
//			document.iform.address_subnet.value = "";
183 d2cfb7a4 Scott Ullrich
			newrows = totalrows+1;
184
			for(i=2; i<newrows; i++) {
185
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
186
				eval(comd);
187 d89924da Bill Marquette
//				comd = 'document.iform.address_subnet' + i + '.value = "32";';
188
//				eval(comd);
189 d2cfb7a4 Scott Ullrich
			}
190 5b237745 Scott Ullrich
			break;
191 4d6b6263 Scott Ullrich
		case 2:	/* port */
192
			var cmd;
193 7fa0c501 Scott Ullrich
			document.iform.address_subnet.disabled = 1;
194 8a1a87cc Scott Ullrich
			document.iform.address_subnet.value = "";
195 4d6b6263 Scott Ullrich
			newrows = totalrows+1;
196
			for(i=2; i<newrows; i++) {
197
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
198
				eval(comd);
199
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
200
				eval(comd);
201
			}
202
			break;
203 5b237745 Scott Ullrich
	}
204
}
205 d2cfb7a4 Scott Ullrich
206
function update_box_type() {
207
	var indexNum = document.forms[0].type.selectedIndex;
208
	var selected = document.forms[0].type.options[indexNum].text;
209
	if(selected == 'Network(s)') {
210
		document.getElementById ("addressnetworkport").firstChild.data = "Network(s)";
211
		document.getElementById ("address_subnet").visible = true;
212 d89924da Bill Marquette
		document.getElementById ("address_subnet").disabled = false;
213 7fa0c501 Scott Ullrich
	} else if(selected == 'Host(s)') {
214
		document.getElementById ("addressnetworkport").firstChild.data = "Host(s)";
215 d2cfb7a4 Scott Ullrich
		document.getElementById ("address_subnet").visible = false;
216 d89924da Bill Marquette
		document.getElementById ("address_subnet").disabled = true;
217 d2cfb7a4 Scott Ullrich
	} else if(selected == 'Port(s)') {
218
		document.getElementById ("addressnetworkport").firstChild.data = "Port(s)";
219
		document.getElementById ("address_subnet").visible = false;
220 8a1a87cc Scott Ullrich
		document.getElementById ("address_subnet").disabled = true;
221 d2cfb7a4 Scott Ullrich
	}
222
}
223
224
-->
225 5b237745 Scott Ullrich
</script>
226
227
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
228
<?php include("fbegin.inc"); ?>
229 d2cfb7a4 Scott Ullrich
230
<script type="text/javascript" language="javascript" src="row_helper.js">
231
</script>
232
233
<input type='hidden' name='address_type' value='textbox'></input>
234
<input type='hidden' name='address_subnet_type' value='select'></input>
235
236
<script type="text/javascript" language='javascript'>
237
<!--
238
239
rowname[0] = "address";
240
rowtype[0] = "textbox";
241
242
rowname[1] = "address_subnet";
243
rowtype[1] = "select";
244
245
rowname[2] = "address_subnet";
246
rowtype[2] = "select";
247
-->
248
</script>
249
250 da7ae7ef Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
251 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
252
            <form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
253 ef97ce1b Bill Marquette
              <?display_topbar()?>
254 5b237745 Scott Ullrich
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
255 d2cfb7a4 Scott Ullrich
                <tr>
256 5b237745 Scott Ullrich
                  <td valign="top" class="vncellreq">Name</td>
257 d2cfb7a4 Scott Ullrich
                  <td class="vtable"> <input name="name" type="text" class="formfld" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>">
258
                    <br> <span class="vexpl">The name of the alias may only consist
259 5b237745 Scott Ullrich
                    of the characters a-z, A-Z and 0-9.</span></td>
260
                </tr>
261 d2cfb7a4 Scott Ullrich
                <tr>
262
                  <td width="22%" valign="top" class="vncell">Description</td>
263
                  <td width="78%" class="vtable"> <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
264
                    <br> <span class="vexpl">You may enter a description here
265
                    for your reference (not parsed).</span></td>
266
                </tr>
267
                <tr>
268 5b237745 Scott Ullrich
                  <td valign="top" class="vncellreq">Type</td>
269 d2cfb7a4 Scott Ullrich
                  <td class="vtable">
270
                    <select name="type" class="formfld" id="type" onChange="update_box_type(); typesel_change();">
271
                      <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
272
                      <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
273
		      <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
274 5b237745 Scott Ullrich
                    </select>
275
                  </td>
276
                </tr>
277 d2cfb7a4 Scott Ullrich
                <tr>
278
                  <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport" name="addressnetworkport">Host(s)</div></td>
279
                  <td width="78%" class="vtable">
280
281
282
		    <table name="maintable" id="maintable">
283
		      <tbody>
284
285
			<?php
286
			$counter = 0;
287
			$address = $a_aliases[$id]['address'];
288 19757279 Scott Ullrich
			$item = explode(" ", $address);
289 d2cfb7a4 Scott Ullrich
			foreach($item as $ww) {
290
				$address = $item[$counter];
291
				$address_subnet = "";
292
				$item2 = explode("/", $address);
293
				foreach($item2 as $current) {
294
					if($item2[1] <> "") {
295
						$address = $item2[0];
296
						$address_subnet = $item2[1];
297
					}
298
				}
299
				if($counter > 0) $tracker = $counter + 1;
300
			?>
301
			<tr><td> <input name="address<?php echo $tracker; ?>" type="text" class="formfld" id="address<?php echo $tracker; ?>" size="20" value="<?=htmlspecialchars($address);?>"></td><td>
302
			<select name="address_subnet<?php echo $tracker; ?>" class="formfld" id="address_subnet<?php echo $tracker; ?>">
303
			  <option></option>
304
			  <?php for ($i = 32; $i >= 1; $i--): ?>
305
			  <option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
306
			  <?php endfor; ?>
307
			</select>
308
			  <?php
309
				if($counter > 0)
310 677c0869 Erik Kristensen
					echo "<input type=\"image\" src=\"/themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\">";
311 d2cfb7a4 Scott Ullrich
			  ?>
312
313
			</td></tr>
314
			<?php $counter++; } ?>
315
316
		     </tbody>
317
		    </table>
318 b31032e4 Bill Marquette
			<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>
319 d2cfb7a4 Scott Ullrich
		    </td>
320 5b237745 Scott Ullrich
                </tr>
321 d2cfb7a4 Scott Ullrich
                <tr>
322 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
323 fc01e414 Scott Ullrich
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
324 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_aliases[$id]): ?>
325 d2cfb7a4 Scott Ullrich
                    <input name="id" type="hidden" value="<?=$id;?>">
326 5b237745 Scott Ullrich
                    <?php endif; ?>
327
                  </td>
328
                </tr>
329
              </table>
330
</form>
331
<script language="JavaScript">
332
<!--
333 d2cfb7a4 Scott Ullrich
field_counter_js = 2;
334
rows = 1;
335
totalrows = <?php echo $counter; ?>;
336
loaded = <?php echo $counter; ?>;
337 5b237745 Scott Ullrich
typesel_change();
338 d89924da Bill Marquette
update_box_type();
339 d2cfb7a4 Scott Ullrich
340 5b237745 Scott Ullrich
//-->
341
</script>
342
<?php include("fend.inc"); ?>
343
</body>
344
</html>