Project

General

Profile

Download (29.2 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
require("guiconfig.inc");
48
require_once("functions.inc");
49
require_once("filter.inc");
50
require_once("shaper.inc");
51

    
52
$pgtitle = array(gettext("Firewall"),gettext("Aliases"),gettext("Edit"));
53

    
54
// Keywords not allowed in names
55
$reserved_keywords = array("all", "pass", "block", "out", "queue", "max", "min", "pptp", "pppoe", "L2TP", "OpenVPN", "IPsec");
56

    
57
// Add all Load balance names to resrved_keywords
58
if (is_array($config['load_balancer']['lbpool']))
59
	foreach ($config['load_balancer']['lbpool'] as $lbpool)
60
		$reserved_keywords[] = $lbpool['name'];
61

    
62
$reserved_ifs = get_configured_interface_list(false, true);
63
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs, $reserved_table_names);
64

    
65
if (!is_array($config['aliases']['alias']))
66
	$config['aliases']['alias'] = array();
67
$a_aliases = &$config['aliases']['alias'];
68

    
69
$tab = $_REQUEST['tab'];
70

    
71
if($_POST)
72
	$origname = $_POST['origname'];
73

    
74
// Debugging
75
if($debug)
76
	exec("rm -f {$g['tmp_path']}/alias_rename_log.txt");
77

    
78
function alias_same_type($name, $type) {
79
	global $config;
80

    
81
	foreach ($config['aliases']['alias'] as $alias) {
82
		if ($name == $alias['name']) {
83
			if (in_array($type, array("host", "network")) &&
84
				in_array($alias['type'], array("host", "network")))
85
				return true;
86
			if ($type  == $alias['type'])
87
				return true;
88
			else
89
				return false;
90
		}
91
	}
92
	return true;
93
}
94

    
95
$id = $_GET['id'];
96
if (isset($_POST['id']))
97
	$id = $_POST['id'];
98

    
99
if (isset($id) && $a_aliases[$id]) {
100
	$original_alias_name = $a_aliases[$id]['name'];
101
	$pconfig['name'] = $a_aliases[$id]['name'];
102
	$pconfig['detail'] = $a_aliases[$id]['detail'];
103
	$pconfig['address'] = $a_aliases[$id]['address'];
104
	$pconfig['type'] = $a_aliases[$id]['type'];
105
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
106

    
107
	/* interface list */
108
	$iflist = get_configured_interface_with_descr(false, true);
109
	foreach ($iflist as $if => $ifdesc)
110
		if($ifdesc == $pconfig['descr'])
111
			$input_errors[] = sprintf(gettext("Sorry, an interface is already named %s."), $pconfig['descr']);
112

    
113
	if($a_aliases[$id]['type'] == "urltable") {
114
		$pconfig['address'] = $a_aliases[$id]['url'];
115
		$pconfig['updatefreq'] = $a_aliases[$id]['updatefreq'];
116
	}
117
	if($a_aliases[$id]['aliasurl'] <> "") {
118
		$pconfig['type'] = "url";
119
		if(is_array($a_aliases[$id]['aliasurl']))
120
			$pconfig['address'] = implode(" ", $a_aliases[$id]['aliasurl']);
121
		else
122
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
123
	}
124
}
125

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

    
129
	/* input validation */
130

    
131
	$reqdfields = explode(" ", "name");
132
	$reqdfieldsn = array(gettext("Name"));
133

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

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

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

    
160
	/* check for name interface description conflicts */
161
	foreach($config['interfaces'] as $interface) {
162
		if($interface['descr'] == $_POST['name']) {
163
			$input_errors[] = gettext("An interface description with this name already exists.");
164
			break;
165
		}
166
	}
167

    
168
	$alias = array();
169
	$address = array();
170
	$final_address_details = array();
171
	$alias['name'] = $_POST['name'];
172

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

    
177
		/* item is a url type */
178
		if ($_POST['address0']) {
179
			/* fetch down and add in */
180
			$_POST['address0'] = trim($_POST['address0']);
181
			$isfirst = 0;
182
			$address[] = $_POST['address0'];
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[] = gettext("You must provide a valid URL.");
187
			} elseif (! process_alias_urltable($alias['name'], $alias['url'], 0, true)) {
188
				$input_errors[] = gettext("Unable to fetch usable data.");
189
			}
190
			if ($_POST["detail0"] <> "")
