Project

General

Profile

Download (30.5 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(preg_match("/urltable/i", $a_aliases[$id]['type'])) {
114
		$pconfig['address'] = $a_aliases[$id]['url'];
115
		$pconfig['updatefreq'] = $a_aliases[$id]['updatefreq'];
116
	}
117
	if($a_aliases[$id]['aliasurl'] <> "") {
118
		if(is_array($a_aliases[$id]['aliasurl']))
119
			$pconfig['address'] = implode(" ", $a_aliases[$id]['aliasurl']);
120
		else
121
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
122
	}
123
}
124

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

    
128
	/* input validation */
129

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

    
133
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
134

    
135
	$x = is_validaliasname($_POST['name']);
136
	if (!isset($x)) {
137
		$input_errors[] = gettext("Reserved word used for alias name.");
138
	} else if ($_POST['type'] == "port" && (getservbyname($_POST['name'], "tcp") || getservbyname($_POST['name'], "udp"))) {
139
		$input_errors[] = gettext("Reserved word used for alias name.");
140
	} else {
141
		if (is_validaliasname($_POST['name']) == false)
142
			$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, _.";
143
	}
144
	/* check for name conflicts */
145
	if (empty($a_aliases[$id])) {
146
		foreach ($a_aliases as $alias) {
147
			if ($alias['name'] == $_POST['name']) {
148
				$input_errors[] = gettext("An alias with this name already exists.");
149
				break;
150
			}
151
		}
152
	}
153

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

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

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

    
172
	if (preg_match("/urltable/i", $_POST['type'])) {
173
		$address = "";
174
		$isfirst = 0;
175

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

    
198
		/* item is a url type */
199
		for($x=0; $x<4999; $x++) {
200
			$_POST['address' . $x] = trim($_POST['address' . $x]);
201
			if($_POST['address' . $x]) {
202
				/* fetch down and add in */
203
				$isfirst = 0;
204
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
205
				unlink($temp_filename);
206
				$verify_ssl = isset($config['system']['checkaliasesurlcert']);
207
				mwexec("/bin/mkdir -p {$temp_filename}");
208
				download_file($_POST['address' . $x], $temp_filename . "/aliases", $verify_ssl);
209

    
210
				/* if the item is tar gzipped then extract */
211
				if(stristr($_POST['address' . $x], ".tgz"))
212
					process_alias_tgz($temp_filename);
213
				else if(stristr($_POST['address' . $x], ".zip"))
214
					process_alias_unzip($temp_filename);
215

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

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

    
225
				if(file_exists("{$temp_filename}/aliases")) {
226
					$file_contents = file_get_contents("{$temp_filename}/aliases");
227
					$file_contents = str_replace("#", "\n#", $file_contents);
228
					$file_contents_split = explode("\n", $file_contents);
229
					foreach($file_contents_split as $fc) {
230
						// Stop at 3000 items, aliases larger than that tend to break both pf and the WebGUI.
231
						if ($address_count >= 3000)
232
							break;
233
						$tmp = trim($fc);
234
						if(stristr($fc, "#")) {
235
							$tmp_split = explode("#", $tmp);
236
							$tmp = trim($tmp_split[0]);
237
						}
238
						$tmp = trim($tmp);
239
						if ($_POST['type'] == "url")
240
							$is_valid = (is_ipaddr($tmp) || is_subnet($tmp));
241
						else
242
							$is_valid = (is_port($tmp) || is_portrange($tmp));
243

    
244
						if (!empty($tmp) && $is_valid) {
245
							$address[] = $tmp;
246
							$isfirst = 1;
247
							$address_count++;
248
						}
249
					}
250
					if($isfirst == 0) {
251
						/* nothing was found */
252
						$input_errors[] = sprintf(gettext("You must provide a valid URL. Could not fetch usable data from '%s'."), $_POST['address' . $x]);
253
					}
254
					mwexec("/bin/rm -rf {$temp_filename}");
255
				} else {
256
					$input_errors[] = sprintf(gettext("URL '%s' is not valid."), $_POST['address' . $x]);
257
				}
258
			}
259
		}
260
		if ($_POST['type'] == "url_ports")
261
			$address = group_ports($address);
262
	} else {
263
		/* item is a normal alias type */
264
		$wrongaliases = "";
265
		for($x=0; $x<4999; $x++) {
266
			if($_POST["address{$x}"] <> "") {
267
				$_POST["address{$x}"] = trim($_POST["address{$x}"]);
268
				if (is_alias($_POST["address{$x}"])) {
269
					if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
270
						// But alias type network can include alias type urltable. Feature#1603.
271
						if (!($_POST['type'] == 'network' &&
272
						      preg_match("/urltable/i", alias_get_type($_POST["address{$x}"]))))
273
							$wrongaliases .= " " . $_POST["address{$x}"];
274
				} else if ($_POST['type'] == "port") {
275
					if (!is_port($_POST["address{$x}"]))
276
						$input_errors[] = $_POST["address{$x}"] . " " . gettext("is not a valid port or alias.");
277
				} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
278
					if (!is_ipaddr($_POST["address{$x}"])
279
					 && !is_hostname($_POST["address{$x}"])
280
					 && !is_iprange($_POST["address{$x}"]))
281
						$input_errors[] = sprintf(gettext('%1$s is not a valid %2$s alias.'), $_POST["address{$x}"], $_POST['type']);
282
				}
283
				if (is_iprange($_POST["address{$x}"])) {
284
					list($startip, $endip) = explode('-', $_POST["address{$x}"]);
285
					$rangesubnets = ip_range_to_subnet_array($startip, $endip);
286
					$address = array_merge($address, $rangesubnets);
287
				} else {
288
					$tmpaddress = $_POST["address{$x}"];
289
					if(is_ipaddr($_POST["address{$x}"]) && $_POST["address_subnet{$x}"] <> "")
290
						$tmpaddress .= "/" . $_POST["address_subnet{$x}"];
291
					$address[] = $tmpaddress;
292
				}
293
				if ($_POST["detail{$x}"] <> "")
294
					$final_address_details[] = $_POST["detail{$x}"];
295
				else
296
					$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
297
			}
298
		}
