Project

General

Profile

Download (25.3 KB) Statistics
| Branch: | Tag: | Revision:
1 d2cfb7a4 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	firewall_aliases_edit.php
5 2e9ab96b Scott Ullrich
	Copyright (C) 2004 Scott Ullrich
6 460b3848 Ermal Lu?i
	Copyright (C) 2009 Ermal Lu?i
7 fff3d2b9 jim-p
	Copyright (C) 2010 Jim Pingle
8 2e9ab96b Scott Ullrich
	All rights reserved.
9
10
	originially part of m0n0wall (http://m0n0.ch/wall)
11 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
12
	All rights reserved.
13 d2cfb7a4 Scott Ullrich
14 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
15
	modification, are permitted provided that the following conditions are met:
16 d2cfb7a4 Scott Ullrich
17 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
18
	   this list of conditions and the following disclaimer.
19 d2cfb7a4 Scott Ullrich
20 5b237745 Scott Ullrich
	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 d2cfb7a4 Scott Ullrich
24 5b237745 Scott Ullrich
	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 7ac5a4cb Scott Ullrich
/*
36
	pfSense_BUILDER_BINARIES:	/bin/rm	/bin/mkdir	/usr/bin/fetch
37
	pfSense_MODULE:	aliases
38
*/
39 5b237745 Scott Ullrich
40 6b07c15a Matthew Grooms
##|+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 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","Aliases","Edit");
48 5a1eebc7 Scott Ullrich
49 f76a479d sullrich
// Keywords not allowed in names
50 a14bc953 Ermal Lu?i
$reserved_keywords = array("pass", "out", "queue", "max", "min", "pptp", "pppoe", "l2tp", "openvpn");
51 f76a479d sullrich
52 5b237745 Scott Ullrich
require("guiconfig.inc");
53 7a927e67 Scott Ullrich
require_once("functions.inc");
54
require_once("filter.inc");
55
require_once("shaper.inc");
56 5b237745 Scott Ullrich
57 7c9d8d71 Ermal Lu?i
$reserved_ifs = get_configured_interface_list(false, true);
58
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs);
59
60 5b237745 Scott Ullrich
if (!is_array($config['aliases']['alias']))
61
	$config['aliases']['alias'] = array();
62
$a_aliases = &$config['aliases']['alias'];
63 ed0b7949 Scott Ullrich
	
64
if($_POST)
65
	$origname = $_POST['origname'];
66
67
// Debugging
68 f5200c44 Scott Ullrich
if($debug)
69 7515fb4b Ermal Lu?i
	exec("rm -f {$g['tmp_path']}/alias_rename_log.txt");
70 ed0b7949 Scott Ullrich
71 5e34cdb2 Ermal Lu?i
function alias_same_type($name, $type) {
72
	global $config;
73
	
74
	foreach ($config['aliases']['alias'] as $alias) {
75
		if ($name == $alias['name']) {
76 d6c9ab97 Ermal Lu?i
			if (in_array($type, array("host", "network")) &&
77 5e34cdb2 Ermal Lu?i
				in_array($alias['type'], array("host", "network")))
78
				return true;
79
			if ($type  == $alias['type'])
80
				return true;
81
			else
82
				return false;
83
		}
84
	}
85
	return true;
86
}
87
88 5b237745 Scott Ullrich
$id = $_GET['id'];
89
if (isset($_POST['id']))
90
	$id = $_POST['id'];
