Project

General

Profile

Download (37.2 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 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
9 2e9ab96b Scott Ullrich
	All rights reserved.
10
11 bbd1f783 Phil Davis
	originally part of m0n0wall (http://m0n0.ch/wall)
12 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
	All rights reserved.
14 d2cfb7a4 Scott Ullrich
15 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
16
	modification, are permitted provided that the following conditions are met:
17 d2cfb7a4 Scott Ullrich
18 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
19
	   this list of conditions and the following disclaimer.
20 d2cfb7a4 Scott Ullrich
21 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
22
	   notice, this list of conditions and the following disclaimer in the
23
	   documentation and/or other materials provided with the distribution.
24 d2cfb7a4 Scott Ullrich
25 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
26
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
29
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
	POSSIBILITY OF SUCH DAMAGE.
35
*/
36 7ac5a4cb Scott Ullrich
/*
37
	pfSense_BUILDER_BINARIES:	/bin/rm	/bin/mkdir	/usr/bin/fetch
38
	pfSense_MODULE:	aliases
39
*/
40 5b237745 Scott Ullrich
41 6b07c15a Matthew Grooms
##|+PRIV
42
##|*IDENT=page-firewall-alias-edit
43
##|*NAME=Firewall: Alias: Edit page
44
##|*DESCR=Allow access to the 'Firewall: Alias: Edit' page.
45
##|*MATCH=firewall_aliases_edit.php*
46
##|-PRIV
47
48 5b237745 Scott Ullrich
require("guiconfig.inc");
49 7a927e67 Scott Ullrich
require_once("functions.inc");
50
require_once("filter.inc");
51
require_once("shaper.inc");
52 5b237745 Scott Ullrich
53 b13f7f80 Carlos Eduardo Ramos
$pgtitle = array(gettext("Firewall"),gettext("Aliases"),gettext("Edit"));
54
55 62424bdb Renato Botelho
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/firewall_aliases.php');
56
57 c48fdaa4 Renato Botelho
// Keywords not allowed in names
58
$reserved_keywords = array("all", "pass", "block", "out", "queue", "max", "min", "pptp", "pppoe", "L2TP", "OpenVPN", "IPsec");
59
60 24445691 Phil Davis
// Add all Load balance names to reserved_keywords
61 c48fdaa4 Renato Botelho
if (is_array($config['load_balancer']['lbpool']))
62
	foreach ($config['load_balancer']['lbpool'] as $lbpool)
63
		$reserved_keywords[] = $lbpool['name'];
64
65 7c9d8d71 Ermal Lu?i
$reserved_ifs = get_configured_interface_list(false, true);
66 c48fdaa4 Renato Botelho
$reserved_keywords = array_merge($reserved_keywords, $reserved_ifs, $reserved_table_names);
67 feb1953e Phil Davis
$max_alias_addresses = 5000;
68 7c9d8d71 Ermal Lu?i
69 5b237745 Scott Ullrich
if (!is_array($config['aliases']['alias']))
70
	$config['aliases']['alias'] = array();
71
$a_aliases = &$config['aliases']['alias'];
72 f29109d0 Renato Botelho
73 ac7f1763 Renato Botelho
$tab = $_REQUEST['tab'];
74
75 ed0b7949 Scott Ullrich
if($_POST)
76
	$origname = $_POST['origname'];
77
78
// Debugging
79 f5200c44 Scott Ullrich
if($debug)
80 552f5a6a Renato Botelho
	unlink_if_exists("{$g['tmp_path']}/alias_rename_log.txt");
81 ed0b7949 Scott Ullrich
82 5e34cdb2 Ermal Lu?i
function alias_same_type($name, $type) {
83
	global $config;
84 f29109d0 Renato Botelho
85 5e34cdb2 Ermal Lu?i
	foreach ($config['aliases']['alias'] as $alias) {
86
		if ($name == $alias['name']) {
87 d6c9ab97 Ermal Lu?i
			if (in_array($type, array("host", "network")) &&
88 5e34cdb2 Ermal Lu?i
				in_array($alias['type'], array("host", "network")))
89
				return true;
90
			if ($type  == $alias['type'])
91
				return true;
92
			else
93
				return false;
94
		}
95
	}
96
	return true;
97
}
98
99 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
100
	$id = $_GET['id'];
101
if (isset($_POST['id']) && is_numericint($_POST['id']))
102 5b237745 Scott Ullrich
	$id = $_POST['id'];
103
104
if (isset($id) && $a_aliases[$id]) {
105 ed0b7949 Scott Ullrich
	$original_alias_name = $a_aliases[$id]['name'];
106 5b237745 Scott Ullrich
	$pconfig['name'] = $a_aliases[$id]['name'];
107 ba393f6c Scott Dale
	$pconfig['detail'] = $a_aliases[$id]['detail'];
108
	$pconfig['address'] = $a_aliases[$id]['address'];
109 b4deddce Ermal Lu?i
	$pconfig['type'] = $a_aliases[$id]['type'];
110 ba393f6c Scott Dale
	$pconfig['descr'] = html_entity_decode($a_aliases[$id]['descr']);
111 e47c266d Scott Ullrich
112 dd042c51 Renato Botelho
	if(preg_match("/urltable/i", $a_aliases[$id]['type'])) {
113 c7de8be4 jim-p
		$pconfig['address'] = $a_aliases[$id]['url'];
114
		$pconfig['updatefreq'] = $a_aliases[$id]['updatefreq'];
115
	}
116 5a1eebc7 Scott Ullrich
	if($a_aliases[$id]['aliasurl'] <> "") {
117 c5eaef8e Renato Botelho
		if(is_array($a_aliases[$id]['aliasurl']))
118
			$pconfig['address'] = implode(" ", $a_aliases[$id]['aliasurl']);
119
		else
120 5a1eebc7 Scott Ullrich
			$pconfig['address'] = $a_aliases[$id]['aliasurl'];
121
	}
122 5b237745 Scott Ullrich
}
123
124
if ($_POST) {
125
	unset($input_errors);
126 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.");
127 5b237745 Scott Ullrich
128
	/* input validation */
129 0cd7ed19 Scott Ullrich
130 69d2ad77 Erik Fonnesbeck
	$reqdfields = explode(" ", "name");
131 bd413d76 Renato Botelho
	$reqdfieldsn = array(gettext("Name"));
132 69d2ad77 Erik Fonnesbeck
133 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
134 69d2ad77 Erik Fonnesbeck
135 0df6adf8 Bill Marquette
	$x = is_validaliasname($_POST['name']);
136
	if (!isset($x)) {
137 24148939 Carlos Eduardo Ramos
		$input_errors[] = gettext("Reserved word used for alias name.");
138 3deb92f7 Renato Botelho
	} else if ($_POST['type'] == "port" && (getservbyname($_POST['name'], "tcp") || getservbyname($_POST['name'], "udp"))) {
139 bd413d76 Renato Botelho
		$input_errors[] = gettext("Reserved word used for alias name.");
140 3deb92f7 Renato Botelho
	} else {
141
		if (is_validaliasname($_POST['name']) == false)
142 dc4a8b9e Chris Buechler
			$input_errors[] = gettext("The alias name must be less than 32 characters long, may not consist of only numbers, and may only contain the following characters") . " a-z, A-Z, 0-9, _.";
143 3deb92f7 Renato Botelho
	}
144 5b237745 Scott Ullrich
	/* check for name conflicts */
145 6c33fb4b Ermal
	if (empty($a_aliases[$id])) {
146 6b487ec6 Ermal
		foreach ($a_aliases as $alias) {
147
			if ($alias['name'] == $_POST['name']) {
148 24148939 Carlos Eduardo Ramos
				$input_errors[] = gettext("An alias with this name already exists.");
149 6b487ec6 Ermal
				break;
150
			}
151 5b237745 Scott Ullrich
		}
152
	}
153 5a1eebc7 Scott Ullrich
154 f76a479d sullrich
	/* Check for reserved keyword names */
155 f29109d0 Renato Botelho
	foreach($reserved_keywords as $rk)
156 f76a479d sullrich
		if($rk == $_POST['name'])
157 24148939 Carlos Eduardo Ramos
			$input_errors[] = sprintf(gettext("Cannot use a reserved keyword as alias name %s"), $rk);
158 f76a479d sullrich
159 cfa466bb Scott Ullrich
	/* check for name interface description conflicts */
160
	foreach($config['interfaces'] as $interface) {
161
		if($interface['descr'] == $_POST['name']) {
162 24148939 Carlos Eduardo Ramos
			$input_errors[] = gettext("An interface description with this name already exists.");
163 5a1eebc7 Scott Ullrich
			break;
164 cfa466bb Scott Ullrich
		}
165 5a1eebc7 Scott Ullrich
	}
166 f29109d0 Renato Botelho
167 ba393f6c Scott Dale
	$alias = array();
168 6c33fb4b Ermal
	$address = array();
169
	$final_address_details = array();
170 ba393f6c Scott Dale
	$alias['name'] = $_POST['name'];
171 c7de8be4 jim-p
172 dd042c51 Renato Botelho
	if (preg_match("/urltable/i", $_POST['type'])) {
173 c7de8be4 jim-p
		$address = "";
174
175 24445691 Phil Davis
		/* item is a url table type */
176 c7de8be4 jim-p
		if ($_POST['address0']) {
177
			/* fetch down and add in */
178 fd86d829 Cristian Feldman
			$_POST['address0'] = trim($_POST['address0']);
179 578c81b6 bcyrill
			$address[] = $_POST['address0'];
180 c7de8be4 jim-p
			$alias['url'] = $_POST['address0'];
181
			$alias['updatefreq'] = $_POST['address_subnet0'] ? $_POST['address_subnet0'] : 7;
182
			if (!is_URL($alias['url']) || empty($alias['url'])) {
183 24148939 Carlos Eduardo Ramos
				$input_errors[] = gettext("You must provide a valid URL.");
184 c7de8be4 jim-p
			} elseif (! process_alias_urltable($alias['name'], $alias['url'], 0, true)) {
185 24148939 Carlos Eduardo Ramos
				$input_errors[] = gettext("Unable to fetch usable data.");
186 c7de8be4 jim-p
			}
187 24445691 Phil Davis
			if ($_POST["detail0"] <> "") {
188
				if ((strpos($_POST["detail0"], "||") === false) && (substr($_POST["detail0"], 0, 1) != "|") && (substr($_POST["detail0"], -1, 1) != "|")) {
189
					$final_address_details[] = $_POST["detail0"];
190
				} else {
191
					/* Remove leading and trailing vertical bars and replace multiple vertical bars with single, */
192
					/* and put in the output array so the text is at least redisplayed for the user. */
193
					$final_address_details[] = preg_replace('/\|\|+/', '|', trim($_POST["detail0"], "|"));
194
					$input_errors[] = $vertical_bar_err_text;
195
				}
196
			} else
197 0b9e4e8f Renato Botelho
				$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
198 c7de8be4 jim-p
		}
199 079d1952 Renato Botelho
	} else if ($_POST['type'] == "url" || $_POST['type'] == "url_ports") {
200 24445691 Phil Davis
		$desc_fmt_err_found = false;
201 ba393f6c Scott Dale
202
		/* item is a url type */
203 feb1953e Phil Davis
		for($x=0; $x<$max_alias_addresses-1; $x++) {
204 fd86d829 Cristian Feldman
			$_POST['address' . $x] = trim($_POST['address' . $x]);
205 ba393f6c Scott Dale
			if($_POST['address' . $x]) {
206
				/* fetch down and add in */
207 7c872d3b Scott Ullrich
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
208 552f5a6a Renato Botelho
				unlink_if_exists($temp_filename);
209 76590ffe Renato Botelho
				$verify_ssl = isset($config['system']['checkaliasesurlcert']);
210 d31ca336 Renato Botelho
				mkdir($temp_filename);
211 76590ffe Renato Botelho
				download_file($_POST['address' . $x], $temp_filename . "/aliases", $verify_ssl);
212
213 ba393f6c Scott Dale
				/* if the item is tar gzipped then extract */
214
				if(stristr($_POST['address' . $x], ".tgz"))
215
					process_alias_tgz($temp_filename);
216 86ffa26d Renato Botelho
				else if(stristr($_POST['address' . $x], ".zip"))
217
					process_alias_unzip($temp_filename);
218 ae5f96c8 Renato Botelho
219
				if (!isset($alias['aliasurl']))
220
					$alias['aliasurl'] = array();
221
222
				$alias['aliasurl'][] = $_POST['address' . $x];
223 24445691 Phil Davis
				if ($_POST["detail{$x}"] <> "") {
224
					if ((strpos($_POST["detail{$x}"], "||") === false) && (substr($_POST["detail{$x}"], 0, 1) != "|") && (substr($_POST["detail{$x}"], -1, 1) != "|")) {
225
						$final_address_details[] = $_POST["detail{$x}"];
226
					} else {
227
						/* Remove leading and trailing vertical bars and replace multiple vertical bars with single, */
228
						/* and put in the output array so the text is at least redisplayed for the user. */
229
						$final_address_details[] = preg_replace('/\|\|+/', '|', trim($_POST["detail{$x}"], "|"));
230
						if (!$desc_fmt_err_found) {
231
							$input_errors[] = $vertical_bar_err_text;
232
							$desc_fmt_err_found = true;
233
						}
234
					}
235
				} else
236 ae5f96c8 Renato Botelho
					$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
237
238 ba393f6c Scott Dale
				if(file_exists("{$temp_filename}/aliases")) {
239 6d1907a3 Renato Botelho
					$address = parse_aliases_file("{$temp_filename}/aliases", $_POST['type'], 3000);
240
					if($address == null) {
241 ba393f6c Scott Dale
						/* nothing was found */
242 7cbeade1 Renato Botelho
						$input_errors[] = sprintf(gettext("You must provide a valid URL. Could not fetch usable data from '%s'."), $_POST['address' . $x]);
243 5a1eebc7 Scott Ullrich
					}
244 d31ca336 Renato Botelho
					mwexec("/bin/rm -rf " . escapeshellarg($temp_filename));
245 ba393f6c Scott Dale
				} else {
246 7cbeade1 Renato Botelho
					$input_errors[] = sprintf(gettext("URL '%s' is not valid."), $_POST['address' . $x]);
247 5a1eebc7 Scott Ullrich
				}
248
			}
249 ba393f6c Scott Dale
		}
250 24445691 Phil Davis
		unset($desc_fmt_err_found);
251 079d1952 Renato Botelho
		if ($_POST['type'] == "url_ports")
252
			$address = group_ports($address);
253 ba393f6c Scott Dale
	} else {
254
		/* item is a normal alias type */
255 5e34cdb2 Ermal Lu?i
		$wrongaliases = "";
256 24445691 Phil Davis
		$desc_fmt_err_found = false;
257 feb1953e Phil Davis
		$alias_address_count = 0;
258 055a43d2 Phil Davis
259
		// First trim and expand the input data. 
260
		// Users can paste strings like "10.1.2.0/24 10.3.0.0/16 9.10.11.0/24" into an address box.
261
		// They can also put an IP range.
262
		// This loop expands out that stuff so it can easily be validated.
263 feb1953e Phil Davis
		for($x=0; $x<($max_alias_addresses-1); $x++) {
264 b6f3005c Ermal Luçi
			if($_POST["address{$x}"] <> "") {
265 24445691 Phil Davis
				if ($_POST["detail{$x}"] <> "") {
266
					if ((strpos($_POST["detail{$x}"], "||") === false) && (substr($_POST["detail{$x}"], 0, 1) != "|") && (substr($_POST["detail{$x}"], -1, 1) != "|")) {
267 055a43d2 Phil Davis
						$detail_text = $_POST["detail{$x}"];
268 24445691 Phil Davis
					} else {
269
						/* Remove leading and trailing vertical bars and replace multiple vertical bars with single, */
270
						/* and put in the output array so the text is at least redisplayed for the user. */
271 055a43d2 Phil Davis
						$detail_text = preg_replace('/\|\|+/', '|', trim($_POST["detail{$x}"], "|"));
272 24445691 Phil Davis
						if (!$desc_fmt_err_found) {
273
							$input_errors[] = $vertical_bar_err_text;
274
							$desc_fmt_err_found = true;
275
						}
276
					}
277 6b18c66b Phil Davis
				} else {
278 055a43d2 Phil Davis
					$detail_text = sprintf(gettext("Entry added %s"), date('r'));
279
				}
280
				$address_items = explode(" ", trim($_POST["address{$x}"]));
281
				foreach ($address_items as $address_item) {
282 feb1953e Phil Davis
					$iprange_type = is_iprange($address_item);
283
					if ($iprange_type == 4) {
284 055a43d2 Phil Davis
						list($startip, $endip) = explode('-', $address_item);
285 feb1953e Phil Davis
						if ($_POST['type'] == "network") {
286
							// For network type aliases, expand an IPv4 range into an array of subnets.
287
							$rangesubnets = ip_range_to_subnet_array($startip, $endip);
288
							foreach ($rangesubnets as $rangesubnet) {
289
								if ($alias_address_count > $max_alias_addresses) {
290
									break;
291
								}
292
								list($address_part, $subnet_part) = explode("/", $rangesubnet);
293
								$input_addresses[] = $address_part;
294
								$input_address_subnet[] = $subnet_part;
295
								$final_address_details[] = $detail_text;
296
								$alias_address_count++;
297
							}
298
						} else {
299
							// For host type aliases, expand an IPv4 range into a list of individual IPv4 addresses.
300
							$rangeaddresses = ip_range_to_address_array($startip, $endip, $max_alias_addresses - $alias_address_count);
301
							if (is_array($rangeaddresses)) {
302
								foreach ($rangeaddresses as $rangeaddress) {
303
									$input_addresses[] = $rangeaddress;
304
									$input_address_subnet[] = "";
305
									$final_address_details[] = $detail_text;
306
									$alias_address_count++;
307
								}
308
							} else {
309
								$input_errors[] = sprintf(gettext('Range is too large to expand into individual host IP addresses (%s)'), $address_item);
310
								$input_errors[] = sprintf(gettext('The maximum number of entries in an alias is %s'), $max_alias_addresses);
311
								// Put the user-entered data in the output anyway, so it will be re-displayed for correction.
312
								$input_addresses[] = $address_item;
313
								$input_address_subnet[] = "";
314
								$final_address_details[] = $detail_text;
315
							}
316 055a43d2 Phil Davis
						}
317 feb1953e Phil Davis
					} else if ($iprange_type == 6) {
318
						$input_errors[] = sprintf(gettext('IPv6 address ranges are not supported (%s)'), $address_item);
319
						// Put the user-entered data in the output anyway, so it will be re-displayed for correction.
320
						$input_addresses[] = $address_item;
321
						$input_address_subnet[] = "";
322 055a43d2 Phil Davis
						$final_address_details[] = $detail_text;
323 feb1953e Phil Davis
					} else {
324
						$subnet_type = is_subnet($address_item);
325
						if (($_POST['type'] == "host") && $subnet_type) {
326
							if ($subnet_type == 4) {
327
								// For host type aliases, if the user enters an IPv4 subnet, expand it into a list of individual IPv4 addresses.
328
								if (subnet_size($address_item) <= ($max_alias_addresses - $alias_address_count)) {
329
									$rangeaddresses = subnetv4_expand($address_item);
330
									foreach ($rangeaddresses as $rangeaddress) {
331
										$input_addresses[] = $rangeaddress;
332
										$input_address_subnet[] = "";
333
										$final_address_details[] = $detail_text;
334
										$alias_address_count++;
335
									}
336
								} else {
337
									$input_errors[] = sprintf(gettext('Subnet is too large to expand into individual host IP addresses (%s)'), $address_item);
338
									$input_errors[] = sprintf(gettext('The maximum number of entries in an alias is %s'), $max_alias_addresses);
339
									// Put the user-entered data in the output anyway, so it will be re-displayed for correction.
340
									$input_addresses[] = $address_item;
341
									$input_address_subnet[] = "";
342
									$final_address_details[] = $detail_text;
343
								}
344
							} else {
345
								$input_errors[] = sprintf(gettext('IPv6 subnets are not supported in host aliases (%s)'), $address_item);
346
								// Put the user-entered data in the output anyway, so it will be re-displayed for correction.
347
								$input_addresses[] = $address_item;
348
								$input_address_subnet[] = "";
349
								$final_address_details[] = $detail_text;
350
							}
351
						} else {
352
							list($address_part, $subnet_part) = explode("/", $address_item);
353
							if (!empty($subnet_part)) {
354
								if (is_subnet($address_item)) {
355
									$input_addresses[] = $address_part;
356
									$input_address_subnet[] = $subnet_part;
357
								} else {
358
									// The user typed something like "1.2.3.444/24" or "1.2.3.0/36" or similar rubbish.
359
									// Feed it through without splitting it apart, then it will be caught by the validation loop below.
360
									$input_addresses[] = $address_item;
361
									$input_address_subnet[] = "";
362
								}
363
							} else {
364
								$input_addresses[] = $address_part;
365
								$input_address_subnet[] = $_POST["address_subnet{$x}"];
366
							}
367
							$final_address_details[] = $detail_text;
368
							$alias_address_count++;
369
						}
370
					}
371
					if ($alias_address_count > $max_alias_addresses) {
372
						$input_errors[] = sprintf(gettext('The maximum number of entries in an alias has been exceeded (%s)'), $max_alias_addresses);
373
						break;
374 055a43d2 Phil Davis
					}
375
				}
376
			}
377
		}
378
379
		// Validate the input data expanded above.
380
		foreach($input_addresses as $idx => $input_address) {
381
			if (is_alias($input_address)) {
382
				if (!alias_same_type($input_address, $_POST['type']))
383
					// But alias type network can include alias type urltable. Feature#1603.
384
					if (!($_POST['type'] == 'network' &&
385
						  preg_match("/urltable/i", alias_get_type($input_address))))
386
						$wrongaliases .= " " . $input_address;
387
			} else if ($_POST['type'] == "port") {
388
				if (!is_port($input_address) && !is_portrange($input_address))
389
					$input_errors[] = $input_address . " " . gettext("is not a valid port or alias.");
390
			} else if ($_POST['type'] == "host" || $_POST['type'] == "network") {
391
				if (is_subnet($input_address) || 
392
					(!is_ipaddr($input_address) && !is_hostname($input_address)))
393
					$input_errors[] = sprintf(gettext('%1$s is not a valid %2$s address, FQDN or alias.'), $input_address, $_POST['type']);
394
			}
395
			$tmpaddress = $input_address;
396
			if ($_POST['type'] != "host" && is_ipaddr($input_address) && $input_address_subnet[$idx] <> "") {
397
				if (!is_subnet($input_address . "/" . $input_address_subnet[$idx]))
398
					$input_errors[] = sprintf(gettext('%s/%s is not a valid subnet.'), $input_address, $input_address_subnet[$idx]);
399
				else
400
					$tmpaddress .= "/" . $input_address_subnet[$idx];
401 5e34cdb2 Ermal Lu?i
			}
402 055a43d2 Phil Davis
			$address[] = $tmpaddress;
403 d2cfb7a4 Scott Ullrich
		}
404 24445691 Phil Davis
		unset($desc_fmt_err_found);
405 5e34cdb2 Ermal Lu?i
		if ($wrongaliases <> "")
406 bcc8d8a3 Erik Fonnesbeck
			$input_errors[] = sprintf(gettext('The alias(es): %s cannot be nested because they are not of the same type.'), $wrongaliases);
407 ba393f6c Scott Dale
	}
408 d2cfb7a4 Scott Ullrich
409 24445691 Phil Davis
	unset($vertical_bar_err_text);
410
411 f29109d0 Renato Botelho
	// Allow extending of the firewall edit page and include custom input validation
412 439cc13f Scott Ullrich
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
413
414 ba393f6c Scott Dale
	if (!$input_errors) {
415 c7de8be4 jim-p
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
416 d865241e jim-p
		$alias['descr'] = $_POST['descr'];
417 ba393f6c Scott Dale
		$alias['type'] = $_POST['type'];
418 6c33fb4b Ermal
		$alias['detail'] = implode("||", $final_address_details);
419 d2cfb7a4 Scott Ullrich
420 ed0b7949 Scott Ullrich
		/*   Check to see if alias name needs to be
421
		 *   renamed on referenced rules and such
422
		 */
423
		if ($_POST['name'] <> $_POST['origname']) {
424
			// Firewall rules
425 f1ac1733 Erik Fonnesbeck
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $_POST['name'], $origname);
426
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
427
			update_alias_names_upon_change(array('filter', 'rule'), array('source', 'port'), $_POST['name'], $origname);
428
			update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
429 ed0b7949 Scott Ullrich
			// NAT Rules
430 f1ac1733 Erik Fonnesbeck
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $_POST['name'], $origname);
431
			update_alias_names_upon_change(array('nat', 'rule'), array('source', 'port'), $_POST['name'], $origname);
432
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
433
			update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'port'), $_POST['name'], $origname);
434
			update_alias_names_upon_change(array('nat', 'rule'), array('target'), $_POST['name'], $origname);
435
			update_alias_names_upon_change(array('nat', 'rule'), array('local-port'), $_POST['name'], $origname);
436 b43b7613 Erik Fonnesbeck
			// NAT 1:1 Rules
437
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('external'), $_POST['name'], $origname);
438
			//update_alias_names_upon_change(array('nat', 'onetoone'), array('source', 'address'), $_POST['name'], $origname);