299
		if ($wrongaliases <> "")
300
			$input_errors[] = sprintf(gettext('The alias(es): %s cannot be nested because they are not of the same type.'), $wrongaliases);
301
	}
302

    
303
	// Allow extending of the firewall edit page and include custom input validation
304
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
305

    
306
	if (!$input_errors) {
307
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
308
		$alias['descr'] = $_POST['descr'];
309
		$alias['type'] = $_POST['type'];
310
		$alias['detail'] = implode("||", $final_address_details);
311

    
312
		/*   Check to see if alias name needs to be
313
		 *   renamed on referenced rules and such
314
		 */
315
		if ($_POST['name'] <> $_POST['origname']) {
316
			// Firewall rules
317
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $_POST['name'], $origname);
318
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
319
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'port'), $_POST['name'], $origname);
320
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
321
			// NAT Rules
322
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $_POST['name'], $origname);
323
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'port'), $_POST['name'], $origname);
324
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
325
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
326
			update_alias_names_upon_change(array('nat', 'rule'), array('target'), $_POST['name'], $origname);
327
			update_alias_names_upon_change(array('nat', 'rule'), array('local-port'), $_POST['name'], $origname);
328
			// NAT 1:1 Rules
329
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('external'), $_POST['name'], $origname);
330
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('source', 'address'), $_POST['name'], $origname);
331
			update_alias_names_upon_change(array('nat', 'onetoone'), array('destination', 'address'), $_POST['name'], $origname);
332
			// NAT Outbound Rules
333
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $_POST['name'], $origname);
334
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $_POST['name'], $origname);
335
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
336
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $_POST['name'], $origname);
337
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('target'), $_POST['name'], $origname);
338
			// Alias in an alias
339
			update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $_POST['name'], $origname);
