Project

General

Profile

Download (32.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 reserved_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
	unlink_if_exists("{$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
	$vertical_bar_err_text = gettext("Vertical bars (|) at start or end, or double in the middle of descriptions not allowed. Descriptions have been cleaned. Check and save again.");
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 (preg_match("/urltable/i", $_POST['type'])) {
174
		$address = "";
175
		$isfirst = 0;
176

    
177
		/* item is a url table 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
				if ((strpos($_POST["detail0"], "||") === false) && (substr($_POST["detail0"], 0, 1) != "|") && (substr($_POST["detail0"], -1, 1) != "|")) {
192
					$final_address_details[] = $_POST["detail0"];
193
				} else {
194
					/* Remove leading and trailing vertical bars and replace multiple vertical bars with single, */
195
					/* and put in the output array so the text is at least redisplayed for the user. */
196
					$final_address_details[] = preg_replace('/\|\|+/', '|', trim($_POST["detail0"], "|"));
197
					$input_errors[] = $vertical_bar_err_text;
198
				}
199
			} else
200
				$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
201
		}
202
	} else if ($_POST['type'] == "url" || $_POST['type'] == "url_ports") {
203
		$isfirst = 0;
204
		$address_count = 2;
205
		$desc_fmt_err_found = false;
206

    
207
		/* item is a url type */
208
		for($x=0; $x<4999; $x++) {
209
			$_POST['address' . $x] = trim($_POST['address' . $x]);
210
			if($_POST['address' . $x]) {
211
				/* fetch down and add in */
212
				$isfirst = 0;
213
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
214
				unlink_if_exists($temp_filename);
215
				$verify_ssl = isset($config['system']['checkaliasesurlcert']);
216
				mkdir($temp_filename);
217
				download_file($_POST['address' . $x], $temp_filename . "/aliases", $verify_ssl);
218

    
219
				/* if the item is tar gzipped then extract */
220
				if(stristr($_POST['address' . $x], ".tgz"))
221
					process_alias_tgz($temp_filename);
222
				else if(stristr($_POST['address' . $x], ".zip"))
223
					process_alias_unzip($temp_filename);
224

    
225
				if (!isset($alias['aliasurl']))
226
					$alias['aliasurl'] = array();
227

    
228
				$alias['aliasurl'][] = $_POST['address' . $x];
229
				if ($_POST["detail{$x}"] <> "") {
230
					if ((strpos($_POST["detail{$x}"], "||") === false) && (substr($_POST["detail{$x}"], 0, 1) != "|") && (substr($_POST["detail{$x}"], -1, 1) != "|")) {
231
						$final_address_details[] = $_POST["detail{$x}"];
232
					} else {
233
						/* Remove leading and trailing vertical bars and replace multiple vertical bars with single, */
234
						/* and put in the output array so the text is at least redisplayed for the user. */
235
						$final_address_details[] = preg_replace('/\|\|+/', '|', trim($_POST["detail{$x}"], "|"));
236
						if (!$desc_fmt_err_found) {
237
							$input_errors[] = $vertical_bar_err_text;
238
							$desc_fmt_err_found = true;
239
						}
240
					}
241
				} else
242
					$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
243

    
244
				if(file_exists("{$temp_filename}/aliases")) {
245
					$file_contents = file_get_contents("{$temp_filename}/aliases");
246
					$file_contents = str_replace("#", "\n#", $file_contents);
247
					$file_contents_split = explode("\n", $file_contents);
248
					foreach($file_contents_split as $fc) {
249
						// Stop at 3000 items, aliases larger than that tend to break both pf and the WebGUI.
250
						if ($address_count >= 3000)
251
							break;
252
						$tmp = trim($fc);
253
						if(stristr($fc, "#")) {
254
							$tmp_split = explode("#", $tmp);
255
							$tmp = trim($tmp_split[0]);
256
						}
257
						$tmp = trim($tmp);
258
						if ($_POST['type'] == "url")
259
							$is_valid = (is_ipaddr($tmp) || is_subnet($tmp));
260
						else
261
							$is_valid = (is_port($tmp) || is_portrange($tmp));
262

    
263
						if (!empty($tmp) && $is_valid) {
264
							$address[] = $tmp;
265
							$isfirst = 1;
266
							$address_count++;
267
						}
268
					}
269
					if($isfirst == 0) {
270
						/* nothing was found */
271
						$input_errors[] = sprintf(gettext("You must provide a valid URL. Could not fetch usable data from '%s'."), $_POST['address' . $x]);
272
					}
273
					mwexec("/bin/rm -rf " . escapeshellarg($temp_filename));
274
				} else {
275
					$input_errors[] = sprintf(gettext("URL '%s' is not valid."), $_POST['address' . $x]);
276
				}
277
			}
278
		}
279
		unset($desc_fmt_err_found);
280
		if ($_POST['type'] == "url_ports")
281
			$address = group_ports($address);
282
	} else {
283
		/* item is a normal alias type */
284
		$wrongaliases = "";
285
		$desc_fmt_err_found = false;
286
		for($x=0; $x<4999; $x++) {
287
			if($_POST["address{$x}"] <> "") {
288
				$_POST["address{$x}"] = trim($_POST["address{$x}"]);
289
				if (is_alias($_POST["address{$x}"])) {
290
					if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
291
						// But alias type network can include alias type urltable. Feature#1603.
292
						if (!($_POST['type'] == 'network' &&
293
						      preg_match("/urltable/i", alias_get_type($_POST["address{$x}"]))))
294
							$wrongaliases .= " " . $_POST["address{$x}"];
295
				} else if ($_POST['type'] == "port") {
296
					if (!is_port($_POST["address{$x}"]))
297
						$input_errors[] = $_POST["address{$x}"] . " " . gettext("is not a valid port or alias.");
298
				} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
299
					if (!is_ipaddr($_POST["address{$x}"])
300
					 && !is_hostname($_POST["address{$x}"])
301
					 && !is_iprange($_POST["address{$x}"]))
302
						$input_errors[] = sprintf(gettext('%1$s is not a valid %2$s alias.'), $_POST["address{$x}"], $_POST['type']);
303
				}
304
				if (is_iprange($_POST["address{$x}"])) {
305
					list($startip, $endip) = explode('-', $_POST["address{$x}"]);
306
					$rangesubnets = ip_range_to_subnet_array($startip, $endip);
307
					$address = array_merge($address, $rangesubnets);
308
				} else {
309
					$tmpaddress = $_POST["address{$x}"];
310
					if(is_ipaddr($_POST["address{$x}"]) && $_POST["address_subnet{$x}"] <> "")
311
						$tmpaddress .= "/" . $_POST["address_subnet{$x}"];
312
					$address[] = $tmpaddress;
313
				}
314
				if ($_POST["detail{$x}"] <> "") {
315
					if ((strpos($_POST["detail{$x}"], "||") === false) && (substr($_POST["detail{$x}"], 0, 1) != "|") && (substr($_POST["detail{$x}"], -1, 1) != "|")) {
316
						$final_address_details[] = $_POST["detail{$x}"];
317
					} else {
318
						/* Remove leading and trailing vertical bars and replace multiple vertical bars with single, */
319
						/* and put in the output array so the text is at least redisplayed for the user. */
320
						$final_address_details[] = preg_replace('/\|\|+/', '|', trim($_POST["detail{$x}"], "|"));
321
						if (!$desc_fmt_err_found) {
322
							$input_errors[] = $vertical_bar_err_text;
323
							$desc_fmt_err_found = true;
324
						}
325
					}
326
				} else
327
					$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
328
			}
329
		}