439
			update_alias_names_upon_change(array('nat', 'onetoone'), array('destination', 'address'), $_POST['name'], $origname);
440
			// NAT Outbound Rules
441
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $_POST['name'], $origname);
442 ca640261 Erik Fonnesbeck
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $_POST['name'], $origname);
443 b43b7613 Erik Fonnesbeck
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $_POST['name'], $origname);
444 ca640261 Erik Fonnesbeck
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $_POST['name'], $origname);
445 b43b7613 Erik Fonnesbeck
			update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('target'), $_POST['name'], $origname);
446 f43ba926 Scott Ullrich
			// Alias in an alias
447 f1ac1733 Erik Fonnesbeck
			update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $_POST['name'], $origname);
448 ed0b7949 Scott Ullrich
		}
449
450 b22bf161 Scott Ullrich
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
451
452 171aa30d Ermal Lu?i
		if (isset($id) && $a_aliases[$id]) {
453
			if ($a_aliases[$id]['name'] <> $alias['name']) {
454
				foreach ($a_aliases as $aliasid => $aliasd) {
455 16f78ff0 Ermal Lu?i
					if ($aliasd['address'] <> "") {
456 96b4269c Ermal Lu?i
						$tmpdirty = false;
457 16f78ff0 Ermal Lu?i
						$tmpaddr = explode(" ", $aliasd['address']);
458
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
459 96b4269c Ermal Lu?i
							if ($tmpalias == $a_aliases[$id]['name']) {
460 16f78ff0 Ermal Lu?i
								$tmpaddr[$tmpidx] = $alias['name'];
461 96b4269c Ermal Lu?i
								$tmpdirty = true;
462
							}
463 16f78ff0 Ermal Lu?i
						}
464 96b4269c Ermal Lu?i
						if ($tmpdirty == true)
465
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
466 16f78ff0 Ermal Lu?i
					}
467 171aa30d Ermal Lu?i
				}
468
			}
