Project

General

Profile

Download (25 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
	Copyright (C) 2010 Jim Pingle
8
	All rights reserved.
9

    
10
	originially part of m0n0wall (http://m0n0.ch/wall)
11
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
	All rights reserved.
13

    
14
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16

    
17
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19

    
20
	2. Redistributions in binary form must reproduce the above copyright
21
	   notice, this list of conditions and the following disclaimer in the
22
	   documentation and/or other materials provided with the distribution.
23

    
24
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
	POSSIBILITY OF SUCH DAMAGE.
34
*/
35
/*
36
	pfSense_BUILDER_BINARIES:	/bin/rm	/bin/mkdir	/usr/bin/fetch
37
	pfSense_MODULE:	aliases
38
*/
39

    
40
##|+PRIV
41
##|*IDENT=page-firewall-alias-edit
42
##|*NAME=Firewall: Alias: Edit page
43
##|*DESCR=Allow access to the 'Firewall: Alias: Edit' page.
44
##|*MATCH=firewall_aliases_edit.php*
45
##|-PRIV
46

    
47
$pgtitle = array("Firewall","Aliases","Edit");
48

    
49
// Keywords not allowed in names
50
$reserved_keywords = array("pass", "out", "queue", "max", "min", "pptp", "pppoe", "l2tp", "openvpn");
51

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

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

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

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

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

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

    
92
if (isset($id) && $a_aliases[$id]) {
93
	$original_alias_name = $a_aliases[$id]['name'];
94
	$pconfig['name'] = $a_aliases[$id]['name'];
95
	$pconfig['detail'] = $a_aliases[$id]['detail'];
96
	$pconfig['address'] = $a_aliases[$id]['address'];
97
	$pconfig['type'] = $a_aliases[$id]['type'];
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
	if($a_aliases[$id]['type'] == "urltable") {
107
		$pconfig['address'] = $a_aliases[$id]['url'];
108
		$pconfig['updatefreq'] = $a_aliases[$id]['updatefreq'];
109
	}
110
	if($a_aliases[$id]['aliasurl'] <> "") {
111
		$pconfig['type'] = "url";
112
		if(is_array($a_aliases[$id]['aliasurl'])) {
113
			$isfirst = 0;
114
			$pconfig['address'] = "";
115
			foreach($a_aliases[$id]['aliasurl'] as $aa) {
116
				if($isfirst == 1)
117
					$pconfig['address'] .= " ";
118
				$isfirst = 1;
119
				$pconfig['address'] .= $aa;
120
			}
121
		} else {
122
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
123
		}
124
	}
125
}
126

    
127
if ($_POST) {
128
	unset($input_errors);
129

    
130
	/* input validation */
131

    
132
	$reqdfields = explode(" ", "name");
133
	$reqdfieldsn = explode(",", "Name");
134

    
135
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
136

    
137
	$x = is_validaliasname($_POST['name']);
138
	if (!isset($x)) {
139
		$input_errors[] = "Reserved word used for alias name.";
140
	} else if ($_POST['type'] == "port" && (getservbyname($_POST['name'], "tcp") || getservbyname($_POST['name'], "udp"))) {
141
		$input_errors[] = "Reserved word used for alias name.";
142
	} else {
143
		if (is_validaliasname($_POST['name']) == false)
144
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
145
	}
146
	/* check for name conflicts */
147
	if (empty($a_aliases[$id])) {
148
		foreach ($a_aliases as $alias) {
149
			if ($alias['name'] == $_POST['name']) {
150
				$input_errors[] = "An alias with this name already exists.";
151
				break;
152
			}
153
		}
154
	}
155

    
156
	/* Check for reserved keyword names */
157
	foreach($reserved_keywords as $rk) 
158
		if($rk == $_POST['name'])
159
			$input_errors[] = "Cannot use a reserved keyword as alias name $rk";
160

    
161
	/* check for name interface description conflicts */
162
	foreach($config['interfaces'] as $interface) {
163
		if($interface['descr'] == $_POST['name']) {
164
			$input_errors[] = "An interface description with this name already exists.";
165
			break;
166
		}
167
	}
168
	
169
	$alias = array();
170
	$address = array();
171
	$final_address_details = array();
172
	$alias['name'] = $_POST['name'];
173

    
174
	if ($_POST['type'] == "urltable") {
175
		$address = "";
176
		$isfirst = 0;
177

    
178
		/* item is a url type */
179
		if ($_POST['address0']) {
180
			/* fetch down and add in */
181
			$isfirst = 0;
182
			$address = "";
183
			$alias['url'] = $_POST['address0'];
184
			$alias['updatefreq'] = $_POST['address_subnet0'] ? $_POST['address_subnet0'] : 7;
185
			if (!is_URL($alias['url']) || empty($alias['url'])) {
186
				$input_errors[] = "You must provide a valid URL.";
187
				$dont_update = true;
188
			} elseif (! process_alias_urltable($alias['name'], $alias['url'], 0, true)) {
189
				$input_errors[] = "Unable to fetch usable data.";
190
				$dont_update = true;
191
			}
192
		}
193
	} elseif($_POST['type'] == "url") {
194
		$isfirst = 0;
195
		$address_count = 2;
196

    
197
		/* item is a url type */
198
		for($x=0; isset($_POST['address'. $x]); $x++) {
199
			if($_POST['address' . $x]) {
200
				/* fetch down and add in */
201
				$isfirst = 0;
202
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
203
				unlink($temp_filename);
204
				$fda = fopen("{$g['tmp_path']}/tmpfetch","w");
205
				fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
206
				fclose($fda);
207
				mwexec("/bin/mkdir -p {$temp_filename}");
208
				mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
209
				/* if the item is tar gzipped then extract */
210
				if(stristr($_POST['address' . $x], ".tgz"))
211
					process_alias_tgz($temp_filename);
212
				if(file_exists("{$temp_filename}/aliases")) {
213
					$file_contents = file_get_contents("{$temp_filename}/aliases");
214
					$file_contents = str_replace("#", "\n#", $file_contents);
215
					$file_contents_split = split("\n", $file_contents);
216
					foreach($file_contents_split as $fc) {
217
						// Stop at 3000 items, aliases larger than that tend to break both pf and the WebGUI.
218
						if ($address_count >= 3000)
219
							break;
220
						$tmp = trim($fc);
221
						if(stristr($fc, "#")) {
222
							$tmp_split = split("#", $tmp);
223
							$tmp = trim($tmp_split[0]);
224
						}
225
						$tmp = trim($tmp);
226
						if(!empty($tmp) && (is_ipaddr($tmp) || is_subnet($tmp))) {
227
							$address[] = $tmp;
228
							$isfirst = 1;
229
							$address_count++;
230
						}
231
					}
232
					if($isfirst == 0) {
233
						/* nothing was found */
234
						$input_errors[] = "You must provide a valid URL. Could not fetch usable data.";
235
						$dont_update = true;
236
						break;
237
					}
238
					$alias['aliasurl'][] = $_POST['address' . $x];
239
					mwexec("/bin/rm -rf {$temp_filename}");
240
				} else {
241
					$input_errors[] = "You must provide a valid URL.";
242
					$dont_update = true;
243
					break;
244
				}
245
			}
246
		}
247
	} else {
248
		/* item is a normal alias type */
249
		$wrongaliases = "";
250
		for($x=0; $x<4999; $x++) {
251
			if($_POST["address{$x}"] <> "") {
252
				if (is_alias($_POST["address{$x}"])) {
253
					if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
254
						$wrongaliases .= " " . $_POST["address{$x}"];
255
				} else if ($_POST['type'] == "port") {
256
					if (!is_port($_POST["address{$x}"]))
257
						$input_errors[] = $_POST["address{$x}"] . " is not a valid port or alias.";
258
				} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
259
					if (!is_ipaddr($_POST["address{$x}"])
260
					 && !is_hostname($_POST["address{$x}"])
261
					 && !is_iprange($_POST["address{$x}"]))
262
						$input_errors[] = $_POST["address{$x}"] . " is not a valid {$_POST['type']} alias.";
263
				}
264
				if (is_iprange($_POST["address{$x}"])) {
265
					list($startip, $endip) = explode('-', $_POST["address{$x}"]);
266
					$rangesubnets = ip_range_to_subnet_array($startip, $endip);
267
					$address = array_merge($address, $rangesubnets);
268
				} else {
269
					$tmpaddress = $_POST["address{$x}"];
270
					if(($_POST['type'] == "network" || is_ipaddr($_POST["address{$x}"])) && $_POST["address_subnet{$x}"] <> "")
271
						$tmpaddress .= "/" . $_POST["address_subnet{$x}"];
272
					$address[] = $tmpaddress;
273
				}
274
				if ($_POST["detail{$x}"] <> "")
275
					$final_address_details[] = $_POST["detail{$x}"];
276
				else
277
					$final_address_details[] = "Entry added " . date('r');
278
			}
279
		}
280
		if ($wrongaliases <> "")
281
			$input_errors[] = "The alias(es): {$wrongaliases} \ncannot be nested cause they are not of the same type.";
282
	}
283

    
284
	if (!$input_errors) {
285
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
286
		$alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
287
		$alias['type'] = $_POST['type'];
288
		$alias['detail'] = implode("||", $final_address_details);
289

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

    
305
		if (isset($id) && $a_aliases[$id]) {
306
			if ($a_aliases[$id]['name'] <> $alias['name']) {
307
				foreach ($a_aliases as $aliasid => $aliasd) {
308
					if ($aliasd['address'] <> "") {
309
						$tmpdirty = false;
310
						$tmpaddr = explode(" ", $aliasd['address']);
311
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
312
							if ($tmpalias == $a_aliases[$id]['name']) {
313
								$tmpaddr[$tmpidx] = $alias['name'];
314
								$tmpdirty = true;
315
							}
316
						}
317
						if ($tmpdirty == true)
318
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
319
					}
320
				}
321
			}
322
			$a_aliases[$id] = $alias;
323
		} else
324
			$a_aliases[] = $alias;
325

    
326
		mark_subsystem_dirty('aliases');
327

    
328
		// Sort list
329
		$a_aliases = msort($a_aliases, "name");
330

    
331
		write_config();
332
		filter_configure();
333

    
334
		header("Location: firewall_aliases.php");
335
		exit;		
336
	}
337
	//we received input errors, copy data to prevent retype
338
	else
339
	{
340
		$pconfig['name'] = $_POST['name'];
341
		$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
342
		$pconfig['address'] = implode(" ", $address);
343
		$pconfig['type'] = $_POST['type'];
344
		$pconfig['detail'] = implode("||", $final_address_details);
345
	}
346
}
347

    
348
include("head.inc");
349

    
350
$jscriptstr = <<<EOD
351

    
352
<script type="text/javascript">
353

    
354
var objAlias = new Array(4999);
355
function typesel_change() {
356
	switch (document.iform.type.selectedIndex) {
357
		case 0:	/* host */
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
		case 1:	/* network */
369
			var cmd;
370

    
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
		case 2:	/* port */
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 = "32";';
385
				eval(comd);
386
			}
387
			break;
388
		case 3:	/* OpenVPN Users */
389
			var cmd;
390

    
391
			newrows = totalrows;
392
			for(i=0; i<newrows; i++) {
393
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
394
				eval(comd);
395
				comd = 'document.iform.address_subnet' + i + '.value = "";';
396
				eval(comd);
397
			}
398
			break;
399

    
400
		case 4:	/* url */
401
			var cmd;
402
			newrows = totalrows;
403
			for(i=0; i<newrows; i++) {
404
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
405
				eval(comd);
406
			}
407
			break;
408

    
409
		case 5:	/* urltable */
410
			var cmd;
411
			newrows = totalrows;
412
			for(i=0; i<newrows; i++) {
413
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
414
				eval(comd);
415
			}
416
			break;
417
	}
