Project

General

Profile

Download (22.3 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
// Keywords not allowed in names
49
$reserved_keywords = array("pass", "out", "queue", "max", "min", "pptp", "pppoe", "l2tp", "openvpn");
50

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

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

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

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

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

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

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

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

    
105

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

    
123
if ($_POST) {
124

    
125
	unset($input_errors);
126
	$pconfig = $_POST;
127

    
128
	/* input validation */
129

    
130
	$x = is_validaliasname($_POST['name']);
131
	if (!isset($x)) {
132
		$input_errors[] = "Reserved word used for alias name.";
133
	} else if ($_POST['type'] == "port" && (getservbyname($_POST['name'], "tcp") || getservbyname($_POST['name'], "udp"))) {
134
		$input_errors[] = "Reserved word used for alias name.";
135
	} else {
136
		if (is_validaliasname($_POST['name']) == false)
137
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
138
	}
139
	/* check for name conflicts */
140
	foreach ($a_aliases as $alias) {
141
		if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
142
			continue;
143

    
144
		if ($alias['name'] == $_POST['name']) {
145
			$input_errors[] = "An alias with this name already exists.";
146
			break;
147
		}
148
	}
149

    
150
	/* Check for reserved keyword names */
151
	foreach($reserved_keywords as $rk) 
152
		if($rk == $_POST['name'])
153
			$input_errors[] = "Cannot use a reserved keyword as alias name $rk";
154

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

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

    
230
	       			if($_POST["detail{$x}"] <> "") {
231
	       				$final_address_details .= $_POST["detail{$x}"];
232
	       			} else {
233
		       			$final_address_details .= "Entry added" . " ";
234
		       			$final_address_details .= date('r');
235
	       			}
236
	       			$final_address_details .= "||";
237
				$isfirst++;
238
				
239
				if (is_alias($_POST["address{$x}"])) {
240
					if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
241
						$wrongaliases .= " " . $_POST["address{$x}"];
242
				} else if ($_POST['type'] == "port") {
243
					if (!is_port($_POST["address{$x}"]))
244
						$input_errors[] = $_POST["address{$x}"] . " is not a valid port or alias.";
245
				} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
246
					if (!is_ipaddr($_POST["address{$x}"]) && !is_hostname($_POST["address{$x}"]))
247
						$input_errors[] = $_POST["address{$x}"] . " is not a valid {$_POST['type']} alias.";
248
				}
249
			}
250
		}
251
		if ($wrongaliases <> "")
252
			$input_errors[] = "The alias(es): {$wrongaliases} \ncannot be nested cause they are not of the same type.";
253
	}
254

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

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

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

    
297
		mark_subsystem_dirty('aliases');
298

    
299
		// Sort list
300
		$a_aliases = msort($a_aliases, "name");
301

    
302
		write_config();
303
		filter_configure();
304

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

    
318
include("head.inc");
319

    
320
$jscriptstr = <<<EOD
321

    
322
<script type="text/javascript">
323

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

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

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

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

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

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

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

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

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

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

    
411
$jscriptstr .= <<<EOD
412

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

    
450
EOD;
451

    
452
?>
453

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

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

    
467
<input type='hidden' name='address_type' value='textbox' />
468
<input type='hidden' name='address_subnet_type' value='select' />
469

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

    
475
	rowname[1] = "address_subnet";
476
	rowtype[1] = "select";
477
	rowsize[1] = "1";
478

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

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

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

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

    
581
       		} // end foreach
582
	} // end if
583
?>
584
        </tbody>
585
        <tfoot>
586

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

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

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

    
630
        var addressarray=new Array(<?php echo $aliasesaddr; ?>);
631

    
632
<?php  
633
	for ($jv = 0; $jv < $counter; $jv++)
634
		echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
635
?>
636

    
637

    
638
</script>
639

    
640
<?php include("fend.inc"); ?>
641
</body>
642
</html>
643

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

    
660
?>
(48-48/215)