Project

General

Profile

Download (31.5 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", "block", "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(preg_match("/urltable/i", $a_aliases[$id]['type'])) {
110
		$pconfig['address'] = $a_aliases[$id]['url'];
111
		$pconfig['updatefreq'] = $a_aliases[$id]['updatefreq'];
112
	}
113
	if($a_aliases[$id]['aliasurl'] <> "") {
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 (preg_match("/urltable/i", $_POST['type'])) {
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
				$dont_update = true;
183
			} elseif (! process_alias_urltable($alias['name'], $alias['url'], 0, true)) {
184
				$input_errors[] = gettext("Unable to fetch usable data.");
185
				$dont_update = true;
186
			}
187
			if ($_POST["detail0"] <> "")
188
				$final_address_details[] = $_POST["detail0"];
189
			else
190
				$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
191
		}
192
	} else if ($_POST['type'] == "url" || $_POST['type'] == "url_ports") {
193
		$isfirst = 0;
194
		$address_count = 2;
195

    
196
		/* item is a url type */
197
		for($x=0; $x<4999; $x++) {
198
			$_POST['address' . $x] = trim($_POST['address' . $x]);
199
			if($_POST['address' . $x]) {
200
				/* fetch down and add in */
201
				$isfirst = 0;
202
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
203
				unlink($temp_filename);
204
				$verify_ssl = isset($config['system']['checkaliasesurlcert']);
205
				mwexec("/bin/mkdir -p {$temp_filename}");
206
				download_file($_POST['address' . $x], $temp_filename . "/aliases", $verify_ssl);
207

    
208
				/* if the item is tar gzipped then extract */
209
				if(stristr($_POST['address' . $x], ".tgz"))
210
					process_alias_tgz($temp_filename);
211
				else if(stristr($_POST['address' . $x], ".zip"))
212
					process_alias_unzip($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 ($_POST['type'] == "url")
238
							$is_valid = (is_ipaddr($tmp) || is_subnet($tmp));
239
						else
240
							$is_valid = (is_port($tmp) || is_portrange($tmp));
241

    
242
						if (!empty($tmp) && $is_valid) {
243
							$address[] = $tmp;
244
							$isfirst = 1;
245
							$address_count++;
246
						}
247
					}
248
					if($isfirst == 0) {
249
						/* nothing was found */
250
						$input_errors[] = sprintf(gettext("You must provide a valid URL. Could not fetch usable data from '%s'."), $_POST['address' . $x]);
251
						$dont_update = true;
252
					}
253
					mwexec("/bin/rm -rf {$temp_filename}");
254
				} else {
255
					$input_errors[] = sprintf(gettext("URL '%s' is not valid."), $_POST['address' . $x]);
256
					$dont_update = true;
257
				}
258
			}
259
		}
260
		if ($_POST['type'] == "url_ports")
261
			$address = group_ports($address);
262
	} else {
263
		/* item is a normal alias type */
264
		$wrongaliases = "";
265
		for($x=0; $x<4999; $x++) {
266
			if($_POST["address{$x}"] <> "") {
267
				$_POST["address{$x}"] = trim($_POST["address{$x}"]);
268
				if (is_alias($_POST["address{$x}"])) {
269
					if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
270
						// But alias type network can include alias type urltable. Feature#1603.
271
						if (!($_POST['type'] == 'network' &&
272
						      preg_match("/urltable/i", alias_get_type($_POST["address{$x}"]))))
273
							$wrongaliases .= " " . $_POST["address{$x}"];
274
				} else if ($_POST['type'] == "port") {
275
					if (!is_port($_POST["address{$x}"]))
276
						$input_errors[] = $_POST["address{$x}"] . " " . gettext("is not a valid port or alias.");
277
				} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
278
					if (!is_ipaddr($_POST["address{$x}"])
279
					 && !is_hostname($_POST["address{$x}"])
280
					 && !is_iprange($_POST["address{$x}"]))
281
						$input_errors[] = sprintf(gettext('%1$s is not a valid %2$s alias.'), $_POST["address{$x}"], $_POST['type']);
282
				}
283
				if (is_iprange($_POST["address{$x}"])) {
284
					list($startip, $endip) = explode('-', $_POST["address{$x}"]);
285
					$rangesubnets = ip_range_to_subnet_array($startip, $endip);
286
					$address = array_merge($address, $rangesubnets);
287
				} else {
288
					$tmpaddress = $_POST["address{$x}"];
289
					if(is_ipaddr($_POST["address{$x}"]) && $_POST["address_subnet{$x}"] <> "")
290
						$tmpaddress .= "/" . $_POST["address_subnet{$x}"];
291
					$address[] = $tmpaddress;
292
				}
293
				if ($_POST["detail{$x}"] <> "")
294
					$final_address_details[] = $_POST["detail{$x}"];
295
				else
296
					$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
297
			}
298
		}
299
		if ($wrongaliases <> "")
300
			$input_errors[] = sprintf(gettext('The alias(es): %s cannot be nested because they are not of the same type.'), $wrongaliases);
301
	}
302

    
303
	// Allow extending of the firewall edit page and include custom input validation
