Project

General

Profile

Download (22.8 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_aliases_edit.php
5
	Copyright (C) 2004 Scott Ullrich
6
	Copyright (C) 2009 Ermal Lu?i
7
	Copyright (C) 2010 Jim Pingle
8
	All rights reserved.
9

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

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

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

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

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

    
40
##|+PRIV
41
##|*IDENT=page-firewall-alias-edit
42
##|*NAME=Firewall: Alias: Edit page
43
##|*DESCR=Allow access to the 'Firewall: Alias: Edit' page.
44
##|*MATCH=firewall_aliases_edit.php*
45
##|-PRIV
46

    
47
$pgtitle = array("Firewall","Aliases","Edit");
48

    
49
// Keywords not allowed in names
50
$reserved_keywords = array("pass", "out", "queue", "max", "min", "pptp", "pppoe", "l2tp", "openvpn");
51

    
52
require("guiconfig.inc");
53
require_once("functions.inc");
54
require_once("filter.inc");
55
require_once("shaper.inc");
56

    
57
$reserved_ifs = get_configured_interface_list(false, true);
58
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs);
59

    
60
if (!is_array($config['aliases']['alias']))
61
	$config['aliases']['alias'] = array();
62
$a_aliases = &$config['aliases']['alias'];
63
	
64
if($_POST)
65
	$origname = $_POST['origname'];
66

    
67
// Debugging
68
if($debug)
69
	exec("rm -f {$g['tmp_path']}/alias_rename_log.txt");
70

    
71
function alias_same_type($name, $type) {
72
	global $config;
73
	
74
	foreach ($config['aliases']['alias'] as $alias) {
75
		if ($name == $alias['name']) {
76
			if (in_array($type, array("host", "network")) &&
77
				in_array($alias['type'], array("host", "network")))
78
				return true;
79
			if ($type  == $alias['type'])
80
				return true;
81
			else
82
				return false;
83
		}
84
	}
85
	return true;
86
}
87

    
88
$id = $_GET['id'];
89
if (isset($_POST['id']))
90
	$id = $_POST['id'];
