Project

General

Profile

Download (12.1 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
	if (!$input_errors) {
122
		$alias = array();
123
		$alias['name'] = $_POST['name'];
124
		if ($_POST['type'] == "network")
125
			$alias['address'] = $_POST['address'] . "/" . $_POST['address_subnet'];
126

    
127
		else
128
			$alias['address'] = $_POST['address'];
129

    
130
		$address = $alias['address'];
131
		$isfirst = 0;
132
		for($x=0; $x<99; $x++) {
133
			$comd = "\$subnet = \$_POST['address" . $x . "'];";
134
			eval($comd);
135
			$comd = "\$subnet_address = \$_POST['address_subnet" . $x . "'];";
136
			eval($comd);
137
			if($subnet <> "") {
138
				$address .= " ";
139
				$address .= $subnet;
140
				if($subnet_address <> "") $address .= "/" . $subnet_address;
141
			}
142
		}
143

    
144
		$alias['address'] = $address;
145
		$alias['descr'] = $_POST['descr'];
146

    
147
		if (isset($id) && $a_aliases[$id])
148
			$a_aliases[$id] = $alias;
149
		else
150
			$a_aliases[] = $alias;
151

    
152
		touch($d_aliasesdirty_path);
153

    
154
		write_config();
155

    
156
		filter_configure();
157

    
158
		header("Location: firewall_aliases.php");
159
		exit;
160
	}
161
}
162

    
163
$pgtitle = "System: Firewall: Aliases: Edit";
164
include("head.inc");
165

    
166
?>
167

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

    
219
function update_box_type() {
220
	var indexNum = document.forms[0].type.selectedIndex;
221
	var selected = document.forms[0].type.options[indexNum].text;
222
	if(selected == 'Network(s)') {
223
		document.getElementById ("addressnetworkport").firstChild.data = "Network(s)";
224
		document.getElementById ("address_subnet").visible = true;
225
		document.getElementById ("address_subnet").disabled = false;
226
	} else if(selected == 'Host(s)') {
227
		document.getElementById ("addressnetworkport").firstChild.data = "Host(s)";
228
		document.getElementById ("address_subnet").visible = false;
229
		document.getElementById ("address_subnet").disabled = true;
230
	} else if(selected == 'Port(s)') {
231
		document.getElementById ("addressnetworkport").firstChild.data = "Port(s)";
232
		document.getElementById ("address_subnet").visible = false;
233
		document.getElementById ("address_subnet").disabled = true;
234
	}
235
}
236

    
237
-->
238
</script>
239

    
240
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
241
<?php include("fbegin.inc"); ?>
242

    
243
<script type="text/javascript" language="javascript" src="row_helper.js">
244
</script>
245

    
246
<input type='hidden' name='address_type' value='textbox'></input>
247
<input type='hidden' name='address_subnet_type' value='select'></input>
248

    
249
<script type="text/javascript" language='javascript'>
250
<!--
251

    
252
rowname[0] = "address";
253
rowtype[0] = "textbox";
254

    
255
rowname[1] = "address_subnet";
256
rowtype[1] = "select";
257

    
258
rowname[2] = "address_subnet";
259
rowtype[2] = "select";
260
-->
261
</script>
262

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

    
302

    
303
		    <table name="maintable" id="maintable">
304
		      <tbody>
305

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

    
334
			</td></tr>
335
			<?php $counter++; } ?>
336

    
337
		     </tbody>
338
		    </table>
339
			<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>
340
		    </td>
341
                </tr>
342
                <tr>
343
                  <td width="22%" valign="top">&nbsp;</td>
344
                  <td width="78%"> <input name="Submit" type="submit" class="formbtn" value="Save"> <input class="formbtn" type="button" value="Cancel" onclick="history.back()">
345
                    <?php if (isset($id) && $a_aliases[$id]): ?>
346
                    <input name="id" type="hidden" value="<?=$id;?>">
347
                    <?php endif; ?>
348
                  </td>
349
                </tr>
350
              </table>
351
</form>
352
<script language="JavaScript">
353
<!--
354
field_counter_js = 2;
355
rows = 1;
356
totalrows = <?php echo $counter; ?>;
357
loaded = <?php echo $counter; ?>;
358
typesel_change();
359
update_box_type();
360

    
361
//-->
362
</script>
363
<?php include("fend.inc"); ?>
364
</body>
365
</html>
(36-36/159)