469 ba393f6c Scott Dale
			$a_aliases[$id] = $alias;
470 171aa30d Ermal Lu?i
		} else
471 ba393f6c Scott Dale
			$a_aliases[] = $alias;
472 a18b6b97 Scott Ullrich
473 974cbfe0 Ermal Lu?i
		// Sort list
474
		$a_aliases = msort($a_aliases, "name");
475
476 3a343d73 jim-p
		if (write_config())
477
			mark_subsystem_dirty('aliases');
478 d2cfb7a4 Scott Ullrich
479 ac7f1763 Renato Botelho
		if(!empty($tab))
480
			header("Location: firewall_aliases.php?tab=" . htmlspecialchars ($tab));
481 a5416de2 Warren Baker
		else
482
			header("Location: firewall_aliases.php");
483
		exit;
484 ba393f6c Scott Dale
	}
485
	//we received input errors, copy data to prevent retype
486
	else
487
	{
488 c7de8be4 jim-p
		$pconfig['name'] = $_POST['name'];
489 d865241e jim-p
		$pconfig['descr'] = $_POST['descr'];
490 079d1952 Renato Botelho
		if (($_POST['type'] == 'url') || ($_POST['type'] == 'url_ports'))
491 6a45942f Renato Botelho
			$pconfig['address'] = implode(" ", $alias['aliasurl']);
492
		else
493
			$pconfig['address'] = implode(" ", $address);
494 ba393f6c Scott Dale
		$pconfig['type'] = $_POST['type'];
495 6c33fb4b Ermal
		$pconfig['detail'] = implode("||", $final_address_details);
496 5b237745 Scott Ullrich
	}