330
		unset($desc_fmt_err_found);
331
		if ($wrongaliases <> "")
332
			$input_errors[] = sprintf(gettext('The alias(es): %s cannot be nested because they are not of the same type.'), $wrongaliases);
333
	}
334

    
335
	unset($vertical_bar_err_text);
336

    
337
	// Allow extending of the firewall edit page and include custom input validation
338
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
339

    
340
	if (!$input_errors) {
341
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
342
		$alias['descr'] = $_POST['descr'];
343
		$alias['type'] = $_POST['type'];
344
		$alias['detail'] = implode("||", $final_address_details);
345

    
346
		/*   Check to see if alias name needs to be
347
		 *   renamed on referenced rules and such
348
		 */
349
		if ($_POST['name'] <> $_POST['origname']) {
350
			// Firewall rules
351
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $_POST['name'], $origname);
352
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
353
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'port'), $_POST['name'], $origname);
354
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
355
			// NAT Rules
356
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $_POST['name'], $origname);
357
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'port'), $_POST['name'], $origname);
358
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
359
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
360
			update_alias_names_upon_change(array('nat', 'rule'), array('target'), $_POST['name'], $origname);
361
			update_alias_names_upon_change(array('nat', 'rule'), array('local-port'), $_POST['name'], $origname);
362
			// NAT 1:1 Rules