91
92
if (isset($id) && $a_aliases[$id]) {
93 ed0b7949 Scott Ullrich
	$original_alias_name = $a_aliases[$id]['name'];
94 5b237745 Scott Ullrich
	$pconfig['name'] = $a_aliases[$id]['name'];
95 ba393f6c Scott Dale
	$pconfig['detail'] = $a_aliases[$id]['detail'];
96
	$pconfig['address'] = $a_aliases[$id]['address'];
97 b4deddce Ermal Lu?i
	$pconfig['type'] = $a_aliases[$id]['type'];
98 ba393f6c Scott Dale
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
99 e47c266d Scott Ullrich
100 cbe3ea96 Ermal Luçi
	/* optional if list */
101
	$iflist = get_configured_interface_with_descr(true, true);
102
	foreach ($iflist as $if => $ifdesc)
103
		if($ifdesc == $pconfig['descr']) 
104 e47c266d Scott Ullrich
			$input_errors[] = "Sorry, an interface is already named {$pconfig['descr']}.";
105
106 c7de8be4 jim-p
	if($a_aliases[$id]['type'] == "urltable") {
107
		$pconfig['address'] = $a_aliases[$id]['url'];
108
		$pconfig['updatefreq'] = $a_aliases[$id]['updatefreq'];
109
	}
110 5a1eebc7 Scott Ullrich
	if($a_aliases[$id]['aliasurl'] <> "") {
111
		$pconfig['type'] = "url";
112
		if(is_array($a_aliases[$id]['aliasurl'])) {
113
			$isfirst = 0;
114
			$pconfig['address'] = "";
115
			foreach($a_aliases[$id]['aliasurl'] as $aa) {
116
				if($isfirst == 1)
117
					$pconfig['address'] .= " ";
118
				$isfirst = 1;
119
				$pconfig['address'] .= $aa;
120
			}
121
		} else {
122
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
123
		}
124
	}
125 5b237745 Scott Ullrich
}
126
127
if ($_POST) {
128
	unset($input_errors);
129
130
	/* input validation */
131 0cd7ed19 Scott Ullrich
132 69d2ad77 Erik Fonnesbeck
	$reqdfields = explode(" ", "name");
133
	$reqdfieldsn = explode(",", "Name");
134
135
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
136
137 0df6adf8 Bill Marquette
	$x = is_validaliasname($_POST['name']);
138
	if (!isset($x)) {
139
		$input_errors[] = "Reserved word used for alias name.";
140 52d618c2 Ermal Lu?i
	} else if ($_POST['type'] == "port" && (getservbyname($_POST['name'], "tcp") || getservbyname($_POST['name'], "udp"))) {
141
		$input_errors[] = "Reserved word used for alias name.";
142 0df6adf8 Bill Marquette
	} else {
143
		if (is_validaliasname($_POST['name']) == false)
144 d87fc50b Seth Mos
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
145 beeef1f0 Bill Marquette
	}
146 5b237745 Scott Ullrich
	/* check for name conflicts */
147 6c33fb4b Ermal
	if (empty($a_aliases[$id])) {
148 6b487ec6 Ermal
		foreach ($a_aliases as $alias) {
149
			if ($alias['name'] == $_POST['name']) {
150
				$input_errors[] = "An alias with this name already exists.";
151
				break;
152
			}
153 5b237745 Scott Ullrich
		}
154
	}
155 5a1eebc7 Scott Ullrich
156 f76a479d sullrich
	/* Check for reserved keyword names */
157
	foreach($reserved_keywords as $rk) 
158
		if($rk == $_POST['name'])
159 58b0abb3 sullrich
			$input_errors[] = "Cannot use a reserved keyword as alias name $rk";
160 f76a479d sullrich
161 cfa466bb Scott Ullrich
	/* check for name interface description conflicts */
162
	foreach($config['interfaces'] as $interface) {
163
		if($interface['descr'] == $_POST['name']) {
164 5a1eebc7 Scott Ullrich
			$input_errors[] = "An interface description with this name already exists.";
165
			break;
166 cfa466bb Scott Ullrich
		}
167 5a1eebc7 Scott Ullrich
	}
168 ba393f6c Scott Dale
	
169
	$alias = array();
170 6c33fb4b Ermal
	$address = array();
171
	$final_address_details = array();
172 ba393f6c Scott Dale
	$alias['name'] = $_POST['name'];
173 c7de8be4 jim-p
174
	if ($_POST['type'] == "urltable") {
175
		$address = "";
176
		$isfirst = 0;
177
178
		/* item is a url type */
179
		if ($_POST['address0']) {
180
			/* fetch down and add in */
181
			$isfirst = 0;
182
			$address = "";
183
			$alias['url'] = $_POST['address0'];
184
			$alias['updatefreq'] = $_POST['address_subnet0'] ? $_POST['address_subnet0'] : 7;
185
			if (!is_URL($alias['url']) || empty($alias['url'])) {
186
				$input_errors[] = "You must provide a valid URL.";
187
				$dont_update = true;
188
			} elseif (! process_alias_urltable($alias['name'], $alias['url'], 0, true)) {
189
				$input_errors[] = "Unable to fetch usable data.";
190
				$dont_update = true;
191
			}
192
		}
193
	} elseif($_POST['type'] == "url") {
194 d2cfb7a4 Scott Ullrich
		$isfirst = 0;
195 ba393f6c Scott Dale
		$address_count = 2;
196
197
		/* item is a url type */
198 d8898df4 Scott Ullrich
		for($x=0; isset($_POST['address'. $x]); $x++) {
199 ba393f6c Scott Dale
			if($_POST['address' . $x]) {
200
				/* fetch down and add in */
201
				$isfirst = 0;
202 7c872d3b Scott Ullrich
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
203 ba393f6c Scott Dale
				unlink($temp_filename);
204 7515fb4b Ermal Lu?i
				$fda = fopen("{$g['tmp_path']}/tmpfetch","w");
205 ba393f6c Scott Dale
				fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
206
				fclose($fda);
207 7ac5a4cb Scott Ullrich
				mwexec("/bin/mkdir -p {$temp_filename}");
208 ba393f6c Scott Dale
				mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
209
				/* if the item is tar gzipped then extract */
210
				if(stristr($_POST['address' . $x], ".tgz"))
211
					process_alias_tgz($temp_filename);
212
				if(file_exists("{$temp_filename}/aliases")) {
213
					$file_contents = file_get_contents("{$temp_filename}/aliases");
214
					$file_contents = str_replace("#", "\n#", $file_contents);
215
					$file_contents_split = split("\n", $file_contents);
216
					foreach($file_contents_split as $fc) {
217 c7de8be4 jim-p
						// Stop at 3000 items, aliases larger than that tend to break both pf and the WebGUI.
218
						if ($address_count >= 3000)
219
							break;
220 ba393f6c Scott Dale
						$tmp = trim($fc);
221
						if(stristr($fc, "#")) {
222
							$tmp_split = split("#", $tmp);
223
							$tmp = trim($tmp_split[0]);
224 5a1eebc7 Scott Ullrich
						}
225 74e861e3 jim-p
						$tmp = trim($tmp);
226
						if(!empty($tmp) && (is_ipaddr($tmp) || is_subnet($tmp))) {
227 6c33fb4b Ermal
							$address[] = $tmp;
228 ba393f6c Scott Dale
							$isfirst = 1;
229 c7de8be4 jim-p
							$address_count++;
230 5a1eebc7 Scott Ullrich
						}
231 ba393f6c Scott Dale
					}
232
					if($isfirst == 0) {
233
						/* nothing was found */
234
						$input_errors[] = "You must provide a valid URL. Could not fetch usable data.";
235 5a1eebc7 Scott Ullrich
						$dont_update = true;
236
						break;
237
					}
238 ba393f6c Scott Dale
					$alias['aliasurl'][] = $_POST['address' . $x];
239
					mwexec("/bin/rm -rf {$temp_filename}");
240
				} else {
241
					$input_errors[] = "You must provide a valid URL.";
242
					$dont_update = true;
243
					break;
244 5a1eebc7 Scott Ullrich
				}
245
			}
246 ba393f6c Scott Dale
		}
247
	} else {
248
		/* item is a normal alias type */
249 5e34cdb2 Ermal Lu?i
		$wrongaliases = "";
250 a2d8d3dd Ermal Luçi
		for($x=0; $x<4999; $x++) {
251 b6f3005c Ermal Luçi
			if($_POST["address{$x}"] <> "") {
252 f71e0ac6 Ermal Lu?i
				if (is_alias($_POST["address{$x}"])) {
253
					if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
254
						$wrongaliases .= " " . $_POST["address{$x}"];
255
				} else if ($_POST['type'] == "port") {
256 231e0606 Ermal Lu?i
					if (!is_port($_POST["address{$x}"]))
257
						$input_errors[] = $_POST["address{$x}"] . " is not a valid port or alias.";
258 f71e0ac6 Ermal Lu?i
				} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
259 ecd1f2d9 jim-p
					if (!is_ipaddr($_POST["address{$x}"])
260
					 && !is_hostname($_POST["address{$x}"])
261
					 && !is_iprange($_POST["address{$x}"]))
262 f71e0ac6 Ermal Lu?i
						$input_errors[] = $_POST["address{$x}"] . " is not a valid {$_POST['type']} alias.";
263
				}
264 6c33fb4b Ermal
				if (is_iprange($_POST["address{$x}"])) {
265
					list($startip, $endip) = explode('-', $_POST["address{$x}"]);
266
					$rangesubnets = ip_range_to_subnet_array($startip, $endip);
267 9ae9a7fc Ermal
					$address = array_merge($address, $rangesubnets);
268 6c33fb4b Ermal
				} else {
269
					$tmpaddress = $_POST["address{$x}"];
270 6775c54e Ermal
					if(is_ipaddr($_POST["address{$x}"]) && $_POST["address_subnet{$x}"] <> "")
271 6c33fb4b Ermal
						$tmpaddress .= "/" . $_POST["address_subnet{$x}"];
272
					$address[] = $tmpaddress;
273
				}
274
				if ($_POST["detail{$x}"] <> "")
275
					$final_address_details[] = $_POST["detail{$x}"];
276
				else
277
					$final_address_details[] = "Entry added " . date('r');
278 5e34cdb2 Ermal Lu?i
			}
279 d2cfb7a4 Scott Ullrich
		}
280 5e34cdb2 Ermal Lu?i
		if ($wrongaliases <> "")
281 f71e0ac6 Ermal Lu?i
			$input_errors[] = "The alias(es): {$wrongaliases} \ncannot be nested cause they are not of the same type.";
282 ba393f6c Scott Dale
	}
