Project

General

Profile

Download (10.3 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 d2cfb7a4 Scott Ullrich
			newrows = totalrows+1;
149
			for(i=2; i<newrows; i++) {
150
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
151
				eval(comd);
152
				comd = 'document.iform.address_subnet' + i + '.value = "";';
153
				eval(comd);
154
			}
155 5b237745 Scott Ullrich
			break;
156
		case 1:	/* network */
157 d2cfb7a4 Scott Ullrich
			var cmd;
158 5b237745 Scott Ullrich
			document.iform.address_subnet.disabled = 0;
159 d2cfb7a4 Scott Ullrich
			newrows = totalrows+1;
160
			for(i=2; i<newrows; i++) {
161
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
162
				eval(comd);
163
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
164
				eval(comd);
165
			}
166 5b237745 Scott Ullrich
			break;
167 4d6b6263 Scott Ullrich
		case 2:	/* port */
168
			var cmd;
169
			document.iform.address_subnet.disabled = 0;
170
			newrows = totalrows+1;
171
			for(i=2; i<newrows; i++) {
172
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
173
				eval(comd);
174
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
175
				eval(comd);
176
			}
177
			break;
178 5b237745 Scott Ullrich
	}
179
}
180 d2cfb7a4 Scott Ullrich
181
function update_box_type() {
182
	var indexNum = document.forms[0].type.selectedIndex;
183
	var selected = document.forms[0].type.options[indexNum].text;
184
	if(selected == 'Network(s)') {
185
		document.getElementById ("addressnetworkport").firstChild.data = "Network(s)";
186
		document.getElementById ("address_subnet").visible = true;
187
	} else if(selected == 'Hosts(s)') {
188
		ument.getElementById ("addressnetworkport").firstChild.data = "Host(s)";
189
		document.getElementById ("address_subnet").visible = false;
190
	} else if(selected == 'Port(s)') {
191
192
		document.getElementById ("addressnetworkport").firstChild.data = "Port(s)";
193
		document.getElementById ("address_subnet").visible = false;
194
	}
195
}
196
197
-->
198 5b237745 Scott Ullrich
</script>
199
</head>
200
201
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
202
<?php include("fbegin.inc"); ?>
203 d2cfb7a4 Scott Ullrich
204
<script type="text/javascript" language="javascript" src="row_helper.js">
205
</script>
206
207
<input type='hidden' name='address_type' value='textbox'></input>
208
<input type='hidden' name='address_subnet_type' value='select'></input>
209
210
<script type="text/javascript" language='javascript'>
211
<!--
212
213
rowname[0] = "address";
214
rowtype[0] = "textbox";
215
216
rowname[1] = "address_subnet";
217
rowtype[1] = "select";
218
219
rowname[2] = "address_subnet";
220
rowtype[2] = "select";
221
-->
222
</script>
223
224 5b237745 Scott Ullrich
<p class="pgtitle">Firewall: Aliases: Edit alias</p>
225
<?php if ($input_errors) print_input_errors($input_errors); ?>
226
            <form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
227
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
228 d2cfb7a4 Scott Ullrich
                <tr>
229 5b237745 Scott Ullrich
                  <td valign="top" class="vncellreq">Name</td>
230 d2cfb7a4 Scott Ullrich
                  <td class="vtable"> <input name="name" type="text" class="formfld" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>">
231
                    <br> <span class="vexpl">The name of the alias may only consist
232 5b237745 Scott Ullrich
                    of the characters a-z, A-Z and 0-9.</span></td>
233
                </tr>
234 d2cfb7a4 Scott Ullrich
                <tr>
235
                  <td width="22%" valign="top" class="vncell">Description</td>
236
                  <td width="78%" class="vtable"> <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
237
                    <br> <span class="vexpl">You may enter a description here
238
                    for your reference (not parsed).</span></td>
239
                </tr>
240
                <tr>
241 5b237745 Scott Ullrich
                  <td valign="top" class="vncellreq">Type</td>
242 d2cfb7a4 Scott Ullrich
                  <td class="vtable">
243
                    <select name="type" class="formfld" id="type" onChange="update_box_type(); typesel_change();">
244
                      <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
245
                      <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
246
		      <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
247 5b237745 Scott Ullrich
                    </select>
248
                  </td>
249
                </tr>
250 d2cfb7a4 Scott Ullrich
                <tr>
251
                  <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport" name="addressnetworkport">Host(s)</div></td>
252
                  <td width="78%" class="vtable">
253
254
255
		    <table name="maintable" id="maintable">
256
		      <tbody>
257
258
			<?php
259
			$counter = 0;
260
			$address = $a_aliases[$id]['address'];
261
			$item = explode(", ", $address);
262
			foreach($item as $ww) {
263
				$address = $item[$counter];
264
				$address_subnet = "";
265
				$item2 = explode("/", $address);
266
				foreach($item2 as $current) {
267
					if($item2[1] <> "") {
268
						$address = $item2[0];
269
						$address_subnet = $item2[1];
270
					}
271
				}
272
				if($counter > 0) $tracker = $counter + 1;
273
			?>
274
			<tr><td> <input name="address<?php echo $tracker; ?>" type="text" class="formfld" id="address<?php echo $tracker; ?>" size="20" value="<?=htmlspecialchars($address);?>"></td><td>
275
			<select name="address_subnet<?php echo $tracker; ?>" class="formfld" id="address_subnet<?php echo $tracker; ?>">
276
			  <option></option>
277
			  <?php for ($i = 32; $i >= 1; $i--): ?>
278
			  <option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
279
			  <?php endfor; ?>
280
			</select>
281
			  <?php
282
				if($counter > 0)
283
					echo "<input type=\"button\" onclick=\"removeRow(this); typesel_change();\" value=\"Delete\">";
284
			  ?>
285
286
			</td></tr>
287
			<?php $counter++; } ?>
288
289
		     </tbody>
290
		    </table>
291
			<input type="button" onclick="addRowTo('maintable'); typesel_change();" value="Add">
292
		    </td>
293 5b237745 Scott Ullrich
                </tr>
294 d2cfb7a4 Scott Ullrich
                <tr>
295 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
296 d2cfb7a4 Scott Ullrich
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
297 5b237745 Scott Ullrich
                    <?php if (isset($id) && $a_aliases[$id]): ?>
298 d2cfb7a4 Scott Ullrich
                    <input name="id" type="hidden" value="<?=$id;?>">
299 5b237745 Scott Ullrich
                    <?php endif; ?>
300
                  </td>
301
                </tr>
302
              </table>
303
</form>
304
<script language="JavaScript">
305
<!--
306 d2cfb7a4 Scott Ullrich
field_counter_js = 2;
307
rows = 1;
308
totalrows = <?php echo $counter; ?>;
309
loaded = <?php echo $counter; ?>;
310 5b237745 Scott Ullrich
typesel_change();
311 d2cfb7a4 Scott Ullrich
312 5b237745 Scott Ullrich
//-->
313
</script>
314
<?php include("fend.inc"); ?>
315
</body>
316
</html>