Project

General

Profile

Download (22.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
// 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

    
62
aliases_sort();
63
$a_aliases = &$config['aliases']['alias'];
64
	
65
if($_POST)
66
	$origname = $_POST['origname'];
67

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

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

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

    
93
if (isset($id) && $a_aliases[$id]) {
94
	$original_alias_name = $a_aliases[$id]['name'];
95
	$pconfig['name'] = $a_aliases[$id]['name'];
96
	$pconfig['detail'] = $a_aliases[$id]['detail'];
97
	$pconfig['address'] = $a_aliases[$id]['address'];
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
	$addresses = explode(' ', $pconfig['address']);
107
	$address = explode("/", $addresses[0]);
108
	if ($address[1])
109
		$addresssubnettest = true;
110
	else
111
		$addresssubnettest = false;	
112
	
113
	if ($addresssubnettest)
114
		$pconfig['type'] = "network";
115
	else
116
		if (is_ipaddr($address[0]))
117
			$pconfig['type'] = "host";
118
		else
119
			$pconfig['type'] = "port";
120

    
121
	if($a_aliases[$id]['aliasurl'] <> "") {
122
		$pconfig['type'] = "url";
123
		if(is_array($a_aliases[$id]['aliasurl'])) {
124
			$isfirst = 0;
125
			$pconfig['address'] = "";
126
			foreach($a_aliases[$id]['aliasurl'] as $aa) {
127
				if($isfirst == 1)
128
					$pconfig['address'] .= " ";
129
				$isfirst = 1;
130
				$pconfig['address'] .= $aa;
131
			}
132
		} else {
133
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
134
		}
135
	}
136
}
137

    
138
if ($_POST) {
139

    
140
	unset($input_errors);
141
	$pconfig = $_POST;
142

    
143
	/* input validation */
144

    
145
	$x = is_validaliasname($_POST['name']);
146
	if (!isset($x)) {
147
		$input_errors[] = "Reserved word used for alias name.";
148
	} else if ($_POST['type'] == "port" && (getservbyname($_POST['name'], "tcp") || getservbyname($_POST['name'], "udp"))) {
149
		$input_errors[] = "Reserved word used for alias name.";
150
	} else {
151
		if (is_validaliasname($_POST['name']) == false)
152
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
153
	}
154
	/* check for name conflicts */
155
	foreach ($a_aliases as $alias) {
156
		if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
157
			continue;
158

    
159
		if ($alias['name'] == $_POST['name']) {
160
			$input_errors[] = "An alias with this name already exists.";
161
			break;
162
		}
163
	}
164

    
165
	/* Check for reserved keyword names */
166
	foreach($reserved_keywords as $rk) 
167
		if($rk == $_POST['name'])
168
			$input_errors[] = "Cannot use a reserved keyword as alias name $rk";
169

    
170
	/* check for name interface description conflicts */
171
	foreach($config['interfaces'] as $interface) {
172
		if($interface['descr'] == $_POST['name']) {
173
			$input_errors[] = "An interface description with this name already exists.";
174
			break;
175
		}
176
	}
177
	
178
	$alias = array();
179
	$alias['name'] = $_POST['name'];
180
	if($_POST['type'] == "url") {
181
		$address = "";
182
		$isfirst = 0;
183
		$address_count = 2;
184

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

    
245
	       			if($_POST["detail{$x}"] <> "") {
246
	       				$final_address_details .= $_POST["detail{$x}"];
247
	       			} else {
248
		       			$final_address_details .= "Entry added" . " ";
249
		       			$final_address_details .= date('r');
250
	       			}
251
	       			$final_address_details .= "||";
252
				$isfirst++;
253
				
254
				if (is_alias($_POST["address{$x}"])) {
255
					if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
256
						$wrongaliases .= " " . $_POST["address{$x}"];
257
				} else if ($_POST['type'] == "port") {
258
					if (!is_port($_POST["address{$x}"]))
259
						$input_errors[] = $_POST["address{$x}"] . " is not a valid port alias.";
260
				} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
261
					if (!is_ipaddr($_POST["address{$x}"]) && !is_hostname($_POST["address{$x}"]))
262
						$input_errors[] = $_POST["address{$x}"] . " is not a valid {$_POST['type']} alias.";
263
				}
264
			}
265
		}
266
		if ($wrongaliases <> "")
267
			$input_errors[] = "The alias(es): {$wrongaliases} \ncannot be nested cause they are not of the same type.";
268
	}
269

    
270
	if (!$input_errors) {
271
		$alias['address'] = $address;
272
		$alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
273
		$alias['type'] = $_POST['type'];
274
		$alias['detail'] = $final_address_details;
275

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

    
291
		if (isset($id) && $a_aliases[$id]) {
292
			if ($a_aliases[$id]['name'] <> $alias['name']) {
293
				foreach ($a_aliases as $aliasid => $aliasd) {
294
					if ($aliasd['address'] <> "") {
295
						$tmpdirty = false;
296
						$tmpaddr = explode(" ", $aliasd['address']);
297
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
298
							if ($tmpalias == $a_aliases[$id]['name']) {
299
								$tmpaddr[$tmpidx] = $alias['name'];
300
								$tmpdirty = true;
301
							}
302
						}
303
						if ($tmpdirty == true)
304
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
305
					}
306
				}
307
			}
308
			$a_aliases[$id] = $alias;
309
		} else
