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