497
}
498 da7ae7ef Bill Marquette
499
include("head.inc");
500
501 5a1eebc7 Scott Ullrich
$jscriptstr = <<<EOD
502 da7ae7ef Bill Marquette
503 5a1eebc7 Scott Ullrich
<script type="text/javascript">
504 709e62f0 Colin Fleming
//<![CDATA[
505 0cea9a23 Ermal Lu?i
var objAlias = new Array(4999);
506 5b237745 Scott Ullrich
function typesel_change() {
507 6794e407 Renato Botelho
	var field_disabled = 0;
508
	var field_value = "";
509
	var set_value = false;
510 5b237745 Scott Ullrich
	switch (document.iform.type.selectedIndex) {
511
		case 0:	/* host */
512 6794e407 Renato Botelho
			field_disabled = 1;
513
			field_value = "";
514
			set_value = true;
515 5b237745 Scott Ullrich
			break;
516
		case 1:	/* network */
517 6794e407 Renato Botelho
			field_disabled = 0;
518 5b237745 Scott Ullrich
			break;
519 4d6b6263 Scott Ullrich
		case 2:	/* port */
520 6794e407 Renato Botelho
			field_disabled = 1;
521
			field_value = "128";
522
			set_value = true;
523 4d6b6263 Scott Ullrich
			break;
524 aa11af07 jim-p
		case 3:	/* url */
525 6794e407 Renato Botelho
			field_disabled = 1;
526 6e7e1814 Scott Ullrich
			break;
527 079d1952 Renato Botelho
		case 4:	/* url_ports */
528 6794e407 Renato Botelho
			field_disabled = 1;
529 079d1952 Renato Botelho
			break;
530
		case 5:	/* urltable */
531 6794e407 Renato Botelho
			field_disabled = 0;
532 c7de8be4 jim-p
			break;
533 dd042c51 Renato Botelho
		case 6:	/* urltable_ports */
534 6794e407 Renato Botelho
			field_disabled = 0;
535 dd042c51 Renato Botelho
			break;
536 5b237745 Scott Ullrich
	}
537 6794e407 Renato Botelho
538 4dd00d25 Phil Davis
	jQuery("select[id^='address_subnet']").prop("disabled", field_disabled);
539
	if (set_value == true)
540
		jQuery("select[id^='address_subnet']").prop("value", field_value);
541 5b237745 Scott Ullrich
}
542 d2cfb7a4 Scott Ullrich
543 0cea9a23 Ermal Lu?i
function add_alias_control() {
544
	var name = "address" + (totalrows - 1);
545
	obj = document.getElementById(name);
546
	obj.setAttribute('class', 'formfldalias');
547
	obj.setAttribute('autocomplete', 'off');
548
	objAlias[totalrows - 1] = new AutoSuggestControl(obj, new StateSuggestions(addressarray));
549
}
550 5a1eebc7 Scott Ullrich
EOD;
551
552 bbd1f783 Phil Davis
$network_str = gettext("Network or FQDN");
553 5a1eebc7 Scott Ullrich
$networks_str = gettext("Network(s)");
554
$cidr_str = gettext("CIDR");
555
$description_str = gettext("Description");
556
$hosts_str = gettext("Host(s)");
557 bbd1f783 Phil Davis
$ip_str = gettext("IP or FQDN");
558 5a1eebc7 Scott Ullrich
$ports_str = gettext("Port(s)");
559
$port_str = gettext("Port");
560 079d1952 Renato Botelho
$url_str = gettext("URL (IPs)");
561
$url_ports_str = gettext("URL (Ports)");
562 dd042c51 Renato Botelho
$urltable_str = gettext("URL Table (IPs)");
563
$urltable_ports_str = gettext("URL Table (Ports)");
564 2b6e6fee Renato Botelho
$update_freq_str = gettext("Update Freq. (days)");
565 5a1eebc7 Scott Ullrich
566 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.");
567 feb1953e Phil Davis
$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. You may also enter an IP range such as 192.168.1.1-192.168.1.10 or a small subnet such as 192.168.1.16/28 and a list of individual IP addresses will be generated.");
568 5aa68a55 Renato Botelho
$ports_help = gettext("Enter as many ports as you wish.  Port ranges can be expressed by separating with a colon.");
569 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']);
570 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']);
571 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']);
572 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']);
573 5a1eebc7 Scott Ullrich
574 3ebd97eb Scott Ullrich
$openvpn_str = gettext("Username");
575
$openvpn_user_str = gettext("OpenVPN Users");
576
$openvpn_help = gettext("Enter as many usernames as you wish.");
577 bd413d76 Renato Botelho
$openvpn_freq = "";
578 3ebd97eb Scott Ullrich
579 5a1eebc7 Scott Ullrich
$jscriptstr .= <<<EOD
580
581 d2cfb7a4 Scott Ullrich
function update_box_type() {
582
	var indexNum = document.forms[0].type.selectedIndex;
583
	var selected = document.forms[0].type.options[indexNum].text;
584 5a1eebc7 Scott Ullrich
	if(selected == '{$networks_str}') {
585
		document.getElementById ("addressnetworkport").firstChild.data = "{$networks_str}";
586
		document.getElementById ("onecolumn").firstChild.data = "{$network_str}";
587
		document.getElementById ("twocolumn").firstChild.data = "{$cidr_str}";
588
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
589 bbd1f783 Phil Davis
		document.getElementById ("threecolumn").style.display = 'block';
590 5a1eebc7 Scott Ullrich
		document.getElementById ("itemhelp").firstChild.data = "{$networks_help}";
591 c7de8be4 jim-p
		document.getElementById ("addrowbutton").style.display = 'block';
592 5a1eebc7 Scott Ullrich
	} else if(selected == '{$hosts_str}') {
593
		document.getElementById ("addressnetworkport").firstChild.data = "{$hosts_str}";
594
		document.getElementById ("onecolumn").firstChild.data = "{$ip_str}";
595
		document.getElementById ("twocolumn").firstChild.data = "";
596
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
597 bbd1f783 Phil Davis
		document.getElementById ("threecolumn").style.display = 'block';
598 5a1eebc7 Scott Ullrich
		document.getElementById ("itemhelp").firstChild.data = "{$hosts_help}";
599 c7de8be4 jim-p
		document.getElementById ("addrowbutton").style.display = 'block';
600 5a1eebc7 Scott Ullrich
	} else if(selected == '{$ports_str}') {
601
		document.getElementById ("addressnetworkport").firstChild.data = "{$ports_str}";
602
		document.getElementById ("onecolumn").firstChild.data = "{$port_str}";
603
		document.getElementById ("twocolumn").firstChild.data = "";
604
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
605 bbd1f783 Phil Davis
		document.getElementById ("threecolumn").style.display = 'block';
606 5a1eebc7 Scott Ullrich
		document.getElementById ("itemhelp").firstChild.data = "{$ports_help}";
607 c7de8be4 jim-p
		document.getElementById ("addrowbutton").style.display = 'block';
608 5a1eebc7 Scott Ullrich
	} else if(selected == '{$url_str}') {
609
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
610
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
611 a0fc25ae Scott Ullrich
		document.getElementById ("twocolumn").firstChild.data = "";
612 5a1eebc7 Scott Ullrich
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
613 bbd1f783 Phil Davis
		document.getElementById ("threecolumn").style.display = 'block';
614 5a1eebc7 Scott Ullrich
		document.getElementById ("itemhelp").firstChild.data = "{$url_help}";
615 c7de8be4 jim-p
		document.getElementById ("addrowbutton").style.display = 'block';
616 079d1952 Renato Botelho
	} else if(selected == '{$url_ports_str}') {
617
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_ports_str}";
618
		document.getElementById ("onecolumn").firstChild.data = "{$url_ports_str}";
619
		document.getElementById ("twocolumn").firstChild.data = "";
620
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
621 bbd1f783 Phil Davis
		document.getElementById ("threecolumn").style.display = 'block';
622 079d1952 Renato Botelho
		document.getElementById ("itemhelp").firstChild.data = "{$url_ports_help}";
623
		document.getElementById ("addrowbutton").style.display = 'block';
624 6e7e1814 Scott Ullrich
	} else if(selected == '{$openvpn_user_str}') {
625
		document.getElementById ("addressnetworkport").firstChild.data = "{$openvpn_user_str}";
626 3ebd97eb Scott Ullrich
		document.getElementById ("onecolumn").firstChild.data = "{$openvpn_str}";
627 4c743413 Scott Ullrich
		document.getElementById ("twocolumn").firstChild.data = "{$openvpn_freq}";
628 6e7e1814 Scott Ullrich
		document.getElementById ("threecolumn").firstChild.data = "{$description_str}";
629 bbd1f783 Phil Davis
		document.getElementById ("threecolumn").style.display = 'block';
630 3ebd97eb Scott Ullrich
		document.getElementById ("itemhelp").firstChild.data = "{$openvpn_help}";
631 c7de8be4 jim-p
		document.getElementById ("addrowbutton").style.display = 'block';
632
	} else if(selected == '{$urltable_str}') {
633
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
634
			addRowTo('maintable', 'formfldalias');
635
			typesel_change();
636
			add_alias_control(this);
637
		}