191
				$final_address_details[] = $_POST["detail0"];
192
			else
193
				$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
194
		}
195
	} elseif($_POST['type'] == "url") {
196
		$isfirst = 0;
197
		$address_count = 2;
198

    
199
		/* item is a url type */
200
		for($x=0; $x<4999; $x++) {
201
			$_POST['address' . $x] = trim($_POST['address' . $x]);
202
			if($_POST['address' . $x]) {
203
				/* fetch down and add in */
204
				$isfirst = 0;
205
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
206
				unlink($temp_filename);
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
				else if(stristr($_POST['address' . $x], ".zip"))
213
					process_alias_unzip($temp_filename);
214

    
215
				if (!isset($alias['aliasurl']))
216
					$alias['aliasurl'] = array();
217

    
218
				$alias['aliasurl'][] = $_POST['address' . $x];
219
				if ($_POST["detail{$x}"] <> "")
220
					$final_address_details[] = $_POST["detail{$x}"];
221
				else
222
					$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
223

    
224
				if(file_exists("{$temp_filename}/aliases")) {
225
					$file_contents = file_get_contents("{$temp_filename}/aliases");
226
					$file_contents = str_replace("#", "\n#", $file_contents);
227
					$file_contents_split = explode("\n", $file_contents);
228
					foreach($file_contents_split as $fc) {
229
						// Stop at 3000 items, aliases larger than that tend to break both pf and the WebGUI.
230
						if ($address_count >= 3000)
231
							break;
232
						$tmp = trim($fc);
233
						if(stristr($fc, "#")) {
234
							$tmp_split = explode("#", $tmp);
235
							$tmp = trim($tmp_split[0]);
236
						}
237
						$tmp = trim($tmp);
238
						if(!empty($tmp) && (is_ipaddr($tmp) || is_subnet($tmp))) {
239
							$address[] = $tmp;
240
							$isfirst = 1;
241
							$address_count++;
242
						}
243
					}
244
					if($isfirst == 0) {
245
						/* nothing was found */
246
						$input_errors[] = sprintf(gettext("You must provide a valid URL. Could not fetch usable data from '%s'."), $_POST['address' . $x]);
247
					}
248
					mwexec("/bin/rm -rf {$temp_filename}");
249
				} else {
250
					$input_errors[] = sprintf(gettext("URL '%s' is not valid."), $_POST['address' . $x]);
251
				}
252
			}
253
		}
254
	} else {
255
		/* item is a normal alias type */
256
		$used_for_routes = 0;
257
		if (isset($config['staticroutes']['route']) && is_array($config['staticroutes']['route'])) {
258
			foreach($config['staticroutes']['route'] as $route) {
259
				if ($route['network'] == $_POST['origname']) {
260
					$used_for_routes = 1;
261
					break;
262
				}
263
			}
264
		}
265
		$wrongaliases = "";
266
		$wrongaliases_fqdn = "";
267
		for($x=0; $x<4999; $x++) {
268
			if($_POST["address{$x}"] <> "") {
269
				$_POST["address{$x}"] = trim($_POST["address{$x}"]);
270
				if (is_alias($_POST["address{$x}"])) {
271
					if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
272
						// But alias type network can include alias type urltable. Feature#1603.
273
						if (!($_POST['type'] == 'network' &&
274
						      alias_get_type($_POST["address{$x}"]) == 'urltable'))
275
							$wrongaliases .= " " . $_POST["address{$x}"];
276
					if ($used_for_routes === 1) {
277
						foreach (filter_expand_alias_array($_POST["address{$x}"], true) as $tgt) {
278
							if (is_ipaddrv4($tgt))
279
								$tgt .= "/32";
280
							if (is_ipaddrv6($tgt))
281
								$tgt .= "/128";
282
							if (!is_subnet($tgt) && is_fqdn($tgt)) {
283
								$wrongaliases_fqdn .= " " . $_POST["address{$x}"];
284
								break;
285
							}
286
						}
287
					}
288
				} else if ($_POST['type'] == "port") {
289
					if (!is_port($_POST["address{$x}"]))
290
						$input_errors[] = $_POST["address{$x}"] . " " . gettext("is not a valid port or alias.");
291
				} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
292
					if (!is_ipaddr($_POST["address{$x}"])
293
					 && !is_hostname($_POST["address{$x}"])
294
					 && !is_iprange($_POST["address{$x}"]))
295
						$input_errors[] = sprintf(gettext('%1$s is not a valid %2$s alias.'), $_POST["address{$x}"], $_POST['type']);
296
					if (($used_for_routes === 1)
297
					 && !is_ipaddr($_POST["address{$x}"])
298
					 && !is_iprange($_POST["address{$x}"])
299
					 && is_hostname($_POST["address{$x}"]))
300
						$input_errors[] = gettext('This alias is used on a static route and cannot contain FQDNs.');
301
				}
302
				if (is_iprange($_POST["address{$x}"])) {
303
					list($startip, $endip) = explode('-', $_POST["address{$x}"]);
304
					$rangesubnets = ip_range_to_subnet_array($startip, $endip);
305
					$address = array_merge($address, $rangesubnets);
306
				} else {
307
					$tmpaddress = $_POST["address{$x}"];
308
					if(is_ipaddr($_POST["address{$x}"]) && $_POST["address_subnet{$x}"] <> "")
309
						$tmpaddress .= "/" . $_POST["address_subnet{$x}"];
310
					$address[] = $tmpaddress;
311
				}
312
				if ($_POST["detail{$x}"] <> "")
313
					$final_address_details[] = $_POST["detail{$x}"];
314
				else
315
					$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
316
			}
317
		}
