Projet

Général

Profil

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

univnautes / usr / local / www / firewall_aliases_edit.php @ 055a43d2

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 and may only consist of the 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

    
284
		// First trim and expand the input data. 
285
		// Users can paste strings like "10.1.2.0/24 10.3.0.0/16 9.10.11.0/24" into an address box.
286
		// They can also put an IP range.
287
		// This loop expands out that stuff so it can easily be validated.
288
		for($x=0; $x<4999; $x++) {
289
			if($_POST["address{$x}"] <> "") {
290
				if ($_POST["detail{$x}"] <> "")
291
					if ((strpos($_POST["detail{$x}"], "||") === false) && (substr($_POST["detail{$x}"], 0, 1) != "|") && (substr($_POST["detail{$x}"], -1, 1) != "|")) {
292
						$detail_text = $_POST["detail{$x}"];
293
					} else {
294
						/* Remove leading and trailing vertical bars and replace multiple vertical bars with single, */
295
						/* and put in the output array so the text is at least redisplayed for the user. */
296
						$detail_text = preg_replace('/\|\|+/', '|', trim($_POST["detail{$x}"], "|"));
297
						if (!$desc_fmt_err_found) {
298
							$input_errors[] = $vertical_bar_err_text;
299
							$desc_fmt_err_found = true;
300
						}
301
					}
302
				else {
303
					$detail_text = sprintf(gettext("Entry added %s"), date('r'));
304
				}
305
				$address_items = explode(" ", trim($_POST["address{$x}"]));
306
				foreach ($address_items as $address_item) {
307
					if (is_iprange($address_item)) {
308
						list($startip, $endip) = explode('-', $address_item);
309
						$rangesubnets = ip_range_to_subnet_array($startip, $endip);
310
						foreach ($rangesubnets as $rangesubnet) {
311
							list($address_part, $subnet_part) = explode("/", $rangesubnet);
312
							$input_addresses[] = $address_part;
313
							$input_address_subnet[] = $subnet_part;
314
							$final_address_details[] = $detail_text;
315
						}
316
					} else {
317
						list($address_part, $subnet_part) = explode("/", $address_item);
318
						$input_addresses[] = $address_part;
319
						if (!empty($subnet_part))
320
							$input_address_subnet[] = $subnet_part;
321
						else
322
							$input_address_subnet[] = $_POST["address_subnet{$x}"];
323
						$final_address_details[] = $detail_text;
324
					}
325
				}
326
			}
327
		}
328

    
329
		// Validate the input data expanded above.
330
		foreach($input_addresses as $idx => $input_address) {
331
			if (is_alias($input_address)) {
332
				if (!alias_same_type($input_address, $_POST['type']))
333
					// But alias type network can include alias type urltable. Feature#1603.
334
					if (!($_POST['type'] == 'network' &&
335
						  preg_match("/urltable/i", alias_get_type($input_address))))
336
						$wrongaliases .= " " . $input_address;
337
			} else if ($_POST['type'] == "port") {
338
				if (!is_port($input_address) && !is_portrange($input_address))
339
					$input_errors[] = $input_address . " " . gettext("is not a valid port or alias.");
340
			} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
341
				if (is_subnet($input_address) || 
342
					(!is_ipaddr($input_address) && !is_hostname($input_address)))
343
					$input_errors[] = sprintf(gettext('%1$s is not a valid %2$s address, FQDN or alias.'), $input_address, $_POST['type']);
344
			}
345
			$tmpaddress = $input_address;
346
			if ($_POST['type'] != "host" && is_ipaddr($input_address) && $input_address_subnet[$idx] <> "") {
347
				if (!is_subnet($input_address . "/" . $input_address_subnet[$idx]))
348
					$input_errors[] = sprintf(gettext('%s/%s is not a valid subnet.'), $input_address, $input_address_subnet[$idx]);
349
				else
350
					$tmpaddress .= "/" . $input_address_subnet[$idx];
351
			}
352
			$address[] = $tmpaddress;
353
		}
354
		unset($desc_fmt_err_found);
355
		if ($wrongaliases <> "")
356
			$input_errors[] = sprintf(gettext('The alias(es): %s cannot be nested because they are not of the same type.'), $wrongaliases);
357
	}
358

    
359
	unset($vertical_bar_err_text);