283 d2cfb7a4 Scott Ullrich
284 ba393f6c Scott Dale
	if (!$input_errors) {
285 c7de8be4 jim-p
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
286 ec3cedf7 Bill Marquette
		$alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
287 ba393f6c Scott Dale
		$alias['type'] = $_POST['type'];
288 6c33fb4b Ermal
		$alias['detail'] = implode("||", $final_address_details);
289 d2cfb7a4 Scott Ullrich
290 ed0b7949 Scott Ullrich
		/*   Check to see if alias name needs to be
291
		 *   renamed on referenced rules and such
292
		 */
293
		if ($_POST['name'] <> $_POST['origname']) {
294
			// Firewall rules
295 978fd2e8 Scott Ullrich
			update_alias_names_upon_change('filter', 'rule', 'source', 'address', $_POST['name'], $origname);
296
			update_alias_names_upon_change('filter', 'rule', 'destination', 'address', $_POST['name'], $origname);
297 ed0b7949 Scott Ullrich
			// NAT Rules
298 b52d3aa5 Renato Botelho
			update_alias_names_upon_change('nat', 'rule', 'source', 'address', $_POST['name'], $origname);
299
			update_alias_names_upon_change('nat', 'rule', 'source', 'port', $_POST['name'], $origname);
300
			update_alias_names_upon_change('nat', 'rule', 'destination', 'address', $_POST['name'], $origname);
301
			update_alias_names_upon_change('nat', 'rule', 'destination', 'port', $_POST['name'], $origname);
302 978fd2e8 Scott Ullrich
			update_alias_names_upon_change('nat', 'rule', 'target', '', $_POST['name'], $origname);
303
			update_alias_names_upon_change('nat', 'rule', 'local-port', ''	, $_POST['name'], $origname);
304 f43ba926 Scott Ullrich
			// Alias in an alias
305 978fd2e8 Scott Ullrich
			update_alias_names_upon_change('aliases', 'alias', 'address', ''	, $_POST['name'], $origname);
306 ed0b7949 Scott Ullrich
		}
307
308 171aa30d Ermal Lu?i
		if (isset($id) && $a_aliases[$id]) {
309
			if ($a_aliases[$id]['name'] <> $alias['name']) {
310
				foreach ($a_aliases as $aliasid => $aliasd) {
311 16f78ff0 Ermal Lu?i
					if ($aliasd['address'] <> "") {
312 96b4269c Ermal Lu?i
						$tmpdirty = false;
313 16f78ff0 Ermal Lu?i
						$tmpaddr = explode(" ", $aliasd['address']);
314
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
315 96b4269c Ermal Lu?i
							if ($tmpalias == $a_aliases[$id]['name']) {
316 16f78ff0 Ermal Lu?i
								$tmpaddr[$tmpidx] = $alias['name'];
317 96b4269c Ermal Lu?i
								$tmpdirty = true;
318
							}
319 16f78ff0 Ermal Lu?i
						}
320 96b4269c Ermal Lu?i
						if ($tmpdirty == true)
321
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
322 16f78ff0 Ermal Lu?i
					}
323 171aa30d Ermal Lu?i
				}
324
			}
325 ba393f6c Scott Dale
			$a_aliases[$id] = $alias;
326 171aa30d Ermal Lu?i
		} else