318
		if ($wrongaliases <> "")
319
			$input_errors[] = sprintf(gettext('The alias(es): %s cannot be nested because they are not of the same type.'), $wrongaliases);
320
		if ($wrongaliases_fqdn <> "")
321
			$input_errors[] = sprintf(gettext('The alias(es): %s cannot be nested because they contain FQDNs and this alias is used on at least one static route.'), $wrongaliases_fqdn);
322
	}
323

    
324
	// Allow extending of the firewall edit page and include custom input validation
325
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
326

    
327
	if (!$input_errors) {
328
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
329
		$alias['descr'] = $_POST['descr'];
330
		$alias['type'] = $_POST['type'];
331
		$alias['detail'] = implode("||", $final_address_details);
332

    
333
		/*   Check to see if alias name needs to be
334
		 *   renamed on referenced rules and such
335
		 */
336
		if ($_POST['name'] <> $_POST['origname']) {
337
			// Firewall rules
338
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $_POST['name'], $origname);
339
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
340
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'port'), $_POST['name'], $origname);
341
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
342
			// NAT Rules
343
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $_POST['name'], $origname);
344
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'port'), $_POST['name'], $origname);
345
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
346
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
347
			update_alias_names_upon_change(array('nat', 'rule'), array('target'), $_POST['name'], $origname);
348
			update_alias_names_upon_change(array('nat', 'rule'), array('local-port'), $_POST['name'], $origname);
349
			// NAT 1:1 Rules
350
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('external'), $_POST['name'], $origname);
351
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('source', 'address'), $_POST['name'], $origname);
352
			update_alias_names_upon_change(array('nat', 'onetoone'), array('destination', 'address'), $_POST['name'], $origname);
353
			// NAT Outbound Rules
354
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $_POST['name'], $origname);
355
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $_POST['name'], $origname);
356
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
357
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $_POST['name'], $origname);
358
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('target'), $_POST['name'], $origname);
359
			// Alias in an alias
360
			update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $_POST['name'], $origname);
361
		}
362

    
363
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
364

    
365
		if (isset($id) && $a_aliases[$id]) {
366
			if ($a_aliases[$id]['name'] <> $alias['name']) {
367
				foreach ($a_aliases as $aliasid => $aliasd) {
368
					if ($aliasd['address'] <> "") {
369
						$tmpdirty = false;
370
						$tmpaddr = explode(" ", $aliasd['address']);
371
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
372
							if ($tmpalias == $a_aliases[$id]['name']) {
373
								$tmpaddr[$tmpidx] = $alias['name'];
374
								$tmpdirty = true;
375
							}
376
						}
377
						if ($tmpdirty == true)
378
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
379
					}
380
				}
381
			}
382
			$a_aliases[$id] = $alias;
383
		} else
384
			$a_aliases[] = $alias;
385

    
386
		// Sort list
387
		$a_aliases = msort($a_aliases, "name");
388

    
389
		if (write_config())
390
			mark_subsystem_dirty('aliases');
391

    
392
		if(!empty($tab))
