Project

General

Profile

Download (21.6 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
	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
	pfSense_BUILDER_BINARIES:	/bin/rm	/bin/mkdir	/usr/bin/fetch
36
	pfSense_MODULE:	aliases
37
*/
38

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

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

    
48
require("guiconfig.inc");
49

    
50
if (!is_array($config['aliases']['alias']))
51
	$config['aliases']['alias'] = array();
52

    
53
aliases_sort();
54
$a_aliases = &$config['aliases']['alias'];
55
	
56
if($_POST)
57
	$origname = $_POST['origname'];
58

    
59
// Debugging
60
if($debug)
61
	exec("rm -f {$g['tmp_path']}/alias_rename_log.txt");
62

    
63
function alias_same_type($name, $type) {
64
	global $config;
65
	
66
	foreach ($config['aliases']['alias'] as $alias) {
67
		if ($name == $alias['name']) {
68
			if (in_array($type, array("host", "network")) &&
69
				in_array($alias['type'], array("host", "network")))
70
				return true;
71
			if ($type  == $alias['type'])
72
				return true;
73
			else
74
				return false;
75
		}
76
	}
77
	return true;
78
}
79

    
80
$id = $_GET['id'];
81
if (isset($_POST['id']))
82
	$id = $_POST['id'];
83

    
84
if (isset($id) && $a_aliases[$id]) {
85
	$original_alias_name = $a_aliases[$id]['name'];
86
	$pconfig['name'] = $a_aliases[$id]['name'];
87
	$pconfig['detail'] = $a_aliases[$id]['detail'];
88
	$pconfig['address'] = $a_aliases[$id]['address'];
89
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
90

    
91
	/* optional if list */
92
	$iflist = get_configured_interface_with_descr(true, true);
93
	foreach ($iflist as $if => $ifdesc)
94
		if($ifdesc == $pconfig['descr']) 
95
			$input_errors[] = "Sorry, an interface is already named {$pconfig['descr']}.";
96

    
97
	$addresses = explode(' ', $pconfig['address']);
98
	$address = explode("/", $addresses[0]);
99
	if ($address[1])
100
		$addresssubnettest = true;
101
	else
102
		$addresssubnettest = false;	
103
	
104
	if ($addresssubnettest)
105
		$pconfig['type'] = "network";
106
	else
107
		if (is_ipaddr($address[0]))
108
			$pconfig['type'] = "host";
109
		else
110
			$pconfig['type'] = "port";
111

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

    
129
if ($_POST) {
130

    
131
	unset($input_errors);
132
	$pconfig = $_POST;
133

    
134
	/* input validation */
135
	if(strtolower($_POST['name']) == "pptp")
136
		$input_errors[] = gettext("Aliases may not be named PPTP.");
137

    
138
	$x = is_validaliasname($_POST['name']);
139
	if (!isset($x)) {
140
		$input_errors[] = "Reserved word used for alias name.";
141
	} else {
142
		if (is_validaliasname($_POST['name']) == false)
143
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
144
	}
145
	/* check for name conflicts */
146
	foreach ($a_aliases as $alias) {
147
		if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
148
			continue;
149

    
150
		if ($alias['name'] == $_POST['name']) {
151
			$input_errors[] = "An alias with this name already exists.";
152
			break;
153
		}
154
	}
155

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

    
171
		/* item is a url type */
172
		for($x=0; isset($_POST['address'. $x]); $x++) {
173
			if($_POST['address' . $x]) {
174
				/* fetch down and add in */
175
				$isfirst = 0;
176
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
177
				unlink($temp_filename);
178
				$fda = fopen("{$g['tmp_path']}/tmpfetch","w");
179
				fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
180
				fclose($fda);
181
				mwexec("/bin/mkdir -p {$temp_filename}");
182
				mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
183
				/* if the item is tar gzipped then extract */
184
				if(stristr($_POST['address' . $x], ".tgz"))
185
					process_alias_tgz($temp_filename);
186
				if(file_exists("{$temp_filename}/aliases")) {
187
					$file_contents = file_get_contents("{$temp_filename}/aliases");
188
					$file_contents = str_replace("#", "\n#", $file_contents);
189
					$file_contents_split = split("\n", $file_contents);
190
					foreach($file_contents_split as $fc) {
191
						$tmp = trim($fc);
192
						if(stristr($fc, "#")) {
193
							$tmp_split = split("#", $tmp);
194
							$tmp = trim($tmp_split[0]);
195
						}
196
						if(trim($tmp) <> "") {
197
							if($isfirst == 1)
198
								$address .= " ";
199
							$address .= $tmp;
200
							$isfirst = 1;
201
						}
202
					}
203
					if($isfirst == 0) {
204
						/* nothing was found */
205
						$input_errors[] = "You must provide a valid URL. Could not fetch usable data.";
206
						$dont_update = true;
207
						break;
208
					}
209
					$alias['aliasurl'][] = $_POST['address' . $x];
210
					mwexec("/bin/rm -rf {$temp_filename}");
211
				} else {
212
					$input_errors[] = "You must provide a valid URL.";
213
					$dont_update = true;
214
					break;
215
				}
216
			}
217
		}
218
	} else {
219
		$address = "";
220
		$isfirst = 0;
221
		/* item is a normal alias type */
222
		$wrongaliases = "";
223
		for($x=0; $x<4999; $x++) {
224
			if($_POST["address{$x}"] <> "") {
225
				if ($isfirst > 0)
226
					$address .= " ";
227
				$address .= $_POST["address{$x}"];
228
				if(is_ipaddr($_POST["address{$x}"]) && $_POST["address_subnet{$x}"] <> "") 
229
					$address .= "/" . $_POST["address_subnet{$x}"];
230

    
231
	       			if($_POST["detail{$x}"] <> "") {
232
	       				$final_address_details .= $_POST["detail{$x}"];
233
	       			} else {
234
		       			$final_address_details .= "Entry added" . " ";
235
		       			$final_address_details .= date('r');
236
	       			}
237
	       			$final_address_details .= "||";
238
				$isfirst++;
239
			}
240
			if (is_alias($_POST["address{$x}"])) {
241
				if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
242
					$wrongaliases .= " " . $_POST["address{$x}"];
243
			}
244
		}
245
		if ($wrongaliases <> "")
246
			$input_errors[] = "The following aliases: {$wrongaliases} \ncannot be nested cause they are not of the same type.";
247
	}
248

    
249
	if (!$input_errors) {
250
		$alias['address'] = $address;
251
		$alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
252
		$alias['type'] = $_POST['type'];
253
		$alias['detail'] = $final_address_details;
254

    
255
		/*   Check to see if alias name needs to be
256
		 *   renamed on referenced rules and such
257
		 */
258
		if ($_POST['name'] <> $_POST['origname']) {
259
			// Firewall rules
260
			update_alias_names_upon_change('filter', 'rule', 'source', 'address', $_POST['name'], $origname);
261
			update_alias_names_upon_change('filter', 'rule', 'destination', 'address', $_POST['name'], $origname);
262
			// NAT Rules
263
			update_alias_names_upon_change('nat', 'rule', 'target', '', $_POST['name'], $origname);
264
			update_alias_names_upon_change('nat', 'rule', 'external-port', '', $_POST['name'], $origname);
265
			update_alias_names_upon_change('nat', 'rule', 'local-port', ''	, $_POST['name'], $origname);
266
			// Alias in an alias
267
			update_alias_names_upon_change('aliases', 'alias', 'address', ''	, $_POST['name'], $origname);
268
		}
269

    
270
		if (isset($id) && $a_aliases[$id]) {
271
			if ($a_aliases[$id]['name'] <> $alias['name']) {
272
				foreach ($a_aliases as $aliasid => $aliasd) {
273
					if ($aliasd['address'] <> "") {
274
						$tmpdirty = false;
275
						$tmpaddr = explode(" ", $aliasd['address']);
276
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
277
							if ($tmpalias == $a_aliases[$id]['name']) {
278
								$tmpaddr[$tmpidx] = $alias['name'];
279
								$tmpdirty = true;
280
							}
281
						}
282
						if ($tmpdirty == true)
283
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
284
					}
285
				}
286
			}
287
			$a_aliases[$id] = $alias;
288
		} else
289
			$a_aliases[] = $alias;
290

    
291
		mark_subsystem_dirty('aliases');
292

    
293
		write_config();
294
		filter_configure();
295

    
296
		header("Location: firewall_aliases.php");
297
		exit;		
298
	}
299
	//we received input errors, copy data to prevent retype
300
	else
301
	{
302
		$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
303
		$pconfig['address'] = $address;
304
		$pconfig['type'] = $_POST['type'];
305
		$pconfig['detail'] = $final_address_details;
306
	}
307
}
308

    
309
include("head.inc");
310

    
311
$jscriptstr = <<<EOD
312

    
313
<script type="text/javascript">
314

    
315
var objAlias = new Array(4999);
316
function typesel_change() {
317
	switch (document.iform.type.selectedIndex) {
318
		case 0:	/* host */
319
			var cmd;
320

    
321
			newrows = totalrows;
322
			for(i=0; i<newrows; i++) {
323
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
324
				eval(comd);
325
				comd = 'document.iform.address_subnet' + i + '.value = "";';
326
				eval(comd);
327
			}
328
			break;
329
		case 1:	/* network */
330
			var cmd;
331

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

    
341
			newrows = totalrows;
342
			for(i=0; i<newrows; i++) {
343
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
344
				eval(comd);
345
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
346
				eval(comd);
347
			}
348
			break;
349
		case 3:	/* OpenVPN Users */
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 = "";';
357
				eval(comd);
358
			}
359
			break;
360

    
361
		case 4:	/* url */
362
			var cmd;
363
			newrows = totalrows;
364
			for(i=0; i<newrows; i++) {
365
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
366
				eval(comd);
367
			}
368
			break;
369
	}
