Project

General

Profile

Download (11.9 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.disabled = 1;
175
			document.iform.address_subnet.value = "";
176
			document.iform.address_subnet.selected = 0;
177
			newrows = totalrows+1;
178
			for(i=2; i<newrows; i++) {
179
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
180
				eval(comd);
181
				comd = 'document.iform.address_subnet' + i + '.value = "";';
182
				eval(comd);
183
			}
184
			break;
185
		case 1:	/* network */
186
			var cmd;
187
			document.iform.address_subnet.disabled = 0;
188
//			document.iform.address_subnet.value = "";
189
			newrows = totalrows+1;
190
			for(i=2; i<newrows; i++) {
191
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
192
				eval(comd);
193
//				comd = 'document.iform.address_subnet' + i + '.value = "32";';
194
//				eval(comd);
195
			}
196
			break;
197
		case 2:	/* port */
198
			var cmd;
199
			document.iform.address_subnet.disabled = 1;
200
			document.iform.address_subnet.value = "";
201
			newrows = totalrows+1;
202
			for(i=2; i<newrows; i++) {
203
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
204
				eval(comd);
205
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
206
				eval(comd);
207
			}
208
			break;
209
	}
210
}
211

    
212
function update_box_type() {
213
	var indexNum = document.forms[0].type.selectedIndex;
214
	var selected = document.forms[0].type.options[indexNum].text;
215
	if(selected == 'Network(s)') {
216
		document.getElementById ("addressnetworkport").firstChild.data = "Network(s)";
217
		document.getElementById ("address_subnet").visible = true;
218
		document.getElementById ("address_subnet").disabled = false;
219
	} else if(selected == 'Host(s)') {
220
		document.getElementById ("addressnetworkport").firstChild.data = "Host(s)";
221
		document.getElementById ("address_subnet").visible = false;
222
		document.getElementById ("address_subnet").disabled = true;
223
	} else if(selected == 'Port(s)') {
224
		document.getElementById ("addressnetworkport").firstChild.data = "Port(s)";
225
		document.getElementById ("address_subnet").visible = false;
226
		document.getElementById ("address_subnet").disabled = true;
227
	}
228
}
229

    
230
-->
231
</script>
232

    
233
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
234
<?php include("fbegin.inc"); ?>
235

    
236
<script type="text/javascript" language="javascript" src="row_helper.js">
237
</script>
238

    
239
<input type='hidden' name='address_type' value='textbox'></input>
240
<input type='hidden' name='address_subnet_type' value='select'></input>
241

    
242
<script type="text/javascript" language='javascript'>
243
<!--
244

    
245
rowname[0] = "address";
246
rowtype[0] = "textbox";
247

    
248
rowname[1] = "address_subnet";
249
rowtype[1] = "select";
250

    
251
rowname[2] = "address_subnet";
252
rowtype[2] = "select";
253
-->
254
</script>
255

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

    
295

    
296
		    <table name="maintable" id="maintable">
297
		      <tbody>
298

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

    
327
			</td></tr>
328
			<?php $counter++; } ?>
329

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

    
354
//-->
355
</script>
356
<?php include("fend.inc"); ?>
357
</body>
358
</html>
(34-34/155)