Project

General

Profile

Download (10.7 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/*
4
	firewall_aliases_edit.php
5
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7

    
8
	originially part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	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

    
22
	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
	list($pconfig['address'],$pconfig['address_subnet']) =
49
		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

    
66
	if ($_POST['type'] == "network") {
67
		$reqdfields[] = "address_subnet";
68
		$reqdfieldsn[] = "Subnet bit count";
69
	}
70

    
71
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
72

    
73
	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

    
83
	/* 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

    
100
		else
101
			$alias['address'] = $_POST['address'];
102

    
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
		$alias['descr'] = $_POST['descr'];
119

    
120
		if (isset($id) && $a_aliases[$id])
121
			$a_aliases[$id] = $alias;
122
		else
123
			$a_aliases[] = $alias;
124

    
125
		touch($d_aliasesdirty_path);
126

    
127
		write_config();
128

    
129
		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
			var cmd;
146
			document.iform.address_subnet.disabled = 1;
147
			document.iform.address_subnet.value = "";
148
			document.iform.address_subnet.selected = 0;
149
			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
			break;
157
		case 1:	/* network */
158
			var cmd;
159
			document.iform.address_subnet.disabled = 0;
160
			document.iform.address_subnet.value = "";
161
			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
			break;
169
		case 2:	/* port */
170
			var cmd;
171
			document.iform.address_subnet.disabled = 1;
172
			document.iform.address_subnet.value = "";
173
			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
	}
182
}
183

    
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
		document.getElementById ("address_subnet").disabled = true;
191
	} else if(selected == 'Host(s)') {
192
		document.getElementById ("addressnetworkport").firstChild.data = "Host(s)";
193
		document.getElementById ("address_subnet").visible = false;
194
		document.getElementById ("address_subnet").disabled = false;
195
	} else if(selected == 'Port(s)') {
196
		document.getElementById ("addressnetworkport").firstChild.data = "Port(s)";
197
		document.getElementById ("address_subnet").visible = false;
198
		document.getElementById ("address_subnet").disabled = true;
199
	}
200
}
201

    
202
-->
203
</script>
204
</head>
205

    
206
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
207
<?php include("fbegin.inc"); ?>
208

    
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
<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
                <tr>
234
                  <td valign="top" class="vncellreq">Name</td>
235
                  <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
                    of the characters a-z, A-Z and 0-9.</span></td>
238
                </tr>
239
                <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
                  <td valign="top" class="vncellreq">Type</td>
247
                  <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
                    </select>
253
                  </td>
254
                </tr>
255
                <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
					echo "<input type=\"image\" src=\"/x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\">";
289
			  ?>
290

    
291
			</td></tr>
292
			<?php $counter++; } ?>
293

    
294
		     </tbody>
295
		    </table>
296
			<a onClick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="/plus.gif"></a>
297
		    </td>
298
                </tr>
299
                <tr>
300
                  <td width="22%" valign="top">&nbsp;</td>
301
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save">
302
                    <?php if (isset($id) && $a_aliases[$id]): ?>
303
                    <input name="id" type="hidden" value="<?=$id;?>">
304
                    <?php endif; ?>
305
                  </td>
306
                </tr>
307
              </table>
308
</form>
309
<script language="JavaScript">
310
<!--
311
field_counter_js = 2;
312
rows = 1;
313
totalrows = <?php echo $counter; ?>;
314
loaded = <?php echo $counter; ?>;
315
typesel_change();
316

    
317
//-->
318
</script>
319
<?php include("fend.inc"); ?>
320
</body>
321
</html>
(20-20/99)