327 ba393f6c Scott Dale
			$a_aliases[] = $alias;
328 a18b6b97 Scott Ullrich
329 a368a026 Ermal Lu?i
		mark_subsystem_dirty('aliases');
330 a18b6b97 Scott Ullrich
331 974cbfe0 Ermal Lu?i
		// Sort list
332
		$a_aliases = msort($a_aliases, "name");
333
334 ba393f6c Scott Dale
		write_config();
335
		filter_configure();
336 d2cfb7a4 Scott Ullrich
337 ba393f6c Scott Dale
		header("Location: firewall_aliases.php");
338
		exit;		
339
	}
340
	//we received input errors, copy data to prevent retype
341
	else
342
	{
343 c7de8be4 jim-p
		$pconfig['name'] = $_POST['name'];
344 ec3cedf7 Bill Marquette
		$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
345 6c33fb4b Ermal
		$pconfig['address'] = implode(" ", $address);
346 ba393f6c Scott Dale
		$pconfig['type'] = $_POST['type'];
347 6c33fb4b Ermal
		$pconfig['detail'] = implode("||", $final_address_details);
348 5b237745 Scott Ullrich
	}
349
}
350 da7ae7ef Bill Marquette
351
include("head.inc");
352
353 5a1eebc7 Scott Ullrich
$jscriptstr = <<<EOD
354 da7ae7ef Bill Marquette
355 5a1eebc7 Scott Ullrich
<script type="text/javascript">
356 0cea9a23 Ermal Lu?i
357
var objAlias = new Array(4999);
358 5b237745 Scott Ullrich
function typesel_change() {
359
	switch (document.iform.type.selectedIndex) {
360
		case 0:	/* host */
361 d2cfb7a4 Scott Ullrich
			var cmd;
362 5a1eebc7 Scott Ullrich
363 b6f3005c Ermal Luçi
			newrows = totalrows;
364
			for(i=0; i<newrows; i++) {
365 5a1eebc7 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
366
				eval(comd);
367
				comd = 'document.iform.address_subnet' + i + '.value = "";';
368
				eval(comd);
369 d2cfb7a4 Scott Ullrich
			}
370 5b237745 Scott Ullrich
			break;
371
		case 1:	/* network */
372 d2cfb7a4 Scott Ullrich
			var cmd;
373 5a1eebc7 Scott Ullrich
374 b6f3005c Ermal Luçi
			newrows = totalrows;
375
			for(i=0; i<newrows; i++) {
376 5a1eebc7 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
377
				eval(comd);
378 d2cfb7a4 Scott Ullrich
			}
379 5b237745 Scott Ullrich
			break;
380 4d6b6263 Scott Ullrich
		case 2:	/* port */
381
			var cmd;
382 5a1eebc7 Scott Ullrich
383 b6f3005c Ermal Luçi
			newrows = totalrows;
384
			for(i=0; i<newrows; i++) {
385 5a1eebc7 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
386
				eval(comd);
387
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
388
				eval(comd);
389
			}
390
			break;
391 cd35a596 Scott Ullrich
		case 3:	/* OpenVPN Users */
392 5a1eebc7 Scott Ullrich
			var cmd;
393 cd35a596 Scott Ullrich
394 b6f3005c Ermal Luçi
			newrows = totalrows;
395
			for(i=0; i<newrows; i++) {
396 cd35a596 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
397
				eval(comd);
398
				comd = 'document.iform.address_subnet' + i + '.value = "";';
399 5a1eebc7 Scott Ullrich
				eval(comd);
400 4d6b6263 Scott Ullrich
			}
401
			break;
402 6e7e1814 Scott Ullrich
403 cd35a596 Scott Ullrich
		case 4:	/* url */
404 6e7e1814 Scott Ullrich
			var cmd;
405 b6f3005c Ermal Luçi
			newrows = totalrows;
406
			for(i=0; i<newrows; i++) {
407 a0fc25ae Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
408 6e7e1814 Scott Ullrich
				eval(comd);
409
			}
410
			break;
411 c7de8be4 jim-p
412
		case 5:	/* urltable */
413
			var cmd;
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 5b237745 Scott Ullrich
	}
421
}
422 d2cfb7a4 Scott Ullrich
423 0cea9a23 Ermal Lu?i
function add_alias_control() {
424
	var name = "address" + (totalrows - 1);
425
	obj = document.getElementById(name);
426
	obj.setAttribute('class', 'formfldalias');
427
	obj.setAttribute('autocomplete', 'off');
428
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
429
}
430 5a1eebc7 Scott Ullrich
EOD;
431
432
$network_str = gettext("Network");
433
$networks_str = gettext("Network(s)");
434
$cidr_str = gettext("CIDR");
435
$description_str = gettext("Description");
436
$hosts_str = gettext("Host(s)");
437
$ip_str = gettext("IP");
438
$ports_str = gettext("Port(s)");
439
$port_str = gettext("Port");
440
$url_str = gettext("URL");
441 c7de8be4 jim-p
$urltable_str = gettext("URL Table");
442 5a1eebc7 Scott Ullrich
$update_freq_str = gettext("Update Freq.");
443
444 7a288dc9 jim-p
$networks_help = gettext("Networks are specified in CIDR format.  Select the CIDR mask that pertains to each entry. /32 specifies a single host, /24 specifies 255.255.255.0, etc. Hostnames (FQDNs) may also be specified, using a /32 mask. 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.");
445 974ff781 Chris Buechler
$hosts_help = gettext("Enter as many hosts as you would like.  Hosts must be specified by their IP address.");
446 5a1eebc7 Scott Ullrich
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by seperating with a colon.");
447 c7de8be4 jim-p
$url_help = gettext("Enter as many URLs as you wish. After saving {$g['product_name']} will download the URL and import the items into the alias. Use only with small sets of IP addresses (less than 3000).");
448
$urltable_help = gettext("Enter a single URL containing a large number of IPs and/or Subnets. After saving {$g['product_name']} 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.");
449 5a1eebc7 Scott Ullrich
450 3ebd97eb Scott Ullrich
$openvpn_str = gettext("Username");
451
$openvpn_user_str = gettext("OpenVPN Users");
452
$openvpn_help = gettext("Enter as many usernames as you wish.");
453 4c743413 Scott Ullrich
$openvpn_freq = gettext("");
454 3ebd97eb Scott Ullrich
455 5a1eebc7 Scott Ullrich
$jscriptstr .= <<<EOD
456
457 d2cfb7a4 Scott Ullrich
function update_box_type() {
458
	var indexNum = document.forms[0].type.selectedIndex;
459
	var selected = document.forms[0].type.options[indexNum].text;
460 5a1eebc7 Scott Ullrich
	if(selected == '{$networks_str}') {
461
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
462
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
463
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
464
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
465
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
466 c7de8be4 jim-p
		document.getElementById ("addrowbutton").style.display = 'block';
467 5a1eebc7 Scott Ullrich
	} else if(selected == '{$hosts_str}') {
468
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
469
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
470
		document.getElementById ("twocolumn").firstChild.data = "";
471
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
472
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
473 c7de8be4 jim-p
		document.getElementById ("addrowbutton").style.display = 'block';
474 5a1eebc7 Scott Ullrich
	} else if(selected == '{$ports_str}') {
475
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
476
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
477
		document.getElementById ("twocolumn").firstChild.data = "";
478
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
479
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
480 c7de8be4 jim-p
		document.getElementById ("addrowbutton").style.display = 'block';
481 5a1eebc7 Scott Ullrich
	} else if(selected == '{$url_str}') {
482
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
483
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
484 a0fc25ae Scott Ullrich
		document.getElementById ("twocolumn").firstChild.data = "";
485 5a1eebc7 Scott Ullrich
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
486
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
487 c7de8be4 jim-p
		document.getElementById ("addrowbutton").style.display = 'block';
488 6e7e1814 Scott Ullrich
	} else if(selected == '{$openvpn_user_str}') {
489
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
490 3ebd97eb Scott Ullrich
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
491 4c743413 Scott Ullrich
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
492 6e7e1814 Scott Ullrich
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
493 3ebd97eb Scott Ullrich
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
494 c7de8be4 jim-p
		document.getElementById ("addrowbutton").style.display = 'block';
495
	} else if(selected == '{$urltable_str}') {
496
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
497
			addRowTo('maintable', 'formfldalias');
498
			typesel_change();
499
			add_alias_control(this);
500
		}
501
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
502
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
503
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
504
		document.getElementById ("threecolumn").firstChild.data = "";
505
		document.getElementById ("threecolumn").style.display = 'none';
506
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_help}";
507
		document.getElementById ("addrowbutton").style.display = 'none';