418
}
419

    
420
function add_alias_control() {
421
	var name = "address" + (totalrows - 1);
422
	obj = document.getElementById(name);
423
	obj.setAttribute('class', 'formfldalias');
424
	obj.setAttribute('autocomplete', 'off');
425
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
426
}
427
EOD;
428

    
429
$network_str = gettext("Network");
430
$networks_str = gettext("Network(s)");
431
$cidr_str = gettext("CIDR");
432
$description_str = gettext("Description");
433
$hosts_str = gettext("Host(s)");
434
$ip_str = gettext("IP");
435
$ports_str = gettext("Port(s)");
436
$port_str = gettext("Port");
437
$url_str = gettext("URL");
438
$urltable_str = gettext("URL Table");
439
$update_freq_str = gettext("Update Freq.");
440

    
441
$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. You may also enter an IP range such as 192.168.1.1-192.168.1.254 and a list of CIDR networks will be derived to fill the range.");
442
$hosts_help = gettext("Enter as many hosts as you would like.  Hosts must be specified by their IP address.");
443
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by seperating with a colon.");
444
$url_help = gettext("Enter as many URLs as you wish. After saving {$g['product_name']} will download the URL and import the items into the alias. Use only with small sets of IP addresses (less than 3000).");
445
$urltable_help = gettext("Enter a single URL containing a large number of IPs and/or Subnets. After saving {$g['product_name']} will download the URL and create a table file containing these addresses. This will work with large numbers of addresses (30,000+) or small numbers.");
446

    
447
$openvpn_str = gettext("Username");
448
$openvpn_user_str = gettext("OpenVPN Users");
449
$openvpn_help = gettext("Enter as many usernames as you wish.");
450
$openvpn_freq = gettext("");
451

    
452
$jscriptstr .= <<<EOD
453

    
454
function update_box_type() {
455
	var indexNum = document.forms[0].type.selectedIndex;
456
	var selected = document.forms[0].type.options[indexNum].text;
457
	if(selected == '{$networks_str}') {
458
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
459
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
460
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
461
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
462
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
463
		document.getElementById ("addrowbutton").style.display = 'block';
464
	} else if(selected == '{$hosts_str}') {
465
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
466
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
467
		document.getElementById ("twocolumn").firstChild.data = "";
468
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
469
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
470
		document.getElementById ("addrowbutton").style.display = 'block';
471
	} else if(selected == '{$ports_str}') {
472
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
473
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
474
		document.getElementById ("twocolumn").firstChild.data = "";
475
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
476
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
477
		document.getElementById ("addrowbutton").style.display = 'block';
478
	} else if(selected == '{$url_str}') {
479
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
480
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
481
		document.getElementById ("twocolumn").firstChild.data = "";
482
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
483
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
484
		document.getElementById ("addrowbutton").style.display = 'block';
485
	} else if(selected == '{$openvpn_user_str}') {
486
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
487
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
488
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
489
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
490
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
491
		document.getElementById ("addrowbutton").style.display = 'block';
492
	} else if(selected == '{$urltable_str}') {
493
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
494
			addRowTo('maintable', 'formfldalias');
495
			typesel_change();
496
			add_alias_control(this);
497
		}
498
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
499
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
500
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
501
		document.getElementById ("threecolumn").firstChild.data = "";
502
		document.getElementById ("threecolumn").style.display = 'none';
503
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_help}";
504
		document.getElementById ("addrowbutton").style.display = 'none';