360

    
361
	// Allow extending of the firewall edit page and include custom input validation
362
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
363

    
364
	if (!$input_errors) {
365
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
366
		$alias['descr'] = $_POST['descr'];
367
		$alias['type'] = $_POST['type'];
368
		$alias['detail'] = implode("||", $final_address_details);
369

    
370
		/*   Check to see if alias name needs to be
371
		 *   renamed on referenced rules and such
372
		 */
373
		if ($_POST['name'] <> $_POST['origname']) {
374
			// Firewall rules
375
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $_POST['name'], $origname);
376
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
377
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'port'), $_POST['name'], $origname);
378
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
379
			// NAT Rules
380
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $_POST['name'], $origname);
381
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'port'), $_POST['name'], $origname);
382
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
383
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
384
			update_alias_names_upon_change(array('nat', 'rule'), array('target'), $_POST['name'], $origname);
385
			update_alias_names_upon_change(array('nat', 'rule'), array('local-port'), $_POST['name'], $origname);
386
			// NAT 1:1 Rules
387
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('external'), $_POST['name'], $origname);
388
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('source', 'address'), $_POST['name'], $origname);
389
			update_alias_names_upon_change(array('nat', 'onetoone'), array('destination', 'address'), $_POST['name'], $origname);
390
			// NAT Outbound Rules
391
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $_POST['name'], $origname);
392
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $_POST['name'], $origname);
393
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
394
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $_POST['name'], $origname);
395
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('target'), $_POST['name'], $origname);
396
			// Alias in an alias
397
			update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $_POST['name'], $origname);
398
		}
399

    
400
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
401

    
402
		if (isset($id) && $a_aliases[$id]) {
403
			if ($a_aliases[$id]['name'] <> $alias['name']) {
404
				foreach ($a_aliases as $aliasid => $aliasd) {
405
					if ($aliasd['address'] <> "") {
406
						$tmpdirty = false;
407
						$tmpaddr = explode(" ", $aliasd['address']);
408
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
409
							if ($tmpalias == $a_aliases[$id]['name']) {
410
								$tmpaddr[$tmpidx] = $alias['name'];
411
								$tmpdirty = true;
412
							}
413
						}
414
						if ($tmpdirty == true)
415
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
416
					}
417
				}
418
			}
419
			$a_aliases[$id] = $alias;
420
		} else
421
			$a_aliases[] = $alias;
422

    
423
		// Sort list
424
		$a_aliases = msort($a_aliases, "name");
425

    
426
		if (write_config())
427
			mark_subsystem_dirty('aliases');
428

    
429
		if(!empty($tab))
430
			header("Location: firewall_aliases.php?tab=" . htmlspecialchars ($tab));
431
		else
432
			header("Location: firewall_aliases.php");
433
		exit;
434
	}
435
	//we received input errors, copy data to prevent retype
436
	else
437
	{
438
		$pconfig['name'] = $_POST['name'];
439
		$pconfig['descr'] = $_POST['descr'];
440
		if (($_POST['type'] == 'url') || ($_POST['type'] == 'url_ports'))
441
			$pconfig['address'] = implode(" ", $alias['aliasurl']);
442
		else
443
			$pconfig['address'] = implode(" ", $address);
444
		$pconfig['type'] = $_POST['type'];
445
		$pconfig['detail'] = implode("||", $final_address_details);
446
	}
