Project

General

Profile

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