505
	}
506
}
507
</script>
508

    
509
EOD;
510

    
511
?>
512

    
513
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
514
<?php
515
	include("fbegin.inc");
516
	echo $jscriptstr;
517
?>
518

    
519
<script type="text/javascript" src="/javascript/row_helper.js">
520
</script>
521
<script type="text/javascript" src="/javascript/autosuggest.js">
522
</script>
523
<script type="text/javascript" src="/javascript/suggestions.js">
524
</script>
525

    
526
<input type='hidden' name='address_type' value='textbox' />
527
<input type='hidden' name='address_subnet_type' value='select' />
528

    
529
<script type="text/javascript">
530
	rowname[0] = "address";
531
	rowtype[0] = "textbox";
532
	rowsize[0] = "30";
533

    
534
	rowname[1] = "address_subnet";
535
	rowtype[1] = "select";
536
	rowsize[1] = "1";
537

    
538
	rowname[2] = "detail";
539
	rowtype[2] = "textbox";
540
	rowsize[2] = "50";
541
</script>
542

    
543
<?php if ($input_errors) print_input_errors($input_errors); ?>
544
<div id="inputerrors"></div>
545

    
546
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
547
<table width="100%" border="0" cellpadding="6" cellspacing="0">
548
  <tr>
549
	<td colspan="2" valign="top" class="listtopic">Alias Edit</td>
