Project

General

Profile

Download (27.6 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
			$isfirst = 0;
183
			$address = "";
184
			$alias['url'] = $_POST['address0'];
185
			$alias['updatefreq'] = $_POST['address_subnet0'] ? $_POST['address_subnet0'] : 7;
186
			if (!is_URL($alias['url']) || empty($alias['url'])) {
187
				$input_errors[] = gettext("You must provide a valid URL.");
188
				$dont_update = true;
189
			} elseif (! process_alias_urltable($alias['name'], $alias['url'], 0, true)) {
190
				$input_errors[] = gettext("Unable to fetch usable data.");
191
				$dont_update = true;
192
			}
193
		}
194
	} elseif($_POST['type'] == "url") {
195
		$isfirst = 0;
196
		$address_count = 2;
197

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

    
288
	if (!$input_errors) {
289
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
290
		$alias['descr'] = $_POST['descr'];
291
		$alias['type'] = $_POST['type'];
292
		$alias['detail'] = implode("||", $final_address_details);
293

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

    
324
		if (isset($id) && $a_aliases[$id]) {
325
			if ($a_aliases[$id]['name'] <> $alias['name']) {
326
				foreach ($a_aliases as $aliasid => $aliasd) {
327
					if ($aliasd['address'] <> "") {
328
						$tmpdirty = false;
329
						$tmpaddr = explode(" ", $aliasd['address']);
330
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
331
							if ($tmpalias == $a_aliases[$id]['name']) {
332
								$tmpaddr[$tmpidx] = $alias['name'];
333
								$tmpdirty = true;
334
							}
335
						}
336
						if ($tmpdirty == true)
337
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
338
					}
339
				}
340
			}
341
			$a_aliases[$id] = $alias;
342
		} else
343
			$a_aliases[] = $alias;
344

    
345
		mark_subsystem_dirty('aliases');
346

    
347
		// Sort list
348
		$a_aliases = msort($a_aliases, "name");
349

    
350
		write_config();
351

    
352
		header("Location: firewall_aliases.php");
353
		exit;		
354
	}
355
	//we received input errors, copy data to prevent retype
356
	else
357
	{
358
		$pconfig['name'] = $_POST['name'];
359
		$pconfig['descr'] = $_POST['descr'];
360
		$pconfig['address'] = implode(" ", $address);
361
		$pconfig['type'] = $_POST['type'];
362
		$pconfig['detail'] = implode("||", $final_address_details);
363
	}
364
}
365

    
366
include("head.inc");
367

    
368
$jscriptstr = <<<EOD
369

    
370
<script type="text/javascript">
371

    
372
var objAlias = new Array(4999);
373
function typesel_change() {
374
	switch (document.iform.type.selectedIndex) {
375
		case 0:	/* host */
376
			var cmd;
377

    
378
			newrows = totalrows;
379
			for(i=0; i<newrows; i++) {
380
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
381
				eval(comd);
382
				comd = 'document.iform.address_subnet' + i + '.value = "";';
383
				eval(comd);
384
			}
385
			break;
386
		case 1:	/* network */
387
			var cmd;
388

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

    
398
			newrows = totalrows;
399
			for(i=0; i<newrows; i++) {
400
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
401
				eval(comd);
402
				comd = 'document.iform.address_subnet' + i + '.value = "128";';
403
				eval(comd);
404
			}
405
			break;
406
		case 3:	/* OpenVPN Users */
407
			var cmd;
408

    
409
			newrows = totalrows;
410
			for(i=0; i<newrows; i++) {
411
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
412
				eval(comd);
413
				comd = 'document.iform.address_subnet' + i + '.value = "";';
414
				eval(comd);
415
			}
416
			break;
417

    
418
		case 4:	/* url */
419
			var cmd;
420
			newrows = totalrows;
421
			for(i=0; i<newrows; i++) {
422
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
423
				eval(comd);
424
			}
425
			break;
426

    
427
		case 5:	/* urltable */
428
			var cmd;
429
			newrows = totalrows;
430
			for(i=0; i<newrows; i++) {
431
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
432
				eval(comd);
433
			}
434
			break;
435
	}
436
}
437

    
438
function add_alias_control() {
439
	var name = "address" + (totalrows - 1);
440
	obj = document.getElementById(name);
441
	obj.setAttribute('class', 'formfldalias');
442
	obj.setAttribute('autocomplete', 'off');
443
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
444
}
445
EOD;
446

    
447
$network_str = gettext("Network");
448
$networks_str = gettext("Network(s)");
449
$cidr_str = gettext("CIDR");
450
$description_str = gettext("Description");
451
$hosts_str = gettext("Host(s)");
452
$ip_str = gettext("IP");
453
$ports_str = gettext("Port(s)");
454
$port_str = gettext("Port");
455
$url_str = gettext("URL");
456
$urltable_str = gettext("URL Table");
457
$update_freq_str = gettext("Update Freq.");
458

    
459
$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.");
460
$hosts_help = gettext("Enter as many hosts as you would like.  Hosts must be specified by their IP address.");
461
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by seperating with a colon.");
462
$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']);
463
$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']);
464

    
465
$openvpn_str = gettext("Username");
466
$openvpn_user_str = gettext("OpenVPN Users");
467
$openvpn_help = gettext("Enter as many usernames as you wish.");
468
$openvpn_freq = "";
469

    
470
$jscriptstr .= <<<EOD
471

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

    
527
EOD;
528

    
529
?>
530

    
531
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
532
<?php
533
	include("fbegin.inc");
