Project

General

Profile

Download (30 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
				$dont_update = true;
188
			} elseif (! process_alias_urltable($alias['name'], $alias['url'], 0, true)) {
189
				$input_errors[] = gettext("Unable to fetch usable data.");
190
				$dont_update = true;
191
			}
192
			if ($_POST["detail0"] <> "")
193
				$final_address_details[] = $_POST["detail0"];
194
			else
195
				$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
196
		}
197
	} elseif($_POST['type'] == "url") {
198
		$isfirst = 0;
199
		$address_count = 2;
200

    
201
		/* item is a url type */
202
		for($x=0; $x<4999; $x++) {
203
			$_POST['address' . $x] = trim($_POST['address' . $x]);
204
			if($_POST['address' . $x]) {
205
				/* fetch down and add in */
206
				$isfirst = 0;
207
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
208
				unlink($temp_filename);
209
				mwexec("/bin/mkdir -p {$temp_filename}");
210
				mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
211
				/* if the item is tar gzipped then extract */
212
				if(stristr($_POST['address' . $x], ".tgz"))
213
					process_alias_tgz($temp_filename);
214
				else if(stristr($_POST['address' . $x], ".zip"))
215
					process_alias_unzip($temp_filename);
216

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

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

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

    
328
	// Allow extending of the firewall edit page and include custom input validation
329
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
330

    
331
	if (!$input_errors) {
332
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
333
		$alias['descr'] = $_POST['descr'];
334
		$alias['type'] = $_POST['type'];
335
		$alias['detail'] = implode("||", $final_address_details);
336

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

    
367
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
368

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

    
390
		// Sort list
391
		$a_aliases = msort($a_aliases, "name");
392

    
393
		if (write_config())
394
			mark_subsystem_dirty('aliases');
395

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

    
416
include("head.inc");
417

    
418
$jscriptstr = <<<EOD
419

    
420
<script type="text/javascript">
421
//<![CDATA[
422
var objAlias = new Array(4999);
423
function typesel_change() {
424
	switch (document.iform.type.selectedIndex) {
425
		case 0:	/* host */
426
			var cmd;
427

    
428
			newrows = totalrows;
429
			for(i=0; i<newrows; i++) {
430
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
431
				eval(comd);
432
				comd = 'document.iform.address_subnet' + i + '.value = "";';
433
				eval(comd);
434
			}
435
			break;
436
		case 1:	/* network */
437
			var cmd;
438

    
439
			newrows = totalrows;
440
			for(i=0; i<newrows; i++) {
441
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
442
				eval(comd);
443
			}
444
			break;
445
		case 2:	/* port */
446
			var cmd;
447

    
448
			newrows = totalrows;
449
			for(i=0; i<newrows; i++) {
450
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
451
				eval(comd);
452
				comd = 'document.iform.address_subnet' + i + '.value = "128";';
453
				eval(comd);
454
			}
455
			break;
456
/*		case 3:	// OpenVPN Users
457
			var cmd;
458

    
459
			newrows = totalrows;
460
			for(i=0; i<newrows; i++) {
461
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
462
				eval(comd);
463
				comd = 'document.iform.address_subnet' + i + '.value = "";';
464
				eval(comd);
465
			}
466
			break;
467
*/
468
		case 3:	/* url */
469
			var cmd;
470
			newrows = totalrows;
471
			for(i=0; i<newrows; i++) {
472
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
473
				eval(comd);
474
			}
475
			break;
476

    
477
		case 4:	/* urltable */
478
			var cmd;
479
			newrows = totalrows;
480
			for(i=0; i<newrows; i++) {
481
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
482
				eval(comd);
483
			}
484
			break;
485
	}
486
}
487

    
488
function add_alias_control() {
489
	var name = "address" + (totalrows - 1);
490
	obj = document.getElementById(name);
491
	obj.setAttribute('class', 'formfldalias');
492
	obj.setAttribute('autocomplete', 'off');
493
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
494
}
495
EOD;
496

    
497
$network_str = gettext("Network");
498
$networks_str = gettext("Network(s)");
499
$cidr_str = gettext("CIDR");
500
$description_str = gettext("Description");
501
$hosts_str = gettext("Host(s)");
502
$ip_str = gettext("IP");
503
$ports_str = gettext("Port(s)");
504
$port_str = gettext("Port");
505
$url_str = gettext("URL");
506
$urltable_str = gettext("URL Table");
507
$update_freq_str = gettext("Update Freq.");
508

    
509
$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.");
510
$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.");
511
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by separating with a colon.");
512
$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']);
513
$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']);
514

    
515
$openvpn_str = gettext("Username");
516
$openvpn_user_str = gettext("OpenVPN Users");
517
$openvpn_help = gettext("Enter as many usernames as you wish.");
518
$openvpn_freq = "";
519

    
520
$jscriptstr .= <<<EOD
521

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

    
578
EOD;
579

    
580
?>
581

    
582
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
583
<?php
584
	include("fbegin.inc");
585
	echo $jscriptstr;
586
?>
587

    
588
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
589
<script type="text/javascript" src="/javascript/row_helper.js"></script>
590
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
591
<script type="text/javascript" src="/javascript/suggestions.js"></script>
592

    
593
<input type='hidden' name='address_type' value='textbox' />
594
<input type='hidden' name='address_subnet_type' value='select' />
595

    
596
<script type="text/javascript">
597
//<![CDATA[
598
	rowname[0] = "address";
599
	rowtype[0] = "textbox,ipv4v6";
600
	rowsize[0] = "30";
601

    
602
	rowname[1] = "address_subnet";
603
	rowtype[1] = "select,ipv4v6";
604
	rowsize[1] = "1";
605

    
606
	rowname[2] = "detail";
607
	rowtype[2] = "textbox";
608
	rowsize[2] = "50";
609
//]]>
610
</script>
611

    
612
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
613
<?php if ($input_errors) print_input_errors($input_errors); ?>
614
<div id="inputerrors"></div>
615

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

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

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

    
743
<script type="text/javascript">
744
//<![CDATA[
745
	field_counter_js = 3;
746
	rows = 1;
747
	totalrows = <?php echo $counter; ?>;
748
	loaded = <?php echo $counter; ?>;
749
	typesel_change();
750
	update_box_type();
751

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

    
754
	function createAutoSuggest() {
755
		<?php
756
		for ($jv = 0; $jv < $counter; $jv++)
757
			echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
758
		?>
759
	}
760

    
761
	setTimeout("createAutoSuggest();", 500);
762
//]]>
763
</script>
764

    
765
<?php include("fend.inc"); ?>
766
</body>
767
</html>
(59-59/246)