508 d2cfb7a4 Scott Ullrich
	}
509
}
510 5b237745 Scott Ullrich
</script>
511
512 66138bf6 Scott Dale
EOD;
513 d2cfb7a4 Scott Ullrich
514 5a1eebc7 Scott Ullrich
?>
515 d2cfb7a4 Scott Ullrich
516 5a1eebc7 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
517
<?php
518
	include("fbegin.inc");
519
	echo $jscriptstr;
520
?>
521
522 625dcc40 Bill Marquette
<script type="text/javascript" src="/javascript/row_helper.js">
523 5a1eebc7 Scott Ullrich
</script>
524 0cea9a23 Ermal Lu?i
<script type="text/javascript" src="/javascript/autosuggest.js">
525
</script>
526
<script type="text/javascript" src="/javascript/suggestions.js">
527
</script>
528 d2cfb7a4 Scott Ullrich
529 5a1eebc7 Scott Ullrich
<input type='hidden' name='address_type' value='textbox' />
530
<input type='hidden' name='address_subnet_type' value='select' />
531 d2cfb7a4 Scott Ullrich
532 5a1eebc7 Scott Ullrich
<script type="text/javascript">
533
	rowname[0] = "address";
534
	rowtype[0] = "textbox";
535
	rowsize[0] = "30";