340
		}
341

    
342
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
343

    
344
		if (isset($id) && $a_aliases[$id]) {
345
			if ($a_aliases[$id]['name'] <> $alias['name']) {
346
				foreach ($a_aliases as $aliasid => $aliasd) {
347
					if ($aliasd['address'] <> "") {
348
						$tmpdirty = false;
349
						$tmpaddr = explode(" ", $aliasd['address']);
350
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
351
							if ($tmpalias == $a_aliases[$id]['name']) {
352
								$tmpaddr[$tmpidx] = $alias['name'];
353
								$tmpdirty = true;
354
							}
355
						}
356
						if ($tmpdirty == true)
357
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
358
					}
359
				}
360
			}
361
			$a_aliases[$id] = $alias;
362
		} else
363
			$a_aliases[] = $alias;
364

    
365
		// Sort list
366
		$a_aliases = msort($a_aliases, "name");
367

    
368
		if (write_config())
369
			mark_subsystem_dirty('aliases');
370

    
371
		if(!empty($tab))
372
			header("Location: firewall_aliases.php?tab=" . htmlspecialchars ($tab));
373
		else
374
			header("Location: firewall_aliases.php");
375
		exit;
376
	}
377
	//we received input errors, copy data to prevent retype
378
	else
379
	{
380
		$pconfig['name'] = $_POST['name'];
381
		$pconfig['descr'] = $_POST['descr'];
382
		if (($_POST['type'] == 'url') || ($_POST['type'] == 'url_ports'))
383
			$pconfig['address'] = implode(" ", $alias['aliasurl']);
384
		else
385
			$pconfig['address'] = implode(" ", $address);
386
		$pconfig['type'] = $_POST['type'];
387
		$pconfig['detail'] = implode("||", $final_address_details);
388
	}
389
}
390

    
391
include("head.inc");
392

    
393
$jscriptstr = <<<EOD
394

    
395
<script type="text/javascript">
396
//<![CDATA[
397
var objAlias = new Array(4999);
398
function typesel_change() {
399
	var field_disabled = 0;
400
	var field_value = "";
401
	var set_value = false;
402
	switch (document.iform.type.selectedIndex) {
403
		case 0:	/* host */
404
			field_disabled = 1;
405
			field_value = "";
406
			set_value = true;
407
			break;
408
		case 1:	/* network */
409
			field_disabled = 0;
410
			break;
411
		case 2:	/* port */
412
			field_disabled = 1;
413
			field_value = "128";
414
			set_value = true;
415
			break;
416
		case 3:	/* url */
417
			field_disabled = 1;
418
			break;
419
		case 4:	/* url_ports */
420
			field_disabled = 1;
421
			break;
422
		case 5:	/* urltable */
423
			field_disabled = 0;
424
			break;
425
		case 6:	/* urltable_ports */
426
			field_disabled = 0;
427
			break;
428
	}
429

    
430
	jQuery("select[id^='address_subnet']").prop("disabled", field_disabled);
431
	if (set_value == true);
432
		jQuery("select[id^='address_subnet']").prop("value", field_value);
433
}
434

    
435
function add_alias_control() {
436
	var name = "address" + (totalrows - 1);
437
	obj = document.getElementById(name);
438
	obj.setAttribute('class', 'formfldalias');
439
	obj.setAttribute('autocomplete', 'off');
440
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
441
}
442
EOD;
443

    
444
$network_str = gettext("Network");
445
$networks_str = gettext("Network(s)");
446
$cidr_str = gettext("CIDR");
447
$description_str = gettext("Description");
448
$hosts_str = gettext("Host(s)");
449
$ip_str = gettext("IP");
450
$ports_str = gettext("Port(s)");
451
$port_str = gettext("Port");
452
$url_str = gettext("URL (IPs)");
453
$url_ports_str = gettext("URL (Ports)");
454
$urltable_str = gettext("URL Table (IPs)");
455
$urltable_ports_str = gettext("URL Table (Ports)");
456
$update_freq_str = gettext("Update Freq. (days)");
457

    
458
$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.");
459
$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.");
460
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by separating with a colon.");
461
$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']);
462
$url_ports_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 Ports (less than 3000)."), $g['product_name']);
463
$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']);
464
$urltable_ports_help = sprintf(gettext("Enter a single URL containing a list of Port numbers and/or Port ranges. After saving %s will download the URL."), $g['product_name']);
465

    
466
$openvpn_str = gettext("Username");
467
$openvpn_user_str = gettext("OpenVPN Users");
468
$openvpn_help = gettext("Enter as many usernames as you wish.");
469
$openvpn_freq = "";
470

    
471
$jscriptstr .= <<<EOD
472

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

    
549
EOD;
550

    
551
?>
552

    
553
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
554
<?php
555
	include("fbegin.inc");
