Project

General

Profile

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