447
}
448

    
449
include("head.inc");
450

    
451
$jscriptstr = <<<EOD
452

    
453
<script type="text/javascript">
454
//<![CDATA[
455
var objAlias = new Array(4999);
456
function typesel_change() {
457
	var field_disabled = 0;
458
	var field_value = "";
459
	var set_value = false;
460
	switch (document.iform.type.selectedIndex) {
461
		case 0:	/* host */
462
			field_disabled = 1;
463
			field_value = "";
464
			set_value = true;
465
			break;
466
		case 1:	/* network */
467
			field_disabled = 0;
468
			break;
469
		case 2:	/* port */
470
			field_disabled = 1;
471
			field_value = "128";
472
			set_value = true;
473
			break;
474
		case 3:	/* url */
475
			field_disabled = 1;
476
			break;
477
		case 4:	/* url_ports */
478
			field_disabled = 1;
479
			break;
480
		case 5:	/* urltable */
481
			field_disabled = 0;
482
			break;
483
		case 6:	/* urltable_ports */
484
			field_disabled = 0;
485
			break;
486
	}
487

    
488
	jQuery("select[id^='address_subnet']").prop("disabled", field_disabled);
489
	if (set_value == true)
490
		jQuery("select[id^='address_subnet']").prop("value", field_value);
491
}
492

    
493
function add_alias_control() {
494
	var name = "address" + (totalrows - 1);
495
	obj = document.getElementById(name);
496
	obj.setAttribute('class', 'formfldalias');
497
	obj.setAttribute('autocomplete', 'off');
498
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
499
}
500
EOD;
501

    
502
$network_str = gettext("Network or FQDN");
503
$networks_str = gettext("Network(s)");
504
$cidr_str = gettext("CIDR");
505
$description_str = gettext("Description");
506
$hosts_str = gettext("Host(s)");
507
$ip_str = gettext("IP or FQDN");
508
$ports_str = gettext("Port(s)");
509
$port_str = gettext("Port");
510
$url_str = gettext("URL (IPs)");
511
$url_ports_str = gettext("URL (Ports)");
512
$urltable_str = gettext("URL Table (IPs)");
513
$urltable_ports_str = gettext("URL Table (Ports)");
514
$update_freq_str = gettext("Update Freq. (days)");
515

    
516
$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.");
517
$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.");
518
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by separating with a colon.");
519
$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']);
520
$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']);
521
$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']);
522
$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']);
523

    
524
$openvpn_str = gettext("Username");
525
$openvpn_user_str = gettext("OpenVPN Users");
526
$openvpn_help = gettext("Enter as many usernames as you wish.");
527
$openvpn_freq = "";
528

    
529
$jscriptstr .= <<<EOD
530

    
531
function update_box_type() {
532
	var indexNum = document.forms[0].type.selectedIndex;
533
	var selected = document.forms[0].type.options[indexNum].text;
534
	if(selected == '{$networks_str}') {
535
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
536
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
537
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
538
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
539
		document.getElementById ("threecolumn").style.display = 'block';
540
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
541
		document.getElementById ("addrowbutton").style.display = 'block';
542
	} else if(selected == '{$hosts_str}') {
543
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
544
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
545
		document.getElementById ("twocolumn").firstChild.data = "";
546
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
547
		document.getElementById ("threecolumn").style.display = 'block';
548
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
549
		document.getElementById ("addrowbutton").style.display = 'block';
550
	} else if(selected == '{$ports_str}') {
551
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
552
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
553
		document.getElementById ("twocolumn").firstChild.data = "";
554
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
555
		document.getElementById ("threecolumn").style.display = 'block';
556
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
557
		document.getElementById ("addrowbutton").style.display = 'block';
558
	} else if(selected == '{$url_str}') {
559
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
560
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
561
		document.getElementById ("twocolumn").firstChild.data = "";
562
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
563
		document.getElementById ("threecolumn").style.display = 'block';
564
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
565
		document.getElementById ("addrowbutton").style.display = 'block';
566
	} else if(selected == '{$url_ports_str}') {
567
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_ports_str}";
568
		document.getElementById ("onecolumn").firstChild.data = "{$url_ports_str}";
569
		document.getElementById ("twocolumn").firstChild.data = "";
570
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
571
		document.getElementById ("threecolumn").style.display = 'block';
572
		document.getElementById ("itemhelp").firstChild.data = "{$url_ports_help}";
573
		document.getElementById ("addrowbutton").style.display = 'block';
574
	} else if(selected == '{$openvpn_user_str}') {
575
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
576
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
577
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
578
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
579
		document.getElementById ("threecolumn").style.display = 'block';
580
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
581
		document.getElementById ("addrowbutton").style.display = 'block';
582
	} else if(selected == '{$urltable_str}') {
583
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
584
			addRowTo('maintable', 'formfldalias');
585
			typesel_change();
586
			add_alias_control(this);
587
		}
588
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
589
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
590
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
591
		document.getElementById ("threecolumn").firstChild.data = "";
592
		document.getElementById ("threecolumn").style.display = 'none';
593
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_help}";
594
		document.getElementById ("addrowbutton").style.display = 'none';
