Project

General

Profile

Download (22.5 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
##|+PRIV
36
##|*IDENT=page-firewall-alias-edit
37
##|*NAME=Firewall: Alias: Edit page
38
##|*DESCR=Allow access to the 'Firewall: Alias: Edit' page.
39
##|*MATCH=firewall_aliases_edit.php*
40
##|-PRIV
41

    
42

    
43
$pgtitle = array("Firewall","Aliases","Edit");
44

    
45
require("guiconfig.inc");
46

    
47
if (!is_array($config['aliases']['alias']))
48
	$config['aliases']['alias'] = array();
49

    
50
aliases_sort();
51
$a_aliases = &$config['aliases']['alias'];
52
	
53
if($_POST)
54
	$origname = $_POST['origname'];
55

    
56
// Debugging
57
if($debug)
58
	exec("rm -f /tmp/alias_rename_log.txt");
59

    
60
function update_alias_names_upon_change($section, $subsection, $fielda, $fieldb, $new_alias_name) {
61
	global $config, $pconfig, $origname, $debug;
62
	if(!$origname) 
63
		return;
64

    
65
	if($debug) $fd = fopen("/tmp/print_r", "a");
66
	if($debug) fwrite($fd, print_r($pconfig, true));
67

    
68
	if($fieldb) {
69
		if($debug) fwrite($fd, "fieldb exists\n");
70
		for ($i = 0; isset($config["$section"]["$subsection"][$i]["$fielda"]); $i++) {
71
			if($debug) fwrite($fd, "$i\n");
72
			if($config["$section"]["$subsection"][$i]["$fielda"]["$fieldb"] == $origname) {
73
				if($debug) fwrite($fd, "Setting old alias value $origname to $new_alias_name\n");
74
				$config["$section"]["$subsection"][$i]["$fielda"]["$fieldb"] = $new_alias_name;
75
			}
76
		}	
77
	} else {
78
		if($debug) fwrite($fd, "fieldb does not exist\n");
79
		for ($i = 0; isset($config["$section"]["$subsection"][$i]["$fielda"]); $i++) {
80
			if($config["$section"]["$subsection"][$i]["$fielda"] == $origname) {
81
				$config["$section"]["$subsection"][$i]["$fielda"] = $new_alias_name;
82
				if($debug) fwrite($fd, "Setting old alias value $origname to $new_alias_name\n");
83
			}
84
		}
85
	}
86

    
87
	if($debug) fclose($fd);
88

    
89
}
90

    
91
function alias_same_type($name, $type) {
92
	global $config;
93
	
94
	foreach ($config['aliases']['alias'] as $alias) {
95
		if ($name == $alias['name']) {
96
			if (in_array($type, array("host", "network")) &&
97
				in_array($alias['type'], array("host", "network")))
98
				return true;
99
			if ($type  == $alias['type'])
100
				return true;
101
			else
102
				return false;
103
		}
104
	}
105
	return true;
106
}
107

    
108
$id = $_GET['id'];
109
if (isset($_POST['id']))
110
	$id = $_POST['id'];
111

    
112
if (isset($id) && $a_aliases[$id]) {
113
	$original_alias_name = $a_aliases[$id]['name'];
114
	$pconfig['name'] = $a_aliases[$id]['name'];
115
	$pconfig['detail'] = $a_aliases[$id]['detail'];
116
	$pconfig['address'] = $a_aliases[$id]['address'];
117
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
118

    
119
	/* optional if list */
120
	$iflist = get_configured_interface_with_descr(true, true);
121
	foreach ($iflist as $if => $ifdesc)
122
		if($ifdesc == $pconfig['descr']) 
123
			$input_errors[] = "Sorry, an interface is already named {$pconfig['descr']}.";
124

    
125
	$addresses = explode(' ', $pconfig['address']);
126
	$address = explode("/", $addresses[0]);
127
	if ($address[1])
128
		$addresssubnettest = true;
129
	else
130
		$addresssubnettest = false;	
131
	
132
	if ($addresssubnettest)
133
		$pconfig['type'] = "network";
134
	else
135
		if (is_ipaddr($address[0]))
136
			$pconfig['type'] = "host";
137
		else
138
			$pconfig['type'] = "port";
139

    
140
	if($a_aliases[$id]['aliasurl'] <> "") {
141
		$pconfig['type'] = "url";
142
		if(is_array($a_aliases[$id]['aliasurl'])) {
143
			$isfirst = 0;
144
			$pconfig['address'] = "";
145
			foreach($a_aliases[$id]['aliasurl'] as $aa) {
146
				if($isfirst == 1)
147
					$pconfig['address'] .= " ";
148
				$isfirst = 1;
149
				$pconfig['address'] .= $aa;
150
			}
151
		} else {
152
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
153
		}
154
	}
155
}
156

    
157
if ($_POST) {
158

    
159
	unset($input_errors);
160
	$pconfig = $_POST;
161

    
162
	/* input validation */
163
	if(strtolower($_POST['name']) == "pptp")
164
		$input_errors[] = gettext("Aliases may not be named PPTP.");
165

    
166
	$x = is_validaliasname($_POST['name']);
167
	if (!isset($x)) {
168
		$input_errors[] = "Reserved word used for alias name.";
169
	} else {
170
		if (is_validaliasname($_POST['name']) == false)
171
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
172
	}
173
	/* check for name conflicts */
174
	foreach ($a_aliases as $alias) {
175
		if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
176
			continue;
177

    
178
		if ($alias['name'] == $_POST['name']) {
179
			$input_errors[] = "An alias with this name already exists.";
180
			break;
181
		}
182
	}
183

    
184
	/* check for name interface description conflicts */
185
	foreach($config['interfaces'] as $interface) {
186
		if($interface['descr'] == $_POST['name']) {
187
			$input_errors[] = "An interface description with this name already exists.";
188
			break;
189
		}
190
	}
191
	
192
	$alias = array();
193
	$alias['name'] = $_POST['name'];
194
	if($_POST['type'] == "url") {
195
		$address = "";
196
		$isfirst = 0;
197
		$address_count = 2;
198

    
199
		/* item is a url type */
200
		for($x=0; isset($_POST['address'. $x]); $x++) {
201
			if($_POST['address' . $x]) {
202
				/* fetch down and add in */
203
				$isfirst = 0;
204
				$temp_filename = tempnam("/tmp/", "alias_import");
205
				unlink($temp_filename);
206
				$fda = fopen("/tmp/tmpfetch","w");
207
				fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
208
				fclose($fda);
209
				mwexec("mkdir -p {$temp_filename}");
210
				mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
211
				/* if the item is tar gzipped then extract */
212
				if(stristr($_POST['address' . $x], ".tgz"))
213
					process_alias_tgz($temp_filename);
214
				if(file_exists("{$temp_filename}/aliases")) {
215
					$file_contents = file_get_contents("{$temp_filename}/aliases");
216
					$file_contents = str_replace("#", "\n#", $file_contents);
217
					$file_contents_split = split("\n", $file_contents);
218
					foreach($file_contents_split as $fc) {
219
						$tmp = trim($fc);
220
						if(stristr($fc, "#")) {
221
							$tmp_split = split("#", $tmp);
222
							$tmp = trim($tmp_split[0]);
223
						}
224
						if(trim($tmp) <> "") {
225
							if($isfirst == 1)
226
								$address .= " ";
227
							$address .= $tmp;
228
							$isfirst = 1;
229
						}
230
					}
231
					if($isfirst == 0) {
232
						/* nothing was found */
233
						$input_errors[] = "You must provide a valid URL. Could not fetch usable data.";
234
						$dont_update = true;
235
						break;
236
					}
237
					$alias['aliasurl'][] = $_POST['address' . $x];
238
					mwexec("/bin/rm -rf {$temp_filename}");
239
				} else {
240
					$input_errors[] = "You must provide a valid URL.";
241
					$dont_update = true;
242
					break;
243
				}
244
			}
245
		}
246
	} else {
247
		$address = "";
248
		$isfirst = 0;
249
		/* item is a normal alias type */
250
		$wrongaliases = "";
251
		for($x=0; $x<4999; $x++) {
252
			if($_POST["address{$x}"] <> "") {
253
				if ($isfirst > 0)
254
					$address .= " ";
255
				$address .= $_POST["address{$x}"];
256
				if(is_ipaddr($_POST["address{$x}"]) && $_POST["address_subnet{$x}"] <> "") 
257
					$address .= "/" . $_POST["address_subnet{$x}"];
258

    
259
	       			if($_POST["detail{$x}"] <> "") {
260
	       				$final_address_details .= $_POST["detail{$x}"];
261
	       			} else {
262
		       			$final_address_details .= "Entry added" . " ";
263
		       			$final_address_details .= date('r');
264
	       			}
265
	       			$final_address_details .= "||";
266
				$isfirst++;
267
			}
268
			if (is_alias($_POST["address{$x}"])) {
269
				if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
270
					$wrongaliases .= " " . $_POST["address{$x}"];
271
			}
272
		}
273
		if ($wrongaliases <> "")
274
			$input_errors[] = "The following aliases: {$wrongaliases} \ncannot be nested cause they are not of the same type.";
275
	}
276

    
277
	if (!$input_errors) {
278
		$alias['address'] = $address;
279
		$alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
280
		$alias['type'] = $_POST['type'];
281
		$alias['detail'] = $final_address_details;
282

    
283
		/*   Check to see if alias name needs to be
284
		 *   renamed on referenced rules and such
285
		 */
286
		if ($_POST['name'] <> $_POST['origname']) {
287
			// Firewall rules
288
			update_alias_names_upon_change('filter', 'rule', 'source', 'address', $_POST['name']);
289
			update_alias_names_upon_change('filter', 'rule', 'destination', 'address', $_POST['name']);
290
			// NAT Rules
291
			update_alias_names_upon_change('nat', 'rule', 'target', '', $_POST['name']);
292
			update_alias_names_upon_change('nat', 'rule', 'external-port', '', $_POST['name']);
293
			update_alias_names_upon_change('nat', 'rule', 'local-port', ''	, $_POST['name']);
294
			// Alias in an alias
295
			update_alias_names_upon_change('aliases', 'alias', 'address', ''	, $_POST['name']);
296
		}
297

    
298
		if (isset($id) && $a_aliases[$id]) {
299
			if ($a_aliases[$id]['name'] <> $alias['name']) {
300
				foreach ($a_aliases as $aliasid => $aliasd) {
301
					if ($aliasd['address'] <> "") {
302
						$tmpdirty = false;
303
						$tmpaddr = explode(" ", $aliasd['address']);
304
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
305
							if ($tmpalias == $a_aliases[$id]['name']) {
306
								$tmpaddr[$tmpidx] = $alias['name'];
307
								$tmpdirty = true;
308
							}
309
						}
310
						if ($tmpdirty == true)
311
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
312
					}
313
				}
314
			}
315
			$a_aliases[$id] = $alias;
316
		} else
317
			$a_aliases[] = $alias;
318

    
319
		mark_subsystem_dirty('aliases');
320

    
321
		write_config();
322
		filter_configure();
323

    
324
		header("Location: firewall_aliases.php");
325
		exit;		
326
	}
327
	//we received input errors, copy data to prevent retype
328
	else
329
	{
330
		$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
331
		$pconfig['address'] = $address;
332
		$pconfig['type'] = $_POST['type'];
333
		$pconfig['detail'] = $final_address_details;
334
	}
335
}
336

    
337
include("head.inc");
338

    
339
$jscriptstr = <<<EOD
340

    
341
<script type="text/javascript">
342

    
343
var objAlias = new Array(4999);
344
function typesel_change() {
345
	switch (document.iform.type.selectedIndex) {
346
		case 0:	/* host */
347
			var cmd;
348

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

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

    
369
			newrows = totalrows;
370
			for(i=0; i<newrows; i++) {
371
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
372
				eval(comd);
373
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
374
				eval(comd);
375
			}
376
			break;
377
		case 3:	/* OpenVPN Users */
378
			var cmd;
379

    
380
			newrows = totalrows;
381
			for(i=0; i<newrows; i++) {
382
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
383
				eval(comd);
384
				comd = 'document.iform.address_subnet' + i + '.value = "";';
385
				eval(comd);
386
			}
387
			break;
388

    
389
		case 4:	/* url */
390
			var cmd;
391
			newrows = totalrows;
392
			for(i=0; i<newrows; i++) {
393
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
394
				eval(comd);
395
			}
396
			break;
397
	}
398
}
399

    
400
function add_alias_control() {
401
	var name = "address" + (totalrows - 1);
402
	obj = document.getElementById(name);
403
	obj.setAttribute('class', 'formfldalias');
404
	obj.setAttribute('autocomplete', 'off');
405
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
406
}
407
EOD;
408

    
409
$network_str = gettext("Network");
410
$networks_str = gettext("Network(s)");
411
$cidr_str = gettext("CIDR");
412
$description_str = gettext("Description");
413
$hosts_str = gettext("Host(s)");
414
$ip_str = gettext("IP");
415
$ports_str = gettext("Port(s)");
416
$port_str = gettext("Port");
417
$url_str = gettext("URL");
418
$update_freq_str = gettext("Update Freq.");
419

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

    
425
$openvpn_str = gettext("Username");
426
$openvpn_user_str = gettext("OpenVPN Users");
427
$openvpn_help = gettext("Enter as many usernames as you wish.");
428
$openvpn_freq = gettext("");
429

    
430
$jscriptstr .= <<<EOD
431

    
432
function update_box_type() {
433
	var indexNum = document.forms[0].type.selectedIndex;
434
	var selected = document.forms[0].type.options[indexNum].text;
435
	if(selected == '{$networks_str}') {
436
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
437
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
438
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
439
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
440
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
441
	} else if(selected == '{$hosts_str}') {
442
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
443
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
444
		document.getElementById ("twocolumn").firstChild.data = "";
445
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
446
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
447
	} else if(selected == '{$ports_str}') {
448
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
449
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
450
		document.getElementById ("twocolumn").firstChild.data = "";
451
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
452
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
453
	} else if(selected == '{$url_str}') {
454
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
455
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
456
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
457
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
458
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
459
	} else if(selected == '{$openvpn_user_str}') {
460
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
461
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
462
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
463
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
464
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
465
	}
466
}
467
</script>
468

    
469
EOD;
470

    
471
?>
472

    
473
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
474
<?php
475
	include("fbegin.inc");
