Project

General

Profile

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