Project

General

Profile

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

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

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

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

    
19
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22

    
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34

    
35
require("guiconfig.inc");
36

    
37
if (!is_array($config['aliases']['alias']))
38
	$config['aliases']['alias'] = array();
39

    
40
aliases_sort();
41
$a_aliases = &$config['aliases']['alias'];
42

    
43
$id = $_GET['id'];
44
if (isset($_POST['id']))
45
	$id = $_POST['id'];
46

    
47
if (isset($id) && $a_aliases[$id]) {
48
	$pconfig['name'] = $a_aliases[$id]['name'];
49
	list($pconfig['address'],$pconfig['address_subnet']) =
50
		explode('/', $a_aliases[$id]['address']);
51
	if ($pconfig['address_subnet'])
52
		$pconfig['type'] = "network";
53
	else
54
		$pconfig['type'] = "host";
55
	$pconfig['descr'] = $a_aliases[$id]['descr'];
56
}
57

    
58
if ($_POST) {
59

    
60
	unset($input_errors);
61
	$pconfig = $_POST;
62

    
63
	/* input validation */
64
	$reqdfields = explode(" ", "name address");
65
	$reqdfieldsn = explode(",", "Name,Address");
66

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

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

    
74
	if (($_POST['name'] && !is_validaliasname($_POST['name']))) {
75
		$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9.";
76
	}
77
	if (($_POST['address'] && !is_ipaddr($_POST['address']))) {
78
// XXX: fixup this to detect correct type of data that should be posted.
79
//		$input_errors[] = "A valid address must be specified.";
80
	}
81
	if (($_POST['address_subnet'] && !is_numeric($_POST['address_subnet']))) {
82
		$input_errors[] = "A valid subnet bit count must be specified.";
83
	}
84

    
85
	/* check for name conflicts */
86
	foreach ($a_aliases as $alias) {
87
		if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
88
			continue;
89

    
90
		if ($alias['name'] == $_POST['name']) {
91
			$input_errors[] = "An alias with this name already exists.";
92
			break;
93
		}
94
	}
95

    
96
	if (!$input_errors) {
97
		$alias = array();
98
		$alias['name'] = $_POST['name'];
99
		if ($_POST['type'] == "network")
100
			$alias['address'] = $_POST['address'] . "/" . $_POST['address_subnet'];
101

    
102
		else
103
			$alias['address'] = $_POST['address'];
104

    
105
		$address = $alias['address'];
106
		$isfirst = 0;
107
		for($x=0; $x<99; $x++) {
108
			$comd = "\$subnet = \$_POST['address" . $x . "'];";
109
			eval($comd);
110
			$comd = "\$subnet_address = \$_POST['address_subnet" . $x . "'];";
111
			eval($comd);
112
			if($subnet <> "") {
113
				$address .= " ";
114
				$address .= $subnet;
115
				if($subnet_address <> "") $address .= "/" . $subnet_address;
116
			}
117
		}
118

    
119
		$alias['address'] = $address;
120
		$alias['descr'] = $_POST['descr'];
121

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

    
127
		touch($d_aliasesdirty_path);
128

    
129
		write_config();
130

    
131
		header("Location: firewall_aliases.php");
132
		exit;
133
	}
134
}
135
?>
136
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
137
<html>
138
<head>
139
<title><?=gentitle("System: Firewall: Aliases: Edit alias");?></title>
140
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
141
<link href="gui.css" rel="stylesheet" type="text/css">
142
<script language="JavaScript">
143
<!--
144
function typesel_change() {
145
	switch (document.iform.type.selectedIndex) {
146
		case 0:	/* host */
147
			var cmd;
148
			document.iform.address_subnet.disabled = 1;
149
			document.iform.address_subnet.value = "";
150
			document.iform.address_subnet.selected = 0;
151
			newrows = totalrows+1;
152
			for(i=2; i<newrows; i++) {
153
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
154
				eval(comd);
155
				comd = 'document.iform.address_subnet' + i + '.value = "";';
156
				eval(comd);
157
			}
158
			break;
159
		case 1:	/* network */
160
			var cmd;
161
			document.iform.address_subnet.disabled = 0;
162
			document.iform.address_subnet.value = "";
163
			newrows = totalrows+1;
164
			for(i=2; i<newrows; i++) {
165
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
166
				eval(comd);
167
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
168
				eval(comd);
169
			}
170
			break;
171
		case 2:	/* port */
172
			var cmd;
173
			document.iform.address_subnet.disabled = 1;
174
			document.iform.address_subnet.value = "";
175
			newrows = totalrows+1;
176
			for(i=2; i<newrows; i++) {
177
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
178
				eval(comd);
179
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
180
				eval(comd);
181
			}
182
			break;
183
	}
184
}
185

    
186
function update_box_type() {
187
	var indexNum = document.forms[0].type.selectedIndex;
188
	var selected = document.forms[0].type.options[indexNum].text;
189
	if(selected == 'Network(s)') {
190
		document.getElementById ("addressnetworkport").firstChild.data = "Network(s)";
191
		document.getElementById ("address_subnet").visible = true;
192
		document.getElementById ("address_subnet").disabled = true;
193
	} else if(selected == 'Host(s)') {
194
		document.getElementById ("addressnetworkport").firstChild.data = "Host(s)";
195
		document.getElementById ("address_subnet").visible = false;
196
		document.getElementById ("address_subnet").disabled = false;
197
	} else if(selected == 'Port(s)') {
198
		document.getElementById ("addressnetworkport").firstChild.data = "Port(s)";
199
		document.getElementById ("address_subnet").visible = false;
200
		document.getElementById ("address_subnet").disabled = true;
201
	}
202
}
203

    
204
-->
205
</script>
206
</head>
207

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

    
211
<script type="text/javascript" language="javascript" src="row_helper.js">
212
</script>
213

    
214
<input type='hidden' name='address_type' value='textbox'></input>
215
<input type='hidden' name='address_subnet_type' value='select'></input>
216

    
217
<script type="text/javascript" language='javascript'>
218
<!--
219

    
220
rowname[0] = "address";
221
rowtype[0] = "textbox";
222

    
223
rowname[1] = "address_subnet";
224
rowtype[1] = "select";
225

    
226
rowname[2] = "address_subnet";
227
rowtype[2] = "select";
228
-->
229
</script>
230

    
231
<p class="pgtitle">Firewall: Aliases: Edit alias</p>
232
<?php if ($input_errors) print_input_errors($input_errors); ?>
233
            <form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
