Project

General

Profile

Download (28.2 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	firewall_aliases_edit.php
5
	Copyright (C) 2004 Scott Ullrich
6
	Copyright (C) 2009 Ermal Lu?i
7
	Copyright (C) 2010 Jim Pingle
8
	All rights reserved.
9

    
10
	originially part of m0n0wall (http://m0n0.ch/wall)
11
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
	All rights reserved.
13

    
14
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16

    
17
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19

    
20
	2. Redistributions in binary form must reproduce the above copyright
21
	   notice, this list of conditions and the following disclaimer in the
22
	   documentation and/or other materials provided with the distribution.
23

    
24
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
	POSSIBILITY OF SUCH DAMAGE.
34
*/
35
/*
36
	pfSense_BUILDER_BINARIES:	/bin/rm	/bin/mkdir	/usr/bin/fetch
37
	pfSense_MODULE:	aliases
38
*/
39

    
40
##|+PRIV
41
##|*IDENT=page-firewall-alias-edit
42
##|*NAME=Firewall: Alias: Edit page
43
##|*DESCR=Allow access to the 'Firewall: Alias: Edit' page.
44
##|*MATCH=firewall_aliases_edit.php*
45
##|-PRIV
46

    
47

    
48
// Keywords not allowed in names
49
$reserved_keywords = array("all", "pass", "out", "queue", "max", "min", "pptp", "pppoe", "L2TP", "OpenVPN", "IPsec");
50

    
51
require("guiconfig.inc");
52
require_once("functions.inc");
53
require_once("filter.inc");
54
require_once("shaper.inc");
55

    
56
$pgtitle = array(gettext("Firewall"),gettext("Aliases"),gettext("Edit"));
57

    
58
$reserved_ifs = get_configured_interface_list(false, true);
59
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs);
60

    
61
if (!is_array($config['aliases']['alias']))
62
	$config['aliases']['alias'] = array();
63
$a_aliases = &$config['aliases']['alias'];
64
	
65
if($_POST)
66
	$origname = $_POST['origname'];
67

    
68
// Debugging
69
if($debug)
70
	exec("rm -f {$g['tmp_path']}/alias_rename_log.txt");
71

    
72
function alias_same_type($name, $type) {
73
	global $config;
74
	
75
	foreach ($config['aliases']['alias'] as $alias) {
76
		if ($name == $alias['name']) {
77
			if (in_array($type, array("host", "network")) &&
78
				in_array($alias['type'], array("host", "network")))
79
				return true;
80
			if ($type  == $alias['type'])
81
				return true;
82
			else
83
				return false;
84
		}
85
	}
86
	return true;
87
}
88

    
89
$id = $_GET['id'];
90
if (isset($_POST['id']))
91
	$id = $_POST['id'];
92

    
93
if (isset($id) && $a_aliases[$id]) {
94
	$original_alias_name = $a_aliases[$id]['name'];
95
	$pconfig['name'] = $a_aliases[$id]['name'];
96
	$pconfig['detail'] = $a_aliases[$id]['detail'];
97
	$pconfig['address'] = $a_aliases[$id]['address'];
98
	$pconfig['type'] = $a_aliases[$id]['type'];
99
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
100

    
101
	/* interface list */
102
	$iflist = get_configured_interface_with_descr(false, true);
103
	foreach ($iflist as $if => $ifdesc)
104
		if($ifdesc == $pconfig['descr']) 
105
			$input_errors[] = sprintf(gettext("Sorry, an interface is already named %s."), $pconfig['descr']);
106

    
107
	if($a_aliases[$id]['type'] == "urltable") {
108
		$pconfig['address'] = $a_aliases[$id]['url'];
109
		$pconfig['updatefreq'] = $a_aliases[$id]['updatefreq'];
110
	}
111
	if($a_aliases[$id]['aliasurl'] <> "") {
112
		$pconfig['type'] = "url";
113
		if(is_array($a_aliases[$id]['aliasurl'])) {
114
			$isfirst = 0;
115
			$pconfig['address'] = "";
116
			foreach($a_aliases[$id]['aliasurl'] as $aa) {
117
				if($isfirst == 1)
118
					$pconfig['address'] .= " ";
119
				$isfirst = 1;
120
				$pconfig['address'] .= $aa;
121
			}
122
		} else {
123
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
124
		}
125
	}
126
}
127

    
128
if ($_POST) {
129
	unset($input_errors);
130

    
131
	/* input validation */
132

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

    
136
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
137

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

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

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

    
175
	if ($_POST['type'] == "urltable") {
176
		$address = "";
177
		$isfirst = 0;
178

    
179
		/* item is a url type */
180
		if ($_POST['address0']) {
181
			/* fetch down and add in */
182
			$_POST['address0'] = trim($_POST['address0']);
183
			$isfirst = 0;
184
			$address[] = $_POST['address0'];
185
			$alias['url'] = $_POST['address0'];
186
			$alias['updatefreq'] = $_POST['address_subnet0'] ? $_POST['address_subnet0'] : 7;
187
			if (!is_URL($alias['url']) || empty($alias['url'])) {
188
				$input_errors[] = gettext("You must provide a valid URL.");
189
				$dont_update = true;
190
			} elseif (! process_alias_urltable($alias['name'], $alias['url'], 0, true)) {
191
				$input_errors[] = gettext("Unable to fetch usable data.");
192
				$dont_update = true;
193
			}
194
		}
195
	} elseif($_POST['type'] == "url") {
196
		$isfirst = 0;
197
		$address_count = 2;
198

    
199
		/* item is a url type */
200
		for($x=0; isset($_POST['address' . $x]); $x++) {
201
			$_POST['address' . $x] = trim($_POST['address' . $x]);
202
			if($_POST['address' . $x]) {
203
				/* fetch down and add in */
204
				$isfirst = 0;
205
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
206
				unlink($temp_filename);
207
				$fda = fopen("{$g['tmp_path']}/tmpfetch","w");
208
				fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
209
				fclose($fda);
210
				mwexec("/bin/mkdir -p {$temp_filename}");
211
				mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
212
				/* if the item is tar gzipped then extract */
213
				if(stristr($_POST['address' . $x], ".tgz"))
214
					process_alias_tgz($temp_filename);
215
				if(file_exists("{$temp_filename}/aliases")) {
216
					$file_contents = file_get_contents("{$temp_filename}/aliases");
217
					$file_contents = str_replace("#", "\n#", $file_contents);
218
					$file_contents_split = explode("\n", $file_contents);
219
					foreach($file_contents_split as $fc) {
220
						// Stop at 3000 items, aliases larger than that tend to break both pf and the WebGUI.
221
						if ($address_count >= 3000)
222
							break;
223
						$tmp = trim($fc);
224
						if(stristr($fc, "#")) {
225
							$tmp_split = explode("#", $tmp);
226
							$tmp = trim($tmp_split[0]);
227
						}
228
						$tmp = trim($tmp);
229
						if(!empty($tmp) && (is_ipaddr($tmp) || is_subnet($tmp))) {
230
							$address[] = $tmp;
231
							$isfirst = 1;
232
							$address_count++;
233
						}
234
					}
235
					if($isfirst == 0) {
236
						/* nothing was found */
237
						$input_errors[] = gettext("You must provide a valid URL. Could not fetch usable data.");
238
						$dont_update = true;
239
						break;
240
					}
241
					$alias['aliasurl'][] = $_POST['address' . $x];
242
					mwexec("/bin/rm -rf {$temp_filename}");
243
				} else {
244
					$input_errors[] = gettext("You must provide a valid URL.");
245
					$dont_update = true;
246
					break;
247
				}
248
			}
249
		}
250
	} else {
251
		/* item is a normal alias type */
252
		$wrongaliases = "";
253
		for($x=0; $x<4999; $x++) {
254
			if($_POST["address{$x}"] <> "") {
255
				$_POST["address{$x}"] = trim($_POST["address{$x}"]);
256
				if (is_alias($_POST["address{$x}"])) {
257
					if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
258
						// But alias type network can include alias type urltable. Feature#1603.
259
						if (!($_POST['type'] == 'network' &&
260
						      alias_get_type($_POST["address{$x}"]) == 'urltable'))
261
							$wrongaliases .= " " . $_POST["address{$x}"];
262
				} else if ($_POST['type'] == "port") {
263
					if (!is_port($_POST["address{$x}"]))
264
						$input_errors[] = $_POST["address{$x}"] . " " . gettext("is not a valid port or alias.");
265
				} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
266
					if (!is_ipaddr($_POST["address{$x}"])
267
					 && !is_hostname($_POST["address{$x}"])
268
					 && !is_iprange($_POST["address{$x}"]))
269
						$input_errors[] = sprintf(gettext('%1$s is not a valid %2$s alias.'), $_POST["address{$x}"], $_POST['type']);
270
				}
271
				if (is_iprange($_POST["address{$x}"])) {
272
					list($startip, $endip) = explode('-', $_POST["address{$x}"]);
273
					$rangesubnets = ip_range_to_subnet_array($startip, $endip);
274
					$address = array_merge($address, $rangesubnets);
275
				} else {
276
					$tmpaddress = $_POST["address{$x}"];
277
					if(is_ipaddr($_POST["address{$x}"]) && $_POST["address_subnet{$x}"] <> "")
278
						$tmpaddress .= "/" . $_POST["address_subnet{$x}"];
279
					$address[] = $tmpaddress;
280
				}
281
				if ($_POST["detail{$x}"] <> "")
282
					$final_address_details[] = $_POST["detail{$x}"];
283
				else
284
					$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
285
			}
286
		}
287
		if ($wrongaliases <> "")
288
			$input_errors[] = sprintf(gettext('The alias(es): %s cannot be nested because they are not of the same type.'), $wrongaliases);
289
	}
290

    
291
	// Allow extending of the firewall edit page and include custom input validation 
292
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
293

    
294
	if (!$input_errors) {
295
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
296
		$alias['descr'] = $_POST['descr'];
297
		$alias['type'] = $_POST['type'];
298
		$alias['detail'] = implode("||", $final_address_details);
299

    
300
		/*   Check to see if alias name needs to be
301
		 *   renamed on referenced rules and such
302
		 */
303
		if ($_POST['name'] <> $_POST['origname']) {
304
			// Firewall rules
305
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $_POST['name'], $origname);
306
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
307
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'port'), $_POST['name'], $origname);
308
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
309
			// NAT Rules