534
	echo $jscriptstr;
535
?>
536

    
537
<script type="text/javascript" src="/javascript/row_helper.js">
538
</script>
539
<script type="text/javascript" src="/javascript/autosuggest.js">
540
</script>
541
<script type="text/javascript" src="/javascript/suggestions.js">
542
</script>
543

    
544
<input type='hidden' name='address_type' value='textbox' />
545
<input type='hidden' name='address_subnet_type' value='select' />
546

    
547
<script type="text/javascript">
548
	rowname[0] = "address";
549
	rowtype[0] = "textbox";
550
	rowsize[0] = "30";
551

    
552
	rowname[1] = "address_subnet";
553
	rowtype[1] = "select";
554
	rowsize[1] = "1";
555

    
556
	rowname[2] = "detail";
557
	rowtype[2] = "textbox";
558
	rowsize[2] = "50";
559
</script>
560

    
561
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
562
<?php if ($input_errors) print_input_errors($input_errors); ?>
563
<div id="inputerrors"></div>
564

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

    
623
	<?php
624
	$counter = 0;
625
	$address = $pconfig['address'];
626
	if ($address <> "") {
627
		$item = explode(" ", $address);
628
		$item3 = explode("||", $pconfig['detail']);
629
		foreach($item as $ww) {
630
			$address = $item[$counter];
631
			$address_subnet = "";
632
			$item2 = explode("/", $address);
633
			foreach($item2 as $current) {
634
				if($item2[1] <> "") {
635
					$address = $item2[0];
636
					$address_subnet = $item2[1];
637
				}
638
				
639
			}
640
			$item4 = $item3[$counter];
641
			$tracker = $counter;
642
	?>
643
          <tr>
644
            <td>
645
              <input autocomplete="off" name="address<?php echo $tracker; ?>" type="text" class="formfldalias" id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
646
            </td>
647
            <td>
648
			        <select name="address_subnet<?php echo $tracker; ?>" class="formselect" id="address_subnet<?php echo $tracker; ?>">
649
				<option></option>
650
			          <?php for ($i = 128; $i >= 1; $i--): ?>
651
			          <option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected"; ?>><?=$i;?></option>
652
			          <?php endfor; ?>
653
			        </select>
654
			      </td>
655
            <td>
656
              <input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
657
            </td>
658
            <td>
659
    		<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>
660
	      </td>
661
          </tr>
662
<?php
663
        	$counter++;
664

    
665
       		} // end foreach
666
	} // end if
667
?>
668
        </tbody>
669
        <tfoot>
670

    
671
        </tfoot>
672
		  </table>
673
			<div id="addrowbutton"><a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
674
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" /></a></div>
675
		</td>
676
  </tr>
677
  <tr>
678
    <td width="22%" valign="top">&nbsp;</td>
679
    <td width="78%">
680
      <input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
681
      <a href="firewall_aliases.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="<?=gettext("Cancel"); ?>" /></a>
682
    </td>
683
  </tr>
684
</table>
685
</form>
686

    
687
<script type="text/javascript">
688
	field_counter_js = 3;
689
	rows = 1;
690
	totalrows = <?php echo $counter; ?>;
691
	loaded = <?php echo $counter; ?>;
692
	typesel_change();
693
	update_box_type();
694

    
695
<?php
696
        $isfirst = 0;
697
        $aliases = "";
698
        $addrisfirst = 0;
699
        $aliasesaddr = "";
700
        if(isset($config['aliases']['alias']) && is_array($config['aliases']['alias']))
701
                foreach($config['aliases']['alias'] as $alias_name) {
702
			if ($pconfig['name'] <> "" && $pconfig['name'] == $alias_name['name'])
703
				continue;
704
			if($addrisfirst == 1) $aliasesaddr .= ",";
705
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
706
			$addrisfirst = 1;
707
                }
708
?>
709

    
710
        var addressarray=new Array(<?php echo $aliasesaddr; ?>);
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>
(53-53/232)