234
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
235
                <tr>
236
                  <td valign="top" class="vncellreq">Name</td>
237
                  <td class="vtable"> <input name="name" type="text" class="formfld" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>">
238
                    <br> <span class="vexpl">The name of the alias may only consist
239
                    of the characters a-z, A-Z and 0-9.</span></td>
240
                </tr>
241
                <tr>
242
                  <td width="22%" valign="top" class="vncell">Description</td>
243
                  <td width="78%" class="vtable"> <input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
244
                    <br> <span class="vexpl">You may enter a description here
245
                    for your reference (not parsed).</span></td>
246
                </tr>
247
                <tr>
248
                  <td valign="top" class="vncellreq">Type</td>
249
                  <td class="vtable">
250
                    <select name="type" class="formfld" id="type" onChange="update_box_type(); typesel_change();">
251
                      <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
252
                      <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
253
		      <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
254
                    </select>
255
                  </td>
256
                </tr>
257
                <tr>
258
                  <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport" name="addressnetworkport">Host(s)</div></td>
259
                  <td width="78%" class="vtable">
260

    
261

    
262
		    <table name="maintable" id="maintable">
263
		      <tbody>
264

    
265
			<?php
266
			$counter = 0;
267
			$address = $a_aliases[$id]['address'];
268
			$item = explode(" ", $address);
269
			foreach($item as $ww) {
270
				$address = $item[$counter];
271
				$address_subnet = "";
272
				$item2 = explode("/", $address);
273
				foreach($item2 as $current) {
274
					if($item2[1] <> "") {
275
						$address = $item2[0];
276
						$address_subnet = $item2[1];
277
					}
278
				}
279
				if($counter > 0) $tracker = $counter + 1;
280
			?>
281
			<tr><td> <input name="address<?php echo $tracker; ?>" type="text" class="formfld" id="address<?php echo $tracker; ?>" size="20" value="<?=htmlspecialchars($address);?>"></td><td>
282
			<select name="address_subnet<?php echo $tracker; ?>" class="formfld" id="address_subnet<?php echo $tracker; ?>">
283
			  <option></option>
284
			  <?php for ($i = 32; $i >= 1; $i--): ?>
285
			  <option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
286
			  <?php endfor; ?>
287
			</select>
288
			  <?php
289
				if($counter > 0)
290
					echo "<input type=\"image\" src=\"/x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\">";
291
			  ?>
292

    
293
			</td></tr>
294
			<?php $counter++; } ?>
295

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

    
319
//-->
320
</script>
321
<?php include("fend.inc"); ?>
322
</body>
323
</html>
(28-28/122)