393
			header("Location: firewall_aliases.php?tab=" . htmlspecialchars ($tab));
394
		else
395
			header("Location: firewall_aliases.php");
396
		exit;
397
	}
398
	//we received input errors, copy data to prevent retype
399
	else
400
	{
401
		$pconfig['name'] = $_POST['name'];
402
		$pconfig['descr'] = $_POST['descr'];
403
		if ($_POST['type'] == 'url')
404
			$pconfig['address'] = implode(" ", $alias['aliasurl']);
405
		else
406
			$pconfig['address'] = implode(" ", $address);
407
		$pconfig['type'] = $_POST['type'];
408
		$pconfig['detail'] = implode("||", $final_address_details);
409
	}
410
}
411

    
412
include("head.inc");
413

    
414
$jscriptstr = <<<EOD
415

    
416
<script type="text/javascript">
417
//<![CDATA[
418
var objAlias = new Array(4999);
419
function typesel_change() {
420
	var field_disabled = 0;
421
	var field_value = "";
422
	var set_value = false;
423
	switch (document.iform.type.selectedIndex) {
424
		case 0:	/* host */
425
			field_disabled = 1;
426
			field_value = "";
427
			set_value = true;
428
			break;
429
		case 1:	/* network */
430
			field_disabled = 0;
431
			break;
432
		case 2:	/* port */
433
			field_disabled = 1;
434
			field_value = "128";
435
			set_value = true;
436
			break;
437
		case 3:	/* url */
438
			field_disabled = 1;
439
			break;
440

    
441
		case 4:	/* urltable */
442
			field_disabled = 0;
443
			break;
444
	}
445

    
446
	jQuery("select[id='address_subnet']").prop("disabled", field_disabled);
447
	if (set_value == true);
448
		jQuery("select[id='address_subnet']").prop("value", field_value);
449
}
450

    
451
function add_alias_control() {
452
	var name = "address" + (totalrows - 1);
453
	obj = document.getElementById(name);
454
	obj.setAttribute('class', 'formfldalias');
455
	obj.setAttribute('autocomplete', 'off');
456
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
457
}
458
EOD;
459

    
460
$network_str = gettext("Network");
461
$networks_str = gettext("Network(s)");
462
$cidr_str = gettext("CIDR");
463
$description_str = gettext("Description");
464
$hosts_str = gettext("Host(s)");
465
$ip_str = gettext("IP");
466
$ports_str = gettext("Port(s)");
467
$port_str = gettext("Port");
468
$url_str = gettext("URL");
469
$urltable_str = gettext("URL Table");
470
$update_freq_str = gettext("Update Freq. (days)");
471

    
472
$networks_help = gettext("Networks are specified in CIDR format.  Select the CIDR mask that pertains to each entry. /32 specifies a single IPv4 host, /128 specifies a single IPv6 host, /24 specifies 255.255.255.0, /64 specifies a normal IPv6 network, etc. Hostnames (FQDNs) may also be specified, using a /32 mask for IPv4 or /128 for IPv6. 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.");
473
$hosts_help = gettext("Enter as many hosts as you would like.  Hosts must be specified by their IP address or fully qualified domain name (FQDN). FQDN hostnames are periodically re-resolved and updated. If multiple IPs are returned by a DNS query, all are used.");
474
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by separating with a colon.");
475
$url_help = sprintf(gettext("Enter as many URLs as you wish. After saving %s will download the URL and import the items into the alias. Use only with small sets of IP addresses (less than 3000)."), $g['product_name']);
476
$urltable_help = sprintf(gettext("Enter a single URL containing a large number of IPs and/or Subnets. After saving %s 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."), $g['product_name']);
477

    
478
$openvpn_str = gettext("Username");
479
$openvpn_user_str = gettext("OpenVPN Users");
480
$openvpn_help = gettext("Enter as many usernames as you wish.");
481
$openvpn_freq = "";
482

    
483
$jscriptstr .= <<<EOD
484

    
485
function update_box_type() {
486
	var indexNum = document.forms[0].type.selectedIndex;
487
	var selected = document.forms[0].type.options[indexNum].text;
488
	if(selected == '{$networks_str}') {
489
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
490
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
491
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
492
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
493
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
494
		document.getElementById ("addrowbutton").style.display = 'block';
495
	} else if(selected == '{$hosts_str}') {
496
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
497
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
498
		document.getElementById ("twocolumn").firstChild.data = "";
499
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
500
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
501
		document.getElementById ("addrowbutton").style.display = 'block';
502
	} else if(selected == '{$ports_str}') {
503
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
504
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
505
		document.getElementById ("twocolumn").firstChild.data = "";
506
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
507
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
508
		document.getElementById ("addrowbutton").style.display = 'block';
509
	} else if(selected == '{$url_str}') {
510
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
511
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
512
		document.getElementById ("twocolumn").firstChild.data = "";
513
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
514
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
515
		document.getElementById ("addrowbutton").style.display = 'block';
516
	} else if(selected == '{$openvpn_user_str}') {
517
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
518
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
519
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
520
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
521
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
522
		document.getElementById ("addrowbutton").style.display = 'block';
523
	} else if(selected == '{$urltable_str}') {
524
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
525
			addRowTo('maintable', 'formfldalias');
526
			typesel_change();
527
			add_alias_control(this);
528
		}
529
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
530
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
531
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
532
		document.getElementById ("threecolumn").firstChild.data = "";
533
		document.getElementById ("threecolumn").style.display = 'none';
534
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_help}";
535
		document.getElementById ("addrowbutton").style.display = 'none';