638
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
639
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
640
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
641
		document.getElementById ("threecolumn").firstChild.data = "";
642
		document.getElementById ("threecolumn").style.display = 'none';
643
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_help}";
644
		document.getElementById ("addrowbutton").style.display = 'none';
645 dd042c51 Renato Botelho
	} else if(selected == '{$urltable_ports_str}') {
646
		if ((typeof(totalrows) == "undefined") || (totalrows < 1)) {
647
			addRowTo('maintable', 'formfldalias');
648
			typesel_change();
649
			add_alias_control(this);
650
		}
651
		document.getElementById ("addressnetworkport").firstChild.data = "{$url_str}";
652
		document.getElementById ("onecolumn").firstChild.data = "{$url_str}";
653
		document.getElementById ("twocolumn").firstChild.data = "{$update_freq_str}";
654
		document.getElementById ("threecolumn").firstChild.data = "";
655
		document.getElementById ("threecolumn").style.display = 'none';
656
		document.getElementById ("itemhelp").firstChild.data = "{$urltable_ports_help}";
657
		document.getElementById ("addrowbutton").style.display = 'none';
658 d2cfb7a4 Scott Ullrich
	}
659
}
660 709e62f0 Colin Fleming
//]]>
661 5b237745 Scott Ullrich
</script>
662
663 66138bf6 Scott Dale
EOD;
664 d2cfb7a4 Scott Ullrich
665 5a1eebc7 Scott Ullrich
?>
666 d2cfb7a4 Scott Ullrich
667 5a1eebc7 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC" onload="<?= $jsevents["body"]["onload"] ?>">
668
<?php
669
	include("fbegin.inc");
