Projet

Général

Profil

Télécharger (33,2 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / firewall_aliases_edit.php @ dc4a8b9e

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
	originally 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
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_aliases.php');
55

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

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

    
64
$reserved_ifs = get_configured_interface_list(false, true);
65
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs, $reserved_table_names);
66

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

    
71
$tab = $_REQUEST['tab'];
72

    
73
if($_POST)
74
	$origname = $_POST['origname'];
75

    
76
// Debugging
77
if($debug)
78
	unlink_if_exists("{$g['tmp_path']}/alias_rename_log.txt");
79

    
80
function alias_same_type($name, $type) {
81
	global $config;
82

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

    
97
if (is_numericint($_GET['id']))
98
	$id = $_GET['id'];
99
if (isset($_POST['id']) && is_numericint($_POST['id']))
100
	$id = $_POST['id'];
101

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

    
110
	if(preg_match("/urltable/i", $a_aliases[$id]['type'])) {
111
		$pconfig['address'] = $a_aliases[$id]['url'];
112
		$pconfig['updatefreq'] = $a_aliases[$id]['updatefreq'];
113
	}
114
	if($a_aliases[$id]['aliasurl'] <> "") {
115
		if(is_array($a_aliases[$id]['aliasurl']))
116
			$pconfig['address'] = implode(" ", $a_aliases[$id]['aliasurl']);
117
		else
118
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
119
	}
120
}
121

    
122
if ($_POST) {
123
	unset($input_errors);
124
	$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.");
125

    
126
	/* input validation */
127

    
128
	$reqdfields = explode(" ", "name");
129
	$reqdfieldsn = array(gettext("Name"));
130

    
131
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
132

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

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

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

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

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

    
174
		/* item is a url table type */
175
		if ($_POST['address0']) {
176
			/* fetch down and add in */
177
			$_POST['address0'] = trim($_POST['address0']);
178
			$isfirst = 0;
179
			$address[] = $_POST['address0'];
180
			$alias['url'] = $_POST['address0'];
181
			$alias['updatefreq'] = $_POST['address_subnet0'] ? $_POST['address_subnet0'] : 7;
182
			if (!is_URL($alias['url']) || empty($alias['url'])) {
183
				$input_errors[] = gettext("You must provide a valid URL.");
184
			} elseif (! process_alias_urltable($alias['name'], $alias['url'], 0, true)) {
185
				$input_errors[] = gettext("Unable to fetch usable data.");
186
			}
187
			if ($_POST["detail0"] <> "") {
188
				if ((strpos($_POST["detail0"], "||") === false) && (substr($_POST["detail0"], 0, 1) != "|") && (substr($_POST["detail0"], -1, 1) != "|")) {
189
					$final_address_details[] = $_POST["detail0"];
190
				} else {
191
					/* Remove leading and trailing vertical bars and replace multiple vertical bars with single, */
192
					/* and put in the output array so the text is at least redisplayed for the user. */
193
					$final_address_details[] = preg_replace('/\|\|+/', '|', trim($_POST["detail0"], "|"));
194
					$input_errors[] = $vertical_bar_err_text;
195
				}
196
			} else
197
				$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
198
		}
199
	} else if ($_POST['type'] == "url" || $_POST['type'] == "url_ports") {
200
		$isfirst = 0;
201
		$address_count = 2;
202
		$desc_fmt_err_found = false;
203

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

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

    
222
				if (!isset($alias['aliasurl']))
223
					$alias['aliasurl'] = array();
224

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

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

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

    
336
	unset($vertical_bar_err_text);
337

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

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

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

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

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

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

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

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

    
426
include("head.inc");
427

    
428
$jscriptstr = <<<EOD
429

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

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

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

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

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

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

    
506
$jscriptstr .= <<<EOD
507

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

    
590
EOD;
591

    
592
?>
593

    
594
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
595
<?php
596
	include("fbegin.inc");
597
	echo $jscriptstr;
598
?>
599

    
600
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
601
<script type="text/javascript" src="/javascript/row_helper.js"></script>
602
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
603
<script type="text/javascript" src="/javascript/suggestions.js"></script>
604

    
605
<input type='hidden' name='address_type' value='textbox' />
606
<input type='hidden' name='address_subnet_type' value='select' />
607

    
608
<script type="text/javascript">
609
//<![CDATA[
610
	rowname[0] = "address";
611
	rowtype[0] = "textbox,ipv4v6";
612
	rowsize[0] = "30";
613

    
614
	rowname[1] = "address_subnet";
615
	rowtype[1] = "select,ipv4v6";
616
	rowsize[1] = "1";
617

    
618
	rowname[2] = "detail";
619
	rowtype[2] = "textbox";
620
	rowsize[2] = "50";
621
//]]>
622
</script>
623

    
624
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
625
<?php if ($input_errors) print_input_errors($input_errors); ?>
626
<div id="inputerrors"></div>
627

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

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

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

    
757
<script type="text/javascript">
758
//<![CDATA[
759
	field_counter_js = 3;
760
	rows = 1;
761
	totalrows = <?php echo $counter; ?>;
762
	loaded = <?php echo $counter; ?>;
763
	typesel_change();
764
	update_box_type();
765

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

    
768
	function createAutoSuggest() {
769
		<?php
770
		for ($jv = 0; $jv < $counter; $jv++)
771
			echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
772
		?>
773
	}
774

    
775
	setTimeout("createAutoSuggest();", 500);
776
//]]>
777
</script>
778

    
779
<?php include("fend.inc"); ?>
780
</body>
781
</html>
(61-61/256)