Project

General

Profile

Download (29.3 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
$tab = $_REQUEST['tab'];
66

    
67
if($_POST)
68
	$origname = $_POST['origname'];
69

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

    
74
function alias_same_type($name, $type) {
75
	global $config;
76

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

    
91
$id = $_GET['id'];
92
if (isset($_POST['id']))
93
	$id = $_POST['id'];
94

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

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

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

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

    
125
	/* input validation */
126

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

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

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

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

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

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

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

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

    
197
		/* item is a url type */
198
		for($x=0; $x<4999; $x++) {
199
			$_POST['address' . $x] = trim($_POST['address' . $x]);
200
			if($_POST['address' . $x]) {
201
				/* fetch down and add in */
202
				$isfirst = 0;
203
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
204
				unlink($temp_filename);
205
				$fda = fopen("{$g['tmp_path']}/tmpfetch","w");
206
				fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
207
				fclose($fda);
208
				mwexec("/bin/mkdir -p {$temp_filename}");
209
				mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
210
				/* if the item is tar gzipped then extract */
211
				if(stristr($_POST['address' . $x], ".tgz"))
212
					process_alias_tgz($temp_filename);
213

    
214
				if (!isset($alias['aliasurl']))
215
					$alias['aliasurl'] = array();
216

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

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

    
310
	// Allow extending of the firewall edit page and include custom input validation
311
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
312

    
313
	if (!$input_errors) {
314
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
315
		$alias['descr'] = $_POST['descr'];
316
		$alias['type'] = $_POST['type'];
317
		$alias['detail'] = implode("||", $final_address_details);
318

    
319
		/*   Check to see if alias name needs to be
320
		 *   renamed on referenced rules and such
321
		 */
322
		if ($_POST['name'] <> $_POST['origname']) {
323
			// Firewall rules
324
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $_POST['name'], $origname);
325
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
326
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'port'), $_POST['name'], $origname);
327
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
328
			// NAT Rules
329
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $_POST['name'], $origname);
330
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'port'), $_POST['name'], $origname);
331
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
332
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
333
			update_alias_names_upon_change(array('nat', 'rule'), array('target'), $_POST['name'], $origname);
334
			update_alias_names_upon_change(array('nat', 'rule'), array('local-port'), $_POST['name'], $origname);
335
			// NAT 1:1 Rules
336
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('external'), $_POST['name'], $origname);
337
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('source', 'address'), $_POST['name'], $origname);
338
			update_alias_names_upon_change(array('nat', 'onetoone'), array('destination', 'address'), $_POST['name'], $origname);
339
			// NAT Outbound Rules
340
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $_POST['name'], $origname);
341
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $_POST['name'], $origname);
342
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
343
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $_POST['name'], $origname);
344
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('target'), $_POST['name'], $origname);
345
			// Alias in an alias
346
			update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $_POST['name'], $origname);
347
		}
348

    
349
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
350

    
351
		if (isset($id) && $a_aliases[$id]) {
352
			if ($a_aliases[$id]['name'] <> $alias['name']) {
353
				foreach ($a_aliases as $aliasid => $aliasd) {
354
					if ($aliasd['address'] <> "") {
355
						$tmpdirty = false;
356
						$tmpaddr = explode(" ", $aliasd['address']);
357
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
358
							if ($tmpalias == $a_aliases[$id]['name']) {
359
								$tmpaddr[$tmpidx] = $alias['name'];
360
								$tmpdirty = true;
361
							}
362
						}
363
						if ($tmpdirty == true)
364
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
365
					}
366
				}
367
			}
368
			$a_aliases[$id] = $alias;
369
		} else
370
			$a_aliases[] = $alias;
371

    
372
		// Sort list
373
		$a_aliases = msort($a_aliases, "name");
374

    
375
		if (write_config())
376
			mark_subsystem_dirty('aliases');
377

    
378
		if(!empty($tab))
379
			header("Location: firewall_aliases.php?tab=" . htmlspecialchars ($tab));
380
		else