670
	echo $jscriptstr;
671
?>
672
673 709e62f0 Colin Fleming
<script type="text/javascript" src="/javascript/jquery.ipv4v6ify.js"></script>
674
<script type="text/javascript" src="/javascript/row_helper.js"></script>
675 6672609b Renato Botelho
<script type="text/javascript" src="/javascript/autosuggest.js?rev=1"></script>
676 709e62f0 Colin Fleming
<script type="text/javascript" src="/javascript/suggestions.js"></script>
677 d2cfb7a4 Scott Ullrich
678 5a1eebc7 Scott Ullrich
<input type='hidden' name='address_type' value='textbox' />
679
<input type='hidden' name='address_subnet_type' value='select' />
680 d2cfb7a4 Scott Ullrich
681 5a1eebc7 Scott Ullrich
<script type="text/javascript">
682 709e62f0 Colin Fleming
//<![CDATA[
683 5a1eebc7 Scott Ullrich
	rowname[0] = "address";
684 a8fe61f1 Darren Embry
	rowtype[0] = "textbox,ipv4v6";
685 5a1eebc7 Scott Ullrich
	rowsize[0] = "30";
686 d2cfb7a4 Scott Ullrich
687 5a1eebc7 Scott Ullrich
	rowname[1] = "address_subnet";