370
}
371

    
372
function add_alias_control() {
373
	var name = "address" + (totalrows - 1);
374
	obj = document.getElementById(name);
375
	obj.setAttribute('class', 'formfldalias');
376
	obj.setAttribute('autocomplete', 'off');
377
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
378
}
379
EOD;
380

    
381
$network_str = gettext("Network");
382
$networks_str = gettext("Network(s)");
383
$cidr_str = gettext("CIDR");
384
$description_str = gettext("Description");
385
$hosts_str = gettext("Host(s)");
386
$ip_str = gettext("IP");
387
$ports_str = gettext("Port(s)");
388
$port_str = gettext("Port");
389
$url_str = gettext("URL");
390
$update_freq_str = gettext("Update Freq.");
391

    
392
$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.");
393
$hosts_help = gettext("Enter as many hosts as you would like.  Hosts must be specified by their IP address.");
394
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by seperating with a colon.");
395
$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.");
396

    
397
$openvpn_str = gettext("Username");
398
$openvpn_user_str = gettext("OpenVPN Users");
399
$openvpn_help = gettext("Enter as many usernames as you wish.");
400
$openvpn_freq = gettext("");
401

    
402
$jscriptstr .= <<<EOD
403

    
404
function update_box_type() {
405
	var indexNum = document.forms[0].type.selectedIndex;
406
	var selected = document.forms[0].type.options[indexNum].text;
407
	if(selected == '{$networks_str}') {
408
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
409
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
410
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
411
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
412
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
413
	} else if(selected == '{$hosts_str}') {
414
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
415
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
416
		document.getElementById ("twocolumn").firstChild.data = "";
417
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
418
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
419
	} else if(selected == '{$ports_str}') {
420
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
421
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
422
		document.getElementById ("twocolumn").firstChild.data = "";
423
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
424
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
425
	} else if(selected == '{$url_str}') {
426
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
427
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
428
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
429
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
430
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
431
	} else if(selected == '{$openvpn_user_str}') {
432
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
433
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
434
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
435
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
436
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
437
	}
438
}
439
</script>
440

    
441
EOD;
442

    
443
?>
444

    
445
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
446
<?php
447
	include("fbegin.inc");