536
	}
537
}
538
//]]>
539
</script>
540

    
541
EOD;
542

    
543
?>
544

    
545
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
546
<?php
547
	include("fbegin.inc");
548
	echo $jscriptstr;
549
?>
550

    
551
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
552
<script type="text/javascript" src="/javascript/row_helper.js"></script>
553
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
554
<script type="text/javascript" src="/javascript/suggestions.js"></script>
555

    
556
<input type='hidden' name='address_type' value='textbox' />
557
<input type='hidden' name='address_subnet_type' value='select' />
558

    
559
<script type="text/javascript">
560
//<![CDATA[
561
	rowname[0] = "address";
562
	rowtype[0] = "textbox,ipv4v6";
563
	rowsize[0] = "30";
564

    
565
	rowname[1] = "address_subnet";
566
	rowtype[1] = "select,ipv4v6";
567
	rowsize[1] = "1";
568

    
569
	rowname[2] = "detail";
570
	rowtype[2] = "textbox";
571
	rowsize[2] = "50";
572
//]]>
573
</script>
574

    
575
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
576
<?php if ($input_errors) print_input_errors($input_errors); ?>
577
<div id="inputerrors"></div>
578

    
579
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
580
<?php
581
if (empty($tab)) {
582
	if ($pconfig['type'] == 'urltable')
583
		$tab = 'url';
584
	else if ($pconfig['type'] == 'host')
585
		$tab = 'ip';
586
	else
587
		$tab = $pconfig['type'];
588
}
589
?>
590
<input name="tab" type="hidden" id="tab" value="<?=htmlspecialchars($tab);?>" />
591
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="firewall aliases edit">
592
	<tr>
593
		<td colspan="2" valign="top" class="listtopic"><?=gettext("Alias Edit"); ?></td>
594
	</tr>
595
	<tr>
596
		<td valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
597
		<td class="vtable">
598
			<input name="origname" type="hidden" id="origname" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
599
			<input name="name" type="text" id="name" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
600
			<?php if (isset($id) && $a_aliases[$id]): ?>
601
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
602
			<?php endif; ?>
603
			<br />
604
			<span class="vexpl">
605
				<?=gettext("The name of the alias may only consist of the characters \"a-z, A-Z, 0-9 and _\"."); ?>
606
			</span>
607
		</td>
608
	</tr>
609
	<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/after_first_tr"); ?>
610
	<tr>
611
		<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
612
		<td width="78%" class="vtable">
613
			<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
614
			<br />
615
			<span class="vexpl">
616
				<?=gettext("You may enter a description here for your reference (not parsed)."); ?>
617
			</span>
618
		</td>
619
	</tr>
620
	<tr>
621
		<td valign="top" class="vncellreq"><?=gettext("Type"); ?></td>
622
		<td class="vtable">
623
			<select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
624
				<option value="host" <?php if ($pconfig['type'] == "host") echo "selected=\"selected\""; ?>><?=gettext("Host(s)"); ?></option>
625
				<option value="network" <?php if ($pconfig['type'] == "network") echo "selected=\"selected\""; ?>><?=gettext("Network(s)"); ?></option>
