Project

General

Profile

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