Project

General

Profile

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