310
			$a_aliases[] = $alias;
311

    
312
		mark_subsystem_dirty('aliases');
313

    
314
		write_config();
315
		filter_configure();
316

    
317
		header("Location: firewall_aliases.php");
318
		exit;		
319
	}
320
	//we received input errors, copy data to prevent retype
321
	else
322
	{
323
		$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
324
		$pconfig['address'] = $address;
325
		$pconfig['type'] = $_POST['type'];
326
		$pconfig['detail'] = $final_address_details;
327
	}
328
}
329

    
330
include("head.inc");
331

    
332
$jscriptstr = <<<EOD
333

    
334
<script type="text/javascript">
335

    
336
var objAlias = new Array(4999);
337
function typesel_change() {
338
	switch (document.iform.type.selectedIndex) {
339
		case 0:	/* host */
340
			var cmd;
341

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

    
353
			newrows = totalrows;
354
			for(i=0; i<newrows; i++) {
355
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
356
				eval(comd);
357
			}
358
			break;
359
		case 2:	/* port */
360
			var cmd;
361

    
362
			newrows = totalrows;
363
			for(i=0; i<newrows; i++) {
364
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
365
				eval(comd);
366
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
367
				eval(comd);
368
			}
369
			break;
370
		case 3:	/* OpenVPN Users */
371
			var cmd;
372

    
373
			newrows = totalrows;
374
			for(i=0; i<newrows; i++) {
375
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
376
				eval(comd);
377
				comd = 'document.iform.address_subnet' + i + '.value = "";';
378
				eval(comd);
379
			}
380
			break;
381

    
382
		case 4:	/* url */
383
			var cmd;
384
			newrows = totalrows;
385
			for(i=0; i<newrows; i++) {
386
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
387
				eval(comd);
388
			}
389
			break;
390
	}
391
}
392

    
393
function add_alias_control() {
394
	var name = "address" + (totalrows - 1);
395
	obj = document.getElementById(name);
396
	obj.setAttribute('class', 'formfldalias');
397
	obj.setAttribute('autocomplete', 'off');
398
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
399
}
400
EOD;
401

    
402
$network_str = gettext("Network");
403
$networks_str = gettext("Network(s)");
404
$cidr_str = gettext("CIDR");
405
$description_str = gettext("Description");
406
$hosts_str = gettext("Host(s)");
407
$ip_str = gettext("IP");
408
$ports_str = gettext("Port(s)");
409
$port_str = gettext("Port");
410
$url_str = gettext("URL");
411
$update_freq_str = gettext("Update Freq.");
412

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

    
418
$openvpn_str = gettext("Username");
419
$openvpn_user_str = gettext("OpenVPN Users");
420
$openvpn_help = gettext("Enter as many usernames as you wish.");
421
$openvpn_freq = gettext("");
422

    
423
$jscriptstr .= <<<EOD
424

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

    
462
EOD;
463

    
464
?>
465

    
466
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
467
<?php
468
	include("fbegin.inc");
469
	echo $jscriptstr;
470
?>
471

    
472
<script type="text/javascript" src="/javascript/row_helper.js">
473
</script>
474
<script type="text/javascript" src="/javascript/autosuggest.js">
475
</script>
476
<script type="text/javascript" src="/javascript/suggestions.js">
477
</script>
478

    
479
<input type='hidden' name='address_type' value='textbox' />
480
<input type='hidden' name='address_subnet_type' value='select' />
481

    
482
<script type="text/javascript">
483
	rowname[0] = "address";
484
	rowtype[0] = "textbox";
485
	rowsize[0] = "30";
486

    
487
	rowname[1] = "address_subnet";
488
	rowtype[1] = "select";
489
	rowsize[1] = "1";
490

    
491
	rowname[2] = "detail";
492
	rowtype[2] = "textbox";
493
	rowsize[2] = "50";
494
</script>
495

    
496
<?php if ($input_errors) print_input_errors($input_errors); ?>
497
<div id="inputerrors"></div>
498

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

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

    
593
       		} // end foreach
594
	} // end if
595
?>
596
        </tbody>
597
        <tfoot>
598

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

    
619
<script type="text/javascript">
620
	field_counter_js = 3;
621
	rows = 1;
622
	totalrows = <?php echo $counter; ?>;
623
	loaded = <?php echo $counter; ?>;
624
	typesel_change();
625
	update_box_type();
626

    
627
<?php
628
        $isfirst = 0;
629
        $aliases = "";
630
        $addrisfirst = 0;
631
        $aliasesaddr = "";
632
        if(isset($config['aliases']['alias']) && is_array($config['aliases']['alias']))
633
                foreach($config['aliases']['alias'] as $alias_name) {
634
			if ($pconfig['name'] <> "" && $pconfig['name'] == $alias_name['name'])
635
				continue;
636
			if($addrisfirst == 1) $aliasesaddr .= ",";
637
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
638
			$addrisfirst = 1;
639
                }
640
?>
641

    
642
        var addressarray=new Array(<?php echo $aliasesaddr; ?>);
643

    
644
<?php  
645
	for ($jv = 0; $jv < $counter; $jv++)
646
		echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
647
?>
648

    
649

    
650
</script>
651

    
652
<?php include("fend.inc"); ?>
653
</body>
654
</html>
655

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

    
672
?>
(47-47/214)