476
	echo $jscriptstr;
477
?>
478

    
479
<script type="text/javascript" src="/javascript/row_helper.js">
480
</script>
481
<script type="text/javascript" src="/javascript/autosuggest.js">
482
</script>
483
<script type="text/javascript" src="/javascript/suggestions.js">
484
</script>
485

    
486
<input type='hidden' name='address_type' value='textbox' />
487
<input type='hidden' name='address_subnet_type' value='select' />
488

    
489
<script type="text/javascript">
490
	rowname[0] = "address";
491
	rowtype[0] = "textbox";
492
	rowsize[0] = "30";
493

    
494
	rowname[1] = "address_subnet";
495
	rowtype[1] = "select";
496
	rowsize[1] = "1";
497

    
498
	rowname[2] = "detail";
499
	rowtype[2] = "textbox";
500
	rowsize[2] = "50";
501
</script>
502

    
503
<?php if ($input_errors) print_input_errors($input_errors); ?>
504
<div id="inputerrors"></div>
505

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

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

    
600
       		} // end foreach
601
	} // end if
602
?>
603
        </tbody>
604
        <tfoot>
605

    
606
        </tfoot>
607
		  </table>
608
			<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
609
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
610
      </a>
611
		</td>
612
  </tr>
613
  <tr>
614
    <td width="22%" valign="top">&nbsp;</td>
