diff --git a/src/www/firewall_aliases_edit.php b/src/www/firewall_aliases_edit.php index e1b7fbc3e..4477ce0f6 100644 --- a/src/www/firewall_aliases_edit.php +++ b/src/www/firewall_aliases_edit.php @@ -1,33 +1,33 @@ . - All rights reserved. + Copyright (C) 2014 Deciso B.V. + Copyright (C) 2004 Scott Ullrich + Copyright (C) 2009 Ermal Luçi + Copyright (C) 2010 Jim Pingle + Copyright (C) 2003-2004 Manuel Kasper . + All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. */ require_once("guiconfig.inc"); @@ -37,27 +37,27 @@ if (!isset($config['aliases'])) { $config['aliases'] = array(); } if (!isset($config['aliases']['alias'])) { - $config['aliases']['alias'] = array(); + $config['aliases']['alias'] = array(); } $a_aliases = &$config['aliases']['alias']; $pconfig = array(); if ($_SERVER['REQUEST_METHOD'] === 'GET') { - if (isset($_GET['id']) && is_numericint($_GET['id']) && isset($a_aliases[$_GET['id']])) { - $id = $_GET['id']; - foreach (array("name","detail","address","type","descr","updatefreq","aliasurl","url") as $fieldname) { - if (isset($a_aliases[$id][$fieldname])) { - $pconfig[$fieldname] = $a_aliases[$id][$fieldname]; - } else { - $pconfig[$fieldname] = null; - } - } - // convert to array if only one is provided - if (!empty($pconfig['aliasurl']) && !is_array($pconfig['aliasurl'])) { - $pconfig['aliasurl'] = array($pconfig['aliasurl']); - } - } elseif (isset($_GET['name'])) { + if (isset($_GET['id']) && is_numericint($_GET['id']) && isset($a_aliases[$_GET['id']])) { + $id = $_GET['id']; + foreach (array("name","detail","address","type","descr","updatefreq","aliasurl","url") as $fieldname) { + if (isset($a_aliases[$id][$fieldname])) { + $pconfig[$fieldname] = $a_aliases[$id][$fieldname]; + } else { + $pconfig[$fieldname] = null; + } + } + // convert to array if only one is provided + if (!empty($pconfig['aliasurl']) && !is_array($pconfig['aliasurl'])) { + $pconfig['aliasurl'] = array($pconfig['aliasurl']); + } + } elseif (isset($_GET['name'])) { // search alias by name foreach ($a_aliases as $alias_id => $alias_data) { if (strtolower($alias_data['name']) == strtolower(trim($_GET['name']))) { @@ -67,170 +67,170 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } // initialize form fields, when not found present empty form foreach (array("name","detail","address","type","descr","updatefreq","aliasurl","url") as $fieldname) { - if (isset($id) && isset($a_aliases[$id][$fieldname])) { - $pconfig[$fieldname] = $a_aliases[$id][$fieldname]; - } else { - $pconfig[$fieldname] = null; - } - } + if (isset($id) && isset($a_aliases[$id][$fieldname])) { + $pconfig[$fieldname] = $a_aliases[$id][$fieldname]; + } else { + $pconfig[$fieldname] = null; + } + } } else { - // init empty - $init_fields = array("name","detail","address","type","descr","updatefreq","url"); - foreach ($init_fields as $fieldname) { - $pconfig[$fieldname] = null; - } - } + // init empty + $init_fields = array("name","detail","address","type","descr","updatefreq","url"); + foreach ($init_fields as $fieldname) { + $pconfig[$fieldname] = null; + } + } } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { - $pconfig = $_POST; - if (isset($_POST['id']) && is_numericint($_POST['id']) && isset($a_aliases[$_POST['id']])) { - $id = $_POST['id']; - } + $pconfig = $_POST; + if (isset($_POST['id']) && is_numericint($_POST['id']) && isset($a_aliases[$_POST['id']])) { + $id = $_POST['id']; + } - // fix form type conversions ( list to string, as saved in config ) - // -- fill in default row description and make sure separators are removed - if (strpos($pconfig['type'],'urltable') !== false) { - $pconfig['url'] = $pconfig['host_url'][0]; - } elseif (strpos($pconfig['type'],'url') !== false) { - $pconfig['aliasurl'] = $pconfig['host_url']; - } else { - $pconfig['address'] = implode(' ',$pconfig['host_url']); - } - unset($pconfig['host_url']); - foreach ($pconfig['detail'] as &$detailDescr) { - if (empty($detailDescr)) { - $detailDescr = sprintf(gettext("Entry added %s"), date('r')); - } else { - // trim and strip pipes - $detailDescr = trim(str_replace('|',' ' , $detailDescr)); - } - } - $pconfig['detail'] = implode('||', $pconfig['detail']); + // fix form type conversions ( list to string, as saved in config ) + // -- fill in default row description and make sure separators are removed + if (strpos($pconfig['type'],'urltable') !== false) { + $pconfig['url'] = $pconfig['host_url'][0]; + } elseif (strpos($pconfig['type'],'url') !== false) { + $pconfig['aliasurl'] = $pconfig['host_url']; + } else { + $pconfig['address'] = implode(' ',$pconfig['host_url']); + } + unset($pconfig['host_url']); + foreach ($pconfig['detail'] as &$detailDescr) { + if (empty($detailDescr)) { + $detailDescr = sprintf(gettext("Entry added %s"), date('r')); + } else { + // trim and strip pipes + $detailDescr = trim(str_replace('|',' ' , $detailDescr)); + } + } + $pconfig['detail'] = implode('||', $pconfig['detail']); - if (isset($pconfig['submit'])) { - $input_errors = array(); - // validate data + if (isset($pconfig['submit'])) { + $input_errors = array(); + // validate data - /* Check for reserved keyword names */ - // Keywords not allowed in names - $reserved_keywords = array("all", "pass", "block", "out", "queue", "max", "min", "pptp", "pppoe", "L2TP", "OpenVPN", "IPsec"); + /* Check for reserved keyword names */ + // Keywords not allowed in names + $reserved_keywords = array("all", "pass", "block", "out", "queue", "max", "min", "pptp", "pppoe", "L2TP", "OpenVPN", "IPsec"); - // Add all Load balance names to reserved_keywords - if (is_array($config['load_balancer']['lbpool'])) - foreach ($config['load_balancer']['lbpool'] as $lbpool) - $reserved_keywords[] = $lbpool['name']; + // Add all Load balance names to reserved_keywords + if (is_array($config['load_balancer']['lbpool'])) + foreach ($config['load_balancer']['lbpool'] as $lbpool) + $reserved_keywords[] = $lbpool['name']; - $reserved_ifs = get_configured_interface_list(false, true); - $reserved_keywords = array_merge($reserved_keywords, $reserved_ifs, $reserved_table_names); - foreach($reserved_keywords as $rk) - if($rk == $pconfig['name']) - $input_errors[] = sprintf(gettext("Cannot use a reserved keyword as alias name %s"), $rk); + $reserved_ifs = get_configured_interface_list(false, true); + $reserved_keywords = array_merge($reserved_keywords, $reserved_ifs, $reserved_table_names); + foreach($reserved_keywords as $rk) + if($rk == $pconfig['name']) + $input_errors[] = sprintf(gettext("Cannot use a reserved keyword as alias name %s"), $rk); - /* check for name interface description conflicts */ - foreach($config['interfaces'] as $interface) { - if($interface['descr'] == $pconfig['name']) { - $input_errors[] = gettext("An interface description with this name already exists."); - break; - } - } - if ( is_validaliasname($pconfig['name']) !== true) { - $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, _."; - } + /* check for name interface description conflicts */ + foreach($config['interfaces'] as $interface) { + if($interface['descr'] == $pconfig['name']) { + $input_errors[] = gettext("An interface description with this name already exists."); + break; + } + } + if ( is_validaliasname($pconfig['name']) !== true) { + $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, _."; + } - if (!empty($pconfig['updatefreq']) && !is_numericint($pconfig['updatefreq'])) { - $input_errors[] = gettext("Update Frequency should by a number"); - } + if (!empty($pconfig['updatefreq']) && !is_numericint($pconfig['updatefreq'])) { + $input_errors[] = gettext("Update Frequency should by a number"); + } - /* check for name conflicts */ - if (empty($a_aliases[$id])) { - foreach ($a_aliases as $alias) { - if ($alias['name'] == $_POST['name']) { - $input_errors[] = gettext("An alias with this name already exists."); - break; - } - } - } + /* check for name conflicts */ + if (empty($a_aliases[$id])) { + foreach ($a_aliases as $alias) { + if ($alias['name'] == $_POST['name']) { + $input_errors[] = gettext("An alias with this name already exists."); + break; + } + } + } - /* user may not change type */ - if (isset($id) && $pconfig['type'] != $a_aliases[$id]['type']) { - $input_errors[] = gettext("Alias type may not be changed for an existing alias."); - } + /* user may not change type */ + if (isset($id) && $pconfig['type'] != $a_aliases[$id]['type']) { + $input_errors[] = gettext("Alias type may not be changed for an existing alias."); + } - if ($pconfig['type'] == 'urltable') { - if (empty($pconfig['url']) || !is_URL($pconfig['url'])) { - $input_errors[] = gettext("You must provide a valid URL."); - } - } + if ($pconfig['type'] == 'urltable') { + if (empty($pconfig['url']) || !is_URL($pconfig['url'])) { + $input_errors[] = gettext("You must provide a valid URL."); + } + } - if (count($input_errors) == 0) { - // save to config - $copy_fields = array("name","detail","address","type","descr","updatefreq","aliasurl","url"); - $confItem = array(); - foreach ($copy_fields as $fieldname) { - if (!empty($pconfig[$fieldname])) { - $confItem[$fieldname] = $pconfig[$fieldname]; - } - } + if (count($input_errors) == 0) { + // save to config + $copy_fields = array("name","detail","address","type","descr","updatefreq","aliasurl","url"); + $confItem = array(); + foreach ($copy_fields as $fieldname) { + if (!empty($pconfig[$fieldname])) { + $confItem[$fieldname] = $pconfig[$fieldname]; + } + } - /* Check to see if alias name needs to be - * renamed on referenced rules and such - */ - if (isset($id) && $pconfig['name'] <> $pconfig['origname']) { - // Firewall rules - $origname = $pconfig['origname']; - update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('filter', 'rule'), array('source', 'port'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'port'), $pconfig['name'], $origname); - // NAT Rules - update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('nat', 'rule'), array('source', 'port'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'port'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('nat', 'rule'), array('target'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('nat', 'rule'), array('local-port'), $pconfig['name'], $origname); - // NAT 1:1 Rules - update_alias_names_upon_change(array('nat', 'onetoone'), array('destination', 'address'), $pconfig['name'], $origname); - // NAT Outbound Rules - update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $pconfig['name'], $origname); - update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('target'), $pconfig['name'], $origname); - // Alias in an alias - update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $pconfig['name'], $origname); - } + /* Check to see if alias name needs to be + * renamed on referenced rules and such + */ + if (isset($id) && $pconfig['name'] <> $pconfig['origname']) { + // Firewall rules + $origname = $pconfig['origname']; + update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('filter', 'rule'), array('source', 'port'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'port'), $pconfig['name'], $origname); + // NAT Rules + update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('nat', 'rule'), array('source', 'port'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'port'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('nat', 'rule'), array('target'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('nat', 'rule'), array('local-port'), $pconfig['name'], $origname); + // NAT 1:1 Rules + update_alias_names_upon_change(array('nat', 'onetoone'), array('destination', 'address'), $pconfig['name'], $origname); + // NAT Outbound Rules + update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('source', 'network'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('sourceport'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('destination', 'address'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('dstport'), $pconfig['name'], $origname); + update_alias_names_upon_change(array('nat', 'advancedoutbound', 'rule'), array('target'), $pconfig['name'], $origname); + // Alias in an alias + update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $pconfig['name'], $origname); + } - // save to config - if (isset($id)) { - $a_aliases[$id] = $confItem; - } else { - $a_aliases[] = $confItem; - } - // Sort list - $a_aliases = msort($a_aliases, "name"); + // save to config + if (isset($id)) { + $a_aliases[$id] = $confItem; + } else { + $a_aliases[] = $confItem; + } + // Sort list + $a_aliases = msort($a_aliases, "name"); - if (write_config()) { - // post save actions - mark_subsystem_dirty('aliases'); - if (strpos($pconfig['type'],'url') !== false) { - // update URL Table Aliases - configd_run('filter refresh_url_alias', true); - } - } + if (write_config()) { + // post save actions + mark_subsystem_dirty('aliases'); + if (strpos($pconfig['type'],'url') !== false) { + // update URL Table Aliases + configd_run('filter refresh_url_alias', true); + } + } - if(!empty($pconfig['type']) == 'host') { - header("Location: firewall_aliases.php?tab=ip"); - } elseif (strpos($pconfig['type'],'url') !== false) { - header("Location: firewall_aliases.php?tab=url"); - } else { - header("Location: firewall_aliases.php?tab=".$pconfig['type']); - } - exit; + if(!empty($pconfig['type']) == 'host') { + header("Location: firewall_aliases.php?tab=ip"); + } elseif (strpos($pconfig['type'],'url') !== false) { + header("Location: firewall_aliases.php?tab=url"); + } else { + header("Location: firewall_aliases.php?tab=".$pconfig['type']); + } + exit; - } - } + } + } } $pgtitle = array(gettext("Firewall"),gettext("Aliases"),gettext("Edit")); @@ -241,239 +241,239 @@ include("head.inc"); ?> -
-
-
- 0) print_input_errors($input_errors); ?> -
-
-
-
-

-
-
-
-
- - - - - - - - - - - - - - - - - - - + + + + + +
- - -
- - - - - - -
- - -
- -
- - - - - - - - - - $aliasurl): +
+
+
+ 0) print_input_errors($input_errors); ?> +
+
+
+
+

+
+
+ +
+
+ + + + + + + + + + + + + + + + + + - - - - -
+ + +
+ + + + + + +
+ + +
+ +
+ + + + + + + + + + $aliasurl): ?> - - - - + + - - $address): + + + $address): ?> - - - - + + - + + - - - - - - - -
- - - "?> - - + + + + "?> + + - -" > + -
- - - "?> - - + + + + "?> + + - -" > + -
-
-
- -
  - " /> - " onclick="window.location.href=''" /> -
- - - - - - - - +
+
+
+ + + +   + + " /> + " onclick="window.location.href=''" /> + + + +
+ +
+
+
+
+
+