381
			header("Location: firewall_aliases.php");
382
		exit;
383
	}
384
	//we received input errors, copy data to prevent retype
385
	else
386
	{
387
		$pconfig['name'] = $_POST['name'];
388
		$pconfig['descr'] = $_POST['descr'];
389
		if ($_POST['type'] == 'url')
390
			$pconfig['address'] = implode(" ", $alias['aliasurl']);
391
		else
392
			$pconfig['address'] = implode(" ", $address);
393
		$pconfig['type'] = $_POST['type'];
394
		$pconfig['detail'] = implode("||", $final_address_details);
395
	}
396
}
397

    
398
include("head.inc");
399

    
400
$jscriptstr = <<<EOD
401

    
402
<script type="text/javascript">
403
//<![CDATA[
404
var objAlias = new Array(4999);
405
function typesel_change() {
406
	switch (document.iform.type.selectedIndex) {
407
		case 0:	/* host */
408
			var cmd;
409

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

    
421
			newrows = totalrows;
422
			for(i=0; i<newrows; i++) {
423
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
424
				eval(comd);
425
			}
426
			break;
427
		case 2:	/* port */
428
			var cmd;
429

    
430
			newrows = totalrows;
431
			for(i=0; i<newrows; i++) {
432
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
433
				eval(comd);
434
				comd = 'document.iform.address_subnet' + i + '.value = "128";';
435
				eval(comd);
436
			}
437
			break;
438
/*		case 3:	// OpenVPN Users
439
			var cmd;
440

    
441
			newrows = totalrows;
442
			for(i=0; i<newrows; i++) {
443
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
444
				eval(comd);
445
				comd = 'document.iform.address_subnet' + i + '.value = "";';
446
				eval(comd);
447
			}
448
			break;
449
*/
450
		case 3:	/* url */
451
			var cmd;
452
			newrows = totalrows;
453
			for(i=0; i<newrows; i++) {
454
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
455
				eval(comd);
456
			}
457
			break;
458

    
459
		case 4:	/* urltable */
460
			var cmd;
461
			newrows = totalrows;
462
			for(i=0; i<newrows; i++) {
463
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
464
				eval(comd);
465
			}
466
			break;
467
	}
468
}
469

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

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

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

    
497
$openvpn_str = gettext("Username");
498
$openvpn_user_str = gettext("OpenVPN Users");
499
$openvpn_help = gettext("Enter as many usernames as you wish.");
500
$openvpn_freq = "";
501

    
502
$jscriptstr .= <<<EOD
503

    
504
function update_box_type() {
505
	var indexNum = document.forms[0].type.selectedIndex;
506
	var selected = document.forms[0].type.options[indexNum].text;
507
	if(selected == '{$networks_str}') {
508
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
509
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
510
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
511
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
512
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
513
		document.getElementById ("addrowbutton").style.display = 'block';
514
	} else if(selected == '{$hosts_str}') {
515
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
516
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
517
		document.getElementById ("twocolumn").firstChild.data = "";
518
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
519
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
520
		document.getElementById ("addrowbutton").style.display = 'block';
521
	} else if(selected == '{$ports_str}') {
522
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
523
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
524
		document.getElementById ("twocolumn").firstChild.data = "";
525
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
526
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
527
		document.getElementById ("addrowbutton").style.display = 'block';
528
	} else if(selected == '{$url_str}') {
529
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
530
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
531
		document.getElementById ("twocolumn").firstChild.data = "";
532
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
533
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
534
		document.getElementById ("addrowbutton").style.display = 'block';
535
	} else if(selected == '{$openvpn_user_str}') {
536
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
537
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
538
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
539
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
540
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
541
		document.getElementById ("addrowbutton").style.display = 'block';
542
	} else if(selected == '{$urltable_str}') {
543
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
544
			addRowTo('maintable', 'formfldalias');
545
			typesel_change();
546
			add_alias_control(this);
547
		}
548
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
549
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
550
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
551
		document.getElementById ("threecolumn").firstChild.data = "";
552
		document.getElementById ("threecolumn").style.display = 'none';
553
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_help}";
554
		document.getElementById ("addrowbutton").style.display = 'none';