91

    
92
if (isset($id) && $a_aliases[$id]) {
93
	$original_alias_name = $a_aliases[$id]['name'];
94
	$pconfig['name'] = $a_aliases[$id]['name'];
95
	$pconfig['detail'] = $a_aliases[$id]['detail'];
96
	$pconfig['address'] = $a_aliases[$id]['address'];
97
	$pconfig['type'] = $a_aliases[$id]['type'];
98
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
99

    
100
	/* optional if list */
101
	$iflist = get_configured_interface_with_descr(true, true);
102
	foreach ($iflist as $if => $ifdesc)
103
		if($ifdesc == $pconfig['descr']) 
104
			$input_errors[] = "Sorry, an interface is already named {$pconfig['descr']}.";
105

    
106

    
107
	if($a_aliases[$id]['aliasurl'] <> "") {
108
		$pconfig['type'] = "url";
109
		if(is_array($a_aliases[$id]['aliasurl'])) {
110
			$isfirst = 0;
111
			$pconfig['address'] = "";
112
			foreach($a_aliases[$id]['aliasurl'] as $aa) {
113
				if($isfirst == 1)
114
					$pconfig['address'] .= " ";
115
				$isfirst = 1;
116
				$pconfig['address'] .= $aa;
117
			}
118
		} else {
119
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
120
		}
121
	}
122
}
123

    
124
if ($_POST) {
125

    
126
	unset($input_errors);
127

    
128
	/* input validation */
129

    
130
	$reqdfields = explode(" ", "name");
131
	$reqdfieldsn = explode(",", "Name");
132

    
133
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
134

    
135
	$x = is_validaliasname($_POST['name']);
136
	if (!isset($x)) {
137
		$input_errors[] = "Reserved word used for alias name.";
138
	} else if ($_POST['type'] == "port" && (getservbyname($_POST['name'], "tcp") || getservbyname($_POST['name'], "udp"))) {
139
		$input_errors[] = "Reserved word used for alias name.";
140
	} else {
141
		if (is_validaliasname($_POST['name']) == false)
142
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
143
	}
144
	/* check for name conflicts */
145
	if (empty($a_aliases[$id])) {
146
		foreach ($a_aliases as $alias) {
147
			if ($alias['name'] == $_POST['name']) {
148
				$input_errors[] = "An alias with this name already exists.";
149
				break;
150
			}
151
		}
152
	}
153

    
154
	/* Check for reserved keyword names */
155
	foreach($reserved_keywords as $rk) 
156
		if($rk == $_POST['name'])
157
			$input_errors[] = "Cannot use a reserved keyword as alias name $rk";
158

    
159
	/* check for name interface description conflicts */
160
	foreach($config['interfaces'] as $interface) {
161
		if($interface['descr'] == $_POST['name']) {
162
			$input_errors[] = "An interface description with this name already exists.";
163
			break;
164
		}
165
	}
166
	
167
	$alias = array();
168
	$address = array();
169
	$final_address_details = array();
170
	$alias['name'] = $_POST['name'];
171
	if($_POST['type'] == "url") {
172
		$isfirst = 0;
173
		$address_count = 2;
174

    
175
		/* item is a url type */
176
		for($x=0; isset($_POST['address'. $x]); $x++) {
177
			if($_POST['address' . $x]) {
178
				/* fetch down and add in */
179
				$isfirst = 0;
180
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
181
				unlink($temp_filename);
182
				$fda = fopen("{$g['tmp_path']}/tmpfetch","w");
183
				fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
184
				fclose($fda);
185
				mwexec("/bin/mkdir -p {$temp_filename}");
186
				mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
187
				/* if the item is tar gzipped then extract */
188
				if(stristr($_POST['address' . $x], ".tgz"))
189
					process_alias_tgz($temp_filename);
190
				if(file_exists("{$temp_filename}/aliases")) {
191
					$file_contents = file_get_contents("{$temp_filename}/aliases");
192
					$file_contents = str_replace("#", "\n#", $file_contents);
193
					$file_contents_split = split("\n", $file_contents);
194
					foreach($file_contents_split as $fc) {
195
						$tmp = trim($fc);
196
						if(stristr($fc, "#")) {
197
							$tmp_split = split("#", $tmp);
198
							$tmp = trim($tmp_split[0]);
199
						}
200
						if(trim($tmp) <> "") {
201
							$address[] = $tmp;
202
							$isfirst = 1;
203
						}
204
					}
205
					if($isfirst == 0) {
206
						/* nothing was found */
207
						$input_errors[] = "You must provide a valid URL. Could not fetch usable data.";
208
						$dont_update = true;
209
						break;
210
					}
211
					$alias['aliasurl'][] = $_POST['address' . $x];
212
					mwexec("/bin/rm -rf {$temp_filename}");
213
				} else {
214
					$input_errors[] = "You must provide a valid URL.";
215
					$dont_update = true;
216
					break;
217
				}
218
			}
219
		}
220
	} else {
221
		/* item is a normal alias type */
222
		$wrongaliases = "";
223
		for($x=0; $x<4999; $x++) {
224
			if($_POST["address{$x}"] <> "") {
225
				if (is_alias($_POST["address{$x}"])) {
226
					if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
227
						$wrongaliases .= " " . $_POST["address{$x}"];
228
				} else if ($_POST['type'] == "port") {
229
					if (!is_port($_POST["address{$x}"]))
230
						$input_errors[] = $_POST["address{$x}"] . " is not a valid port or alias.";
231
				} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
232
					if (!is_ipaddr($_POST["address{$x}"])
233
					 && !is_hostname($_POST["address{$x}"])
234
					 && !is_iprange($_POST["address{$x}"]))
235
						$input_errors[] = $_POST["address{$x}"] . " is not a valid {$_POST['type']} alias.";
236
				}
237
				if (is_iprange($_POST["address{$x}"])) {
238
					list($startip, $endip) = explode('-', $_POST["address{$x}"]);
239
					$rangesubnets = ip_range_to_subnet_array($startip, $endip);
240
					array_merge($address, $rangesubnets); //$address .= implode($rangesubnets, ' ');
241
				} else {
242
					$tmpaddress = $_POST["address{$x}"];
243
					if(($_POST['type'] == "network" || is_ipaddr($_POST["address{$x}"])) && $_POST["address_subnet{$x}"] <> "")
244
						$tmpaddress .= "/" . $_POST["address_subnet{$x}"];
245
					$address[] = $tmpaddress;
246
				}
247
				if ($_POST["detail{$x}"] <> "")
248
					$final_address_details[] = $_POST["detail{$x}"];
249
				else
250
					$final_address_details[] = "Entry added " . date('r');
251
			}
252
		}
253
		if ($wrongaliases <> "")
254
			$input_errors[] = "The alias(es): {$wrongaliases} \ncannot be nested cause they are not of the same type.";
255
	}