363
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('external'), $_POST['name'], $origname);
364
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('source', 'address'), $_POST['name'], $origname);
365
			update_alias_names_upon_change(array('nat', 'onetoone'), array('destination', 'address'), $_POST['name'], $origname);
366
			// NAT Outbound Rules
367
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $_POST['name'], $origname);
368
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $_POST['name'], $origname);
369
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
370
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $_POST['name'], $origname);
371
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('target'), $_POST['name'], $origname);
372
			// Alias in an alias
373
			update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $_POST['name'], $origname);
374
		}
375

    
376
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
377

    
378
		if (isset($id) && $a_aliases[$id]) {
379
			if ($a_aliases[$id]['name'] <> $alias['name']) {
380
				foreach ($a_aliases as $aliasid => $aliasd) {
381
					if ($aliasd['address'] <> "") {
382
						$tmpdirty = false;
383
						$tmpaddr = explode(" ", $aliasd['address']);
384
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
385
							if ($tmpalias == $a_aliases[$id]['name']) {
386
								$tmpaddr[$tmpidx] = $alias['name'];
387
								$tmpdirty = true;
388
							}
389
						}
390
						if ($tmpdirty == true)
391
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
392
					}
393
				}
394
			}
395
			$a_aliases[$id] = $alias;
396
		} else
397
			$a_aliases[] = $alias;
398

    
399
		// Sort list
400
		$a_aliases = msort($a_aliases, "name");
401

    
402
		if (write_config())
403
			mark_subsystem_dirty('aliases');
404

    
405
		if(!empty($tab))
406
			header("Location: firewall_aliases.php?tab=" . htmlspecialchars ($tab));
407
		else
408
			header("Location: firewall_aliases.php");
409
		exit;
410
	}
411
	//we received input errors, copy data to prevent retype
412
	else
413
	{
414
		$pconfig['name'] = $_POST['name'];
415
		$pconfig['descr'] = $_POST['descr'];
416
		if (($_POST['type'] == 'url') || ($_POST['type'] == 'url_ports'))
417
			$pconfig['address'] = implode(" ", $alias['aliasurl']);
418
		else
419
			$pconfig['address'] = implode(" ", $address);
420
		$pconfig['type'] = $_POST['type'];
421
		$pconfig['detail'] = implode("||", $final_address_details);
422
	}
