Project

General

Profile

Download (12.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
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
	$addresses = explode(' ', $a_aliases[$id]['address']);
49
	if (is_array($addresses))
50
		$address = $addresses[0];
51
	else
52
		$address = $addresses;
53
	list($pconfig['address'],$pconfig['address_subnet']) =
54
		explode('/', $address);
55
	if ($pconfig['address_subnet'])
56
		$pconfig['type'] = "network";
57
	else
58
		if (is_ipaddr($pconfig['address']))
59
			$pconfig['type'] = "host";
60
		else
61
			$pconfig['type'] = "port";
62
			
63
	$pconfig['descr'] = $a_aliases[$id]['descr'];
64
}
65

    
66
if ($_POST) {
67

    
68
	unset($input_errors);
69
	$pconfig = $_POST;
70

    
71
	/* input validation */
72
	$reqdfields = explode(" ", "name address");
73
	$reqdfieldsn = explode(",", "Name,Address");
74

    
75
	if ($_POST['type'] == "network") {
76
		$reqdfields[] = "address_subnet";
77
		$reqdfieldsn[] = "Subnet bit count";
78
	}
79

    
80
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
81

    
82
	if(strtolower($_POST['name']) == "lan")
83
		$input_errors[] = "Aliases may not be named LAN.";
84
	if(strtolower($_POST['name']) == "wan")
85
		$input_errors[] = "Aliases may not be named WAN.";
86

    
87
	$x = is_validaliasname($_POST['name']);
88
	if (!isset($x)) {
89
		$input_errors[] = "Reserved word used for alias name.";
90
	} else {
91
		if (is_validaliasname($_POST['name']) == false)
92
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9.";
93
	}
94
	if ($_POST['type'] == "host")
95
		if (!is_ipaddr($_POST['address'])) {
96
			$input_errors[] = "A valid address must be specified.";
97
		}
98
	if ($_POST['type'] == "network") {
99
		if (!is_ipaddr($_POST['address'])) {
100
			$input_errors[] = "A valid address must be specified.";
101
		}
102
		if (!is_numeric($_POST['address_subnet'])) {
103
			$input_errors[] = "A valid subnet bit count must be specified.";
104
		}
105
	}
106
	if ($_POST['type'] == "port")
107
		if (!is_port($_POST['address']))
108
			$input_errors[] = "The port must be an integer between 1 and 65535.";
109

    
110
	/* check for name conflicts */
111
	foreach ($a_aliases as $alias) {
112
		if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
113
			continue;
114

    
115
		if ($alias['name'] == $_POST['name']) {
116
			$input_errors[] = "An alias with this name already exists.";
117
			break;
118
		}
119
	}
120
	
121
	/* check for name interface description conflicts */
122
	foreach($config['interfaces'] as $interface) {
123
		if($interface['descr'] == $_POST['name']) {
124
			$input_errors[] = gettext("An interface description with this name already exists.");
125
			break;	
126
		}
127
	}	
128

    
129
	if (!$input_errors) {
130
		$alias = array();
131
		$alias['name'] = $_POST['name'];
132
		if ($_POST['type'] == "network")
133
			$alias['address'] = $_POST['address'] . "/" . $_POST['address_subnet'];
134

    
135
		else
136
			$alias['address'] = $_POST['address'];
137

    
138
		$address = $alias['address'];
139
		$isfirst = 0;
140
		for($x=0; $x<99; $x++) {
141
			$comd = "\$subnet = \$_POST['address" . $x . "'];";
142
			eval($comd);
143
			$comd = "\$subnet_address = \$_POST['address_subnet" . $x . "'];";
144
			eval($comd);
145
			if($subnet <> "") {
146
				$address .= " ";
147
				$address .= $subnet;
148
				if($subnet_address <> "") $address .= "/" . $subnet_address;
149
			}
150
		}
151

    
152
		$alias['address'] = $address;
153
		$alias['descr'] = $_POST['descr'];
154

    
155
		if (isset($id) && $a_aliases[$id])
156
			$a_aliases[$id] = $alias;
157
		else
158
			$a_aliases[] = $alias;
159

    
160
		touch($d_aliasesdirty_path);
161

    
162
		write_config();
163

    
164
		filter_configure();
165

    
166
		header("Location: firewall_aliases.php");
167
		exit;
168
	}
169
}
170

    
171
$pgtitle = "System: Firewall: Aliases: Edit";
172
include("head.inc");
173

    
174
?>
175

    
176
<script language="JavaScript">
177
<!--
178
function typesel_change() {
179
	switch (document.iform.type.selectedIndex) {
180
		case 0:	/* host */
181
			var cmd;
182
			document.iform.address_subnet.value = "";
183
			document.iform.address_subnet.selected = 0;
184
			document.iform.address_subnet.disabled = 1;
185
			newrows = totalrows+100;
186
			for(i=1; i<newrows; i++) {
187
				var working_with = 'address_subnet' + i;
188
				var item = document.getElementById(working_with);
189
				if(item) {
190
					comd = 'document.iform.' + working_with + '.value = "";';
191
					eval(comd);
192
					comd = 'document.iform.' + working_with + '.disabled = 1;';
193
					eval(comd);
194
				}
195
			}
196
			break;
197
		case 1:	/* network */
198
			var cmd;
199
			document.iform.address_subnet.disabled = 0;
200
			newrows = totalrows+100;
201
			for(i=2; i<newrows; i++) {
202
				var item = document.getElementById('address_subnet' + i);
203
				if(item) {
204
					comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
205
					eval(comd);
206
				}
207
			}
208
			break;
209
		case 2:	/* port */
210
			var cmd;
211
			document.iform.address_subnet.disabled = 1;
212
			document.iform.address_subnet.value = "";
213
			newrows = totalrows+100;
214
			for(i=2; i<newrows; i++) {
215
				var item = document.getElementById('address_subnet' + i);
216
				if(item) {
217
					comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
218
					eval(comd);
219
					comd = 'document.iform.address_subnet' + i + '.value = "32";';
220
					eval(comd);
221
				}
222
			}
223
			break;
224
	}
225
}
226

    
227
function update_box_type() {
228
	var indexNum = document.forms[0].type.selectedIndex;
229
	var selected = document.forms[0].type.options[indexNum].text;
230
	if(selected == 'Network(s)') {
231
		document.getElementById ("addressnetworkport").firstChild.data = "Network(s)";
232
		document.getElementById ("address_subnet").visible = true;
233
		document.getElementById ("address_subnet").disabled = false;
234
	} else if(selected == 'Host(s)') {
235
		document.getElementById ("addressnetworkport").firstChild.data = "Host(s)";
236
		document.getElementById ("address_subnet").visible = false;
237
		document.getElementById ("address_subnet").disabled = true;
238
	} else if(selected == 'Port(s)') {
239
		document.getElementById ("addressnetworkport").firstChild.data = "Port(s)";
240
		document.getElementById ("address_subnet").visible = false;
241
		document.getElementById ("address_subnet").disabled = true;
242
	}
243
}
244

    
245
-->
246
</script>
247

    
248
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
249
<?php include("fbegin.inc"); ?>
250

    
251
<script type="text/javascript" language="javascript" src="row_helper.js">
252
</script>
253

    
254
<input type='hidden' name='address_type' value='textbox'></input>
255
<input type='hidden' name='address_subnet_type' value='select'></input>
256

    
257
<script type="text/javascript" language='javascript'>
258
<!--
259

    
260
rowname[0] = "address";
261
rowtype[0] = "textbox";
262

    
263
rowname[1] = "address_subnet";
264
rowtype[1] = "select";
265

    
266
rowname[2] = "address_subnet";
267
rowtype[2] = "select";
268
-->
269
</script>
270

    
271
<p class="pgtitle"><?=$pgtitle?></p>
272
<?php if ($input_errors) print_input_errors($input_errors); ?>
273
            <form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