310
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $_POST['name'], $origname);
311
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'port'), $_POST['name'], $origname);
312
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
313
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
314
			update_alias_names_upon_change(array('nat', 'rule'), array('target'), $_POST['name'], $origname);
315
			update_alias_names_upon_change(array('nat', 'rule'), array('local-port'), $_POST['name'], $origname);
316
			// NAT 1:1 Rules
317
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('external'), $_POST['name'], $origname);
318
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('source', 'address'), $_POST['name'], $origname);
319
			update_alias_names_upon_change(array('nat', 'onetoone'), array('destination', 'address'), $_POST['name'], $origname);
320
			// NAT Outbound Rules
321
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $_POST['name'], $origname);
322
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $_POST['name'], $origname);
323
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
324
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $_POST['name'], $origname);
325
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('target'), $_POST['name'], $origname);
326
			// Alias in an alias
327
			update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $_POST['name'], $origname);
328
		}
329

    
330
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
331

    
332
		if (isset($id) && $a_aliases[$id]) {
333
			if ($a_aliases[$id]['name'] <> $alias['name']) {
334
				foreach ($a_aliases as $aliasid => $aliasd) {
335
					if ($aliasd['address'] <> "") {
336
						$tmpdirty = false;
337
						$tmpaddr = explode(" ", $aliasd['address']);
338
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
339
							if ($tmpalias == $a_aliases[$id]['name']) {
340
								$tmpaddr[$tmpidx] = $alias['name'];
341
								$tmpdirty = true;
342
							}
343
						}
344
						if ($tmpdirty == true)
345
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
346
					}
347
				}
348
			}
