Project

General

Profile

Download (21.6 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 2e9ab96b Scott Ullrich
	All rights reserved.
8
9
	originially part of m0n0wall (http://m0n0.ch/wall)
10 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12 d2cfb7a4 Scott Ullrich
13 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15 d2cfb7a4 Scott Ullrich
16 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18 d2cfb7a4 Scott Ullrich
19 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22 d2cfb7a4 Scott Ullrich
23 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34 7ac5a4cb Scott Ullrich
/*
35
	pfSense_BUILDER_BINARIES:	/bin/rm	/bin/mkdir	/usr/bin/fetch
36
	pfSense_MODULE:	aliases
37
*/
38 5b237745 Scott Ullrich
39 6b07c15a Matthew Grooms
##|+PRIV
40
##|*IDENT=page-firewall-alias-edit
41
##|*NAME=Firewall: Alias: Edit page
42
##|*DESCR=Allow access to the 'Firewall: Alias: Edit' page.
43
##|*MATCH=firewall_aliases_edit.php*
44
##|-PRIV
45
46 d88c6a9f Scott Ullrich
$pgtitle = array("Firewall","Aliases","Edit");
47 5a1eebc7 Scott Ullrich
48 5b237745 Scott Ullrich
require("guiconfig.inc");
49
50
if (!is_array($config['aliases']['alias']))
51
	$config['aliases']['alias'] = array();
52
53
aliases_sort();
54
$a_aliases = &$config['aliases']['alias'];
55 ed0b7949 Scott Ullrich
	
56
if($_POST)
57
	$origname = $_POST['origname'];
58
59
// Debugging
60 f5200c44 Scott Ullrich
if($debug)
61 7515fb4b Ermal Lu?i
	exec("rm -f {$g['tmp_path']}/alias_rename_log.txt");
62 ed0b7949 Scott Ullrich
63 5e34cdb2 Ermal Lu?i
function alias_same_type($name, $type) {
64
	global $config;
65
	
66
	foreach ($config['aliases']['alias'] as $alias) {
67
		if ($name == $alias['name']) {
68 d6c9ab97 Ermal Lu?i
			if (in_array($type, array("host", "network")) &&
69 5e34cdb2 Ermal Lu?i
				in_array($alias['type'], array("host", "network")))
70
				return true;
71
			if ($type  == $alias['type'])
72
				return true;
73
			else
74
				return false;
75
		}
76
	}
77
	return true;
78
}
79
80 5b237745 Scott Ullrich
$id = $_GET['id'];
81
if (isset($_POST['id']))
82
	$id = $_POST['id'];
83
84
if (isset($id) && $a_aliases[$id]) {
85 ed0b7949 Scott Ullrich
	$original_alias_name = $a_aliases[$id]['name'];
86 5b237745 Scott Ullrich
	$pconfig['name'] = $a_aliases[$id]['name'];
87 ba393f6c Scott Dale
	$pconfig['detail'] = $a_aliases[$id]['detail'];
88
	$pconfig['address'] = $a_aliases[$id]['address'];
89
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
90 e47c266d Scott Ullrich
91 cbe3ea96 Ermal Luçi
	/* optional if list */
92
	$iflist = get_configured_interface_with_descr(true, true);
93
	foreach ($iflist as $if => $ifdesc)
94
		if($ifdesc == $pconfig['descr']) 
95 e47c266d Scott Ullrich
			$input_errors[] = "Sorry, an interface is already named {$pconfig['descr']}.";
96
97 ba393f6c Scott Dale
	$addresses = explode(' ', $pconfig['address']);
98
	$address = explode("/", $addresses[0]);
99
	if ($address[1])
100
		$addresssubnettest = true;
101 d89924da Bill Marquette
	else
102 ba393f6c Scott Dale
		$addresssubnettest = false;	
103
	
104
	if ($addresssubnettest)
105 5b237745 Scott Ullrich
		$pconfig['type'] = "network";
106
	else
107 ba393f6c Scott Dale
		if (is_ipaddr($address[0]))
108 d89924da Bill Marquette
			$pconfig['type'] = "host";
109
		else
110
			$pconfig['type'] = "port";
111 5a1eebc7 Scott Ullrich
112
	if($a_aliases[$id]['aliasurl'] <> "") {
113
		$pconfig['type'] = "url";
114
		if(is_array($a_aliases[$id]['aliasurl'])) {
115
			$isfirst = 0;
116
			$pconfig['address'] = "";
117
			foreach($a_aliases[$id]['aliasurl'] as $aa) {
118
				if($isfirst == 1)
119
					$pconfig['address'] .= " ";
120
				$isfirst = 1;
121
				$pconfig['address'] .= $aa;
122
			}
123
		} else {
124
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
125
		}
126
	}
127 5b237745 Scott Ullrich
}
128
129
if ($_POST) {
130
131
	unset($input_errors);
132
	$pconfig = $_POST;
133
134
	/* input validation */
135 d27d8cdc Scott Ullrich
	if(strtolower($_POST['name']) == "pptp")
136 4fdff4ae Scott Ullrich
		$input_errors[] = gettext("Aliases may not be named PPTP.");
137 0cd7ed19 Scott Ullrich
138 0df6adf8 Bill Marquette
	$x = is_validaliasname($_POST['name']);
139
	if (!isset($x)) {
140
		$input_errors[] = "Reserved word used for alias name.";
141
	} else {
142
		if (is_validaliasname($_POST['name']) == false)
143 d87fc50b Seth Mos
			$input_errors[] = "The alias name may only consist of the characters a-z, A-Z, 0-9, _.";
144 beeef1f0 Bill Marquette
	}
145 5b237745 Scott Ullrich
	/* check for name conflicts */
146
	foreach ($a_aliases as $alias) {
147
		if (isset($id) && ($a_aliases[$id]) && ($a_aliases[$id] === $alias))
148
			continue;
149
150
		if ($alias['name'] == $_POST['name']) {
151
			$input_errors[] = "An alias with this name already exists.";
152
			break;
153
		}
154
	}
155 5a1eebc7 Scott Ullrich
156 cfa466bb Scott Ullrich
	/* check for name interface description conflicts */
157
	foreach($config['interfaces'] as $interface) {
158
		if($interface['descr'] == $_POST['name']) {
159 5a1eebc7 Scott Ullrich
			$input_errors[] = "An interface description with this name already exists.";
160
			break;
161 cfa466bb Scott Ullrich
		}
162 5a1eebc7 Scott Ullrich
	}
163 ba393f6c Scott Dale
	
164
	$alias = array();
165
	$alias['name'] = $_POST['name'];
166
	if($_POST['type'] == "url") {
167
		$address = "";
168 d2cfb7a4 Scott Ullrich
		$isfirst = 0;
169 ba393f6c Scott Dale
		$address_count = 2;
170
171
		/* item is a url type */
172 d8898df4 Scott Ullrich
		for($x=0; isset($_POST['address'. $x]); $x++) {
173 ba393f6c Scott Dale
			if($_POST['address' . $x]) {
174
				/* fetch down and add in */
175
				$isfirst = 0;
176 7c872d3b Scott Ullrich
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
177 ba393f6c Scott Dale
				unlink($temp_filename);
178 7515fb4b Ermal Lu?i
				$fda = fopen("{$g['tmp_path']}/tmpfetch","w");
179 ba393f6c Scott Dale
				fwrite($fda, "/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
180
				fclose($fda);
181 7ac5a4cb Scott Ullrich
				mwexec("/bin/mkdir -p {$temp_filename}");
182 ba393f6c Scott Dale
				mwexec("/usr/bin/fetch -q -o \"{$temp_filename}/aliases\" \"" . $_POST['address' . $x] . "\"");
183
				/* if the item is tar gzipped then extract */
184
				if(stristr($_POST['address' . $x], ".tgz"))
185
					process_alias_tgz($temp_filename);
186
				if(file_exists("{$temp_filename}/aliases")) {
187
					$file_contents = file_get_contents("{$temp_filename}/aliases");
188
					$file_contents = str_replace("#", "\n#", $file_contents);
189
					$file_contents_split = split("\n", $file_contents);
190
					foreach($file_contents_split as $fc) {
191
						$tmp = trim($fc);
192
						if(stristr($fc, "#")) {
193
							$tmp_split = split("#", $tmp);
194
							$tmp = trim($tmp_split[0]);
195 5a1eebc7 Scott Ullrich
						}
196 ba393f6c Scott Dale
						if(trim($tmp) <> "") {
197
							if($isfirst == 1)
198
								$address .= " ";
199
							$address .= $tmp;
200
							$isfirst = 1;
201 5a1eebc7 Scott Ullrich
						}
202 ba393f6c Scott Dale
					}
203
					if($isfirst == 0) {
204
						/* nothing was found */
205
						$input_errors[] = "You must provide a valid URL. Could not fetch usable data.";
206 5a1eebc7 Scott Ullrich
						$dont_update = true;
207
						break;
208
					}
209 ba393f6c Scott Dale
					$alias['aliasurl'][] = $_POST['address' . $x];
210
					mwexec("/bin/rm -rf {$temp_filename}");
211
				} else {
212
					$input_errors[] = "You must provide a valid URL.";
213
					$dont_update = true;
214
					break;
215 5a1eebc7 Scott Ullrich
				}
216
			}
217 ba393f6c Scott Dale
		}
218
	} else {
219 b6f3005c Ermal Luçi
		$address = "";
220
		$isfirst = 0;
221 ba393f6c Scott Dale
		/* item is a normal alias type */
222 5e34cdb2 Ermal Lu?i
		$wrongaliases = "";
223 a2d8d3dd Ermal Luçi
		for($x=0; $x<4999; $x++) {
224 b6f3005c Ermal Luçi
			if($_POST["address{$x}"] <> "") {
225
				if ($isfirst > 0)
226
					$address .= " ";
227
				$address .= $_POST["address{$x}"];
228 92b9f237 Ermal Lu?i
				if(is_ipaddr($_POST["address{$x}"]) && $_POST["address_subnet{$x}"] <> "") 
229 b6f3005c Ermal Luçi
					$address .= "/" . $_POST["address_subnet{$x}"];
230
231
	       			if($_POST["detail{$x}"] <> "") {
232
	       				$final_address_details .= $_POST["detail{$x}"];
233
	       			} else {
234
		       			$final_address_details .= "Entry added" . " ";
235
		       			$final_address_details .= date('r');
236
	       			}
237
	       			$final_address_details .= "||";
238
				$isfirst++;
239 d2cfb7a4 Scott Ullrich
			}
240 5e34cdb2 Ermal Lu?i
			if (is_alias($_POST["address{$x}"])) {
241
				if (!alias_same_type($_POST["address{$x}"], $_POST['type']))
242
					$wrongaliases .= " " . $_POST["address{$x}"];
243
			}
244 d2cfb7a4 Scott Ullrich
		}
245 5e34cdb2 Ermal Lu?i
		if ($wrongaliases <> "")
246
			$input_errors[] = "The following aliases: {$wrongaliases} \ncannot be nested cause they are not of the same type.";
247 ba393f6c Scott Dale
	}
248 d2cfb7a4 Scott Ullrich
249 ba393f6c Scott Dale
	if (!$input_errors) {
250
		$alias['address'] = $address;
251 ec3cedf7 Bill Marquette
		$alias['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
252 ba393f6c Scott Dale
		$alias['type'] = $_POST['type'];
253
		$alias['detail'] = $final_address_details;
254 d2cfb7a4 Scott Ullrich
255 ed0b7949 Scott Ullrich
		/*   Check to see if alias name needs to be
256
		 *   renamed on referenced rules and such
257
		 */
258
		if ($_POST['name'] <> $_POST['origname']) {
259
			// Firewall rules
260 978fd2e8 Scott Ullrich
			update_alias_names_upon_change('filter', 'rule', 'source', 'address', $_POST['name'], $origname);
261
			update_alias_names_upon_change('filter', 'rule', 'destination', 'address', $_POST['name'], $origname);
262 ed0b7949 Scott Ullrich
			// NAT Rules
263 978fd2e8 Scott Ullrich
			update_alias_names_upon_change('nat', 'rule', 'target', '', $_POST['name'], $origname);
264
			update_alias_names_upon_change('nat', 'rule', 'external-port', '', $_POST['name'], $origname);
265
			update_alias_names_upon_change('nat', 'rule', 'local-port', ''	, $_POST['name'], $origname);
266 f43ba926 Scott Ullrich
			// Alias in an alias
267 978fd2e8 Scott Ullrich
			update_alias_names_upon_change('aliases', 'alias', 'address', ''	, $_POST['name'], $origname);
268 ed0b7949 Scott Ullrich
		}
269
270 171aa30d Ermal Lu?i
		if (isset($id) && $a_aliases[$id]) {
271
			if ($a_aliases[$id]['name'] <> $alias['name']) {
272
				foreach ($a_aliases as $aliasid => $aliasd) {
273 16f78ff0 Ermal Lu?i
					if ($aliasd['address'] <> "") {
274 96b4269c Ermal Lu?i
						$tmpdirty = false;
275 16f78ff0 Ermal Lu?i
						$tmpaddr = explode(" ", $aliasd['address']);
276
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
277 96b4269c Ermal Lu?i
							if ($tmpalias == $a_aliases[$id]['name']) {
278 16f78ff0 Ermal Lu?i
								$tmpaddr[$tmpidx] = $alias['name'];
279 96b4269c Ermal Lu?i
								$tmpdirty = true;
280
							}
281 16f78ff0 Ermal Lu?i
						}
282 96b4269c Ermal Lu?i
						if ($tmpdirty == true)
283
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
284 16f78ff0 Ermal Lu?i
					}
285 171aa30d Ermal Lu?i
				}
286
			}
287 ba393f6c Scott Dale
			$a_aliases[$id] = $alias;
288 171aa30d Ermal Lu?i
		} else
289 ba393f6c Scott Dale
			$a_aliases[] = $alias;
290 a18b6b97 Scott Ullrich
291 a368a026 Ermal Lu?i
		mark_subsystem_dirty('aliases');
292 a18b6b97 Scott Ullrich
293 ba393f6c Scott Dale
		write_config();
294
		filter_configure();
295 d2cfb7a4 Scott Ullrich
296 ba393f6c Scott Dale
		header("Location: firewall_aliases.php");
297
		exit;		
298
	}
299
	//we received input errors, copy data to prevent retype
300
	else
301
	{
302 ec3cedf7 Bill Marquette
		$pconfig['descr'] = mb_convert_encoding($_POST['descr'],"HTML-ENTITIES","auto");
303 ba393f6c Scott Dale
		$pconfig['address'] = $address;
304
		$pconfig['type'] = $_POST['type'];
305 ec3cedf7 Bill Marquette
		$pconfig['detail'] = $final_address_details;
306 5b237745 Scott Ullrich
	}
307
}
308 da7ae7ef Bill Marquette
309
include("head.inc");
310
311 5a1eebc7 Scott Ullrich
$jscriptstr = <<<EOD
312 da7ae7ef Bill Marquette
313 5a1eebc7 Scott Ullrich
<script type="text/javascript">
314 0cea9a23 Ermal Lu?i
315
var objAlias = new Array(4999);
316 5b237745 Scott Ullrich
function typesel_change() {
317
	switch (document.iform.type.selectedIndex) {
318
		case 0:	/* host */
319 d2cfb7a4 Scott Ullrich
			var cmd;
320 5a1eebc7 Scott Ullrich
321 b6f3005c Ermal Luçi
			newrows = totalrows;
322
			for(i=0; i<newrows; i++) {
323 5a1eebc7 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
324
				eval(comd);
325
				comd = 'document.iform.address_subnet' + i + '.value = "";';
326
				eval(comd);
327 d2cfb7a4 Scott Ullrich
			}
328 5b237745 Scott Ullrich
			break;
329
		case 1:	/* network */
330 d2cfb7a4 Scott Ullrich
			var cmd;
331 5a1eebc7 Scott Ullrich
332 b6f3005c Ermal Luçi
			newrows = totalrows;
333
			for(i=0; i<newrows; i++) {
334 5a1eebc7 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
335
				eval(comd);
336 d2cfb7a4 Scott Ullrich
			}
337 5b237745 Scott Ullrich
			break;
338 4d6b6263 Scott Ullrich
		case 2:	/* port */
339
			var cmd;
340 5a1eebc7 Scott Ullrich
341 b6f3005c Ermal Luçi
			newrows = totalrows;
342
			for(i=0; i<newrows; i++) {
343 5a1eebc7 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
344
				eval(comd);
345
				comd = 'document.iform.address_subnet' + i + '.value = "32";';
346
				eval(comd);
347
			}
348
			break;
349 cd35a596 Scott Ullrich
		case 3:	/* OpenVPN Users */
350 5a1eebc7 Scott Ullrich
			var cmd;
351 cd35a596 Scott Ullrich
352 b6f3005c Ermal Luçi
			newrows = totalrows;
353
			for(i=0; i<newrows; i++) {
354 cd35a596 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 1;';
355
				eval(comd);
356
				comd = 'document.iform.address_subnet' + i + '.value = "";';
357 5a1eebc7 Scott Ullrich
				eval(comd);
358 4d6b6263 Scott Ullrich
			}
359
			break;
360 6e7e1814 Scott Ullrich
361 cd35a596 Scott Ullrich
		case 4:	/* url */
362 6e7e1814 Scott Ullrich
			var cmd;
363 b6f3005c Ermal Luçi
			newrows = totalrows;
364
			for(i=0; i<newrows; i++) {
365 6e7e1814 Scott Ullrich
				comd = 'document.iform.address_subnet' + i + '.disabled = 0;';
366
				eval(comd);
367
			}
368
			break;
369 5b237745 Scott Ullrich
	}
370
}
371 d2cfb7a4 Scott Ullrich
372 0cea9a23 Ermal Lu?i
function add_alias_control() {
373
	var name = "address" + (totalrows - 1);
374
	obj = document.getElementById(name);
375
	obj.setAttribute('class', 'formfldalias');
376
	obj.setAttribute('autocomplete', 'off');
377
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
378
}
379 5a1eebc7 Scott Ullrich
EOD;
380
381
$network_str = gettext("Network");
382
$networks_str = gettext("Network(s)");
383
$cidr_str = gettext("CIDR");
384
$description_str = gettext("Description");
385
$hosts_str = gettext("Host(s)");
386
$ip_str = gettext("IP");
387
$ports_str = gettext("Port(s)");
388
$port_str = gettext("Port");
389
$url_str = gettext("URL");
390
$update_freq_str = gettext("Update Freq.");
391
392 974ff781 Chris Buechler
$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.");
393
$hosts_help = gettext("Enter as many hosts as you would like.  Hosts must be specified by their IP address.");
394 5a1eebc7 Scott Ullrich
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by seperating with a colon.");
395
$url_help = gettext("Enter as many urls as you wish.  Also set the time that you would like the url refreshed in days.  After saving {$g['product_name']} will download the URL and import the items into the alias.");
396
397 3ebd97eb Scott Ullrich
$openvpn_str = gettext("Username");
398
$openvpn_user_str = gettext("OpenVPN Users");
399
$openvpn_help = gettext("Enter as many usernames as you wish.");
400 4c743413 Scott Ullrich
$openvpn_freq = gettext("");
401 3ebd97eb Scott Ullrich
402 5a1eebc7 Scott Ullrich
$jscriptstr .= <<<EOD
403
404 d2cfb7a4 Scott Ullrich
function update_box_type() {
405
	var indexNum = document.forms[0].type.selectedIndex;
406
	var selected = document.forms[0].type.options[indexNum].text;
407 5a1eebc7 Scott Ullrich
	if(selected == '{$networks_str}') {
408
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
409
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
410
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
411
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
412
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
413
	} else if(selected == '{$hosts_str}') {
414
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
415
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
416
		document.getElementById ("twocolumn").firstChild.data = "";
417
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
418
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
419
	} else if(selected == '{$ports_str}') {
420
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
421
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
422
		document.getElementById ("twocolumn").firstChild.data = "";
423
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
424
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
425
	} else if(selected == '{$url_str}') {
426
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
427
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
428
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
429
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
430
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
431 6e7e1814 Scott Ullrich
	} else if(selected == '{$openvpn_user_str}') {
432
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
433 3ebd97eb Scott Ullrich
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
434 4c743413 Scott Ullrich
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
435 6e7e1814 Scott Ullrich
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
436 3ebd97eb Scott Ullrich
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
437 d2cfb7a4 Scott Ullrich
	}
438
}
439 5b237745 Scott Ullrich
</script>
440
441 66138bf6 Scott Dale
EOD;
442 d2cfb7a4 Scott Ullrich
443 5a1eebc7 Scott Ullrich
?>
444 d2cfb7a4 Scott Ullrich
445 5a1eebc7 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
446
<?php
447
	include("fbegin.inc");
448
	echo $jscriptstr;
449
?>
450
451 625dcc40 Bill Marquette
<script type="text/javascript" src="/javascript/row_helper.js">
452 5a1eebc7 Scott Ullrich
</script>
453 0cea9a23 Ermal Lu?i
<script type="text/javascript" src="/javascript/autosuggest.js">
454
</script>
455
<script type="text/javascript" src="/javascript/suggestions.js">
456
</script>
457 d2cfb7a4 Scott Ullrich
458 5a1eebc7 Scott Ullrich
<input type='hidden' name='address_type' value='textbox' />
459
<input type='hidden' name='address_subnet_type' value='select' />
460 d2cfb7a4 Scott Ullrich
461 5a1eebc7 Scott Ullrich
<script type="text/javascript">
462
	rowname[0] = "address";
463
	rowtype[0] = "textbox";
464
	rowsize[0] = "30";
465 d2cfb7a4 Scott Ullrich
466 5a1eebc7 Scott Ullrich
	rowname[1] = "address_subnet";
467
	rowtype[1] = "select";
468
	rowsize[1] = "1";
469 d2cfb7a4 Scott Ullrich
470 5a1eebc7 Scott Ullrich
	rowname[2] = "detail";
471
	rowtype[2] = "textbox";
472 b6f3005c Ermal Luçi
	rowsize[2] = "50";
473 d2cfb7a4 Scott Ullrich
</script>
474
475 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
476 5a1eebc7 Scott Ullrich
<div id="inputerrors"></div>
477
478
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
479
<table width="100%" border="0" cellpadding="6" cellspacing="0">
480 c823d56b Scott Ullrich
  <tr>
481
	<td colspan="2" valign="top" class="listtopic">Alias Edit</td>
482
  </tr>
483 5a1eebc7 Scott Ullrich
  <tr>
484
    <td valign="top" class="vncellreq">Name</td>
485
    <td class="vtable">
486 ed0b7949 Scott Ullrich
      <input name="origname" type="hidden" id="origname" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
487 b5c78501 Seth Mos
      <input name="name" type="text" id="name" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
488 5a1eebc7 Scott Ullrich
      <br />
489
      <span class="vexpl">
490
        The name of the alias may only consist of the characters a-z, A-Z and 0-9.
491
      </span>
492
    </td>
493
  </tr>
494
  <tr>
495
    <td width="22%" valign="top" class="vncell">Description</td>
496
    <td width="78%" class="vtable">
497 b5c78501 Seth Mos
      <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=$pconfig['descr'];?>" />
498 5a1eebc7 Scott Ullrich
      <br />
499
      <span class="vexpl">
500
        You may enter a description here for your reference (not parsed).
501
      </span>
502
    </td>
503
  </tr>
504
  <tr>
505
    <td valign="top" class="vncellreq">Type</td>
506
    <td class="vtable">
507
      <select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
508
        <option value="host" <?php if ($pconfig['type'] == "host") echo "selected"; ?>>Host(s)</option>
509
        <option value="network" <?php if ($pconfig['type'] == "network") echo "selected"; ?>>Network(s)</option>
510
        <option value="port" <?php if ($pconfig['type'] == "port") echo "selected"; ?>>Port(s)</option>
511 b6f3005c Ermal Luçi
        <option value="openvpn" <?php if ($pconfig['type'] == "openvpn") echo "selected"; ?>>OpenVPN Users</option>
512 5a1eebc7 Scott Ullrich
      </select>
513
    </td>
514
  </tr>
515
  <tr>
516
    <td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport">Host(s)</div></td>
517
    <td width="78%" class="vtable">
518
      <table id="maintable">
519
        <tbody>
520
          <tr>
521
            <td colspan="4">
522
      		    <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>
523
            </td>
524
          </tr>
525
          <tr>
526
            <td><div id="onecolumn">Network</div></td>
527
            <td><div id="twocolumn">CIDR</div></td>
528
           <td><div id="threecolumn">Description</div></td>
529
          </tr>
530 d2cfb7a4 Scott Ullrich
531 0d3f3e90 Ermal Luçi
	<?php
532
	$counter = 0;
533
	$address = $pconfig['address'];
534
	if ($address <> "") {
535
		$item = explode(" ", $address);
536
		$item3 = explode("||", $pconfig['detail']);
537
		foreach($item as $ww) {
538
			$address = $item[$counter];
539
			$address_subnet = "";
540
			$item2 = explode("/", $address);
541
			foreach($item2 as $current) {
542
				if($item2[1] <> "") {
543
					$address = $item2[0];
544
					$address_subnet = $item2[1];
545 d2cfb7a4 Scott Ullrich
				}
546 0d3f3e90 Ermal Luçi
			}
547
			$item4 = $item3[$counter];
548
			$tracker = $counter;
549
	?>
550 5a1eebc7 Scott Ullrich
          <tr>
551
            <td>
552 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);?>" />
553 5a1eebc7 Scott Ullrich
            </td>
554
            <td>
555
			        <select name="address_subnet<?php echo $tracker; ?>" class="formselect" id="address_subnet<?php echo $tracker; ?>">
556
			          <option></option>
557
			          <?php for ($i = 32; $i >= 1; $i--): ?>
558
			          <option value="<?=$i;?>" <?php if ($i == $address_subnet) echo "selected"; ?>><?=$i;?></option>
559
			          <?php endfor; ?>
560
			        </select>
561
			      </td>
562
            <td>
563 b5c78501 Seth Mos
              <input name="detail<?php echo $tracker; ?>" type="text" class="formfld unknown" id="detail<?php echo $tracker; ?>" size="50" value="<?=$item4;?>" />
564 5a1eebc7 Scott Ullrich
            </td>
565
            <td>
566 b6f3005c Ermal Luçi
    		<input type="image" src="/themes/<?echo $g['theme'];?>/images/icons/icon_x.gif" onclick="removeRow(this); return false;" value="Delete" />
567
	      </td>
568 5a1eebc7 Scott Ullrich
          </tr>
569 0d3f3e90 Ermal Luçi
<?php
570
        	$counter++;
571 5a1eebc7 Scott Ullrich
572 0d3f3e90 Ermal Luçi
       		} // end foreach
573
	} // end if
574
?>
575 5a1eebc7 Scott Ullrich
        </tbody>
576
        <tfoot>
577
578
        </tfoot>
579
		  </table>
580 0cea9a23 Ermal Lu?i
			<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
581 5a1eebc7 Scott Ullrich
        <img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="add another entry" />
582
      </a>
583
		</td>
584
  </tr>
585
  <tr>
586
    <td width="22%" valign="top">&nbsp;</td>
587
    <td width="78%">
588
      <input id="submit" name="submit" type="submit" class="formbtn" value="Save" />
589 b6f3005c Ermal Luçi
      <a href="firewall_aliases.php"><input id="cancelbutton" name="cancelbutton" type="button" class="formbtn" value="Cancel" /></a>
590 5a1eebc7 Scott Ullrich
      <?php if (isset($id) && $a_aliases[$id]): ?>
591
      <input name="id" type="hidden" value="<?=$id;?>" />
592
      <?php endif; ?>
593
    </td>
594
  </tr>
595
</table>
596 5b237745 Scott Ullrich
</form>
597 5a1eebc7 Scott Ullrich
598
<script type="text/javascript">
599
	field_counter_js = 3;
600
	rows = 1;
601
	totalrows = <?php echo $counter; ?>;
602
	loaded = <?php echo $counter; ?>;
603
	typesel_change();
604
	update_box_type();
605 0cea9a23 Ermal Lu?i
606
<?php
607
        $isfirst = 0;
608
        $aliases = "";
609
        $addrisfirst = 0;
610
        $aliasesaddr = "";
611
        if(isset($config['aliases']['alias']) && is_array($config['aliases']['alias']))
612
                foreach($config['aliases']['alias'] as $alias_name) {
613 5e34cdb2 Ermal Lu?i
			if ($pconfig['name'] <> "" && $pconfig['name'] == $alias_name['name'])
614
				continue;
615 0cea9a23 Ermal Lu?i
			if($addrisfirst == 1) $aliasesaddr .= ",";
616
			$aliasesaddr .= "'" . $alias_name['name'] . "'";
617
			$addrisfirst = 1;
618
                }
619
?>
620
621
        var addressarray=new Array(<?php echo $aliasesaddr; ?>);
622
623
<?php  
624
	for ($jv = 0; $jv < $counter; $jv++)
625
		echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
626
?>
627
628
629 5b237745 Scott Ullrich
</script>
630 5a1eebc7 Scott Ullrich
631 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
632
</body>
633
</html>
634 5a1eebc7 Scott Ullrich
635
<?php
636
function process_alias_tgz($temp_filename) {
637
	mwexec("/bin/mv {$temp_filename}/aliases {$temp_filename}/aliases.tgz");
638
	mwexec("/usr/bin/tar xzf {$temp_filename}/aliases.tgz -C {$temp_filename}/aliases/");
639
	unlink("{$temp_filename}/aliases.tgz");
640
	$files_to_process = return_dir_as_array("{$temp_filename}/");
641
	/* foreach through all extracted files and build up aliases file */
642
	$fd = fopen("{$temp_filename}/aliases", "a");
643
	foreach($files_to_process as $f2p) {
644
		$file_contents = file_get_contents($f2p);
645
		fwrite($fd, $file_contents);
646
		unlink($f2p);
647
	}
648
	fclose($fd);
649
}
650 7ac5a4cb Scott Ullrich
651
?>