615
    <td width="78%">
616
      <input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
617
      <a href="firewall_aliases.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" /></a>
618
      <?php if (isset($id) && $a_aliases[$id]): ?>
619
      <input name="id" type="hidden" value="<?=$id;?>" />
620
      <?php endif; ?>
621
    </td>
622
  </tr>
623
</table>
624
</form>
625

    
626
<script type="text/javascript">
627
	field_counter_js = 3;
628
	rows = 1;
629
	totalrows = <?php echo $counter; ?>;
630
	loaded = <?php echo $counter; ?>;
631
	typesel_change();
632
	update_box_type();
633

    
634
<?php
635
        $isfirst = 0;
636
        $aliases = "";
637
        $addrisfirst = 0;
638
        $aliasesaddr = "";
639
        if(isset($config['aliases']['alias']) && is_array($config['aliases']['alias']))
640
                foreach($config['aliases']['alias'] as $alias_name) {
641
			if ($pconfig['name'] <> "" && $pconfig['name'] == $alias_name['name'])
642
				continue;
643
			if($addrisfirst == 1) $aliasesaddr .= ",";
644
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
645
			$addrisfirst = 1;
646
                }
647
?>
648

    
649
        var addressarray=new Array(<?php echo $aliasesaddr; ?>);
650

    
651
<?php  
652
	for ($jv = 0; $jv < $counter; $jv++)
653
		echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
654
?>
655

    
656

    
657
</script>
658

    
659
<?php include("fend.inc"); ?>
660
</body>
661
</html>
662

    
663
<?php
664
function process_alias_tgz($temp_filename) {
665
	mwexec("/bin/mv {$temp_filename}/aliases {$temp_filename}/aliases.tgz");
666
	mwexec("/usr/bin/tar xzf {$temp_filename}/aliases.tgz -C {$temp_filename}/aliases/");
667
	unlink("{$temp_filename}/aliases.tgz");
668
	$files_to_process = return_dir_as_array("{$temp_filename}/");
669
	/* foreach through all extracted files and build up aliases file */
670
	$fd = fopen("{$temp_filename}/aliases", "a");
671
	foreach($files_to_process as $f2p) {
672
		$file_contents = file_get_contents($f2p);
673
		fwrite($fd, $file_contents);
674
		unlink($f2p);
675
	}
676
	fclose($fd);
677
}
678
?>
(48-48/217)