Project

General

Profile

Download (19.5 KB) Statistics
| Branch: | Tag: | Revision:
1 d2cfb7a4 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	firewall_aliases_edit.php
5 2e9ab96b Scott Ullrich
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7
8
	originially part of m0n0wall (http://m0n0.ch/wall)
9 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11 d2cfb7a4 Scott Ullrich
12 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 d2cfb7a4 Scott Ullrich
15 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 d2cfb7a4 Scott Ullrich
18 5b237745 Scott Ullrich
	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 d2cfb7a4 Scott Ullrich
22 5b237745 Scott Ullrich
	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 5a1eebc7 Scott Ullrich
$pgtitle = "Firewall: Aliases: Edit";
35
36 5b237745 Scott Ullrich
require("guiconfig.inc");
37
38
if (!is_array($config['aliases']['alias']))
39
	$config['aliases']['alias'] = array();
40
41
aliases_sort();
42
$a_aliases = &$config['aliases']['alias'];
43
44
$id = $_GET['id'];
45
if (isset($_POST['id']))
46
	$id = $_POST['id'];
47
48
if (isset($id) && $a_aliases[$id]) {
49
	$pconfig['name'] = $a_aliases[$id]['name'];
50 ba393f6c Scott Dale
	$pconfig['detail'] = $a_aliases[$id]['detail'];
51
	$pconfig['address'] = $a_aliases[$id]['address'];
52
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
53
	
54
	$addresses = explode(' ', $pconfig['address']);
55
	$address = explode("/", $addresses[0]);
56
	if ($address[1])
57
		$addresssubnettest = true;
58 d89924da Bill Marquette
	else
59 ba393f6c Scott Dale
		$addresssubnettest = false;	
60
	
61
	if ($addresssubnettest)
62 5b237745 Scott Ullrich
		$pconfig['type'] = "network";
63
	else
64 ba393f6c Scott Dale
		if (is_ipaddr($address[0]))
65 d89924da Bill Marquette
			$pconfig['type'] = "host";
66
		else
67
			$pconfig['type'] = "port";
68 5a1eebc7 Scott Ullrich
69
	if($a_aliases[$id]['aliasurl'] <> "") {
70
		$pconfig['type'] = "url";
71
		if(is_array($a_aliases[$id]['aliasurl'])) {
72
			$isfirst = 0;
73
			$pconfig['address'] = "";
74
			foreach($a_aliases[$id]['aliasurl'] as $aa) {
75
				if($isfirst == 1)
76
					$pconfig['address'] .= " ";
77
				$isfirst = 1;
78
				$pconfig['address'] .= $aa;
79
			}
80
		} else {
81
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
82
		}
83
	}
84 5b237745 Scott Ullrich
}
85
86
if ($_POST) {
87
88
	unset($input_errors);
89
	$pconfig = $_POST;
90
91
	/* input validation */
92
	$reqdfields = explode(" ", "name address");
93
	$reqdfieldsn = explode(",", "Name,Address");
94 d2cfb7a4 Scott Ullrich
95 5b237745 Scott Ullrich
	if ($_POST['type'] == "network") {
96
		$reqdfields[] = "address_subnet";
97
		$reqdfieldsn[] = "Subnet bit count";
98
	}
99 d2cfb7a4 Scott Ullrich
100 5b237745 Scott Ullrich
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
101 d2cfb7a4 Scott Ullrich
102 0cd7ed19 Scott Ullrich
	if(strtolower($_POST['name']) == "lan")
103
		$input_errors[] = "Aliases may not be named LAN.";
104
	if(strtolower($_POST['name']) == "wan")
105
		$input_errors[] = "Aliases may not be named WAN.";
106
107 0df6adf8 Bill Marquette
	$x = is_validaliasname($_POST['name']);
108
	if (!isset($x)) {
109
		$input_errors[] = "Reserved word used for alias name.";
110
	} else {
111
		if (is_validaliasname($_POST['name']) == false)
112 d87fc50b Seth Mos
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
113 beeef1f0 Bill Marquette
	}
114 93a48ed8 Bill Marquette
	if ($_POST['type'] == "host")
115
		if (!is_ipaddr($_POST['address'])) {
116
			$input_errors[] = "A valid address must be specified.";
117
		}
118
	if ($_POST['type'] == "network") {
119
		if (!is_ipaddr($_POST['address'])) {
120
			$input_errors[] = "A valid address must be specified.";
121
		}
122
		if (!is_numeric($_POST['address_subnet'])) {
123
			$input_errors[] = "A valid subnet bit count must be specified.";
124
		}
125 5b237745 Scott Ullrich
	}
126 5a1eebc7 Scott Ullrich
127
	if ($_POST['type'] == "url") {
128
		if(stristr($_POST['address'], "http") == false)
129
			$input_errors[] = "You must provide a valid URL to the resource.";
130
	}
131
132 93a48ed8 Bill Marquette
	if ($_POST['type'] == "port")
133 5a1eebc7 Scott Ullrich
		if (! is_port($_POST['address']) && ! is_portrange($_POST['address']))
134
			$input_errors[] = "Please specify a valid port or portrange.";
135 d2cfb7a4 Scott Ullrich
136 5b237745 Scott Ullrich
	/* check for name conflicts */
137
	foreach ($a_aliases as $alias) {
138
		if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
139
			continue;
140
141
		if ($alias['name'] == $_POST['name']) {
142
			$input_errors[] = "An alias with this name already exists.";
143
			break;
144
		}
145
	}
146 5a1eebc7 Scott Ullrich
147 cfa466bb Scott Ullrich
	/* check for name interface description conflicts */
148
	foreach($config['interfaces'] as $interface) {
149
		if($interface['descr'] == $_POST['name']) {
150 5a1eebc7 Scott Ullrich
			$input_errors[] = "An interface description with this name already exists.";
151
			break;
152 cfa466bb Scott Ullrich
		}
153 5a1eebc7 Scott Ullrich
	}
154 ba393f6c Scott Dale
	
155
	$alias = array();
156
	$alias['name'] = $_POST['name'];
157
	if ($_POST['type'] == "network")
158
		$alias['address'] = $_POST['address'] . "/" . $_POST['address_subnet'];
159 5b237745 Scott Ullrich
160 ba393f6c Scott Dale
	else
161
		$alias['address'] = $_POST['address'];
162 d2cfb7a4 Scott Ullrich
163 ba393f6c Scott Dale
	$address = $alias['address'];
164
	$final_address_detail = htmlentities($_POST['detail'], ENT_QUOTES, 'UTF-8');
165
  		if($final_address_detail <> "") {
166
	       	$final_address_details .= $final_address_detail;
167
	} else {
168
		$final_address_details .= "Entry added" . " ";
169
   			$final_address_details .= date('r');
170
		}
171
    	$final_address_details .= "||";
172
	$isfirst = 0;
173 d2cfb7a4 Scott Ullrich
174 ba393f6c Scott Dale
	if($_POST['type'] == "url") {
175
		$address = "";
176 d2cfb7a4 Scott Ullrich
		$isfirst = 0;
177 ba393f6c Scott Dale
		$address_count = 2;
178
179
		/* item is a url type */
180
		if($_POST['address'])
181
			$_POST['address0'] = $_POST['address'];
182
		for($x=0; $x<99; $x++) {
183
			if($_POST['address' . $x]) {
184
				/* fetch down and add in */
185
				$isfirst = 0;
186
				$temp_filename = tempnam("/tmp/", "alias_import");
187
				unlink($temp_filename);
188
				$fda = fopen("/tmp/tmpfetch","w");
189
				fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
190
				fclose($fda);
191
				mwexec("mkdir -p {$temp_filename}");
192
				mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
193
				/* if the item is tar gzipped then extract */
194
				if(stristr($_POST['address' . $x], ".tgz"))
195
					process_alias_tgz($temp_filename);
196
				if(file_exists("{$temp_filename}/aliases")) {
197
					$file_contents = file_get_contents("{$temp_filename}/aliases");
198
					$file_contents = str_replace("#", "\n#", $file_contents);
199
					$file_contents_split = split("\n", $file_contents);
200
					foreach($file_contents_split as $fc) {
201
						$tmp = trim($fc);
202
						if(stristr($fc, "#")) {
203
							$tmp_split = split("#", $tmp);
204
							$tmp = trim($tmp_split[0]);
205 5a1eebc7 Scott Ullrich
						}
206 ba393f6c Scott Dale
						if(trim($tmp) <> "") {
207
							if($isfirst == 1)
208
								$address .= " ";
209
							$address .= $tmp;
210
							$isfirst = 1;
211 5a1eebc7 Scott Ullrich
						}
212 ba393f6c Scott Dale
					}
213
					if($isfirst == 0) {
214
						/* nothing was found */
215
						$input_errors[] = "You must provide a valid URL. Could not fetch usable data.";
216 5a1eebc7 Scott Ullrich
						$dont_update = true;
217
						break;
218
					}
219 ba393f6c Scott Dale
					$alias['aliasurl'][] = $_POST['address' . $x];
220
					mwexec("/bin/rm -rf {$temp_filename}");
221
				} else {
222
					$input_errors[] = "You must provide a valid URL.";
223
					$dont_update = true;
224
					break;
225 5a1eebc7 Scott Ullrich
				}
226
			}
227 ba393f6c Scott Dale
		}
228
	} else {
229
		/* item is a normal alias type */
230
		for($x=0; $x<99; $x++) {
231
			$comd = "\$subnet = \$_POST['address" . $x . "'];";
232
			eval($comd);
233
			$comd = "\$subnet_address = \$_POST['address_subnet" . $x . "'];";
234
			eval($comd);
235
			if($subnet <> "") {
236
				$address .= " ";
237
				$address .= $subnet;
238
				if($subnet_address <> "") $address .= "/" . $subnet_address;
239
240
				/* Compress in details to a single key, data separated by pipes.
241
				   Pulling details here lets us only pull in details for valid
242
				   address entries, saving us from having to track which ones to
243
				   process later. */
244
	       $comd = "\$final_address_detail = htmlentities( \$_POST['detail" . $x . "'], ENT_QUOTES, 'UTF-8' );";
245
	       eval($comd);
246
	       if($final_address_detail <> "") {
247
	       $final_address_details .= $final_address_detail;
248
	       } else {
249
		       $final_address_details .= "Entry added" . " ";
250
		       $final_address_details .= date('r');
251
	       }
252
	       $final_address_details .= "||";
253 d2cfb7a4 Scott Ullrich
			}
254
		}
255 ba393f6c Scott Dale
	}
256 d2cfb7a4 Scott Ullrich
257 ba393f6c Scott Dale
	if (!$input_errors) {
258
		$alias['address'] = $address;
259
		$alias['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8');
260
		$alias['type'] = $_POST['type'];
261
		$alias['detail'] = $final_address_details;
262 d2cfb7a4 Scott Ullrich
263 ba393f6c Scott Dale
		if (isset($id) && $a_aliases[$id])
264
			$a_aliases[$id] = $alias;
265
		else
266
			$a_aliases[] = $alias;
267 a18b6b97 Scott Ullrich
268 ba393f6c Scott Dale
		touch($d_aliasesdirty_path);
269 a18b6b97 Scott Ullrich
270 ba393f6c Scott Dale
		write_config();
271
		filter_configure();
272 d2cfb7a4 Scott Ullrich
273 ba393f6c Scott Dale
		header("Location: firewall_aliases.php");
274
		exit;		
275
	}
276
	//we received input errors, copy data to prevent retype
277
	else
278
	{
279
		$pconfig['descr'] = htmlentities($_POST['descr'], ENT_QUOTES, 'UTF-8');
280
		$pconfig['address'] = $address;
281
		$pconfig['type'] = $_POST['type'];
282
		$pconfig['detail'] = $final_address_details;;
283 5b237745 Scott Ullrich
	}
284
}
285 da7ae7ef Bill Marquette
286
include("head.inc");
287
288 5a1eebc7 Scott Ullrich
$jscriptstr = <<<EOD
289 da7ae7ef Bill Marquette
290 5a1eebc7 Scott Ullrich
<script type="text/javascript">
291 5b237745 Scott Ullrich
function typesel_change() {
292
	switch (document.iform.type.selectedIndex) {
293
		case 0:	/* host */
294 d2cfb7a4 Scott Ullrich
			var cmd;
295 5a1eebc7 Scott Ullrich
296
			document.iform.address_subnet.disabled = 1;
297 5b237745 Scott Ullrich
			document.iform.address_subnet.value = "";
298 8a1a87cc Scott Ullrich
			document.iform.address_subnet.selected = 0;
299 5a1eebc7 Scott Ullrich
			newrows = totalrows+1;
300
			for(i=2; i<newrows; i++) {
301
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
302
				eval(comd);
303
				comd = 'document.iform.address_subnet' + i + '.value = "";';
304
				eval(comd);
305 d2cfb7a4 Scott Ullrich
			}
306 5b237745 Scott Ullrich
			break;
307
		case 1:	/* network */
308 d2cfb7a4 Scott Ullrich
			var cmd;
309 5a1eebc7 Scott Ullrich
310 5b237745 Scott Ullrich
			document.iform.address_subnet.disabled = 0;
311 5a1eebc7 Scott Ullrich
			newrows = totalrows+1;
312 d2cfb7a4 Scott Ullrich
			for(i=2; i<newrows; i++) {
313 5a1eebc7 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
314
				eval(comd);
315 d2cfb7a4 Scott Ullrich
			}
316 5b237745 Scott Ullrich
			break;
317 4d6b6263 Scott Ullrich
		case 2:	/* port */
318
			var cmd;
319 5a1eebc7 Scott Ullrich
320 7fa0c501 Scott Ullrich
			document.iform.address_subnet.disabled = 1;
321 8a1a87cc Scott Ullrich
			document.iform.address_subnet.value = "";
322 5a1eebc7 Scott Ullrich
			newrows = totalrows+1;
323 4d6b6263 Scott Ullrich
			for(i=2; i<newrows; i++) {
324 5a1eebc7 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
325
				eval(comd);
326
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
327
				eval(comd);
328
			}
329
			break;
330
		case 3:	/* url */
331
			var cmd;
332
			document.iform.address_subnet.disabled = 0;
333
			newrows = totalrows+1;
334
			for(i=2; i<newrows; i++) {
335
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
336
				eval(comd);
337 4d6b6263 Scott Ullrich
			}
338
			break;
339 5b237745 Scott Ullrich
	}
340
}
341 d2cfb7a4 Scott Ullrich
342 5a1eebc7 Scott Ullrich
EOD;
343
344
$network_str = gettext("Network");
345
$networks_str = gettext("Network(s)");
346
$cidr_str = gettext("CIDR");
347
$description_str = gettext("Description");
348
$hosts_str = gettext("Host(s)");
349
$ip_str = gettext("IP");
350
$ports_str = gettext("Port(s)");
351
$port_str = gettext("Port");
352
$url_str = gettext("URL");
353
$update_freq_str = gettext("Update Freq.");
354
355
$networks_help = gettext("Networks can be expressed like 10.0.0.0 format.  Select the CIDR (network mask) that pertains to each entry.");
356
$hosts_help = gettext("Enter as many hosts as you would like.  Hosts should be expressed in their ip address format.");
357
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by seperating with a colon.");
358
$url_help = gettext("Enter as many urls as you wish.  Also set the time that you would like the url refreshed in days.  After saving {$g['product_name']} will download the URL and import the items into the alias.");
359
360
$jscriptstr .= <<<EOD
361
362 d2cfb7a4 Scott Ullrich
function update_box_type() {
363
	var indexNum = document.forms[0].type.selectedIndex;
364
	var selected = document.forms[0].type.options[indexNum].text;
365 5a1eebc7 Scott Ullrich
	if(selected == '{$networks_str}') {
366
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
367 d2cfb7a4 Scott Ullrich
		document.getElementById ("address_subnet").visible = true;
368 d89924da Bill Marquette
		document.getElementById ("address_subnet").disabled = false;
369 5a1eebc7 Scott Ullrich
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
370
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
371
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
372
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
373
	} else if(selected == '{$hosts_str}') {
374
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
375 d2cfb7a4 Scott Ullrich
		document.getElementById ("address_subnet").visible = false;
376 d89924da Bill Marquette
		document.getElementById ("address_subnet").disabled = true;
377 5a1eebc7 Scott Ullrich
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
378
		document.getElementById ("twocolumn").firstChild.data = "";
379
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
380
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
381
	} else if(selected == '{$ports_str}') {
382
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
383 d2cfb7a4 Scott Ullrich
		document.getElementById ("address_subnet").visible = false;
384 8a1a87cc Scott Ullrich
		document.getElementById ("address_subnet").disabled = true;
385 5a1eebc7 Scott Ullrich
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
386
		document.getElementById ("twocolumn").firstChild.data = "";
387
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
388
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
389
	} else if(selected == '{$url_str}') {
390
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
391
		document.getElementById ("address_subnet").visible = true;
392
		document.getElementById ("address_subnet").disabled = false;
393
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
394
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
395
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
396
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
397 d2cfb7a4 Scott Ullrich
	}
398
}
399 5b237745 Scott Ullrich
</script>
400
401 66138bf6 Scott Dale
EOD;
402 d2cfb7a4 Scott Ullrich
403 5a1eebc7 Scott Ullrich
?>
404 d2cfb7a4 Scott Ullrich
405 5a1eebc7 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
406
<?php
407
	include("fbegin.inc");
408
	echo $jscriptstr;
409
?>
410
411
<script type="text/javascript" src="row_helper.js">
412
</script>
413 d2cfb7a4 Scott Ullrich
414 5a1eebc7 Scott Ullrich
<input type='hidden' name='address_type' value='textbox' />
415
<input type='hidden' name='address_subnet_type' value='select' />
416 d2cfb7a4 Scott Ullrich
417 5a1eebc7 Scott Ullrich
<script type="text/javascript">
418
	rowname[0] = "address";
419
	rowtype[0] = "textbox";
420
	rowsize[0] = "30";
421 d2cfb7a4 Scott Ullrich
422 5a1eebc7 Scott Ullrich
	rowname[1] = "address_subnet";
423
	rowtype[1] = "select";
424
	rowsize[1] = "1";
425 d2cfb7a4 Scott Ullrich
426 5a1eebc7 Scott Ullrich
	rowname[2] = "detail";
427
	rowtype[2] = "textbox";
428
	rowsize[2] = "61";
429 d2cfb7a4 Scott Ullrich
</script>
430
431 da7ae7ef Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
432 5a1eebc7 Scott Ullrich
433 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
434 5a1eebc7 Scott Ullrich
<div id="inputerrors"></div>
435
436
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
437
<table width="100%" border="0" cellpadding="6" cellspacing="0">
438 a18b6b97 Scott Ullrich
<?php if(is_alias_inuse($pconfig['name']) == true): ?>
439 5a1eebc7 Scott Ullrich
  <tr>
440
    <td valign="top" class="vncellreq">Name</td>
441
    <td class="vtable"> <input name="name" type="hidden" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
442 a18b6b97 Scott Ullrich
		  <?php echo $pconfig['name']; ?>
443 5a1eebc7 Scott Ullrich
      <p>
444
        <span class="vexpl">NOTE: This alias is in use so the name may not be modified!</span>
445
      </p>
446
    </td>
447
  </tr>
448 a18b6b97 Scott Ullrich
<?php else: ?>
449 5a1eebc7 Scott Ullrich
  <tr>
450
    <td valign="top" class="vncellreq">Name</td>
451
    <td class="vtable">
452
      <input name="name" type="text" id="name" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
453
      <br />
454
      <span class="vexpl">
455
        The name of the alias may only consist of the characters a-z, A-Z and 0-9.
456
      </span>
457
    </td>
458
  </tr>
459 a18b6b97 Scott Ullrich
<?php endif; ?>
460 5a1eebc7 Scott Ullrich
  <tr>
461
    <td width="22%" valign="top" class="vncell">Description</td>
462
    <td width="78%" class="vtable">
463
      <input name="descr" type="text"  id="descr" size="40" value="<?=$pconfig['descr'];?>" />
464
      <br />
465
      <span class="vexpl">
466
        You may enter a description here for your reference (not parsed).
467
      </span>
468
    </td>
469
  </tr>
470
  <tr>
471
    <td valign="top" class="vncellreq">Type</td>
472
    <td class="vtable">
473
      <select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
474
        <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
475
        <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
476
        <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
477
      </select>
478
    </td>
479
  </tr>
480
  <tr>
481
    <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport">Host(s)</div></td>
482
    <td width="78%" class="vtable">
483
      <table id="maintable">
484
        <tbody>
485
          <tr>
486
            <td colspan="4">
487
      		    <div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">Item information</div>
488
            </td>
489
          </tr>
490
          <tr>
491
            <td><div id="onecolumn">Network</div></td>
492
            <td><div id="twocolumn">CIDR</div></td>
493
           <td><div id="threecolumn">Description</div></td>
494
          </tr>
495 d2cfb7a4 Scott Ullrich
496
			<?php
497
			$counter = 0;
498 ba393f6c Scott Dale
			$address = $pconfig['address'];
499 19757279 Scott Ullrich
			$item = explode(" ", $address);
500 ba393f6c Scott Dale
			$item3 = explode("||", $pconfig['detail']);
501 d2cfb7a4 Scott Ullrich
			foreach($item as $ww) {
502
				$address = $item[$counter];
503
				$address_subnet = "";
504
				$item2 = explode("/", $address);
505
				foreach($item2 as $current) {
506
					if($item2[1] <> "") {
507
						$address = $item2[0];
508
						$address_subnet = $item2[1];
509
					}
510
				}
511 5a1eebc7 Scott Ullrich
				$item4 = $item3[$counter];
512 d2cfb7a4 Scott Ullrich
				if($counter > 0) $tracker = $counter + 1;
513
			?>
514 5a1eebc7 Scott Ullrich
          <tr>
515
            <td>
516
              <input name="address<?php echo $tracker; ?>" type="text"  id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
517
            </td>
518
            <td>
519
			        <select name="address_subnet<?php echo $tracker; ?>" class="formselect" id="address_subnet<?php echo $tracker; ?>">
520
			          <option></option>
521
			          <?php for ($i = 32; $i >= 1; $i--): ?>
522
			          <option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
523
			          <?php endfor; ?>
524
			        </select>
525
			      </td>
526
            <td>
527
              <input name="detail<?php echo $tracker; ?>" type="text"  id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
528
            </td>
529
            <td>
530
    			  <?php
531
    				if($counter > 0)
532
    					echo "<input type=\"image\" src=\"/themes/".$g['theme']."/images/icons/icon_x.gif\" onclick=\"removeRow(this); return false;\" value=\"Delete\" />";
533
    			  ?>
534
			      </td>
535
          </tr>
536
			<?php
537
        $counter++;
538
539
        } // end foreach
540
      ?>
541
        </tbody>
542
        <tfoot>
543
544
        </tfoot>
545
		  </table>
546
			<a onclick="javascript:addRowTo('maintable'); typesel_change(); return false;" href="#">
547
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
548
      </a>
549
		</td>
550
  </tr>
551
  <tr>
552
    <td width="22%" valign="top">&nbsp;</td>
553
    <td width="78%">
554
      <input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
555
      <input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" onclick="history.back()" />
556
      <?php if (isset($id) && $a_aliases[$id]): ?>
557
      <input name="id" type="hidden" value="<?=$id;?>" />
558
      <?php endif; ?>
559
    </td>
560
  </tr>
561
</table>
562 5b237745 Scott Ullrich
</form>
563 5a1eebc7 Scott Ullrich
564
<script type="text/javascript">
565
	field_counter_js = 3;
566
	rows = 1;
567
	totalrows = <?php echo $counter; ?>;
568
	loaded = <?php echo $counter; ?>;
569
	typesel_change();
570
	update_box_type();
571 5b237745 Scott Ullrich
</script>
572 5a1eebc7 Scott Ullrich
573 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
574
</body>
575
</html>
576 5a1eebc7 Scott Ullrich
577
<?php
578
function process_alias_tgz($temp_filename) {
579
	mwexec("/bin/mv {$temp_filename}/aliases {$temp_filename}/aliases.tgz");
580
	mwexec("/usr/bin/tar xzf {$temp_filename}/aliases.tgz -C {$temp_filename}/aliases/");
581
	unlink("{$temp_filename}/aliases.tgz");
582
	$files_to_process = return_dir_as_array("{$temp_filename}/");
583
	/* foreach through all extracted files and build up aliases file */
584
	$fd = fopen("{$temp_filename}/aliases", "a");
585
	foreach($files_to_process as $f2p) {
586
		$file_contents = file_get_contents($f2p);
587
		fwrite($fd, $file_contents);
588
		unlink($f2p);
589
	}
590
	fclose($fd);
591
}
592
?>