256

    
257
	if (!$input_errors) {
258
		$alias['address'] = implode(" ", $address);
259
		$alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
260
		$alias['type'] = $_POST['type'];
261
		$alias['detail'] = implode("||", $final_address_details);
262

    
263
		/*   Check to see if alias name needs to be
264
		 *   renamed on referenced rules and such
265
		 */
266
		if ($_POST['name'] <> $_POST['origname']) {
267
			// Firewall rules
268
			update_alias_names_upon_change('filter', 'rule', 'source', 'address', $_POST['name'], $origname);
269
			update_alias_names_upon_change('filter', 'rule', 'destination', 'address', $_POST['name'], $origname);
270
			// NAT Rules
271
			update_alias_names_upon_change('nat', 'rule', 'target', '', $_POST['name'], $origname);
272
			update_alias_names_upon_change('nat', 'rule', 'external-port', '', $_POST['name'], $origname);
273
			update_alias_names_upon_change('nat', 'rule', 'local-port', ''	, $_POST['name'], $origname);
274
			// Alias in an alias
275
			update_alias_names_upon_change('aliases', 'alias', 'address', ''	, $_POST['name'], $origname);
276
		}
277

    
278
		if (isset($id) && $a_aliases[$id]) {
279
			if ($a_aliases[$id]['name'] <> $alias['name']) {
280
				foreach ($a_aliases as $aliasid => $aliasd) {
281
					if ($aliasd['address'] <> "") {
282
						$tmpdirty = false;
283
						$tmpaddr = explode(" ", $aliasd['address']);
284
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
285
							if ($tmpalias == $a_aliases[$id]['name']) {
286
								$tmpaddr[$tmpidx] = $alias['name'];
287
								$tmpdirty = true;
288
							}
289
						}
290
						if ($tmpdirty == true)
291
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
292
					}
293
				}
294
			}
295
			$a_aliases[$id] = $alias;
296
		} else
297
			$a_aliases[] = $alias;
298

    
299
		mark_subsystem_dirty('aliases');
300

    
301
		// Sort list
302
		$a_aliases = msort($a_aliases, "name");
303

    
304
		write_config();
305
		filter_configure();
306

    
307
		header("Location: firewall_aliases.php");
308
		exit;		
309
	}
310
	//we received input errors, copy data to prevent retype
311
	else
312
	{
313
		$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
314
		$pconfig['address'] = implode(" ", $address);
315
		$pconfig['type'] = $_POST['type'];
316
		$pconfig['detail'] = implode("||", $final_address_details);
317
	}