550
  </tr>
551
  <tr>
552
    <td valign="top" class="vncellreq">Name</td>
553
    <td class="vtable">
554
      <input name="origname" type="hidden" id="origname" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
555
      <input name="name" type="text" id="name" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
556
      <?php if (isset($id) && $a_aliases[$id]): ?>
557
      <input name="id" type="hidden" value="<?=$id;?>" />
558
      <?php endif; ?>
559
      <br />
560
      <span class="vexpl">
561
        The name of the alias may only consist of the characters a-z, A-Z and 0-9.
562
      </span>
563
    </td>
564
  </tr>
565
  <tr>
566
    <td width="22%" valign="top" class="vncell">Description</td>
567
    <td width="78%" class="vtable">
568
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
569
      <br />
570
      <span class="vexpl">
571
        You may enter a description here for your reference (not parsed).
572
      </span>
573
    </td>
574
  </tr>
575
  <tr>
576
    <td valign="top" class="vncellreq">Type</td>
577
    <td class="vtable">
578
      <select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
579
        <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
580
        <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
581
        <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
582
        <option value="openvpn" <?php if ($pconfig['type'] == "openvpn") echo "selected"; ?>>OpenVPN Users</option>
583
        <option value="url" <?php if ($pconfig['type'] == "url") echo "selected"; ?>>URL</option>
