Project

General

Profile

Download (10.7 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
$pgtitle = "System: Firewall: Aliases: Edit";
137
include("head.inc");
138

    
139
?>
140

    
141
<script language="JavaScript">
142
<!--
143
function typesel_change() {
144
	switch (document.iform.type.selectedIndex) {
145
		case 0:	/* host */
146
			var cmd;
147
			document.iform.address_subnet.disabled = 1;
148
			document.iform.address_subnet.value = "";
149
			document.iform.address_subnet.selected = 0;
150
			newrows = totalrows+1;
151
			for(i=2; i<newrows; i++) {
152
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
153
				eval(comd);
154
				comd = 'document.iform.address_subnet' + i + '.value = "";';
155
				eval(comd);
156
			}
157
			break;
158
		case 1:	/* network */
159
			var cmd;
160
			document.iform.address_subnet.disabled = 0;
161
			document.iform.address_subnet.value = "";
162
			newrows = totalrows+1;
163
			for(i=2; i<newrows; i++) {
164
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
165
				eval(comd);
166
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
167
				eval(comd);
168
			}
169
			break;
170
		case 2:	/* port */
171
			var cmd;
172
			document.iform.address_subnet.disabled = 1;
173
			document.iform.address_subnet.value = "";
174
			newrows = totalrows+1;
175
			for(i=2; i<newrows; i++) {
176
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
177
				eval(comd);
178
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
179
				eval(comd);
180
			}
181
			break;
182
	}
183
}
184

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

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

    
260

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

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

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

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

    
318
//-->
319
</script>
320
<?php include("fend.inc"); ?>
321
</body>
322
</html>
(29-29/129)