556
	echo $jscriptstr;
557
?>
558

    
559
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
560
<script type="text/javascript" src="/javascript/row_helper.js"></script>
561
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
562
<script type="text/javascript" src="/javascript/suggestions.js"></script>
563

    
564
<input type='hidden' name='address_type' value='textbox' />
565
<input type='hidden' name='address_subnet_type' value='select' />
566

    
567
<script type="text/javascript">
568
//<![CDATA[
569
	rowname[0] = "address";
570
	rowtype[0] = "textbox,ipv4v6";
571
	rowsize[0] = "30";
572

    
573
	rowname[1] = "address_subnet";
574
	rowtype[1] = "select,ipv4v6";
575
	rowsize[1] = "1";
576

    
577
	rowname[2] = "detail";
578
	rowtype[2] = "textbox";
579
	rowsize[2] = "50";
580
//]]>
581
</script>
582

    
583
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
584
<?php if ($input_errors) print_input_errors($input_errors); ?>
585
<div id="inputerrors"></div>
586

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

    
659
					<?php
660
					$counter = 0;
661
					if ($pconfig['address'] <> ""):
662
						$addresses = explode(" ", $pconfig['address']);
663
						$details = explode("||", $pconfig['detail']);
664
						while ($counter < count($addresses)):
665
							if (is_subnet($addresses[$counter])) {
666
								list($address, $address_subnet) = explode("/", $addresses[$counter]);
667
							} else {
668
								$address = $addresses[$counter];
669
								$address_subnet = "";
670
							}
671
					?>
672
					<tr>
673
						<td>
674
							<input autocomplete="off" name="address<?php echo $counter; ?>" type="text" class="formfldalias ipv4v6" id="address<?php echo $counter; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
675
						</td>
676
						<td>
677
							<select name="address_subnet<?php echo $counter; ?>" class="formselect ipv4v6" id="address_subnet<?php echo $counter; ?>">
678
								<option></option>
679
								<?php for ($i = 128; $i >= 1; $i--): ?>
680
									<option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected=\"selected\""; ?>><?=$i;?></option>
681
								<?php endfor; ?>
682
							</select>
683
						</td>
684
						<td>
685
							<input name="detail<?php echo $counter; ?>" type="text" class="formfld unknown" id="detail<?php echo $counter; ?>" size="50" value="<?=$details[$counter];?>" />
686
						</td>
687
						<td>
688
							<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>
689
						</td>
690
					</tr>
691
					<?php
692
						$counter++;
693

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

    
716
<script type="text/javascript">
717
//<![CDATA[
718
	field_counter_js = 3;
719
	rows = 1;
720
	totalrows = <?php echo $counter; ?>;
721
	loaded = <?php echo $counter; ?>;
722
	typesel_change();
723
	update_box_type();
724

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

    
727
	function createAutoSuggest() {
728
		<?php
729
		for ($jv = 0; $jv < $counter; $jv++)
730
			echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
731
		?>
732
	}
733

    
734
	setTimeout("createAutoSuggest();", 500);
735
//]]>
736
</script>
737

    
738
<?php include("fend.inc"); ?>
739
</body>
740
</html>
(59-59/246)