423
}
424

    
425
include("head.inc");
426

    
427
$jscriptstr = <<<EOD
428

    
429
<script type="text/javascript">
430
//<![CDATA[
431
var objAlias = new Array(4999);
432
function typesel_change() {
433
	var field_disabled = 0;
434
	var field_value = "";
435
	var set_value = false;
436
	switch (document.iform.type.selectedIndex) {
437
		case 0:	/* host */
438
			field_disabled = 1;
439
			field_value = "";
440
			set_value = true;
441
			break;
442
		case 1:	/* network */
443
			field_disabled = 0;
444
			break;
445
		case 2:	/* port */
446
			field_disabled = 1;
447
			field_value = "128";
448
			set_value = true;
449
			break;
450
		case 3:	/* url */
451
			field_disabled = 1;
452
			break;
453
		case 4:	/* url_ports */
454
			field_disabled = 1;
455
			break;
456
		case 5:	/* urltable */
457
			field_disabled = 0;
458
			break;
459
		case 6:	/* urltable_ports */
460
			field_disabled = 0;
461
			break;
462
	}
463

    
464
	jQuery("select[id^='address_subnet']").prop("disabled", field_disabled);
465
	if (set_value == true)
466
		jQuery("select[id^='address_subnet']").prop("value", field_value);
467
}
468

    
469
function add_alias_control() {
470
	var name = "address" + (totalrows - 1);
471
	obj = document.getElementById(name);
472
	obj.setAttribute('class', 'formfldalias');
473
	obj.setAttribute('autocomplete', 'off');
474
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
475
}
476
EOD;
477

    
478
$network_str = gettext("Network");
479
$networks_str = gettext("Network(s)");
480
$cidr_str = gettext("CIDR");
481
$description_str = gettext("Description");
482
$hosts_str = gettext("Host(s)");
483
$ip_str = gettext("IP");
484
$ports_str = gettext("Port(s)");
485
$port_str = gettext("Port");
486
$url_str = gettext("URL (IPs)");
487
$url_ports_str = gettext("URL (Ports)");
488
$urltable_str = gettext("URL Table (IPs)");
489
$urltable_ports_str = gettext("URL Table (Ports)");
490
$update_freq_str = gettext("Update Freq. (days)");
491

    
492
$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.");
493
$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.");
494
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by separating with a colon.");
495
$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']);
496
$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']);
497
$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']);
498
$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']);
499

    
500
$openvpn_str = gettext("Username");
501
$openvpn_user_str = gettext("OpenVPN Users");
502
$openvpn_help = gettext("Enter as many usernames as you wish.");
503
$openvpn_freq = "";
504

    
505
$jscriptstr .= <<<EOD
506

    
507
function update_box_type() {
508
	var indexNum = document.forms[0].type.selectedIndex;
509
	var selected = document.forms[0].type.options[indexNum].text;
510
	if(selected == '{$networks_str}') {
511
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
512
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
513
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
514
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
515
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
516
		document.getElementById ("addrowbutton").style.display = 'block';
517
	} else if(selected == '{$hosts_str}') {
518
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
519
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
520
		document.getElementById ("twocolumn").firstChild.data = "";
521
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
522
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
523
		document.getElementById ("addrowbutton").style.display = 'block';
524
	} else if(selected == '{$ports_str}') {
525
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
526
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
527
		document.getElementById ("twocolumn").firstChild.data = "";
528
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
529
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
530
		document.getElementById ("addrowbutton").style.display = 'block';
531
	} else if(selected == '{$url_str}') {
532
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
533
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
534
		document.getElementById ("twocolumn").firstChild.data = "";
535
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
536
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
537
		document.getElementById ("addrowbutton").style.display = 'block';
538
	} else if(selected == '{$url_ports_str}') {
539
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_ports_str}";
540
		document.getElementById ("onecolumn").firstChild.data = "{$url_ports_str}";
541
		document.getElementById ("twocolumn").firstChild.data = "";
542
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
543
		document.getElementById ("itemhelp").firstChild.data = "{$url_ports_help}";
544
		document.getElementById ("addrowbutton").style.display = 'block';
545
	} else if(selected == '{$openvpn_user_str}') {
546
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
547
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
548
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
549
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
550
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
551
		document.getElementById ("addrowbutton").style.display = 'block';
552
	} else if(selected == '{$urltable_str}') {
553
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
554
			addRowTo('maintable', 'formfldalias');
555
			typesel_change();
556
			add_alias_control(this);
557
		}
558
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
559
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
560
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
561
		document.getElementById ("threecolumn").firstChild.data = "";
562
		document.getElementById ("threecolumn").style.display = 'none';
563
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_help}";
564
		document.getElementById ("addrowbutton").style.display = 'none';