626
				<option value="port" <?php if (($pconfig['type'] == "port") || (empty($pconfig['type']) && ($tab == "port"))) echo "selected=\"selected\""; ?>><?=gettext("Port(s)"); ?></option>
627
				<!--<option value="openvpn" <?php if ($pconfig['type'] == "openvpn") echo "selected=\"selected\""; ?>><?=gettext("OpenVPN Users"); ?></option> -->
628
				<option value="url" <?php if (($pconfig['type'] == "url") || (empty($pconfig['type']) && ($tab == "url"))) echo "selected=\"selected\""; ?>><?=gettext("URL");?></option>
629
				<option value="urltable" <?php if ($pconfig['type'] == "urltable") echo "selected=\"selected\""; ?>><?=gettext("URL Table"); ?></option>
630
			</select>
631
		</td>
632
	</tr>
633
	<tr>
634
		<td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport"><?=gettext("Host(s)"); ?></div></td>
635
		<td width="78%" class="vtable">
636
			<table id="maintable" summary="maintable">
637
				<tbody>
638
					<tr>
639
						<td colspan="4">
640
							<div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp"><?=gettext("Item information"); ?></div>
641
						</td>
642
					</tr>
643
					<tr>
644
						<td><div id="onecolumn"><?=gettext("Network"); ?></div></td>
645
						<td><div id="twocolumn">CIDR</div></td>
646
						<td><div id="threecolumn"><?=gettext("Description"); ?></div></td>
647
					</tr>
648

    
649
					<?php
650
					$counter = 0;
651
					if ($pconfig['address'] <> ""):
652
						$addresses = explode(" ", $pconfig['address']);
653
						$details = explode("||", $pconfig['detail']);
654
						while ($counter < count($addresses)):
655
							if (is_subnet($addresses[$counter])) {
656
								list($address, $address_subnet) = explode("/", $addresses[$counter]);
657
							} else {
658
								$address = $addresses[$counter];
659
								$address_subnet = "";
660
							}
661
					?>
662
					<tr>
663
						<td>
664
							<input autocomplete="off" name="address<?php echo $counter; ?>" type="text" class="formfldalias ipv4v6" id="address<?php echo $counter; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
665
						</td>
666
						<td>
667
							<select name="address_subnet<?php echo $counter; ?>" class="formselect ipv4v6" id="address_subnet<?php echo $counter; ?>">
668
								<option></option>
669
								<?php for ($i = 128; $i >= 1; $i--): ?>
670
									<option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected=\"selected\""; ?>><?=$i;?></option>
671
								<?php endfor; ?>
672
							</select>
673
						</td>
674
						<td>
675
							<input name="detail<?php echo $counter; ?>" type="text" class="formfld unknown" id="detail<?php echo $counter; ?>" size="50" value="<?=$details[$counter];?>" />
676
						</td>
677
						<td>
678
							<a onclick="removeRow(this); return false;" href="#"><img border="0" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" alt="" title="<?=gettext("remove this entry"); ?>" /></a>
679
						</td>
680
					</tr>
681
					<?php
682
						$counter++;
683

    
684
						endwhile;
685
					endif;
686
					?>
687
				</tbody>
688
			</table>
689
			<div id="addrowbutton">
690
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
691
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" />
692
				</a>
693
			</div>
694
		</td>
695
	</tr>
696
	<tr>
697
		<td width="22%" valign="top">&nbsp;</td>
698
		<td width="78%">
699
			<input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
700
			<a href="firewall_aliases.php?tab=<?=$tab;?>"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" /></a>
701
		</td>
702
	</tr>
703
</table>
704
</form>
705

    
706
<script type="text/javascript">
707
//<![CDATA[
708
	field_counter_js = 3;
709
	rows = 1;
710
	totalrows = <?php echo $counter; ?>;
711
	loaded = <?php echo $counter; ?>;
712
	typesel_change();
713
	update_box_type();
714

    
715
	var addressarray = <?= json_encode(array_exclude($pconfig['name'], get_alias_list($pconfig['type']))) ?>;
716

    
717
	function createAutoSuggest() {
718
		<?php
719
		for ($jv = 0; $jv < $counter; $jv++)
720
			echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
721
		?>
722
	}
723

    
724
	setTimeout("createAutoSuggest();", 500);
725
//]]>
726
</script>
727

    
728
<?php include("fend.inc"); ?>
729
</body>
730
</html>
(59-59/246)