Project

General

Profile

Download (10.8 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 d2cfb7a4 Scott Ullrich
<?php
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 d2cfb7a4 Scott Ullrich
	list($pconfig['address'],$pconfig['address_subnet']) =
49 5b237745 Scott Ullrich
		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 d2cfb7a4 Scott Ullrich
66 5b237745 Scott Ullrich
	if ($_POST['type'] == "network") {
67
		$reqdfields[] = "address_subnet";
68
		$reqdfieldsn[] = "Subnet bit count";
69
	}
70 d2cfb7a4 Scott Ullrich
71 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
72 d2cfb7a4 Scott Ullrich
73 5b237745 Scott Ullrich
	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 19757279 Scott Ullrich
// XXX: fixup this to detect correct type of data that should be posted.
78
//		$input_errors[] = "A valid address must be specified.";
79 5b237745 Scott Ullrich
	}
80
	if (($_POST['address_subnet'] && !is_numeric($_POST['address_subnet']))) {
81
		$input_errors[] = "A valid subnet bit count must be specified.";
82
	}
83 d2cfb7a4 Scott Ullrich
84 5b237745 Scott Ullrich
	/* 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 d2cfb7a4 Scott Ullrich
101 5b237745 Scott Ullrich
		else
102
			$alias['address'] = $_POST['address'];
103 d2cfb7a4 Scott Ullrich
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 19757279 Scott Ullrich
				$address .= " ";
113 d2cfb7a4 Scott Ullrich
				$address .= $subnet;
114
				if($subnet_address <> "") $address .= "/" . $subnet_address;
115
			}
116
		}
117
118
		$alias['address'] = $address;
119 5b237745 Scott Ullrich
		$alias['descr'] = $_POST['descr'];
120
121
		if (isset($id) && $a_aliases[$id])
122
			$a_aliases[$id] = $alias;
123
		else
124
			$a_aliases[] = $alias;
125 d2cfb7a4 Scott Ullrich
126 5b237745 Scott Ullrich
		touch($d_aliasesdirty_path);
127 d2cfb7a4 Scott Ullrich
128 5b237745 Scott Ullrich
		write_config();
129 d2cfb7a4 Scott Ullrich
130 5b237745 Scott Ullrich
		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 d2cfb7a4 Scott Ullrich
			var cmd;
147 5b237745 Scott Ullrich
			document.iform.address_subnet.disabled = 1;
148
			document.iform.address_subnet.value = "";
149 8a1a87cc Scott Ullrich
			document.iform.address_subnet.selected = 0;
150 d2cfb7a4 Scott Ullrich
			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 5b237745 Scott Ullrich
			break;
158
		case 1:	/* network */
159 d2cfb7a4 Scott Ullrich
			var cmd;
160 5b237745 Scott Ullrich
			document.iform.address_subnet.disabled = 0;
161 8a1a87cc Scott Ullrich
			document.iform.address_subnet.value = "";
162 d2cfb7a4 Scott Ullrich
			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 5b237745 Scott Ullrich
			break;
170 4d6b6263 Scott Ullrich
		case 2:	/* port */
171
			var cmd;
172 7fa0c501 Scott Ullrich
			document.iform.address_subnet.disabled = 1;
173 8a1a87cc Scott Ullrich
			document.iform.address_subnet.value = "";
174 4d6b6263 Scott Ullrich
			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 5b237745 Scott Ullrich
	}
183
}
184 d2cfb7a4 Scott Ullrich
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 8a1a87cc Scott Ullrich
		document.getElementById ("address_subnet").disabled = true;
192 7fa0c501 Scott Ullrich
	} else if(selected == 'Host(s)') {
193
		document.getElementById ("addressnetworkport").firstChild.data = "Host(s)";
194 d2cfb7a4 Scott Ullrich
		document.getElementById ("address_subnet").visible = false;
195 8a1a87cc Scott Ullrich
		document.getElementById ("address_subnet").disabled = false;
196 d2cfb7a4 Scott Ullrich
	} else if(selected == 'Port(s)') {
197
		document.getElementById ("addressnetworkport").firstChild.data = "Port(s)";
198
		document.getElementById ("address_subnet").visible = false;
199 8a1a87cc Scott Ullrich
		document.getElementById ("address_subnet").disabled = true;
200 d2cfb7a4 Scott Ullrich
	}
201
}
202
203
-->
204 5b237745 Scott Ullrich
</script>
205
</head>
206
207
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
208
<?php include("fbegin.inc"); ?>
209 d2cfb7a4 Scott Ullrich
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 5b237745 Scott Ullrich
<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 d2cfb7a4 Scott Ullrich
                <tr>
235 5b237745 Scott Ullrich
                  <td valign="top" class="vncellreq">Name</td>
236 d2cfb7a4 Scott Ullrich
                  <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 5b237745 Scott Ullrich
                    of the characters a-z, A-Z and 0-9.</span></td>
239
                </tr>
240 d2cfb7a4 Scott Ullrich
                <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 5b237745 Scott Ullrich
                  <td valign="top" class="vncellreq">Type</td>
248 d2cfb7a4 Scott Ullrich
                  <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 5b237745 Scott Ullrich
                    </select>
254
                  </td>
255
                </tr>
256 d2cfb7a4 Scott Ullrich
                <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 19757279 Scott Ullrich
			$item = explode(" ", $address);
268 d2cfb7a4 Scott Ullrich
			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 e02a6839 Scott Ullrich
					echo "<input type=\"image\" src=\"/x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\">";
290 d2cfb7a4 Scott Ullrich
			  ?>
291
292
			</td></tr>
293
			<?php $counter++; } ?>
294
295
		     </tbody>
296
		    </table>
297 19757279 Scott Ullrich
			<a onClick="javascript:addRowTo('maintable'); typesel_change(); return false;" href="#"><img border="0" src="/plus.gif"></a>
298 d2cfb7a4 Scott Ullrich
		    </td>
299 5b237745 Scott Ullrich
                </tr>
300 d2cfb7a4 Scott Ullrich
                <tr>
301 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
302 d2cfb7a4 Scott Ullrich
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
303 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_aliases[$id]): ?>
304 d2cfb7a4 Scott Ullrich
                    <input name="id" type="hidden" value="<?=$id;?>">
305 5b237745 Scott Ullrich
                    <?php endif; ?>
306
                  </td>
307
                </tr>
308
              </table>
309
</form>
310
<script language="JavaScript">
311
<!--
312 d2cfb7a4 Scott Ullrich
field_counter_js = 2;
313
rows = 1;
314
totalrows = <?php echo $counter; ?>;
315
loaded = <?php echo $counter; ?>;
316 5b237745 Scott Ullrich
typesel_change();
317 d2cfb7a4 Scott Ullrich
318 5b237745 Scott Ullrich
//-->
319
</script>
320
<?php include("fend.inc"); ?>
321
</body>
322
</html>