536 d2cfb7a4 Scott Ullrich
537 5a1eebc7 Scott Ullrich
	rowname[1] = "address_subnet";
538
	rowtype[1] = "select";
539
	rowsize[1] = "1";
540 d2cfb7a4 Scott Ullrich
541 5a1eebc7 Scott Ullrich
	rowname[2] = "detail";
542
	rowtype[2] = "textbox";
543 b6f3005c Ermal Luçi
	rowsize[2] = "50";
544 d2cfb7a4 Scott Ullrich
</script>
545
546 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
547 5a1eebc7 Scott Ullrich
<div id="inputerrors"></div>
548
549
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
550
<table width="100%" border="0" cellpadding="6" cellspacing="0">
551 c823d56b Scott Ullrich
  <tr>
552
	<td colspan="2" valign="top" class="listtopic">Alias Edit</td>
553
  </tr>
554 5a1eebc7 Scott Ullrich
  <tr>
555
    <td valign="top" class="vncellreq">Name</td>
556
    <td class="vtable">
557 ed0b7949 Scott Ullrich
      <input name="origname" type="hidden" id="origname" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
558 b5c78501 Seth Mos
      <input name="name" type="text" id="name" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
559 6c33fb4b Ermal
      <?php if (isset($id) && $a_aliases[$id]): ?>