688 a8fe61f1 Darren Embry
	rowtype[1] = "select,ipv4v6";
689 5a1eebc7 Scott Ullrich
	rowsize[1] = "1";
690 d2cfb7a4 Scott Ullrich
691 5a1eebc7 Scott Ullrich
	rowname[2] = "detail";
692
	rowtype[2] = "textbox";
693 b6f3005c Ermal Luçi
	rowsize[2] = "50";
694 709e62f0 Colin Fleming
//]]>
695 d2cfb7a4 Scott Ullrich
</script>
696
697 193716d0 Scott Ullrich
<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_input_errors"); ?>
698 5b237745 Scott Ullrich
<?php if ($input_errors) print_input_errors($input_errors); ?>
699 5a1eebc7 Scott Ullrich
<div id="inputerrors"></div>
700
701
<form action="firewall_aliases_edit.php" method="post" name="iform" id="iform">
702 ac7f1763 Renato Botelho
<?php
703
if (empty($tab)) {
704 079d1952 Renato Botelho
	if (preg_match("/url/i", $pconfig['type']))
705 ac7f1763 Renato Botelho
		$tab = 'url';
706
	else if ($pconfig['type'] == 'host')
707
		$tab = 'ip';
708
	else
709
		$tab = $pconfig['type'];
710
}
711
?>
712
<input name="tab" type="hidden" id="tab" value="<?=htmlspecialchars($tab);?>" />
713 709e62f0 Colin Fleming
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="firewall aliases edit">
714 f29109d0 Renato Botelho
	<tr>
715
		<td colspan="2" valign="top" class="listtopic"><?=gettext("Alias Edit"); ?></td>
716
	</tr>
717
	<tr>
718
		<td valign="top" class="vncellreq"><?=gettext("Name"); ?></td>
719
		<td class="vtable">
720
			<input name="origname" type="hidden" id="origname" class="formfld unknown" size="40" value="<?=htmlspecialchars($pconfig['name']);?>" />
721 eab05c00 Renato Botelho
			<input name="name" type="text" id="name" class="formfld unknown" size="40" maxlength="31" value="<?=htmlspecialchars($pconfig['name']);?>" />
722 f29109d0 Renato Botelho
			<?php if (isset($id) && $a_aliases[$id]): ?>
723
				<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" />
724
			<?php endif; ?>
725
			<br />
726
			<span class="vexpl">
727
				<?=gettext("The name of the alias may only consist of the characters \"a-z, A-Z, 0-9 and _\"."); ?>
728
			</span>
729
		</td>
730
	</tr>
731
	<?php pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/after_first_tr"); ?>
732
	<tr>
733
		<td width="22%" valign="top" class="vncell"><?=gettext("Description"); ?></td>
734
		<td width="78%" class="vtable">
735
			<input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
736
			<br />
737
			<span class="vexpl">
738
				<?=gettext("You may enter a description here for your reference (not parsed)."); ?>
739
			</span>
740
		</td>
741
	</tr>
742
	<tr>
743
		<td valign="top" class="vncellreq"><?=gettext("Type"); ?></td>
744
		<td class="vtable">
745
			<select name="type" class="formselect" id="type" onchange="update_box_type(); typesel_change();">
746 709e62f0 Colin Fleming
				<option value="host" <?php if ($pconfig['type'] == "host") echo "selected=\"selected\""; ?>><?=gettext("Host(s)"); ?></option>
747
				<option value="network" <?php if ($pconfig['type'] == "network") echo "selected=\"selected\""; ?>><?=gettext("Network(s)"); ?></option>
