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

    
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['type'] = $a_aliases[$id]['type'];
99
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
100

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

    
107

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

    
125
if ($_POST) {
126

    
127
	unset($input_errors);
128
	$pconfig = $_POST;
129

    
130
	/* input validation */
131

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

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

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

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

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

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

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

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

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

    
299
		mark_subsystem_dirty('aliases');
300

    
301
		write_config();
302
		filter_configure();
303

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

    
317
include("head.inc");
318

    
319
$jscriptstr = <<<EOD
320

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

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

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

    
340
			newrows = totalrows;
341
			for(i=0; i<newrows; i++) {
342
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
343
				eval(comd);
344
			}
345
			break;
346
		case 2:	/* port */
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 = "32";';
354
				eval(comd);
355
			}
356
			break;
357
		case 3:	/* OpenVPN Users */
358
			var cmd;
359

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

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

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

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

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

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

    
410
$jscriptstr .= <<<EOD
411

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

    
449
EOD;
450

    
451
?>
452

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
636

    
637
</script>
638

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

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

    
659
?>
(47-47/214)