304
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
305

    
306
	if (!$input_errors) {
307
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
308
		$alias['descr'] = $_POST['descr'];
309
		$alias['type'] = $_POST['type'];
310
		$alias['detail'] = implode("||", $final_address_details);
311

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

    
342
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
343

    
344
		if (isset($id) && $a_aliases[$id]) {
345
			if ($a_aliases[$id]['name'] <> $alias['name']) {
346
				foreach ($a_aliases as $aliasid => $aliasd) {
347
					if ($aliasd['address'] <> "") {
348
						$tmpdirty = false;
349
						$tmpaddr = explode(" ", $aliasd['address']);
350
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
351
							if ($tmpalias == $a_aliases[$id]['name']) {
352
								$tmpaddr[$tmpidx] = $alias['name'];
353
								$tmpdirty = true;
354
							}
355
						}
356
						if ($tmpdirty == true)
357
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
358
					}
359
				}
360
			}
361
			$a_aliases[$id] = $alias;
362
		} else
363
			$a_aliases[] = $alias;
364

    
365
		// Sort list
366
		$a_aliases = msort($a_aliases, "name");
367

    
368
		if (write_config())
369
			mark_subsystem_dirty('aliases');
370

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

    
391
include("head.inc");
392

    
393
$jscriptstr = <<<EOD
394

    
395
<script type="text/javascript">
396
//<![CDATA[
397
var objAlias = new Array(4999);
398
function typesel_change() {
399
	switch (document.iform.type.selectedIndex) {
400
		case 0:	/* host */
401
			var cmd;
402

    
403
			newrows = totalrows;
404
			for(i=0; i<newrows; i++) {
405
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
406
				eval(comd);
407
				comd = 'document.iform.address_subnet' + i + '.value = "";';
408
				eval(comd);
409
			}
410
			break;
411
		case 1:	/* network */
412
			var cmd;
413

    
414
			newrows = totalrows;
415
			for(i=0; i<newrows; i++) {
416
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
417
				eval(comd);
418
			}
419
			break;
420
		case 2:	/* port */
421
			var cmd;
422

    
423
			newrows = totalrows;
424
			for(i=0; i<newrows; i++) {
425
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
426
				eval(comd);
427
				comd = 'document.iform.address_subnet' + i + '.value = "128";';
428
				eval(comd);
429
			}
430
			break;
431
/*		case 3:	// OpenVPN Users
432
			var cmd;
433

    
434
			newrows = totalrows;
435
			for(i=0; i<newrows; i++) {
436
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
437
				eval(comd);
438
				comd = 'document.iform.address_subnet' + i + '.value = "";';
439
				eval(comd);
440
			}
441
			break;
442
*/
443
		case 3:	/* url */
444
			var cmd;
445
			newrows = totalrows;
446
			for(i=0; i<newrows; i++) {
447
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
448
				eval(comd);
449
			}
450
			break;
451
		case 4:	/* url_ports */
452
			var cmd;
453
			newrows = totalrows;
454
			for(i=0; i<newrows; i++) {
455
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
456
				eval(comd);
457
			}
458
			break;
459
		case 5:	/* 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
		case 6:	/* urltable_ports */
468
			var cmd;
469
			newrows = totalrows;
470
			for(i=0; i<newrows; i++) {
471
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
472
				eval(comd);
473
			}
474
			break;
475
	}
476
}
477

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

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

    
501
$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.");
502
$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.");
503
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by separating with a colon.");
504
$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']);
505
$url_ports_help = sprintf(gettext("Enter as many URLs as you wish. After saving %s will download the URL and import the items into the alias. Use only with small sets of Ports (less than 3000)."), $g['product_name']);
506
$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']);
507
$urltable_ports_help = sprintf(gettext("Enter a single URL containing a list of Port numbers and/or Port ranges. After saving %s will download the URL."), $g['product_name']);
508

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

    
514
$jscriptstr .= <<<EOD
515

    
516
function update_box_type() {
517
	var indexNum = document.forms[0].type.selectedIndex;
518
	var selected = document.forms[0].type.options[indexNum].text;
519
	if(selected == '{$networks_str}') {
520
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
521
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
522
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
523
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
524
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
525
		document.getElementById ("addrowbutton").style.display = 'block';
526
	} else if(selected == '{$hosts_str}') {
527
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
528
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
529
		document.getElementById ("twocolumn").firstChild.data = "";
530
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
531
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
532
		document.getElementById ("addrowbutton").style.display = 'block';
533
	} else if(selected == '{$ports_str}') {
534
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
535
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
536
		document.getElementById ("twocolumn").firstChild.data = "";
537
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
538
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
539
		document.getElementById ("addrowbutton").style.display = 'block';
540
	} else if(selected == '{$url_str}') {
541
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
542
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
543
		document.getElementById ("twocolumn").firstChild.data = "";
544
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
545
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
546
		document.getElementById ("addrowbutton").style.display = 'block';
547
	} else if(selected == '{$url_ports_str}') {
548
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_ports_str}";
549
		document.getElementById ("onecolumn").firstChild.data = "{$url_ports_str}";
550
		document.getElementById ("twocolumn").firstChild.data = "";
551
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
552
		document.getElementById ("itemhelp").firstChild.data = "{$url_ports_help}";
553
		document.getElementById ("addrowbutton").style.display = 'block';
554
	} else if(selected == '{$openvpn_user_str}') {
555
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
556
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
557
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
558
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
559
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
560
		document.getElementById ("addrowbutton").style.display = 'block';
561
	} else if(selected == '{$urltable_str}') {
562
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
563
			addRowTo('maintable', 'formfldalias');
564
			typesel_change();
565
			add_alias_control(this);
566
		}