274
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
275
<?php if(is_alias_inuse($pconfig['name']) == true): ?>
276
                <tr>
277
                  <td valign="top" class="vncellreq">Name</td>
278
                  <td class="vtable"> <input name="name" type="hidden" class="formfld" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>">
279
		  <?php echo $pconfig['name']; ?>
280
                    <p><span class="vexpl">NOTE: This alias is in use so the name may not be modified!</span></td>
281
                </tr>
282
<?php else: ?>
283
                <tr>
284
                  <td valign="top" class="vncellreq">Name</td>
285
                  <td class="vtable"> <input name="name" type="text" class="formfld" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>">
286
                    <br> <span class="vexpl">The name of the alias may only consist
287
                    of the characters a-z, A-Z and 0-9.</span></td>
288
                </tr>
289
<?php endif; ?>
290
                <tr>
291
                  <td width="22%" valign="top" class="vncell">Description</td>
292
                  <td width="78%" class="vtable"> <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
293
                    <br> <span class="vexpl">You may enter a description here
294
                    for your reference (not parsed).</span></td>
295
                </tr>
296
                <tr>
297
                  <td valign="top" class="vncellreq">Type</td>
298
                  <td class="vtable">
299
                    <select name="type" class="formfld" id="type" onChange="update_box_type(); typesel_change();">
