Projet

Général

Profil

Télécharger (29,9 ko) Statistiques
| Branche: | Tag: | Révision:

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

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
// Keywords not allowed in names
55
$reserved_keywords = array("all", "pass", "block", "out", "queue", "max", "min", "pptp", "pppoe", "L2TP", "OpenVPN", "IPsec");
56

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

    
62
$reserved_ifs = get_configured_interface_list(false, true);
63
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs, $reserved_table_names);
64

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

    
69
$tab = $_REQUEST['tab'];
70

    
71
if($_POST)
72
	$origname = $_POST['origname'];
73

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

    
78
function alias_same_type($name, $type) {
79
	global $config;
80

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

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

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

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

    
121
if ($_POST) {
122
	unset($input_errors);
123

    
124
	/* input validation */
125

    
126
	$reqdfields = explode(" ", "name");
127
	$reqdfieldsn = array(gettext("Name"));
128

    
129
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
130

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

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

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

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

    
168
	if ($_POST['type'] == "urltable") {
169
		$address = "";
170
		$isfirst = 0;
171

    
172
		/* item is a url type */
173
		if ($_POST['address0']) {
174
			/* fetch down and add in */
175
			$_POST['address0'] = trim($_POST['address0']);
176
			$isfirst = 0;
177
			$address[] = $_POST['address0'];
178
			$alias['url'] = $_POST['address0'];
179
			$alias['updatefreq'] = $_POST['address_subnet0'] ? $_POST['address_subnet0'] : 7;
180
			if (!is_URL($alias['url']) || empty($alias['url'])) {
181
				$input_errors[] = gettext("You must provide a valid URL.");
182
			} elseif (! process_alias_urltable($alias['name'], $alias['url'], 0, true)) {
183
				$input_errors[] = gettext("Unable to fetch usable data.");
184
			}
185
			if ($_POST["detail0"] <> "")
186
				$final_address_details[] = $_POST["detail0"];
187
			else
188
				$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
189
		}
190
	} elseif($_POST['type'] == "url") {
191
		$isfirst = 0;
192
		$address_count = 2;
193

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

    
210
				if (!isset($alias['aliasurl']))
211
					$alias['aliasurl'] = array();
212

    
213
				$alias['aliasurl'][] = $_POST['address' . $x];
214
				if ($_POST["detail{$x}"] <> "")
215
					$final_address_details[] = $_POST["detail{$x}"];
216
				else
217
					$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
218

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

    
323
	// Allow extending of the firewall edit page and include custom input validation
324
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
325

    
326
	if (!$input_errors) {
327
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
328
		$alias['descr'] = $_POST['descr'];
329
		$alias['type'] = $_POST['type'];
330
		$alias['detail'] = implode("||", $final_address_details);
331

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

    
362
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
363

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

    
385
		// Sort list
386
		$a_aliases = msort($a_aliases, "name");
387

    
388
		if (write_config())
389
			mark_subsystem_dirty('aliases');
390

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

    
411
include("head.inc");
412

    
413
$jscriptstr = <<<EOD
414

    
415
<script type="text/javascript">
416
//<![CDATA[
417
var objAlias = new Array(4999);
418
function typesel_change() {
419
	var field_disabled = 0;
420
	var field_value = "";
421
	var set_value = false;
422
	switch (document.iform.type.selectedIndex) {
423
		case 0:	/* host */
424
			field_disabled = 1;
425
			field_value = "";
426
			set_value = true;
427
			break;
428
		case 1:	/* network */
429
			field_disabled = 0;
430
			break;
431
		case 2:	/* port */
432
			field_disabled = 1;
433
			field_value = "128";
434
			set_value = true;
435
			break;
436
		case 3:	/* url */
437
			field_disabled = 1;
438
			break;
439

    
440
		case 4:	/* urltable */
441
			field_disabled = 0;
442
			break;
443
	}
444

    
445
	jQuery("select[id^='address_subnet']").prop("disabled", field_disabled);
446
	if (set_value == true)
447
		jQuery("select[id^='address_subnet']").prop("value", field_value);
448
}
449

    
450
function add_alias_control() {
451
	var name = "address" + (totalrows - 1);
452
	obj = document.getElementById(name);
453
	obj.setAttribute('class', 'formfldalias');
454
	obj.setAttribute('autocomplete', 'off');
455
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
456
}
457
EOD;
458

    
459
$network_str = gettext("Network or FQDN");
460
$networks_str = gettext("Network(s)");
461
$cidr_str = gettext("CIDR");
462
$description_str = gettext("Description");
463
$hosts_str = gettext("Host(s)");
464
$ip_str = gettext("IP or FQDN");
465
$ports_str = gettext("Port(s)");
466
$port_str = gettext("Port");
467
$url_str = gettext("URL");
468
$urltable_str = gettext("URL Table");
469
$update_freq_str = gettext("Update Freq. (days)");
470

    
471
$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.");
472
$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.");
473
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by separating with a colon.");
474
$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']);
475
$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']);
476

    
477
$openvpn_str = gettext("Username");
478
$openvpn_user_str = gettext("OpenVPN Users");
479
$openvpn_help = gettext("Enter as many usernames as you wish.");
480
$openvpn_freq = "";
481

    
482
$jscriptstr .= <<<EOD
483

    
484
function update_box_type() {
485
	var indexNum = document.forms[0].type.selectedIndex;
486
	var selected = document.forms[0].type.options[indexNum].text;
487
	if(selected == '{$networks_str}') {
488
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
489
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
490
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
491
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
492
		document.getElementById ("threecolumn").style.display = 'block';
493
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
494
		document.getElementById ("addrowbutton").style.display = 'block';
495
	} else if(selected == '{$hosts_str}') {
496
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
497
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
498
		document.getElementById ("twocolumn").firstChild.data = "";
499
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
500
		document.getElementById ("threecolumn").style.display = 'block';
501
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
502
		document.getElementById ("addrowbutton").style.display = 'block';
503
	} else if(selected == '{$ports_str}') {
504
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
505
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
506
		document.getElementById ("twocolumn").firstChild.data = "";
507
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
508
		document.getElementById ("threecolumn").style.display = 'block';
509
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
510
		document.getElementById ("addrowbutton").style.display = 'block';
511
	} else if(selected == '{$url_str}') {
512
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
513
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
514
		document.getElementById ("twocolumn").firstChild.data = "";
515
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
516
		document.getElementById ("threecolumn").style.display = 'block';
517
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
518
		document.getElementById ("addrowbutton").style.display = 'block';
519
	} else if(selected == '{$openvpn_user_str}') {
520
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
521
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
522
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
523
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
524
		document.getElementById ("threecolumn").style.display = 'block';
525
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
526
		document.getElementById ("addrowbutton").style.display = 'block';
527
	} else if(selected == '{$urltable_str}') {
528
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
529
			addRowTo('maintable', 'formfldalias');
530
			typesel_change();
531
			add_alias_control(this);
532
		}
533
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
534
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
535
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
536
		document.getElementById ("threecolumn").firstChild.data = "";
537
		document.getElementById ("threecolumn").style.display = 'none';
538
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_help}";
539
		document.getElementById ("addrowbutton").style.display = 'none';
540
	}
541
}
542
//]]>
543
</script>
544

    
545
EOD;
546

    
547
?>
548

    
549
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
550
<?php
551
	include("fbegin.inc");
552
	echo $jscriptstr;
553
?>
554

    
555
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
556
<script type="text/javascript" src="/javascript/row_helper.js"></script>
557
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
558
<script type="text/javascript" src="/javascript/suggestions.js"></script>
559

    
560
<input type='hidden' name='address_type' value='textbox' />
561
<input type='hidden' name='address_subnet_type' value='select' />
562

    
563
<script type="text/javascript">
564
//<![CDATA[
565
	rowname[0] = "address";
566
	rowtype[0] = "textbox,ipv4v6";
567
	rowsize[0] = "30";
568

    
569
	rowname[1] = "address_subnet";
570
	rowtype[1] = "select,ipv4v6";
571
	rowsize[1] = "1";
572

    
573
	rowname[2] = "detail";
574
	rowtype[2] = "textbox";
575
	rowsize[2] = "50";
576
//]]>
577
</script>
578

    
579
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
580
<?php if ($input_errors) print_input_errors($input_errors); ?>
581
<div id="inputerrors"></div>
582

    
583
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
584
<?php
585
if (empty($tab)) {
586
	if ($pconfig['type'] == 'urltable')
587
		$tab = 'url';
588
	else if ($pconfig['type'] == 'host')
589
		$tab = 'ip';
590
	else
591
		$tab = $pconfig['type'];
592
}
593
?>
594
<input name="tab" type="hidden" id="tab" value="<?=htmlspecialchars($tab);?>" />
595
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="firewall aliases edit">
596
	<tr>
597
		<td colspan="2" valign="top" class="listtopic"><?=gettext("Alias Edit"); ?></td>
598
	</tr>
599
	<tr>
600
		<td valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
601
		<td class="vtable">
602
			<input name="origname" type="hidden" id="origname" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
603
			<input name="name" type="text" id="name" class="formfld unknown" size="40" maxlength="31" value="<?=htmlspecialchars($pconfig['name']);?>" />
604
			<?php if (isset($id) && $a_aliases[$id]): ?>
605
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
606
			<?php endif; ?>
607
			<br />
608
			<span class="vexpl">
609
				<?=gettext("The name of the alias may only consist of the characters \"a-z, A-Z, 0-9 and _\"."); ?>
610
			</span>
611
		</td>
612
	</tr>
613
	<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/after_first_tr"); ?>
614
	<tr>
615
		<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
616
		<td width="78%" class="vtable">
617
			<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
618
			<br />
619
			<span class="vexpl">
620
				<?=gettext("You may enter a description here for your reference (not parsed)."); ?>
621
			</span>
622
		</td>
623
	</tr>
624
	<tr>
625
		<td valign="top" class="vncellreq"><?=gettext("Type"); ?></td>
626
		<td class="vtable">
627
			<select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
628
				<option value="host" <?php if ($pconfig['type'] == "host") echo "selected=\"selected\""; ?>><?=gettext("Host(s)"); ?></option>
629
				<option value="network" <?php if ($pconfig['type'] == "network") echo "selected=\"selected\""; ?>><?=gettext("Network(s)"); ?></option>
630
				<option value="port" <?php if (($pconfig['type'] == "port") || (empty($pconfig['type']) && ($tab == "port"))) echo "selected=\"selected\""; ?>><?=gettext("Port(s)"); ?></option>
631
				<!--<option value="openvpn" <?php if ($pconfig['type'] == "openvpn") echo "selected=\"selected\""; ?>><?=gettext("OpenVPN Users"); ?></option> -->
632
				<option value="url" <?php if (($pconfig['type'] == "url") || (empty($pconfig['type']) && ($tab == "url"))) echo "selected=\"selected\""; ?>><?=gettext("URL");?></option>
633
				<option value="urltable" <?php if ($pconfig['type'] == "urltable") echo "selected=\"selected\""; ?>><?=gettext("URL Table"); ?></option>
634
			</select>
635
		</td>
636
	</tr>
637
	<tr>
638
		<td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport"><?=gettext("Host(s)"); ?></div></td>
639
		<td width="78%" class="vtable">
640
			<table id="maintable" summary="maintable">
641
				<tbody>
642
					<tr>
643
						<td colspan="4">
644
							<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>
645
						</td>
646
					</tr>
647
					<tr>
648
						<td><div id="onecolumn"><?=gettext("Network"); ?></div></td>
649
						<td><div id="twocolumn">CIDR</div></td>
650
						<td><div id="threecolumn"><?=gettext("Description"); ?></div></td>
651
					</tr>
652

    
653
					<?php
654
					$counter = 0;
655
					if ($pconfig['address'] <> ""):
656
						$addresses = explode(" ", $pconfig['address']);
657
						$details = explode("||", $pconfig['detail']);
658
						while ($counter < count($addresses)):
659
							if (is_subnet($addresses[$counter])) {
660
								list($address, $address_subnet) = explode("/", $addresses[$counter]);
661
							} else {
662
								$address = $addresses[$counter];
663
								$address_subnet = "";
664
							}
665
					?>
666
					<tr>
667
						<td>
668
							<input style="autocomplete:off" name="address<?php echo $counter; ?>" type="text" class="formfldalias ipv4v6" id="address<?php echo $counter; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
669
						</td>
670
						<td>
671
							<select name="address_subnet<?php echo $counter; ?>" class="formselect ipv4v6" id="address_subnet<?php echo $counter; ?>">
672
								<option></option>
673
								<?php for ($i = 128; $i >= 1; $i--): ?>
674
									<option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected=\"selected\""; ?>><?=$i;?></option>
675
								<?php endfor; ?>
676
							</select>
677
						</td>
678
						<td>
679
							<input name="detail<?php echo $counter; ?>" type="text" class="formfld unknown" id="detail<?php echo $counter; ?>" size="50" value="<?=htmlspecialchars($details[$counter]);?>" />
680
						</td>
681
						<td>
682
							<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>
683
						</td>
684
					</tr>
685
					<?php
686
						$counter++;
687

    
688
						endwhile;
689
					endif;
690
					?>
691
				</tbody>
692
			</table>
693
			<div id="addrowbutton">
694
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
695
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" />
696
				</a>
697
			</div>
698
		</td>
699
	</tr>
700
	<tr>
701
		<td width="22%" valign="top">&nbsp;</td>
702
		<td width="78%">
703
			<input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
704
			<input type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" onclick="history.back()" />
705
		</td>
706
	</tr>
707
</table>
708
</form>
709

    
710
<script type="text/javascript">
711
//<![CDATA[
712
var autocomplete_off = ['address'];
713
for (var i = 0; i < autocomplete_off.length; i++) {
714
	var node = document.getElementById(autocomplete_off[i]);
715
	node.setAttribute("autocomplete",node.style.autocomplete);
716
}
717
//]]>
718
</script>
719

    
720
<script type="text/javascript">
721
//<![CDATA[
722
	field_counter_js = 3;
723
	rows = 1;
724
	totalrows = <?php echo $counter; ?>;
725
	loaded = <?php echo $counter; ?>;
726
	typesel_change();
727
	update_box_type();
728

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

    
731
	function createAutoSuggest() {
732
		<?php
733
		for ($jv = 0; $jv < $counter; $jv++)
734
			echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
735
		?>
736
	}
737

    
738
	setTimeout("createAutoSuggest();", 500);
739
//]]>
740
</script>
741

    
742
<?php include("fend.inc"); ?>
743
</body>
744
</html>
(59-59/246)