555
	}
556
}
557
//]]>
558
</script>
559

    
560
EOD;
561

    
562
?>
563

    
564
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
565
<?php
566
	include("fbegin.inc");
567
	echo $jscriptstr;
568
?>
569

    
570
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
571
<script type="text/javascript" src="/javascript/row_helper.js"></script>
572
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
573
<script type="text/javascript" src="/javascript/suggestions.js"></script>
574

    
575
<input type='hidden' name='address_type' value='textbox' />
576
<input type='hidden' name='address_subnet_type' value='select' />
577

    
578
<script type="text/javascript">
579
//<![CDATA[
580
	rowname[0] = "address";
581
	rowtype[0] = "textbox,ipv4v6";
582
	rowsize[0] = "30";
583

    
584
	rowname[1] = "address_subnet";
585
	rowtype[1] = "select,ipv4v6";
586
	rowsize[1] = "1";
587

    
588
	rowname[2] = "detail";
589
	rowtype[2] = "textbox";
590
	rowsize[2] = "50";
591
//]]>
592
</script>
593

    
594
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
595
<?php if ($input_errors) print_input_errors($input_errors); ?>
596
<div id="inputerrors"></div>
597

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

    
668
					<?php
669
					$counter = 0;
670
					$address = $pconfig['address'];
671
					if ($address <> "") {
672
						$item = explode(" ", $address);
673
						$item3 = explode("||", $pconfig['detail']);
674
						foreach($item as $ww) {
675
							$address = $item[$counter];
676
							$address_subnet = "";
677
							$item2 = explode("/", $address);
678
							foreach($item2 as $current) {
679
								if($item2[1] <> "") {
680
									$address = $item2[0];
681
									$address_subnet = $item2[1];
682
								}
683

    
684
							}
685
							$item4 = $item3[$counter];
686
							$tracker = $counter;
687
					?>
688
					<tr>
689
						<td>
690
							<input autocomplete="off" name="address<?php echo $tracker; ?>" type="text" class="formfldalias ipv4v6" id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
691
						</td>
692
						<td>
693
							<select name="address_subnet<?php echo $tracker; ?>" class="formselect ipv4v6" id="address_subnet<?php echo $tracker; ?>">
694
								<option></option>
695
								<?php for ($i = 128; $i >= 1; $i--): ?>
696
									<option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected=\"selected\""; ?>><?=$i;?></option>
697
								<?php endfor; ?>
698
							</select>
699
						</td>
700
						<td>
701
							<input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
702
						</td>
703
						<td>
704
							<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>
705
						</td>
706
					</tr>
707
					<?php
708
						$counter++;
709

    
710
						} // end foreach
711
					} // end if
712
					?>
713
				</tbody>
714
			</table>
715
			<div id="addrowbutton">
716
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
717
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" />
718
				</a>
719
			</div>
720
		</td>
721
	</tr>
722
	<tr>
723
		<td width="22%" valign="top">&nbsp;</td>
724
		<td width="78%">
725
			<input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
726
			<a href="firewall_aliases.php?tab=<?=$tab;?>"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" /></a>
727
		</td>
728
	</tr>
729
</table>
730
</form>
731

    
732
<script type="text/javascript">
733
//<![CDATA[
734
	field_counter_js = 3;
735
	rows = 1;
736
	totalrows = <?php echo $counter; ?>;
737
	loaded = <?php echo $counter; ?>;
738
	typesel_change();
739
	update_box_type();
740

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

    
743
	function createAutoSuggest() {
744
		<?php
745
		for ($jv = 0; $jv < $counter; $jv++)
746
			echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
747
		?>
748
	}
749

    
750
	setTimeout("createAutoSuggest();", 500);
751
//]]>
752
</script>
753

    
754
<?php include("fend.inc"); ?>
755
</body>
756
</html>
(59-59/246)