diff --git a/src/www/system_routes_edit.php b/src/www/system_routes_edit.php index 9b81d8439..a66975271 100644 --- a/src/www/system_routes_edit.php +++ b/src/www/system_routes_edit.php @@ -1,31 +1,31 @@ . - Copyright (C) 2010 Scott Ullrich - All rights reserved. + Copyright (C) 2014-2015 Deciso B.V. + Copyright (C) 2003-2004 Manuel Kasper . + Copyright (C) 2010 Scott Ullrich + 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"); @@ -35,44 +35,45 @@ require_once("pfsense-utils.inc"); $referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_routes.php'); -if (!is_array($config['staticroutes'])) { +if (!isset($config['staticroutes']) || !is_array($config['staticroutes'])) { $config['staticroutes'] = array(); } -if (!is_array($config['staticroutes']['route'])) { +if (!isset($config['staticroutes']['route']) || !is_array($config['staticroutes']['route'])) { $config['staticroutes']['route'] = array(); } $a_routes = &$config['staticroutes']['route']; $a_gateways = return_gateways_array(true, true); -if (is_numericint($_GET['id'])) { - $id = $_GET['id']; -} -if (isset($_POST['id']) && is_numericint($_POST['id'])) { - $id = $_POST['id']; -} +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + if (isset($_GET['id']) && isset($a_routes[$_GET['id']])) { + $id = $_GET['id']; + $configId = $id; + } elseif (isset($_GET['dup']) && isset($a_routes[$_GET['dup']])) { + $configId = $_GET['dup']; + } + $pconfig = array(); -if (isset($_GET['dup']) && is_numericint($_GET['dup'])) { - $id = $_GET['dup']; -} - -if (isset($id) && $a_routes[$id]) { - list($pconfig['network'],$pconfig['network_subnet']) = - explode('/', $a_routes[$id]['network']); - $pconfig['gateway'] = $a_routes[$id]['gateway']; - $pconfig['descr'] = $a_routes[$id]['descr']; - $pconfig['disabled'] = isset($a_routes[$id]['disabled']); -} - -if (isset($_GET['dup']) && is_numericint($_GET['dup'])) { - unset($id); -} - -if ($_POST) { + if (isset($configId)) { + list($pconfig['network'],$pconfig['network_subnet']) = + explode('/', $a_routes[$configId]['network']); + $pconfig['gateway'] = $a_routes[$configId]['gateway']; + $pconfig['descr'] = $a_routes[$configId]['descr']; + $pconfig['disabled'] = isset($a_routes[$configId]['disabled']); + } else { + $pconfig['network'] = null; + $pconfig['network_subnet'] = null; + $pconfig['gateway'] = null; + $pconfig['disabled'] = false; + } +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['id']) && isset($a_routes[$_POST['id']])) { + $id = $_POST['id']; + } global $aliastable; - unset($input_errors); + $input_errors = array(); $pconfig = $_POST; /* input validation */ @@ -84,39 +85,39 @@ if ($_POST) { gettext("Gateway") ); - do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors); + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); - if (($_POST['network'] && !is_ipaddr($_POST['network']) && !is_alias($_POST['network']))) { + if (($pconfig['network'] && !is_ipaddr($pconfig['network']) && !is_alias($pconfig['network']))) { $input_errors[] = gettext("A valid IPv4 or IPv6 destination network must be specified."); } - if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) { + if (($_POST['network_subnet'] && !is_numeric($pconfig['network_subnet']))) { $input_errors[] = gettext("A valid destination network bit count must be specified."); } - if (($_POST['gateway']) && is_ipaddr($_POST['network'])) { - if (!isset($a_gateways[$_POST['gateway']])) { + if (($_POST['gateway']) && is_ipaddr($pconfig['network'])) { + if (!isset($a_gateways[$pconfig['gateway']])) { $input_errors[] = gettext("A valid gateway must be specified."); } - if (!validate_address_family($_POST['network'], lookup_gateway_ip_by_name($_POST['gateway']))) { - $input_errors[] = gettext("The gateway '{$a_gateways[$_POST['gateway']]['gateway']}' is a different Address Family as network '{$_POST['network']}'."); + if (!validate_address_family($pconfig['network'], lookup_gateway_ip_by_name($pconfig['gateway']))) { + $input_errors[] = gettext("The gateway '{$a_gateways[$pconfig['gateway']]['gateway']}' is a different Address Family as network '{$pconfig['network']}'."); } } /* check for overlaps */ $current_targets = get_staticroutes(true); $new_targets = array(); - if (is_ipaddrv6($_POST['network'])) { - $osn = gen_subnetv6($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet']; + if (is_ipaddrv6($pconfig['network'])) { + $osn = gen_subnetv6($pconfig['network'], $pconfig['network_subnet']) . "/" . $pconfig['network_subnet']; $new_targets[] = $osn; } - if (is_ipaddrv4($_POST['network'])) { - if ($_POST['network_subnet'] > 32) { + if (is_ipaddrv4($pconfig['network'])) { + if ($pconfig['network_subnet'] > 32) { $input_errors[] = gettext("A IPv4 subnet can not be over 32 bits."); } else { - $osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet']; + $osn = gen_subnet($pconfig['network'], $pconfig['network_subnet']) . "/" . $pconfig['network_subnet']; $new_targets[] = $osn; } - } elseif (is_alias($_POST['network'])) { - $osn = $_POST['network']; + } elseif (is_alias($pconfig['network'])) { + $osn = $pconfig['network']; foreach (preg_split('/\s+/', $aliastable[$osn]) as $tgt) { if (is_ipaddrv4($tgt)) { $tgt .= "/32"; @@ -164,28 +165,28 @@ if ($_POST) { if (is_array($config['interfaces'])) { foreach ($config['interfaces'] as $if) { - if (is_ipaddrv4($_POST['network']) + if (is_ipaddrv4($pconfig['network']) && isset($if['ipaddr']) && isset($if['subnet']) && is_ipaddrv4($if['ipaddr']) && is_numeric($if['subnet']) && ($_POST['network_subnet'] == $if['subnet']) - && (gen_subnet($_POST['network'], $_POST['network_subnet']) == gen_subnet($if['ipaddr'], $if['subnet']))) { + && (gen_subnet($pconfig['network'], $pconfig['network_subnet']) == gen_subnet($if['ipaddr'], $if['subnet']))) { $input_errors[] = sprintf(gettext("This network conflicts with address configured on interface %s."), $if['descr']); - } elseif (is_ipaddrv6($_POST['network']) + } elseif (is_ipaddrv6($pconfig['network']) && isset($if['ipaddrv6']) && isset($if['subnetv6']) && is_ipaddrv6($if['ipaddrv6']) && is_numeric($if['subnetv6']) && ($_POST['network_subnet'] == $if['subnetv6']) - && (gen_subnetv6($_POST['network'], $_POST['network_subnet']) == gen_subnetv6($if['ipaddrv6'], $if['subnetv6']))) { + && (gen_subnetv6($pconfig['network'], $pconfig['network_subnet']) == gen_subnetv6($if['ipaddrv6'], $if['subnetv6']))) { $input_errors[] = sprintf(gettext("This network conflicts with address configured on interface %s."), $if['descr']); } } } - if (!$input_errors) { + if (count($input_errors) == 0){ $route = array(); $route['network'] = $osn; - $route['gateway'] = $_POST['gateway']; - $route['descr'] = $_POST['descr']; - if ($_POST['disabled']) { + $route['gateway'] = $pconfig['gateway']; + $route['descr'] = $pconfig['descr']; + if (!empty($pconfig['disabled'])) { $route['disabled'] = true; } else { unset($route['disabled']); @@ -210,9 +211,7 @@ if ($_POST) { } } file_put_contents('/tmp/.system_routes.apply', serialize($toapplylist)); - mark_subsystem_dirty('staticroutes'); - write_config(); header("Location: system_routes.php"); @@ -220,247 +219,116 @@ if ($_POST) { } } + + $pgtitle = array(gettext('System'), gettext('Routes'), gettext('Edit')); $shortcut_section = "routing"; +legacy_html_escape_form_data($a_gateways); +legacy_html_escape_form_data($pconfig); include("head.inc"); ?> + - - - - - - -
- -
- -
- 0) { - print_input_errors($input_errors); + + +
+
+
+ 0) { + print_input_errors($input_errors); } ?> - -
- -
- -
- -
- - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - -
- - - -
-
-
-
-
- -
-
-
- - -
- /> -
- -
- -
-
  - " /> - " onclick="window.location.href=''" /> - - - -
-
-
-
-
-
-
-
- - +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + / + + +
+ + +
+ /> + +
+ + +
+ " /> + " onclick="window.location.href=''" /> + + + +
+
+
+
+
+
+
+