Project

General

Profile

Download (22.1 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * alias-utils.inc
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
require_once("config.gui.inc");
29
require_once("functions.inc");
30
require_once("filter.inc");
31
require_once("shaper.inc");
32

    
33
init_config_arr(array('aliases', 'alias'));
34
$a_aliases = &$config['aliases']['alias'];
35

    
36
function deleteAlias($id, $apply = false) {
37
	global $config;
38

    
39
	/* make sure rule is not being referenced by any nat or filter rules */
40
	init_config_arr(array('aliases', 'alias'));
41
	$a_aliases = &$config['aliases']['alias'];
42

    
43
	$delete_error = "";
44
	$is_alias_referenced = false;
45
	$referenced_by = false;
46
	$alias_name = $a_aliases[$id]['name'];
47
	// Firewall rules
48
	find_alias_reference(array('filter', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
49
	find_alias_reference(array('filter', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
50
	find_alias_reference(array('filter', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
51
	find_alias_reference(array('filter', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
52
	// NAT Rules
53
	find_alias_reference(array('nat', 'rule'), array('source', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
54
	find_alias_reference(array('nat', 'rule'), array('source', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
55
	find_alias_reference(array('nat', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
56
	find_alias_reference(array('nat', 'rule'), array('destination', 'port'), $alias_name, $is_alias_referenced, $referenced_by);
57
	find_alias_reference(array('nat', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
58
	find_alias_reference(array('nat', 'rule'), array('local-port'), $alias_name, $is_alias_referenced, $referenced_by);
59
	// NAT 1:1 Rules
60
	find_alias_reference(array('nat', 'onetoone'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
61
	// NAT Outbound Rules
62
	find_alias_reference(array('nat', 'outbound', 'rule'), array('source', 'network'), $alias_name, $is_alias_referenced, $referenced_by);
63
	find_alias_reference(array('nat', 'outbound', 'rule'), array('sourceport'), $alias_name, $is_alias_referenced, $referenced_by);
64
	find_alias_reference(array('nat', 'outbound', 'rule'), array('destination', 'address'), $alias_name, $is_alias_referenced, $referenced_by);
65
	find_alias_reference(array('nat', 'outbound', 'rule'), array('dstport'), $alias_name, $is_alias_referenced, $referenced_by);
66
	find_alias_reference(array('nat', 'outbound', 'rule'), array('target'), $alias_name, $is_alias_referenced, $referenced_by);
67
	// Alias in an alias
68
	find_alias_reference(array('aliases', 'alias'), array('address'), $alias_name, $is_alias_referenced, $referenced_by);
69
	// Static routes
70
	find_alias_reference(array('staticroutes', 'route'), array('network'), $alias_name, $is_alias_referenced, $referenced_by);
71
	if ($is_alias_referenced == true) {
72
		$delete_error = sprintf(gettext("Cannot delete alias. Currently in use by %s."), htmlspecialchars($referenced_by));
73
	} else {
74
		if (preg_match("/urltable/i", $a_aliases[$id]['type'])) {
75
			// this is a URL table type alias, delete its file as well
76
			unlink_if_exists("/var/db/aliastables/" . $a_aliases[$id]['name'] . ".txt");
77
		}
78
		unset($a_aliases[$id]);
79
		if (write_config(gettext("Deleted firewall alias " . $a_aliases[$id]['name']))) {
80
			filter_configure();
81

    
82
			if (!$apply) {
83
				mark_subsystem_dirty('aliases');
84
			} 
85
		}
86
	}
87

    
88
	return $delete_error;
89
}
90

    
91
function find_alias_reference($section, $field, $origname, &$is_alias_referenced, &$referenced_by) {
92
	global $config;
93
	if (!$origname || $is_alias_referenced) {
94
		return;
95
	}
96

    
97
	$sectionref = &$config;
98
	foreach ($section as $sectionname) {
99
		if (is_array($sectionref) && isset($sectionref[$sectionname])) {
100
			$sectionref = &$sectionref[$sectionname];
101
		} else {
102
			return;
103
		}
104
	}
105

    
106
	if (is_array($sectionref)) {
107
		foreach ($sectionref as $itemkey => $item) {
108
			$fieldfound = true;
109
			$fieldref = &$sectionref[$itemkey];
110
			foreach ($field as $fieldname) {
111
				if (is_array($fieldref) && isset($fieldref[$fieldname])) {
112
					$fieldref = &$fieldref[$fieldname];
113
				} else {
114
					$fieldfound = false;
115
					break;
116
				}
117
			}
118
			/* explode() alias address string, see https://redmine.pfsense.org/issues/11372 */
119
			if ($fieldfound && in_array($origname, explode(' ', $fieldref))) {
120
				$is_alias_referenced = true;
121
				if (is_array($item)) {
122
					$referenced_by = $item['descr'];
123
				}
124
				break;
125
			}
126
		}
127
	}
128
}
129

    
130
function alias_same_type($name, $type) {
131
	global $config;
132

    
133
	foreach ($config['aliases']['alias'] as $alias) {
134
		if ($name == $alias['name']) {
135
			if (in_array($type, array("host", "network")) &&
136
			    in_array($alias['type'], array("host", "network"))) {
137
				return true;
138
			}
139

    
140
			if ($type == $alias['type']) {
141
				return true;
142
			} else {
143
				return false;
144
			}
145
		}
146
	}
147
	return true;
148
}
149

    
150
function saveAlias($post, $id) {
151
	global $config, $pf_reserved_keywords, $reserved_table_names, $pconfig;
152

    
153
	$origname = $post['origname'];
154
	$reserved_ifs = get_configured_interface_list(true);
155
	$pf_reserved_keywords = array_merge($pf_reserved_keywords, $reserved_ifs, $reserved_table_names);
156
	$max_alias_addresses = 5000;
157

    
158
	init_config_arr(array('aliases', 'alias'));
159
	$a_aliases = &$config['aliases']['alias'];
160

    
161
	$data_errors = array();
162

    
163
	$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.");
164

    
165
	/* input validation */
166

    
167
	$reqdfields = explode(" ", "name");
168
	$reqdfieldsn = array(gettext("Name"));
169

    
170
	do_local_input_validation($post, $reqdfields, $reqdfieldsn, $data_errors);
171

    
172
	if (!is_validaliasname($post['name'])) {
173
		$data_errors[] = invalidaliasnamemsg($post['name']);
174
	}
175

    
176
	/* check for name conflicts */
177
	foreach ($a_aliases as $key => $alias) {
178
		if (($alias['name'] == $post['name']) && (empty($a_aliases[$id]) || ($key != $id))) {
179
			$data_errors[] = gettext("An alias with this name already exists.");
180
			break;
181
		}
182
	}
183

    
184
	/* Check for reserved keyword names */
185
	foreach ($pf_reserved_keywords as $rk) {
186
		if (strcasecmp($rk, $post['name']) == 0) {
187
			$data_errors[] = sprintf(gettext("Cannot use a reserved keyword as an alias name: %s"), $rk);
188
		}
189
	}
190

    
191
	/*
192
	 * Packages (e.g. tinc) create interface groups, reserve this
193
	 * namespace pkg_ for them.
194
	 * One namespace is shared by Interfaces, Interface Groups and Aliases.
195
	 */
196
	if (substr($post['name'], 0, 4) == 'pkg_') {
197
		$data_errors[] = gettext("The alias name cannot start with pkg_");
198
	}
199

    
200
	/* check for name interface description conflicts */
201
	foreach ($config['interfaces'] as $interface) {
202
		if (strcasecmp($interface['descr'], $post['name']) == 0) {
203
			$data_errors[] = gettext("An interface description with this name already exists.");
204
			break;
205
		}
206
	}
207

    
208
	/* Is the description already used as an interface group name? */
209
	if (is_array($config['ifgroups']['ifgroupentry'])) {
210
		foreach ($config['ifgroups']['ifgroupentry'] as $ifgroupentry) {
211
			if ($ifgroupentry['ifname'] == $post['name']) {
212
				$data_errors[] = gettext("Sorry, an interface group with this name already exists.");
213
			}
214
		}
215
	}
216

    
217
	/* To prevent infinite loops make sure the alias name does not equal the value. */
218
	for($i = 0; isset($post['address' . $i]); $i++) {
219
			if($post['address' . $i] == $post['name']){
220
				$data_errors[] = gettext("Alias value cannot be the same as the alias name: `" . $post['name'] . " and " . $post['address' . $i] . "`");
221
			}
222
	}
223

    
224
	$alias = array();
225
	$address = array();
226
	$final_address_details = array();
227
	$alias['name'] = $post['name'];
228
	$alias['type'] = $post['type'];
229

    
230
	if (preg_match("/urltable/i", $post['type'])) {
231
		$address = array();
232

    
233
		/* item is a url table type */
234
		if ($post['address0']) {
235
			/* fetch down and add in */
236
			$address[] = $post['address0'];
237
			$alias['url'] = $post['address0'];
238
			$alias['updatefreq'] = $post['address_subnet0'] ? $post['address_subnet0'] : 7;
239
			if (!is_URL($alias['url']) || empty($alias['url'])) {
240
				$data_errors[] = gettext("A valid URL must be provided.");
241
			} elseif (!process_alias_urltable($alias['name'], $alias['type'], $alias['url'], 0, true, true)) {
242
				$data_errors[] = sprintf(gettext("Unable to fetch usable data from URL %s"), htmlspecialchars($alias['url']));
243
			}
244
			if ($post["detail0"] <> "") {
245
				if ((strpos($post["detail0"], "||") === false) && (substr($post["detail0"], 0, 1) != "|") && (substr($post["detail0"], -1, 1) != "|")) {
246
					$final_address_details[] = $post["detail0"];
247
				} else {
248
					/* Remove leading and trailing vertical bars and replace multiple vertical bars with single, */
249
					/* and put in the output array so the text is at least redisplayed for the user. */
250
					$final_address_details[] = preg_replace('/\|\|+/', '|', trim($post["detail0"], "|"));
251
					$data_errors[] = $vertical_bar_err_text;
252
				}
253
			} else {
254
				$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
255
			}
256
		}
257
	} elseif (($post['type'] == "url") || ($post['type'] == "url_ports")) {
258
		$desc_fmt_err_found = false;
259

    
260
		/* item is a url type */
261
		for ($x = 0; $x < $max_alias_addresses - 1; $x++) {
262
			if ($post['address' . $x]) {
263
				/* fetch down and add in */
264
				$temp_filename = tempnam("{$g['tmp_path']}/", "alias_import");
265
				unlink_if_exists($temp_filename);
266
				$verify_ssl = isset($config['system']['checkaliasesurlcert']);
267
				mkdir($temp_filename);
268
				if (!download_file($post['address' . $x], $temp_filename . "/aliases", $verify_ssl)) {
269
					$data_errors[] = sprintf(gettext("Could not fetch the URL '%s'."), $post['address' . $x]);
270
					continue;
271
				}
272

    
273
				/* if the item is tar gzipped then extract */
274
				if (stristr($post['address' . $x], ".tgz")) {
275
					process_alias_tgz($temp_filename);
276
				}
277

    
278
				if (!isset($alias['aliasurl'])) {
279
					$alias['aliasurl'] = array();
280
				}
281

    
282
				$alias['aliasurl'][] = $post['address' . $x];
283
				if ($post["detail{$x}"] <> "") {
284
					if ((strpos($post["detail{$x}"], "||") === false) && (substr($post["detail{$x}"], 0, 1) != "|") && (substr($post["detail{$x}"], -1, 1) != "|")) {
285
						$final_address_details[] = $post["detail{$x}"];
286
					} else {
287
						/* Remove leading and trailing vertical bars and replace multiple vertical bars with single, */
288
						/* and put in the output array so the text is at least redisplayed for the user. */
289
						$final_address_details[] = preg_replace('/\|\|+/', '|', trim($post["detail{$x}"], "|"));
290
						if (!$desc_fmt_err_found) {
291
							$data_errors[] = $vertical_bar_err_text;
292
							$desc_fmt_err_found = true;
293
						}
294
					}
295
				} else {
296
					$final_address_details[] = sprintf(gettext("Entry added %s"), date('r'));
297
				}
298

    
299
				if (file_exists("{$temp_filename}/aliases")) {
300
					$t_address = parse_aliases_file("{$temp_filename}/aliases", $post['type'], 5000);
301
					if ($t_address == null) {
302
						/* nothing was found */
303
						$data_errors[] = sprintf(gettext("A valid URL must be provided. Could not fetch usable data from '%s'."), $post['address' . $x]);
304
					} else {
305
						array_push($address, ...$t_address);
306
					}
307
					unset($t_address);
308
					mwexec("/bin/rm -rf " . escapeshellarg($temp_filename));
309
				} else {
310
					$data_errors[] = sprintf(gettext("URL '%s' is not valid."), $post['address' . $x]);
311
				}
312
			}
313
		}
314
		unset($desc_fmt_err_found);
315
		if ($post['type'] == "url_ports") {
316
			$address = group_ports($address);
317
		}
318
	} else {
319
		/* item is a normal alias type */
320
		$wrongaliases = "";
321
		$desc_fmt_err_found = false;
322
		$alias_address_count = 0;
323
		$input_addresses = array();
324

    
325
		// First trim and expand the input data.
326
		// Users can paste strings like "10.1.2.0/24 10.3.0.0/16 9.10.11.0/24" into an address box.
327
		// They can also put an IP range.
328
		// This loop expands out that stuff so it can easily be validated.
329
		for ($x = 0; $x < ($max_alias_addresses - 1); $x++) {
330
			if ($post["address{$x}"] <> "") {
331
				if ($post["detail{$x}"] <> "") {
332
					if ((strpos($post["detail{$x}"], "||") === false) && (substr($post["detail{$x}"], 0, 1) != "|") && (substr($post["detail{$x}"], -1, 1) != "|")) {
333
						$detail_text = $post["detail{$x}"];
334
					} else {
335
						/* Remove leading and trailing vertical bars and replace multiple vertical bars with single, */
336
						/* and put in the output array so the text is at least redisplayed for the user. */
337
						$detail_text = preg_replace('/\|\|+/', '|', trim($post["detail{$x}"], "|"));
338
						if (!$desc_fmt_err_found) {
339
							$data_errors[] = $vertical_bar_err_text;
340
							$desc_fmt_err_found = true;
341
						}
342
					}
343
				} else {
344
					$detail_text = sprintf(gettext("Entry added %s"), date('r'));
345
				}
346

    
347
				$address_items = explode(" ", trim(alias_idn_to_ascii($post["address{$x}"])));
348
				foreach ($address_items as $address_item) {
349
					$iprange_type = is_iprange($address_item);
350
					if ($iprange_type == 4) {
351
						list($startip, $endip) = explode('-', $address_item);
352
						if ($post['type'] == "network") {
353
							// For network type aliases, expand an IPv4 range into an array of subnets.
354
							$rangesubnets = ip_range_to_subnet_array($startip, $endip);
355
							foreach ($rangesubnets as $rangesubnet) {
356
								if ($alias_address_count > $max_alias_addresses) {
357
									break;
358
								}
359
								list($address_part, $subnet_part) = explode("/", $rangesubnet);
360
								$input_addresses[] = $address_part;
361
								$input_address_subnet[] = $subnet_part;
362
								$final_address_details[] = $detail_text;
363
								$alias_address_count++;
364
							}
365
						} else {
366
							// For host type aliases, expand an IPv4 range into a list of individual IPv4 addresses.
367
							$rangeaddresses = ip_range_to_address_array($startip, $endip, $max_alias_addresses - $alias_address_count);
368
							if (is_array($rangeaddresses)) {
369
								foreach ($rangeaddresses as $rangeaddress) {
370
									$input_addresses[] = $rangeaddress;
371
									$input_address_subnet[] = "";
372
									$final_address_details[] = $detail_text;
373
									$alias_address_count++;
374
								}
375
							} else {
376
								$data_errors[] = sprintf(gettext('Range is too large to expand into individual host IP addresses (%s)'), $address_item);
377
								$data_errors[] = sprintf(gettext('The maximum number of entries in an alias is %s'), $max_alias_addresses);
378
								// Put the user-entered data in the output anyway, so it will be re-displayed for correction.
379
								$input_addresses[] = $address_item;
380
								$input_address_subnet[] = "";
381
								$final_address_details[] = $detail_text;
382
							}
383
						}
384
					} else if ($iprange_type == 6) {
385
						$data_errors[] = sprintf(gettext('IPv6 address ranges are not supported (%s)'), $address_item);
386
						// Put the user-entered data in the output anyway, so it will be re-displayed for correction.
387
						$input_addresses[] = $address_item;
388
						$input_address_subnet[] = "";
389
						$final_address_details[] = $detail_text;
390
					} else {
391
						$subnet_type = is_subnet($address_item);
392
						if (($post['type'] == "host") && $subnet_type) {
393
							if ($subnet_type == 4) {
394
								// For host type aliases, if the user enters an IPv4 subnet, expand it into a list of individual IPv4 addresses.
395
								$subnet_size = subnet_size($address_item);
396
								if ($subnet_size > 0 &&
397
								    $subnet_size <= ($max_alias_addresses - $alias_address_count)) {
398
									$rangeaddresses = subnetv4_expand($address_item);
399
									foreach ($rangeaddresses as $rangeaddress) {
400
										$input_addresses[] = $rangeaddress;
401
										$input_address_subnet[] = "";
402
										$final_address_details[] = $detail_text;
403
										$alias_address_count++;
404
									}
405
								} else {
406
									$data_errors[] = sprintf(gettext('Subnet is too large to expand into individual host IP addresses (%s)'), $address_item);
407
									$data_errors[] = sprintf(gettext('The maximum number of entries in an alias is %s'), $max_alias_addresses);
408
									// Put the user-entered data in the output anyway, so it will be re-displayed for correction.
409
									$input_addresses[] = $address_item;
410
									$input_address_subnet[] = "";
411
									$final_address_details[] = $detail_text;
412
								}
413
							} else {
414
								$data_errors[] = sprintf(gettext('IPv6 subnets are not supported in host aliases (%s)'), $address_item);
415
								// Put the user-entered data in the output anyway, so it will be re-displayed for correction.
416
								$input_addresses[] = $address_item;
417
								$input_address_subnet[] = "";
418
								$final_address_details[] = $detail_text;
419
							}
420
						} else {
421
							list($address_part, $subnet_part) = explode("/", $address_item);
422
							if (!empty($subnet_part)) {
423
								if (is_subnet($address_item)) {
424
									$input_addresses[] = $address_part;
425
									$input_address_subnet[] = $subnet_part;
426
								} else {
427
									// The user typed something like "1.2.3.444/24" or "1.2.3.0/36" or similar rubbish.
428
									// Feed it through without splitting it apart, then it will be caught by the validation loop below.
429
									$input_addresses[] = $address_item;
430
									$input_address_subnet[] = "";
431
								}
432
							} else {
433
								$input_addresses[] = $address_part;
434
								$input_address_subnet[] = $post["address_subnet{$x}"];
435
							}
436
							$final_address_details[] = $detail_text;
437
							$alias_address_count++;
438
						}
439
					}
440
					if ($alias_address_count > $max_alias_addresses) {
441
						$data_errors[] = sprintf(gettext('The maximum number of entries in an alias has been exceeded (%s)'), $max_alias_addresses);
442
						break;
443
					}
444
				}
445
			}
446
		}
447

    
448
		// Validate the input data expanded above.
449
		foreach ($input_addresses as $idx => $input_address) {
450
			if (is_alias($input_address)) {
451
				if (!alias_same_type($input_address, $post['type'])) {
452
					// But alias type network can include alias type urltable. Feature#1603.
453
					if (!($post['type'] == 'network' &&
454
					    preg_match("/urltable/i", alias_get_type($input_address)))) {
455
						$wrongaliases .= " " . $input_address;
456
					}
457
				}
458
			} else if ($post['type'] == "port") {
459
				if (!is_port_or_range($input_address)) {
460
					$data_errors[] = sprintf(gettext("%s is not a valid port or alias."), $input_address);
461
				}
462
			} else if (($post['type'] == "host") || ($post['type'] == "network")) {
463
				if (is_subnet($input_address) ||
464
				    (!is_ipaddr($input_address) && !is_hostname($input_address))) {
465
					$data_errors[] = sprintf(gettext('%1$s is not a valid %2$s address, FQDN or alias.'), $input_address, $singular_types[$post['type']]);
466
				}
467
			}
468
			$tmpaddress = $input_address;
469
			if (($post['type'] != "host") && is_ipaddr($input_address) && ($input_address_subnet[$idx] <> "")) {
470
				if (!is_subnet($input_address . "/" . $input_address_subnet[$idx])) {
471
					$data_errors[] = sprintf(gettext('%1$s/%2$s is not a valid subnet.'), $input_address, $input_address_subnet[$idx]);
472
				} else {
473
					$tmpaddress .= "/" . $input_address_subnet[$idx];
474
				}
475
			}
476
			$address[] = addrtolower($tmpaddress);
477
		}
478
		unset($desc_fmt_err_found);
479
		if ($wrongaliases <> "") {
480
			$data_errors[] = sprintf(gettext('The alias(es): %s cannot be nested because they are not of the same type.'), $wrongaliases);
481
		}
482
	}
483

    
484
	unset($vertical_bar_err_text);
485

    
486
	// Allow extending of the firewall edit page and include custom input validation
487
	pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/input_validation");
488

    
489
	if (!$data_errors) {
490
		$alias['address'] = is_array($address) ? implode(" ", $address) : $address;
491
		$alias['descr'] = $post['descr'];
492
		$alias['type'] = $post['type'];
493
		$alias['detail'] = implode("||", $final_address_details);
494

    
495
		/*	 Check to see if alias name needs to be
496
		 *	 renamed on referenced rules and such
497
		 */
498
		if ($post['name'] <> $origname) {
499
			update_alias_name($post['name'], $origname);
500
		}
501

    
502
		pfSense_handle_custom_code("/usr/local/pkg/firewall_aliases_edit/pre_write_config");
503

    
504
		if (isset($id) && $a_aliases[$id]) {
505
			if ($a_aliases[$id]['name'] <> $alias['name']) {
506
				foreach ($a_aliases as $aliasid => $aliasd) {
507
					if ($aliasd['address'] <> "") {
508
						$tmpdirty = false;
509
						$tmpaddr = explode(" ", $aliasd['address']);
510
						foreach ($tmpaddr as $tmpidx => $tmpalias) {
511
							if ($tmpalias == $a_aliases[$id]['name']) {
512
								$tmpaddr[$tmpidx] = $alias['name'];
513
								$tmpdirty = true;
514
							}
515
						}
516
						if ($tmpdirty == true) {
517
							$a_aliases[$aliasid]['address'] = implode(" ", $tmpaddr);
518
						}
519
					}
520
				}
521
			}
522
			$a_aliases[$id] = $alias;
523
		} else {
524
			$a_aliases[] = $alias;
525
		}
526

    
527
		// Sort list
528
		$a_aliases = msort($a_aliases, "name");
529

    
530
		write_config(gettext("Edited a firewall alias."));
531
	} else if (isset($pconfig)) {
532
		//we received input errors, copy data to prevent retype
533
		$pconfig['name'] = $post['name'];
534
		$pconfig['descr'] = $post['descr'];
535
		if (isset($alias['aliasurl']) && ($post['type'] == 'url') || ($post['type'] == 'url_ports')) {
536
			$pconfig['address'] = implode(" ", $alias['aliasurl']);
537
		} else {
538
			$pconfig['address'] = implode(" ", $address);
539
		}
540
		$pconfig['type'] = $post['type'];
541
		$pconfig['detail'] = implode("||", $final_address_details);
542
	}
543

    
544
	return $data_errors;
545
}
546

    
547
function do_local_input_validation($postdata, $reqdfields, $reqdfieldsn, &$input_errors) {
548

    
549
	/* check for bad control characters */
550
	foreach ($postdata as $pn => $pd) {
551
		if (is_string($pd) && preg_match("/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]/", $pd)) {
552
			$input_errors[] = sprintf(gettext("The field %s contains invalid characters."), $pn);
553
		}
554
	}
555

    
556
	if (is_array($reqdfields)) {
557
		for ($i = 0; $i < count($reqdfields); $i++) {
558
			if ($postdata[$reqdfields[$i]] == "") {
559
				$input_errors[] = sprintf(gettext("The field %s is required."), $reqdfieldsn[$i]);
560
			}
561
		}
562
	}
563
}
564

    
565
?>
(1-1/6)