Projet

Général

Profil

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

univnautes / usr / local / www / firewall_aliases_edit.php @ 62424bdb

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
$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
	/* interface list */
111
	$iflist = get_configured_interface_with_descr(false, true);
112
	foreach ($iflist as $if => $ifdesc)
113
		if($ifdesc == $pconfig['descr'])
114
			$input_errors[] = sprintf(gettext("Sorry, an interface is already named %s."), $pconfig['descr']);
115

    
116
	if(preg_match("/urltable/i", $a_aliases[$id]['type'])) {
117
		$pconfig['address'] = $a_aliases[$id]['url'];
118
		$pconfig['updatefreq'] = $a_aliases[$id]['updatefreq'];
119
	}
120
	if($a_aliases[$id]['aliasurl'] <> "") {
121
		if(is_array($a_aliases[$id]['aliasurl']))
122
			$pconfig['address'] = implode(" ", $a_aliases[$id]['aliasurl']);
123
		else
124
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
125
	}
126
}
127

    
128
if ($_POST) {
129
	unset($input_errors);
130
	$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.");
131

    
132
	/* input validation */
133

    
134
	$reqdfields = explode(" ", "name");
135
	$reqdfieldsn = array(gettext("Name"));
136

    
137
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
138

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

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

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

    
171
	$alias = array();
172
	$address = array();
173
	$final_address_details = array();
174
	$alias['name'] = $_POST['name'];
175

    
176
	if (preg_match("/urltable/i", $_POST['type'])) {
177
		$address = "";
178
		$isfirst = 0;
179

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

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

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

    
228
				if (!isset($alias['aliasurl']))
229
					$alias['aliasurl'] = array();
230

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

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

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

    
342
	unset($vertical_bar_err_text);
343

    
344
	// Allow extending of the firewall edit page and include custom input validation
345
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
346

    
347
	if (!$input_errors) {
348
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
349
		$alias['descr'] = $_POST['descr'];
350
		$alias['type'] = $_POST['type'];
351
		$alias['detail'] = implode("||", $final_address_details);
352

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

    
383
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
384

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

    
406
		// Sort list
407
		$a_aliases = msort($a_aliases, "name");
408

    
409
		if (write_config())
410
			mark_subsystem_dirty('aliases');
411

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

    
432
include("head.inc");
433

    
434
$jscriptstr = <<<EOD
435

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

    
471
	jQuery("select[id^='address_subnet']").prop("disabled", field_disabled);
472
	if (set_value == true)
473
		jQuery("select[id^='address_subnet']").prop("value", field_value);
474
}
475

    
476
function add_alias_control() {
477
	var name = "address" + (totalrows - 1);
478
	obj = document.getElementById(name);
479
	obj.setAttribute('class', 'formfldalias');
480
	obj.setAttribute('autocomplete', 'off');
481
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
482
}
483
EOD;
484

    
485
$network_str = gettext("Network");
486
$networks_str = gettext("Network(s)");
487
$cidr_str = gettext("CIDR");
488
$description_str = gettext("Description");
489
$hosts_str = gettext("Host(s)");
490
$ip_str = gettext("IP");
491
$ports_str = gettext("Port(s)");
492
$port_str = gettext("Port");
493
$url_str = gettext("URL (IPs)");
494
$url_ports_str = gettext("URL (Ports)");
495
$urltable_str = gettext("URL Table (IPs)");
496
$urltable_ports_str = gettext("URL Table (Ports)");
497
$update_freq_str = gettext("Update Freq. (days)");
498

    
499
$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.");
500
$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.");
501
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by separating with a colon.");
502
$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']);
503
$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']);
504
$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']);
505
$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']);
506

    
507
$openvpn_str = gettext("Username");
508
$openvpn_user_str = gettext("OpenVPN Users");
509
$openvpn_help = gettext("Enter as many usernames as you wish.");
510
$openvpn_freq = "";
511

    
512
$jscriptstr .= <<<EOD
513

    
514
function update_box_type() {
515
	var indexNum = document.forms[0].type.selectedIndex;
516
	var selected = document.forms[0].type.options[indexNum].text;
517
	if(selected == '{$networks_str}') {
518
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
519
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
520
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
521
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
522
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
523
		document.getElementById ("addrowbutton").style.display = 'block';
524
	} else if(selected == '{$hosts_str}') {
525
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
526
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
527
		document.getElementById ("twocolumn").firstChild.data = "";
528
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
529
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
530
		document.getElementById ("addrowbutton").style.display = 'block';
531
	} else if(selected == '{$ports_str}') {
532
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
533
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
534
		document.getElementById ("twocolumn").firstChild.data = "";
535
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
536
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
537
		document.getElementById ("addrowbutton").style.display = 'block';
538
	} else if(selected == '{$url_str}') {
539
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
540
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
541
		document.getElementById ("twocolumn").firstChild.data = "";
542
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
543
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
544
		document.getElementById ("addrowbutton").style.display = 'block';
545
	} else if(selected == '{$url_ports_str}') {
546
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_ports_str}";
547
		document.getElementById ("onecolumn").firstChild.data = "{$url_ports_str}";
548
		document.getElementById ("twocolumn").firstChild.data = "";
549
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
550
		document.getElementById ("itemhelp").firstChild.data = "{$url_ports_help}";
551
		document.getElementById ("addrowbutton").style.display = 'block';
552
	} else if(selected == '{$openvpn_user_str}') {
553
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
554
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
555
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
556
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
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)