565
	} else if(selected == '{$urltable_ports_str}') {
566
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
567
			addRowTo('maintable', 'formfldalias');
568
			typesel_change();
569
			add_alias_control(this);
570
		}
571
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
572
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
573
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
574
		document.getElementById ("threecolumn").firstChild.data = "";
575
		document.getElementById ("threecolumn").style.display = 'none';
576
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_ports_help}";
577
		document.getElementById ("addrowbutton").style.display = 'none';
578
	}
579
}
580
//]]>
581
</script>
582

    
583
EOD;
584

    
585
?>
586

    
587
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
588
<?php
589
	include("fbegin.inc");
590
	echo $jscriptstr;
591
?>
592

    
593
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
594
<script type="text/javascript" src="/javascript/row_helper.js"></script>
595
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
596
<script type="text/javascript" src="/javascript/suggestions.js"></script>
597

    
598
<input type='hidden' name='address_type' value='textbox' />
599
<input type='hidden' name='address_subnet_type' value='select' />
600

    
601
<script type="text/javascript">
602
//<![CDATA[
603
	rowname[0] = "address";
604
	rowtype[0] = "textbox,ipv4v6";
605
	rowsize[0] = "30";
606

    
607
	rowname[1] = "address_subnet";
608
	rowtype[1] = "select,ipv4v6";
609
	rowsize[1] = "1";
610

    
611
	rowname[2] = "detail";
612
	rowtype[2] = "textbox";
613
	rowsize[2] = "50";
614
//]]>
615
</script>
616

    
617
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
618
<?php if ($input_errors) print_input_errors($input_errors); ?>
619
<div id="inputerrors"></div>
620

    
621
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
622
<?php
623
if (empty($tab)) {
624
	if (preg_match("/url/i", $pconfig['type']))
625
		$tab = 'url';
626
	else if ($pconfig['type'] == 'host')
627
		$tab = 'ip';
628
	else
629
		$tab = $pconfig['type'];
630
}
631
?>
632
<input name="tab" type="hidden" id="tab" value="<?=htmlspecialchars($tab);?>" />
633
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="firewall aliases edit">
634
	<tr>
635
		<td colspan="2" valign="top" class="listtopic"><?=gettext("Alias Edit"); ?></td>
636
	</tr>
637
	<tr>
638
		<td valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
639
		<td class="vtable">
640
			<input name="origname" type="hidden" id="origname" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
641
			<input name="name" type="text" id="name" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
642
			<?php if (isset($id) && $a_aliases[$id]): ?>
643
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
644
			<?php endif; ?>
645
			<br />
646
			<span class="vexpl">
647
				<?=gettext("The name of the alias may only consist of the characters \"a-z, A-Z, 0-9 and _\"."); ?>
648
			</span>
649
		</td>
650
	</tr>
651
	<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/after_first_tr"); ?>
652
	<tr>
653
		<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
654
		<td width="78%" class="vtable">
655
			<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
656
			<br />
657
			<span class="vexpl">
658
				<?=gettext("You may enter a description here for your reference (not parsed)."); ?>
659
			</span>
660
		</td>
661
	</tr>
662
	<tr>
663
		<td valign="top" class="vncellreq"><?=gettext("Type"); ?></td>
664
		<td class="vtable">
665
			<select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
666
				<option value="host" <?php if ($pconfig['type'] == "host") echo "selected=\"selected\""; ?>><?=gettext("Host(s)"); ?></option>
667
				<option value="network" <?php if ($pconfig['type'] == "network") echo "selected=\"selected\""; ?>><?=gettext("Network(s)"); ?></option>
668
				<option value="port" <?php if (($pconfig['type'] == "port") || (empty($pconfig['type']) && ($tab == "port"))) echo "selected=\"selected\""; ?>><?=gettext("Port(s)"); ?></option>
669
				<!--<option value="openvpn" <?php if ($pconfig['type'] == "openvpn") echo "selected=\"selected\""; ?>><?=gettext("OpenVPN Users"); ?></option> -->
