Project

General

Profile

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