595
	} else if(selected == '{$urltable_ports_str}') {
596
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
597
			addRowTo('maintable', 'formfldalias');
598
			typesel_change();
599
			add_alias_control(this);
600
		}
601
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
602
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
603
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
604
		document.getElementById ("threecolumn").firstChild.data = "";
605
		document.getElementById ("threecolumn").style.display = 'none';
606
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_ports_help}";
607
		document.getElementById ("addrowbutton").style.display = 'none';
608
	}
609
}
610
//]]>
611
</script>
612

    
613
EOD;
614

    
615
?>
616

    
617
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
618
<?php
619
	include("fbegin.inc");
620
	echo $jscriptstr;
621
?>
622

    
623
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
624
<script type="text/javascript" src="/javascript/row_helper.js"></script>
625
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
626
<script type="text/javascript" src="/javascript/suggestions.js"></script>
627

    
628
<input type='hidden' name='address_type' value='textbox' />
629
<input type='hidden' name='address_subnet_type' value='select' />
630

    
631
<script type="text/javascript">
632
//<![CDATA[
633
	rowname[0] = "address";
634
	rowtype[0] = "textbox,ipv4v6";
635
	rowsize[0] = "30";
636

    
637
	rowname[1] = "address_subnet";
638
	rowtype[1] = "select,ipv4v6";
639
	rowsize[1] = "1";
640

    
641
	rowname[2] = "detail";
642
	rowtype[2] = "textbox";
643
	rowsize[2] = "50";
644
//]]>
645
</script>
646

    
647
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
648
<?php if ($input_errors) print_input_errors($input_errors); ?>
649
<div id="inputerrors"></div>
650

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

    
723
					<?php
724
					$counter = 0;
725
					if ($pconfig['address'] <> ""):
726
						$addresses = explode(" ", $pconfig['address']);
727
						$details = explode("||", $pconfig['detail']);
728
						while ($counter < count($addresses)):
729
							if (is_subnet($addresses[$counter])) {
730
								list($address, $address_subnet) = explode("/", $addresses[$counter]);
731
							} else {
732
								$address = $addresses[$counter];
733
								$address_subnet = "";
734
							}
735
					?>
736
					<tr>
737
						<td>
738
							<input autocomplete="off" name="address<?php echo $counter; ?>" type="text" class="formfldalias ipv4v6" id="address<?php echo $counter; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
739
						</td>
740
						<td>
741
							<select name="address_subnet<?php echo $counter; ?>" class="formselect ipv4v6" id="address_subnet<?php echo $counter; ?>">
742
								<option></option>
743
								<?php for ($i = 128; $i >= 1; $i--): ?>
744
									<option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected=\"selected\""; ?>><?=$i;?></option>
745
								<?php endfor; ?>
746
							</select>
747
						</td>
748
						<td>
749
							<input name="detail<?php echo $counter; ?>" type="text" class="formfld unknown" id="detail<?php echo $counter; ?>" size="50" value="<?=htmlspecialchars($details[$counter]);?>" />
750
						</td>
751
						<td>
752
							<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>
753
						</td>
754
					</tr>
755
					<?php
756
						$counter++;
757

    
758
						endwhile;
759
					endif;
760
					?>
761
				</tbody>
762
			</table>
763
			<div id="addrowbutton">
764
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
765
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" />
766
				</a>
767
			</div>
768
		</td>
769
	</tr>
770
	<tr>
771
		<td width="22%" valign="top">&nbsp;</td>
772
		<td width="78%">
773
			<input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
774
			<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
775
		</td>
776
	</tr>
777
</table>
778
</form>
779

    
780
<script type="text/javascript">
781
//<![CDATA[
782
	field_counter_js = 3;
783
	rows = 1;
784
	totalrows = <?php echo $counter; ?>;
785
	loaded = <?php echo $counter; ?>;
786
	typesel_change();
787
	update_box_type();
788

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

    
791
	function createAutoSuggest() {
792
		<?php
793
		for ($jv = 0; $jv < $counter; $jv++)
794
			echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
795
		?>
796
	}
797

    
798
	setTimeout("createAutoSuggest();", 500);
799
//]]>
800
</script>
801

    
802
<?php include("fend.inc"); ?>
803
</body>
804
</html>
(61-61/256)