670
				<option value="url" <?php if (($pconfig['type'] == "url") || (empty($pconfig['type']) && ($tab == "url"))) echo "selected=\"selected\""; ?>><?=gettext("URL (IPs)");?></option>
671
				<option value="url_ports" <?php if ($pconfig['type'] == "url_ports") echo "selected=\"selected\""; ?>><?=gettext("URL (Ports)");?></option>
672
				<option value="urltable" <?php if ($pconfig['type'] == "urltable") echo "selected=\"selected\""; ?>><?=gettext("URL Table (IPs)"); ?></option>
673
				<option value="urltable_ports" <?php if ($pconfig['type'] == "urltable_ports") echo "selected=\"selected\""; ?>><?=gettext("URL Table (Ports)"); ?></option>
674
			</select>
675
		</td>
676
	</tr>
677
	<tr>
678
		<td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport"><?=gettext("Host(s)"); ?></div></td>
679
		<td width="78%" class="vtable">
680
			<table id="maintable" summary="maintable">
681
				<tbody>
682
					<tr>
683
						<td colspan="4">
684
							<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>
685
						</td>
686
					</tr>
687
					<tr>
688
						<td><div id="onecolumn"><?=gettext("Network"); ?></div></td>
689
						<td><div id="twocolumn">CIDR</div></td>
690
						<td><div id="threecolumn"><?=gettext("Description"); ?></div></td>
691
					</tr>
692

    
693
					<?php
694
					$counter = 0;
695
					if ($pconfig['address'] <> ""):
696
						$addresses = explode(" ", $pconfig['address']);
697
						$details = explode("||", $pconfig['detail']);
698
						while ($counter < count($addresses)):
699
							if (is_subnet($addresses[$counter])) {
700
								list($address, $address_subnet) = explode("/", $addresses[$counter]);
701
							} else {
702
								$address = $addresses[$counter];
703
								$address_subnet = "";
704
							}
705
					?>
706
					<tr>
707
						<td>
708
							<input autocomplete="off" name="address<?php echo $counter; ?>" type="text" class="formfldalias ipv4v6" id="address<?php echo $counter; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
709
						</td>
710
						<td>
711
							<select name="address_subnet<?php echo $counter; ?>" class="formselect ipv4v6" id="address_subnet<?php echo $counter; ?>">
712
								<option></option>
713
								<?php for ($i = 128; $i >= 1; $i--): ?>
714
									<option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected=\"selected\""; ?>><?=$i;?></option>
715
								<?php endfor; ?>
716
							</select>
717
						</td>
718
						<td>
719
							<input name="detail<?php echo $counter; ?>" type="text" class="formfld unknown" id="detail<?php echo $counter; ?>" size="50" value="<?=$details[$counter];?>" />
720
						</td>
721
						<td>
722
							<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>
723
						</td>
724
					</tr>
725
					<?php
726
						$counter++;
727

    
728
						endwhile;
729
					endif;
730
					?>
731
				</tbody>
732
			</table>
733
			<div id="addrowbutton">
734
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
735
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" />
736
				</a>
737
			</div>
738
		</td>
739
	</tr>
740
	<tr>
741
		<td width="22%" valign="top">&nbsp;</td>
742
		<td width="78%">
743
			<input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
744
			<a href="firewall_aliases.php?tab=<?=$tab;?>"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" /></a>
745
		</td>
746
	</tr>
747
</table>
748
</form>
749

    
750
<script type="text/javascript">
751
//<![CDATA[
752
	field_counter_js = 3;
753
	rows = 1;
754
	totalrows = <?php echo $counter; ?>;
755
	loaded = <?php echo $counter; ?>;
756
	typesel_change();
757
	update_box_type();
758

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

    
761
	function createAutoSuggest() {
762
		<?php
763
		for ($jv = 0; $jv < $counter; $jv++)
764
			echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
765
		?>
766
	}
767

    
768
	setTimeout("createAutoSuggest();", 500);
769
//]]>
770
</script>
771

    
772
<?php include("fend.inc"); ?>
773
</body>
774
</html>
(59-59/249)