349
			$a_aliases[$id] = $alias;
350
		} else
351
			$a_aliases[] = $alias;
352

    
353
		// Sort list
354
		$a_aliases = msort($a_aliases, "name");
355

    
356
		if (write_config())
357
			mark_subsystem_dirty('aliases');
358

    
359
		if($_POST['tab'])
360
			header("Location: firewall_aliases.php?tab=" . htmlspecialchars ($_POST['tab']));
361
		else
362
			header("Location: firewall_aliases.php");
363
		exit;
364
	}
365
	//we received input errors, copy data to prevent retype
366
	else
367
	{
368
		$pconfig['name'] = $_POST['name'];
369
		$pconfig['descr'] = $_POST['descr'];
370
		$pconfig['address'] = implode(" ", $address);
371
		$pconfig['type'] = $_POST['type'];
372
		$pconfig['detail'] = implode("||", $final_address_details);
373
	}
374
}
375

    
376
include("head.inc");
377

    
378
$jscriptstr = <<<EOD
379

    
380
<script type="text/javascript">
381

    
382
var objAlias = new Array(4999);
383
function typesel_change() {
384
	switch (document.iform.type.selectedIndex) {
385
		case 0:	/* host */
386
			var cmd;
387

    
388
			newrows = totalrows;
389
			for(i=0; i<newrows; i++) {
390
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
391
				eval(comd);
392
				comd = 'document.iform.address_subnet' + i + '.value = "";';
393
				eval(comd);
394
			}
395
			break;
396
		case 1:	/* network */
397
			var cmd;
398

    
399
			newrows = totalrows;
400
			for(i=0; i<newrows; i++) {
401
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
402
				eval(comd);
403
			}
404
			break;
405
		case 2:	/* port */
406
			var cmd;
407

    
408
			newrows = totalrows;
409
			for(i=0; i<newrows; i++) {
410
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
411
				eval(comd);
412
				comd = 'document.iform.address_subnet' + i + '.value = "128";';
413
				eval(comd);
414
			}
415
			break;
416
/*		case 3:	 // OpenVPN Users
417
			var cmd;
418

    
419
			newrows = totalrows;
420
			for(i=0; i<newrows; i++) {
421
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
422
				eval(comd);
423
				comd = 'document.iform.address_subnet' + i + '.value = "";';
424
				eval(comd);
425
			}
426
			break;
427
*/
428
		case 3:	/* url */
429
			var cmd;
430
			newrows = totalrows;
431
			for(i=0; i<newrows; i++) {
432
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
433
				eval(comd);
434
			}
435
			break;
436

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

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

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

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

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

    
480
$jscriptstr .= <<<EOD
481

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

    
537
EOD;
538

    
539
?>
540

    
541
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
542
<?php
543
	include("fbegin.inc");
544
	echo $jscriptstr;
545
?>
546

    
547
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js">
548
</script>
549
<script type="text/javascript" src="/javascript/row_helper.js">
550
</script>
551
<script type="text/javascript" src="/javascript/autosuggest.js">
552
</script>
553
<script type="text/javascript" src="/javascript/suggestions.js">
554
</script>
555

    
556
<input type='hidden' name='address_type' value='textbox' />
557
<input type='hidden' name='address_subnet_type' value='select' />
558

    
559
<script type="text/javascript">
560
	rowname[0] = "address";
561
	rowtype[0] = "textbox,ipv4v6";
562
	rowsize[0] = "30";
563

    
564
	rowname[1] = "address_subnet";
565
	rowtype[1] = "select,ipv4v6";
566
	rowsize[1] = "1";
567

    
568
	rowname[2] = "detail";
569
	rowtype[2] = "textbox";
570
	rowsize[2] = "50";
571
</script>
572

    
573
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
574
<?php if ($input_errors) print_input_errors($input_errors); ?>
575
<div id="inputerrors"></div>
576

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

    
637
	<?php
638
	$counter = 0;
639
	$address = $pconfig['address'];
640
	if ($address <> "") {
641
		$item = explode(" ", $address);
642
		$item3 = explode("||", $pconfig['detail']);
643
		foreach($item as $ww) {
644
			$address = $item[$counter];
645
			$address_subnet = "";
646
			$item2 = explode("/", $address);
647
			foreach($item2 as $current) {
648
				if($item2[1] <> "") {
649
					$address = $item2[0];
650
					$address_subnet = $item2[1];
651
				}
652
				
653
			}
654
			$item4 = $item3[$counter];
655
			$tracker = $counter;
656
	?>
657
          <tr>
658
            <td>
659
              <input autocomplete="off" name="address<?php echo $tracker; ?>" type="text" class="formfldalias ipv4v6" id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
660
            </td>
661
            <td>
662
			        <select name="address_subnet<?php echo $tracker; ?>" class="formselect ipv4v6" id="address_subnet<?php echo $tracker; ?>">
663
				<option></option>
664
			          <?php for ($i = 128; $i >= 1; $i--): ?>
665
			          <option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected"; ?>><?=$i;?></option>
666
			          <?php endfor; ?>
667
			        </select>
668
			      </td>
669
            <td>
670
              <input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
671
            </td>
672
            <td>
673
    		<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>
674
	      </td>
675
          </tr>
676
<?php
677
        	$counter++;
678

    
679
       		} // end foreach
680
	} // end if
681
?>
682
        </tbody>
683
        <tfoot>
684

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

    
701
<script type="text/javascript">
702
//<![CDATA[
703
	field_counter_js = 3;
704
	rows = 1;
705
	totalrows = <?php echo $counter; ?>;
706
	loaded = <?php echo $counter; ?>;
707
	typesel_change();
708
	update_box_type();
709

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

    
712
	function createAutoSuggest() {
713
		<?php  
714
		for ($jv = 0; $jv < $counter; $jv++)
715
			echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
716
		?>
717
	}
718

    
719
	setTimeout("createAutoSuggest();", 500);
720
//]]>
721
</script>
722

    
723
<?php include("fend.inc"); ?>
724
</body>
725
</html>
(58-58/249)