Project

General

Profile

Download (22.7 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");
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
	if(strtolower($_POST['name']) == "pptp")
145
		$input_errors[] = gettext("Aliases may not be named PPTP.");
146

    
147
	$x = is_validaliasname($_POST['name']);
148
	if (!isset($x)) {
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 (preg_match("/[^[[:digit:]]]/", $_POST["address{$x}"]) || strlen($_POST["address{$x}"]) > 5)
259
						$input_errors[] = $_POST["address{$x}"] . " is not a valid {$_POST['type']} alias.";
260
					else if (intval($_POST["address{$x}"]) < 0 || intval($_POST["address{$x}"]) > 65535)
261
						$input_errors[] = $_POST["address{$x}"] . " is not a valid port alias.";
262
				} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
263
					if (!is_ipaddr($_POST["address{$x}"]) && !is_hostname($_POST["address{$x}"]))
264
						$input_errors[] = $_POST["address{$x}"] . " is not a valid {$_POST['type']} alias.";
265
				}
266
			}
267
		}
268
		if ($wrongaliases <> "")
269
			$input_errors[] = "The alias(es): {$wrongaliases} \ncannot be nested cause they are not of the same type.";
270
	}
271

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

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

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

    
314
		mark_subsystem_dirty('aliases');
315

    
316
		write_config();
317
		filter_configure();
318

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

    
332
include("head.inc");
333

    
334
$jscriptstr = <<<EOD
335

    
336
<script type="text/javascript">
337

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

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

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

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

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

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

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

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

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

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

    
425
$jscriptstr .= <<<EOD
426

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

    
464
EOD;
465

    
466
?>
467

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

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

    
481
<input type='hidden' name='address_type' value='textbox' />
482
<input type='hidden' name='address_subnet_type' value='select' />
483

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

    
489
	rowname[1] = "address_subnet";
490
	rowtype[1] = "select";
491
	rowsize[1] = "1";
492

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

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

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

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

    
595
       		} // end foreach
596
	} // end if
597
?>
598
        </tbody>
599
        <tfoot>
600

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

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

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

    
644
        var addressarray=new Array(<?php echo $aliasesaddr; ?>);
645

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

    
651

    
652
</script>
653

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

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

    
674
?>
(47-47/214)