300
                      <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
301
                      <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
302
		      <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
303
                    </select>
304
                  </td>
305
                </tr>
306
                <tr>
307
                  <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport" name="addressnetworkport">Host(s)</div></td>
308
                  <td width="78%" class="vtable">
309

    
310

    
311
		    <table name="maintable" id="maintable">
312
		      <tbody>
313

    
314
			<?php
315
			$counter = 0;
316
			$address = $a_aliases[$id]['address'];
317
			$item = explode(" ", $address);
318
			foreach($item as $ww) {
319
				$address = $item[$counter];
320
				$address_subnet = "";
321
				$item2 = explode("/", $address);
322
				foreach($item2 as $current) {
323
					if($item2[1] <> "") {
324
						$address = $item2[0];
325
						$address_subnet = $item2[1];
326
					}
327
				}
328
				if($counter > 0) $tracker = $counter + 1;
329
			?>
330
			<tr><td> <input name="address<?php echo $tracker; ?>" type="text" class="formfld" id="address<?php echo $tracker; ?>" size="20" value="<?=htmlspecialchars($address);?>"></td><td>
331
			<select name="address_subnet<?php echo $tracker; ?>" class="formfld" id="address_subnet<?php echo $tracker; ?>">
332
			  <option></option>
333
			  <?php for ($i = 32; $i >= 1; $i--): ?>
334
			  <option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
335
			  <?php endfor; ?>
336
			</select>
337
			  <?php
338
				if($counter > 0)
339
					echo "<input type=\"image\" src=\"/themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\">";
340
			  ?>
341

    
342
			</td></tr>
343
			<?php $counter++; } ?>
344

    
345
		     </tbody>
346
		    </table>
347
			<a onClick="javascript:addRowTo('maintable'); typesel_change(); return false;" href="#"><img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" title="add another entry"></a>
348
		    </td>
349
                </tr>
350
                <tr>
351
                  <td width="22%" valign="top">&nbsp;</td>
352
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
353
                    <?php if (isset($id) && $a_aliases[$id]): ?>
354
                    <input name="id" type="hidden" value="<?=$id;?>">
355
                    <?php endif; ?>
356
                  </td>
357
                </tr>
358
              </table>
359
</form>
360
<script language="JavaScript">
361
<!--
362
field_counter_js = 2;
363
rows = 1;
364
totalrows = <?php echo $counter; ?>;
365
loaded = <?php echo $counter; ?>;
366
typesel_change();
367
update_box_type();
368

    
369
//-->
370
</script>
371
<?php include("fend.inc"); ?>
372
</body>
373
</html>
(38-38/165)