318
}
319

    
320
include("head.inc");
321

    
322
$jscriptstr = <<<EOD
323

    
324
<script type="text/javascript">
325

    
326
var objAlias = new Array(4999);
327
function typesel_change() {
328
	switch (document.iform.type.selectedIndex) {
329
		case 0:	/* host */
330
			var cmd;
331

    
332
			newrows = totalrows;
333
			for(i=0; i<newrows; i++) {
334
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
335
				eval(comd);
336
				comd = 'document.iform.address_subnet' + i + '.value = "";';
337
				eval(comd);
338
			}
339
			break;
340
		case 1:	/* network */
341
			var cmd;
342

    
343
			newrows = totalrows;
344
			for(i=0; i<newrows; i++) {
345
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
346
				eval(comd);
347
			}
348
			break;
349
		case 2:	/* port */
350
			var cmd;
351

    
352
			newrows = totalrows;
353
			for(i=0; i<newrows; i++) {
354
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
355
				eval(comd);
356
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
357
				eval(comd);
358
			}
359
			break;
360
		case 3:	/* OpenVPN Users */
361
			var cmd;
362

    
363
			newrows = totalrows;
364
			for(i=0; i<newrows; i++) {
365
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
366
				eval(comd);
367
				comd = 'document.iform.address_subnet' + i + '.value = "";';
368
				eval(comd);
369
			}
370
			break;
371

    
372
		case 4:	/* url */
373
			var cmd;
374
			newrows = totalrows;
375
			for(i=0; i<newrows; i++) {
376
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
377
				eval(comd);
378
			}
379
			break;
380
	}
381
}
382

    
383
function add_alias_control() {
384
	var name = "address" + (totalrows - 1);
385
	obj = document.getElementById(name);
386
	obj.setAttribute('class', 'formfldalias');
387
	obj.setAttribute('autocomplete', 'off');
388
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
389
}
390
EOD;
391

    
392
$network_str = gettext("Network");
393
$networks_str = gettext("Network(s)");
394
$cidr_str = gettext("CIDR");
395
$description_str = gettext("Description");
396
$hosts_str = gettext("Host(s)");
397
$ip_str = gettext("IP");
398
$ports_str = gettext("Port(s)");
399
$port_str = gettext("Port");
400
$url_str = gettext("URL");
401
$update_freq_str = gettext("Update Freq.");
402

    
403
$networks_help = gettext("Networks are specified in CIDR format.  Select the CIDR mask that pertains to each entry. /32 specifies a single host, /24 specifies 255.255.255.0, etc. Hostnames (FQDNs) may also be specified, using a /32 mask. You may also enter an IP range such as 192.168.1.1-192.168.1.254 and a list of CIDR networks will be derived to fill the range.");
404
$hosts_help = gettext("Enter as many hosts as you would like.  Hosts must be specified by their IP address.");
405
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by seperating with a colon.");
406
$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.");
407

    
408
$openvpn_str = gettext("Username");
409
$openvpn_user_str = gettext("OpenVPN Users");
410
$openvpn_help = gettext("Enter as many usernames as you wish.");
411
$openvpn_freq = gettext("");
412

    
413
$jscriptstr .= <<<EOD
414

    
415
function update_box_type() {
416
	var indexNum = document.forms[0].type.selectedIndex;
417
	var selected = document.forms[0].type.options[indexNum].text;
418
	if(selected == '{$networks_str}') {
419
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
420
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
421
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
422
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
423
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
424
	} else if(selected == '{$hosts_str}') {
425
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
426
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
427
		document.getElementById ("twocolumn").firstChild.data = "";
428
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
429
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
430
	} else if(selected == '{$ports_str}') {
431
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
432
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
433
		document.getElementById ("twocolumn").firstChild.data = "";
434
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
435
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
436
	} else if(selected == '{$url_str}') {
437
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
438
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
439
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
440
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
441
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
442
	} else if(selected == '{$openvpn_user_str}') {
443
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
444
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
445
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
446
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
447
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
448
	}
449
}
450
</script>
451

    
452
EOD;
453

    
454
?>
455

    
456
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
457
<?php
458
	include("fbegin.inc");
459
	echo $jscriptstr;
460
?>
461

    
462
<script type="text/javascript" src="/javascript/row_helper.js">
463
</script>
464
<script type="text/javascript" src="/javascript/autosuggest.js">
465
</script>
466
<script type="text/javascript" src="/javascript/suggestions.js">
467
</script>
468

    
469
<input type='hidden' name='address_type' value='textbox' />
470
<input type='hidden' name='address_subnet_type' value='select' />
471

    
472
<script type="text/javascript">
473
	rowname[0] = "address";
474
	rowtype[0] = "textbox";
475
	rowsize[0] = "30";
476

    
477
	rowname[1] = "address_subnet";
478
	rowtype[1] = "select";
479
	rowsize[1] = "1";
480

    
481
	rowname[2] = "detail";
482
	rowtype[2] = "textbox";
483
	rowsize[2] = "50";
484
</script>
485

    
486
<?php if ($input_errors) print_input_errors($input_errors); ?>
487
<div id="inputerrors"></div>
488

    
489
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
490
<table width="100%" border="0" cellpadding="6" cellspacing="0">
491
  <tr>
492
	<td colspan="2" valign="top" class="listtopic">Alias Edit</td>
493
  </tr>
494
  <tr>
495
    <td valign="top" class="vncellreq">Name</td>
496
    <td class="vtable">
497
      <input name="origname" type="hidden" id="origname" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
498
      <input name="name" type="text" id="name" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
499
      <?php if (isset($id) && $a_aliases[$id]): ?>
500
      <input name="id" type="hidden" value="<?=$id;?>" />
501
      <?php endif; ?>
502
      <br />
503
      <span class="vexpl">
504
        The name of the alias may only consist of the characters a-z, A-Z and 0-9.
505
      </span>
506
    </td>
507
  </tr>
508
  <tr>
509
    <td width="22%" valign="top" class="vncell">Description</td>
510
    <td width="78%" class="vtable">
511
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
512
      <br />
513
      <span class="vexpl">
514
        You may enter a description here for your reference (not parsed).
515
      </span>
516
    </td>
517
  </tr>
518
  <tr>
519
    <td valign="top" class="vncellreq">Type</td>
520
    <td class="vtable">
521
      <select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
522
        <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
523
        <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
524
        <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
525
        <option value="openvpn" <?php if ($pconfig['type'] == "openvpn") echo "selected"; ?>>OpenVPN Users</option>
526
      </select>