567
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
568
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
569
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
570
		document.getElementById ("threecolumn").firstChild.data = "";
571
		document.getElementById ("threecolumn").style.display = 'none';
572
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_help}";
573
		document.getElementById ("addrowbutton").style.display = 'none';
574
	} else if(selected == '{$urltable_ports_str}') {
575
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
576
			addRowTo('maintable', 'formfldalias');
577
			typesel_change();
578
			add_alias_control(this);
579
		}
580
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
581
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
582
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
583
		document.getElementById ("threecolumn").firstChild.data = "";
584
		document.getElementById ("threecolumn").style.display = 'none';
585
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_ports_help}";
586
		document.getElementById ("addrowbutton").style.display = 'none';
587
	}
588
}
589
//]]>
590
</script>
591

    
592
EOD;
593

    
594
?>
595

    
596
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
597
<?php
598
	include("fbegin.inc");
599
	echo $jscriptstr;
600
?>
601

    
602
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
603
<script type="text/javascript" src="/javascript/row_helper.js"></script>
604
<script type="text/javascript" src="/javascript/autosuggest.js"></script>
605
<script type="text/javascript" src="/javascript/suggestions.js"></script>
606

    
607
<input type='hidden' name='address_type' value='textbox' />
608
<input type='hidden' name='address_subnet_type' value='select' />
609

    
610
<script type="text/javascript">
611
//<![CDATA[
612
	rowname[0] = "address";
613
	rowtype[0] = "textbox,ipv4v6";
614
	rowsize[0] = "30";
615

    
616
	rowname[1] = "address_subnet";
617
	rowtype[1] = "select,ipv4v6";
618
	rowsize[1] = "1";
619

    
620
	rowname[2] = "detail";
621
	rowtype[2] = "textbox";
622
	rowsize[2] = "50";
623
//]]>
624
</script>
625

    
626
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
627
<?php if ($input_errors) print_input_errors($input_errors); ?>
628
<div id="inputerrors"></div>
629

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

    
702
					<?php
703
					$counter = 0;
704
					$address = $pconfig['address'];
705
					if ($address <> "") {
706
						$item = explode(" ", $address);
707
						$item3 = explode("||", $pconfig['detail']);
708
						foreach($item as $ww) {
709
							$address = $item[$counter];
710
							$address_subnet = "";
711
							$item2 = explode("/", $address);
712
							foreach($item2 as $current) {
713
								if($item2[1] <> "") {
714
									$address = $item2[0];
715
									$address_subnet = $item2[1];
716
								}
717

    
718
							}
719
							$item4 = $item3[$counter];
720
							$tracker = $counter;
721
					?>
722
					<tr>
723
						<td>
724
							<input autocomplete="off" name="address<?php echo $tracker; ?>" type="text" class="formfldalias ipv4v6" id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
725
						</td>
726
						<td>
727
							<select name="address_subnet<?php echo $tracker; ?>" class="formselect ipv4v6" id="address_subnet<?php echo $tracker; ?>">
728
								<option></option>
729
								<?php for ($i = 128; $i >= 1; $i--): ?>
730
									<option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected=\"selected\""; ?>><?=$i;?></option>
731
								<?php endfor; ?>
732
							</select>
733
						</td>
734
						<td>
735
							<input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
736
						</td>
737
						<td>
738
							<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>
739
						</td>
740
					</tr>
741
					<?php
742
						$counter++;
743

    
744
						} // end foreach
745
					} // end if
746
					?>
747
				</tbody>
748
			</table>
749
			<div id="addrowbutton">
750
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
751
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" />
752
				</a>
753
			</div>
754
		</td>
755
	</tr>
756
	<tr>
757
		<td width="22%" valign="top">&nbsp;</td>
758
		<td width="78%">
759
			<input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
760
			<a href="firewall_aliases.php?tab=<?=$tab;?>"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" /></a>
761
		</td>
762
	</tr>
763
</table>
764
</form>
765

    
766
<script type="text/javascript">
767
//<![CDATA[
768
	field_counter_js = 3;
769
	rows = 1;
770
	totalrows = <?php echo $counter; ?>;
771
	loaded = <?php echo $counter; ?>;
772
	typesel_change();
773
	update_box_type();
774

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

    
777
	function createAutoSuggest() {
778
		<?php
779
		for ($jv = 0; $jv < $counter; $jv++)
780
			echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
781
		?>
782
	}
783

    
784
	setTimeout("createAutoSuggest();", 500);
785
//]]>
786
</script>
787

    
788
<?php include("fend.inc"); ?>
789
</body>
790
</html>
(59-59/246)