560
      <input name="id" type="hidden" value="<?=$id;?>" />
561
      <?php endif; ?>
562 5a1eebc7 Scott Ullrich
      <br />
563
      <span class="vexpl">
564
        The name of the alias may only consist of the characters a-z, A-Z and 0-9.
565
      </span>
566
    </td>
567
  </tr>
568
  <tr>
569
    <td width="22%" valign="top" class="vncell">Description</td>
570
    <td width="78%" class="vtable">
571 b5c78501 Seth Mos
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
572 5a1eebc7 Scott Ullrich
      <br />
573
      <span class="vexpl">
574
        You may enter a description here for your reference (not parsed).
575
      </span>
576
    </td>
577
  </tr>
578
  <tr>
579
    <td valign="top" class="vncellreq">Type</td>
580
    <td class="vtable">
581
      <select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
582
        <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
583
        <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
584
        <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
585 b6f3005c Ermal Luçi
        <option value="openvpn" <?php if ($pconfig['type'] == "openvpn") echo "selected"; ?>>OpenVPN Users</option>
586 2aed5121 Scott Ullrich
        <option value="url" <?php if ($pconfig['type'] == "url") echo "selected"; ?>>URL</option>
587 c7de8be4 jim-p
        <option value="urltable" <?php if ($pconfig['type'] == "urltable") echo "selected"; ?>>URL Table</option>
588 5a1eebc7 Scott Ullrich
      </select>
589
    </td>
590
  </tr>
591
  <tr>
592
    <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport">Host(s)</div></td>
593
    <td width="78%" class="vtable">
594
      <table id="maintable">
595
        <tbody>
596
          <tr>
597
            <td colspan="4">
598
      		    <div style="padding:5px; margin-top: 16px; margin-bottom: 16px; border:1px dashed #000066; background-color: #ffffff; color: #000000; font-size: 8pt;" id="itemhelp">Item information</div>
599
            </td>
600
          </tr>
601
          <tr>
602
            <td><div id="onecolumn">Network</div></td>
603
            <td><div id="twocolumn">CIDR</div></td>
604
           <td><div id="threecolumn">Description</div></td>
605
          </tr>
606 d2cfb7a4 Scott Ullrich
607 0d3f3e90 Ermal Luçi
	<?php
608
	$counter = 0;
609
	$address = $pconfig['address'];