584
        <option value="urltable" <?php if ($pconfig['type'] == "urltable") echo "selected"; ?>>URL Table</option>
585
      </select>
586
    </td>
587
  </tr>
588
  <tr>
589
    <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport">Host(s)</div></td>
590
    <td width="78%" class="vtable">
591
      <table id="maintable">
592
        <tbody>
593
          <tr>
594
            <td colspan="4">
595
      		    <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>
596
            </td>
597
          </tr>
598
          <tr>
599
            <td><div id="onecolumn">Network</div></td>
600
            <td><div id="twocolumn">CIDR</div></td>
601
           <td><div id="threecolumn">Description</div></td>
602
          </tr>
603

    
604
	<?php
605
	$counter = 0;
606
	$address = $pconfig['address'];
607
	if ($address <> "") {
608
		$item = explode(" ", $address);
609
		$item3 = explode("||", $pconfig['detail']);
610
		foreach($item as $ww) {
611
			$address = $item[$counter];
612
			$address_subnet = "";
613
			$item2 = explode("/", $address);
614
			foreach($item2 as $current) {
615
				if($item2[1] <> "") {
616
					$address = $item2[0];
617
					$address_subnet = $item2[1];
618
				}
619
				
620
			}
621
			$item4 = $item3[$counter];
622
			$tracker = $counter;
623
	?>
624
          <tr>
625
            <td>
626
              <input autocomplete="off" name="address<?php echo $tracker; ?>" type="text" class="formfldalias" id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
627
            </td>
628
            <td>
629
			        <select name="address_subnet<?php echo $tracker; ?>" class="formselect" id="address_subnet<?php echo $tracker; ?>">
630
				<option></option>
631
			          <?php for ($i = 32; $i >= 1; $i--): ?>
632
			          <option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected"; ?>><?=$i;?></option>
633
			          <?php endfor; ?>
634
			        </select>
635
			      </td>
636
            <td>
637
              <input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
638
            </td>
639
            <td>
640
    		<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
641
	      </td>
642
          </tr>
643
<?php
644
        	$counter++;
645

    
646
       		} // end foreach
647
	} // end if
648
?>
649
        </tbody>
650
        <tfoot>
651

    
652
        </tfoot>
653
		  </table>
654
			<div id="addrowbutton"><a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
655
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" /></div>
656
      </a>
657
		</td>
658
  </tr>
659
  <tr>
660
    <td width="22%" valign="top">&nbsp;</td>
661
    <td width="78%">
662
      <input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
663
      <a href="firewall_aliases.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" /></a>
664
    </td>
665
  </tr>
666
</table>
667
</form>
668

    
669
<script type="text/javascript">
670
	field_counter_js = 3;
671
	rows = 1;
672
	totalrows = <?php echo $counter; ?>;
673
	loaded = <?php echo $counter; ?>;
674
	typesel_change();
675
	update_box_type();
676

    
677
<?php
678
        $isfirst = 0;
679
        $aliases = "";
680
        $addrisfirst = 0;
681
        $aliasesaddr = "";
682
        if(isset($config['aliases']['alias']) && is_array($config['aliases']['alias']))
683
                foreach($config['aliases']['alias'] as $alias_name) {
684
			if ($pconfig['name'] <> "" && $pconfig['name'] == $alias_name['name'])
685
				continue;
686
			if($addrisfirst == 1) $aliasesaddr .= ",";
687
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
688
			$addrisfirst = 1;
689
                }
690
?>
691

    
692
        var addressarray=new Array(<?php echo $aliasesaddr; ?>);
693

    
694
function createAutoSuggest() {
695
<?php  
696
	for ($jv = 0; $jv < $counter; $jv++)
697
		echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
698
?>
699
}
700

    
701
setTimeOut("createAutoSuggest();", 500);
702

    
703
</script>
704

    
705
<?php include("fend.inc"); ?>
706
</body>
707
</html>
(47-47/216)