748 09a68ea4 Phil Davis
				<option value="port" <?php if (($pconfig['type'] == "port") || (empty($pconfig['type']) && ($tab == "port"))) echo "selected=\"selected\""; ?>><?=gettext("Port(s)"); ?></option>
749 709e62f0 Colin Fleming
				<!--<option value="openvpn" <?php if ($pconfig['type'] == "openvpn") echo "selected=\"selected\""; ?>><?=gettext("OpenVPN Users"); ?></option> -->
750 09a68ea4 Phil Davis
				<option value="url" <?php if (($pconfig['type'] == "url") || (empty($pconfig['type']) && ($tab == "url"))) echo "selected=\"selected\""; ?>><?=gettext("URL (IPs)");?></option>
751 079d1952 Renato Botelho
				<option value="url_ports" <?php if ($pconfig['type'] == "url_ports") echo "selected=\"selected\""; ?>><?=gettext("URL (Ports)");?></option>
752 dd042c51 Renato Botelho
				<option value="urltable" <?php if ($pconfig['type'] == "urltable") echo "selected=\"selected\""; ?>><?=gettext("URL Table (IPs)"); ?></option>
753
				<option value="urltable_ports" <?php if ($pconfig['type'] == "urltable_ports") echo "selected=\"selected\""; ?>><?=gettext("URL Table (Ports)"); ?></option>
754 f29109d0 Renato Botelho
			</select>
755
		</td>
756
	</tr>
757
	<tr>
758
		<td width="22%" valign="top" class="vncellreq"><div id="addressnetworkport"><?=gettext("Host(s)"); ?></div></td>
759
		<td width="78%" class="vtable">
760 709e62f0 Colin Fleming
			<table id="maintable" summary="maintable">
761 f29109d0 Renato Botelho
				<tbody>
762
					<tr>
763
						<td colspan="4">
764
							<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>
765
						</td>
766
					</tr>
767
					<tr>
768
						<td><div id="onecolumn"><?=gettext("Network"); ?></div></td>
769
						<td><div id="twocolumn">CIDR</div></td>
770
						<td><div id="threecolumn"><?=gettext("Description"); ?></div></td>
771
					</tr>
772
773
					<?php
774
					$counter = 0;
775 4e8a79a8 Renato Botelho
					if ($pconfig['address'] <> ""):
776
						$addresses = explode(" ", $pconfig['address']);
777
						$details = explode("||", $pconfig['detail']);
778
						while ($counter < count($addresses)):
779 feb1953e Phil Davis
							if (($pconfig['type'] != "host") && is_subnet($addresses[$counter])) {
780 4e8a79a8 Renato Botelho
								list($address, $address_subnet) = explode("/", $addresses[$counter]);
781
							} else {
782
								$address = $addresses[$counter];
783
								$address_subnet = "";
784 f29109d0 Renato Botelho
							}
785
					?>
786
					<tr>
787
						<td>
788 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);?>" />
789 f29109d0 Renato Botelho
						</td>
790
						<td>
791 4e8a79a8 Renato Botelho
							<select name="address_subnet<?php echo $counter; ?>" class="formselect ipv4v6" id="address_subnet<?php echo $counter; ?>">
792 f29109d0 Renato Botelho
								<option></option>
793
								<?php for ($i = 128; $i >= 1; $i--): ?>
794 709e62f0 Colin Fleming
									<option value="<?=$i;?>" <?php if (($i == $address_subnet) || ($i == $pconfig['updatefreq'])) echo "selected=\"selected\""; ?>><?=$i;?></option>
795 f29109d0 Renato Botelho
								<?php endfor; ?>
796
							</select>
797
						</td>
798
						<td>
799 92ca4bc3 jim-p
							<input name="detail<?php echo $counter; ?>" type="text" class="formfld unknown" id="detail<?php echo $counter; ?>" size="50" value="<?=htmlspecialchars($details[$counter]);?>" />
800 f29109d0 Renato Botelho
						</td>
801
						<td>
802
							<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>
803
						</td>
804
					</tr>
805
					<?php
806
						$counter++;
807
808 4e8a79a8 Renato Botelho
						endwhile;
809
					endif;
810 f29109d0 Renato Botelho
					?>
811
				</tbody>
812
			</table>
813
			<div id="addrowbutton">
814
				<a onclick="javascript:addRowTo('maintable', 'formfldalias'); typesel_change(); add_alias_control(this); return false;" href="#">
815
					<img border="0" src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" title="<?=gettext("add another entry"); ?>" />
816
				</a>
817
			</div>
818
		</td>
819
	</tr>
820
	<tr>
821
		<td width="22%" valign="top">&nbsp;</td>
822
		<td width="78%">
823
			<input id="submit" name="submit" type="submit" class="formbtn" value="<?=gettext("Save"); ?>" />
824 62424bdb Renato Botelho
			<input type="button" class="formbtn" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=$referer;?>'" />
825 5a1eebc7 Scott Ullrich
		</td>
826 f29109d0 Renato Botelho
	</tr>
827 5a1eebc7 Scott Ullrich
</table>
828 5b237745 Scott Ullrich
</form>
829 5a1eebc7 Scott Ullrich
830
<script type="text/javascript">
831 4dfd930e Darren Embry
//<![CDATA[
832 5a1eebc7 Scott Ullrich
	field_counter_js = 3;
833
	rows = 1;
834
	totalrows = <?php echo $counter; ?>;
835
	loaded = <?php echo $counter; ?>;
836
	typesel_change();
837
	update_box_type();
838 0cea9a23 Ermal Lu?i
839 dd760cfc r-duran
	var addressarray = <?= json_encode(array_exclude($pconfig['name'], get_alias_list($pconfig['type']))) ?>;
840 0cea9a23 Ermal Lu?i
841 4dfd930e Darren Embry
	function createAutoSuggest() {
842 f29109d0 Renato Botelho
		<?php
843 4dfd930e Darren Embry
		for ($jv = 0; $jv < $counter; $jv++)
844
			echo "objAlias[{$jv}] = new AutoSuggestControl(document.getElementById(\"address{$jv}\"), new StateSuggestions(addressarray));\n";
845
		?>
846
	}
847 0cea9a23 Ermal Lu?i
848 4dfd930e Darren Embry
	setTimeout("createAutoSuggest();", 500);
849
//]]>
850 5b237745 Scott Ullrich
</script>
851 5a1eebc7 Scott Ullrich
852 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
853
</body>
854
</html>