610
	if ($address <> "") {
611
		$item = explode(" ", $address);
612
		$item3 = explode("||", $pconfig['detail']);
613
		foreach($item as $ww) {
614
			$address = $item[$counter];
615
			$address_subnet = "";
616
			$item2 = explode("/", $address);
617
			foreach($item2 as $current) {
618
				if($item2[1] <> "") {
619
					$address = $item2[0];
620
					$address_subnet = $item2[1];
621 d2cfb7a4 Scott Ullrich
				}
622 6c33fb4b Ermal
				
623 0d3f3e90 Ermal Luçi
			}
624
			$item4 = $item3[$counter];
625
			$tracker = $counter;
626
	?>
627 5a1eebc7 Scott Ullrich
          <tr>
628
            <td>
629 0cea9a23 Ermal Lu?i
              <input autocomplete="off" name="address<?php echo $tracker; ?>" type="text" class="formfldalias" id="address<?php echo $tracker; ?>" size="30" value="<?=htmlspecialchars($address);?>" />
630 5a1eebc7 Scott Ullrich
            </td>
631
            <td>
632
			        <select name="address_subnet<?php echo $tracker; ?>" class="formselect" id="address_subnet<?php echo $tracker; ?>">
633 6c33fb4b Ermal
				<option></option>
634 5a1eebc7 Scott Ullrich
			          <?php for ($i = 32; $i >= 1; $i--): ?>
635 c7de8be4 jim-p
			          <option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected"; ?>><?=$i;?></option>
636 5a1eebc7 Scott Ullrich
			          <?php endfor; ?>
637
			        </select>
638
			      </td>
639
            <td>
640 b5c78501 Seth Mos
              <input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
641 5a1eebc7 Scott Ullrich
            </td>
642
            <td>
643 b6f3005c Ermal Luçi
    		<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
644
	      </td>
645 5a1eebc7 Scott Ullrich
          </tr>
646 0d3f3e90 Ermal Luçi
<?php
647
        	$counter++;
648 5a1eebc7 Scott Ullrich
649 0d3f3e90 Ermal Luçi
       		} // end foreach
650
	} // end if
651
?>
652 5a1eebc7 Scott Ullrich
        </tbody>
653
        <tfoot>
654
655
        </tfoot>
656
		  </table>
657 c7de8be4 jim-p
			<div id="addrowbutton"><a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
658
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" /></div>
659 5a1eebc7 Scott Ullrich
      </a>
660
		</td>
661
  </tr>
662
  <tr>
663
    <td width="22%" valign="top">&nbsp;</td>
664
    <td width="78%">
665
      <input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
666 b6f3005c Ermal Luçi
      <a href="firewall_aliases.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" /></a>
667 5a1eebc7 Scott Ullrich
    </td>
668
  </tr>
669
</table>
670 5b237745 Scott Ullrich
</form>
671 5a1eebc7 Scott Ullrich
672
<script type="text/javascript">
673
	field_counter_js = 3;
674
	rows = 1;
675
	totalrows = <?php echo $counter; ?>;
676
	loaded = <?php echo $counter; ?>;
677
	typesel_change();
678
	update_box_type();
679 0cea9a23 Ermal Lu?i
680
<?php
681
        $isfirst = 0;
682
        $aliases = "";
683
        $addrisfirst = 0;
684
        $aliasesaddr = "";
685
        if(isset($config['aliases']['alias']) && is_array($config['aliases']['alias']))
686
                foreach($config['aliases']['alias'] as $alias_name) {
687 5e34cdb2 Ermal Lu?i
			if ($pconfig['name'] <> "" && $pconfig['name'] == $alias_name['name'])
688
				continue;
689 0cea9a23 Ermal Lu?i
			if($addrisfirst == 1) $aliasesaddr .= ",";
690
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
691
			$addrisfirst = 1;
692
                }
693
?>
694
695
        var addressarray=new Array(<?php echo $aliasesaddr; ?>);
696
697 6c33fb4b Ermal
function createAutoSuggest() {
698 0cea9a23 Ermal Lu?i
<?php  
699
	for ($jv = 0; $jv < $counter; $jv++)
700
		echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
701
?>
702 6c33fb4b Ermal
}
703 0cea9a23 Ermal Lu?i
704 6c33fb4b Ermal
setTimeOut("createAutoSuggest();", 500);
705 0cea9a23 Ermal Lu?i
706 5b237745 Scott Ullrich
</script>
707 5a1eebc7 Scott Ullrich
708 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
709
</body>
710
</html>