448
	echo $jscriptstr;
449
?>
450

    
451
<script type="text/javascript" src="/javascript/row_helper.js">
452
</script>
453
<script type="text/javascript" src="/javascript/autosuggest.js">
454
</script>
455
<script type="text/javascript" src="/javascript/suggestions.js">
456
</script>
457

    
458
<input type='hidden' name='address_type' value='textbox' />
459
<input type='hidden' name='address_subnet_type' value='select' />
460

    
461
<script type="text/javascript">
462
	rowname[0] = "address";
463
	rowtype[0] = "textbox";
464
	rowsize[0] = "30";
465

    
466
	rowname[1] = "address_subnet";
467
	rowtype[1] = "select";
468
	rowsize[1] = "1";
469

    
470
	rowname[2] = "detail";
471
	rowtype[2] = "textbox";
472
	rowsize[2] = "50";
473
</script>
474

    
475
<?php if ($input_errors) print_input_errors($input_errors); ?>
476
<div id="inputerrors"></div>
477

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

    
531
	<?php
532
	$counter = 0;
533
	$address = $pconfig['address'];
534
	if ($address <> "") {
535
		$item = explode(" ", $address);
536
		$item3 = explode("||", $pconfig['detail']);
537
		foreach($item as $ww) {
538
			$address = $item[$counter];
539
			$address_subnet = "";
540
			$item2 = explode("/", $address);
541
			foreach($item2 as $current) {
542
				if($item2[1] <> "") {
543
					$address = $item2[0];
544
					$address_subnet = $item2[1];
545
				}
546
			}
547
			$item4 = $item3[$counter];
548
			$tracker = $counter;
549
	?>
550
          <tr>
551
            <td>
552
              <input autocomplete="off" name="address<?php echo $tracker; ?>" type="text" class="formfldalias" id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
553
            </td>
554
            <td>
555
			        <select name="address_subnet<?php echo $tracker; ?>" class="formselect" id="address_subnet<?php echo $tracker; ?>">
556
			          <option></option>
557
			          <?php for ($i = 32; $i >= 1; $i--): ?>
558
			          <option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
559
			          <?php endfor; ?>
560
			        </select>
561
			      </td>
562
            <td>
563
              <input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
564
            </td>
565
            <td>
566
    		<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
567
	      </td>
568
          </tr>
569
<?php
570
        	$counter++;
571

    
572
       		} // end foreach
573
	} // end if