527
    </td>
528
  </tr>
529
  <tr>
530
    <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport">Host(s)</div></td>
531
    <td width="78%" class="vtable">
532
      <table id="maintable">
533
        <tbody>
534
          <tr>
535
            <td colspan="4">
536
      		    <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>
537
            </td>
538
          </tr>
539
          <tr>
540
            <td><div id="onecolumn">Network</div></td>
541
            <td><div id="twocolumn">CIDR</div></td>
542
           <td><div id="threecolumn">Description</div></td>
543
          </tr>
544

    
545
	<?php
546
	$counter = 0;
547
	$address = $pconfig['address'];
548
	if ($address <> "") {
549
		$item = explode(" ", $address);
550
		$item3 = explode("||", $pconfig['detail']);
551
		foreach($item as $ww) {
552
			$address = $item[$counter];
553
			$address_subnet = "";
554
			$item2 = explode("/", $address);
555
			foreach($item2 as $current) {
556
				if($item2[1] <> "") {
557
					$address = $item2[0];
558
					$address_subnet = $item2[1];
559
				}
560
				
561
			}
562
			$item4 = $item3[$counter];
563
			$tracker = $counter;
564
	?>
565
          <tr>
566
            <td>
567
              <input autocomplete="off" name="address<?php echo $tracker; ?>" type="text" class="formfldalias" id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
568
            </td>
569
            <td>
570
			        <select name="address_subnet<?php echo $tracker; ?>" class="formselect" id="address_subnet<?php echo $tracker; ?>">
571
				<option></option>
572
			          <?php for ($i = 32; $i >= 1; $i--): ?>
573
			          <option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
574
			          <?php endfor; ?>
575
			        </select>
576
			      </td>
577
            <td>
578
              <input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
579
            </td>
580
            <td>
581
    		<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
582
	      </td>
583
          </tr>
584
<?php
585
        	$counter++;
586

    
587
       		} // end foreach
588
	} // end if
589
?>
590
        </tbody>
591
        <tfoot>
592

    
593
        </tfoot>
594
		  </table>
595
			<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
596
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
597
      </a>
598
		</td>
599
  </tr>
600
  <tr>
601
    <td width="22%" valign="top">&nbsp;</td>
602
    <td width="78%">
603
      <input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
604
      <a href="firewall_aliases.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" /></a>
605
    </td>
606
  </tr>
607
</table>
608
</form>
609

    
610
<script type="text/javascript">
611
	field_counter_js = 3;
612
	rows = 1;
613
	totalrows = <?php echo $counter; ?>;
614
	loaded = <?php echo $counter; ?>;
615
	typesel_change();
616
	update_box_type();
617

    
618
<?php
619
        $isfirst = 0;
620
        $aliases = "";
621
        $addrisfirst = 0;
622
        $aliasesaddr = "";
623
        if(isset($config['aliases']['alias']) && is_array($config['aliases']['alias']))
624
                foreach($config['aliases']['alias'] as $alias_name) {
625
			if ($pconfig['name'] <> "" && $pconfig['name'] == $alias_name['name'])
626
				continue;
627
			if($addrisfirst == 1) $aliasesaddr .= ",";
628
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
629
			$addrisfirst = 1;
630
                }
631
?>
632

    
633
        var addressarray=new Array(<?php echo $aliasesaddr; ?>);
634

    
635
function createAutoSuggest() {
636
<?php  
637
	for ($jv = 0; $jv < $counter; $jv++)
638
		echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
639
?>
640
}
641

    
642
setTimeOut("createAutoSuggest();", 500);
643

    
644
</script>
645

    
646
<?php include("fend.inc"); ?>
647
</body>
648
</html>
649

    
650
<?php
651
function process_alias_tgz($temp_filename) {
652
	mwexec("/bin/mv {$temp_filename}/aliases {$temp_filename}/aliases.tgz");
653
	mwexec("/usr/bin/tar xzf {$temp_filename}/aliases.tgz -C {$temp_filename}/aliases/");
654
	unlink("{$temp_filename}/aliases.tgz");
655
	$files_to_process = return_dir_as_array("{$temp_filename}/");
656
	/* foreach through all extracted files and build up aliases file */
657
	$fd = fopen("{$temp_filename}/aliases", "a");
658
	foreach($files_to_process as $f2p) {
659
		$file_contents = file_get_contents($f2p);
660
		fwrite($fd, $file_contents);
661
		unlink($f2p);
662
	}
663
	fclose($fd);
664
}
665

    
666
?>
(49-49/218)