574
?>
575
        </tbody>
576
        <tfoot>
577

    
578
        </tfoot>
579
		  </table>
580
			<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
581
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
582
      </a>
583
		</td>
584
  </tr>
585
  <tr>
586
    <td width="22%" valign="top">&nbsp;</td>
587
    <td width="78%">
588
      <input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
589
      <a href="firewall_aliases.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" /></a>
590
      <?php if (isset($id) && $a_aliases[$id]): ?>
591
      <input name="id" type="hidden" value="<?=$id;?>" />
592
      <?php endif; ?>
593
    </td>
594
  </tr>
595
</table>
596
</form>
597

    
598
<script type="text/javascript">
599
	field_counter_js = 3;
600
	rows = 1;
601
	totalrows = <?php echo $counter; ?>;
602
	loaded = <?php echo $counter; ?>;
603
	typesel_change();
604
	update_box_type();
605

    
606
<?php
607
        $isfirst = 0;
608
        $aliases = "";
609
        $addrisfirst = 0;
610
        $aliasesaddr = "";
611
        if(isset($config['aliases']['alias']) && is_array($config['aliases']['alias']))
612
                foreach($config['aliases']['alias'] as $alias_name) {
613
			if ($pconfig['name'] <> "" && $pconfig['name'] == $alias_name['name'])
614
				continue;
615
			if($addrisfirst == 1) $aliasesaddr .= ",";
616
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
617
			$addrisfirst = 1;
618
                }
619
?>
620

    
621
        var addressarray=new Array(<?php echo $aliasesaddr; ?>);
622

    
623
<?php  
624
	for ($jv = 0; $jv < $counter; $jv++)
625
		echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
626
?>
627

    
628

    
629
</script>
630

    
631
<?php include("fend.inc"); ?>
632
</body>
633
</html>
634

    
635
<?php
636
function process_alias_tgz($temp_filename) {
637
	mwexec("/bin/mv {$temp_filename}/aliases {$temp_filename}/aliases.tgz");
638
	mwexec("/usr/bin/tar xzf {$temp_filename}/aliases.tgz -C {$temp_filename}/aliases/");
639
	unlink("{$temp_filename}/aliases.tgz");
640
	$files_to_process = return_dir_as_array("{$temp_filename}/");
641
	/* foreach through all extracted files and build up aliases file */
642
	$fd = fopen("{$temp_filename}/aliases", "a");
643
	foreach($files_to_process as $f2p) {
644
		$file_contents = file_get_contents($f2p);
645
		fwrite($fd, $file_contents);
646
		unlink($f2p);
647
	}
648
	fclose($fd);
649
}
650

    
651
?>
(48-48/217)