From 9a01d22d4fb39e29fbda87f7980045603222a36a Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Sun, 12 Jul 2015 11:34:17 +0545 Subject: Static routes merge "else" and "if" into "else if" As suggested by Renato. --- usr/local/www/system_gateways_edit.php | 36 ++++++++++++++++------------------ usr/local/www/system_routes_edit.php | 12 +++++------- 2 files changed, 22 insertions(+), 26 deletions(-) (limited to 'usr/local') diff --git a/usr/local/www/system_gateways_edit.php b/usr/local/www/system_gateways_edit.php index b80b2bf..3d0bc78 100644 --- a/usr/local/www/system_gateways_edit.php +++ b/usr/local/www/system_gateways_edit.php @@ -126,29 +126,27 @@ if ($_POST) { } if (!is_validaliasname($_POST['name'])) { $input_errors[] = gettext("The gateway name must not contain invalid characters."); - } else { - if (isset($_POST['disabled'])) { - // We have a valid gateway name that the user wants to mark as disabled. - // Check if the gateway name is used in any gateway group. - if (is_array($config['gateways']['gateway_group'])) { - foreach ($config['gateways']['gateway_group'] as $group) { - foreach ($group['item'] as $item) { - $items = explode("|", $item); - if ($items[0] == $_POST['name']) { - $input_errors[] = sprintf(gettext("Gateway '%s' cannot be disabled because it is in use on Gateway Group '%s'"), $_POST['name'], $group['name']); - } + } else if (isset($_POST['disabled'])) { + // We have a valid gateway name that the user wants to mark as disabled. + // Check if the gateway name is used in any gateway group. + if (is_array($config['gateways']['gateway_group'])) { + foreach ($config['gateways']['gateway_group'] as $group) { + foreach ($group['item'] as $item) { + $items = explode("|", $item); + if ($items[0] == $_POST['name']) { + $input_errors[] = sprintf(gettext("Gateway '%s' cannot be disabled because it is in use on Gateway Group '%s'"), $_POST['name'], $group['name']); } } } + } - // Check if the gateway name is used in any enabled Static Route. - if (is_array($config['staticroutes']['route'])) { - foreach ($config['staticroutes']['route'] as $route) { - if ($route['gateway'] == $_POST['name']) { - if (!isset($route['disabled'])) { - // There is a static route that uses this gateway and is enabled (not disabled). - $input_errors[] = sprintf(gettext("Gateway '%s' cannot be disabled because it is in use on Static Route '%s'"), $_POST['name'], $route['network']); - } + // Check if the gateway name is used in any enabled Static Route. + if (is_array($config['staticroutes']['route'])) { + foreach ($config['staticroutes']['route'] as $route) { + if ($route['gateway'] == $_POST['name']) { + if (!isset($route['disabled'])) { + // There is a static route that uses this gateway and is enabled (not disabled). + $input_errors[] = sprintf(gettext("Gateway '%s' cannot be disabled because it is in use on Static Route '%s'"), $_POST['name'], $route['network']); } } } diff --git a/usr/local/www/system_routes_edit.php b/usr/local/www/system_routes_edit.php index ea9047f..5d57622 100644 --- a/usr/local/www/system_routes_edit.php +++ b/usr/local/www/system_routes_edit.php @@ -102,14 +102,12 @@ if ($_POST) { if (($_POST['gateway']) && is_ipaddr($_POST['network'])) { if (!isset($a_gateways[$_POST['gateway']])) { $input_errors[] = gettext("A valid gateway must be specified."); + } else if (isset($a_gateways[$_POST['gateway']]['disabled']) && !$_POST['disabled']) { + $input_errors[] = gettext("The gateway is disabled but the route is not. You must disable the route in order to choose a disabled gateway."); } else { - if (isset($a_gateways[$_POST['gateway']]['disabled']) && !$_POST['disabled']) { - $input_errors[] = gettext("The gateway is disabled but the route is not. You must disable the route in order to choose a disabled gateway."); - } else { - // Note that the 3rd parameter "disabled" must be passed as explicitly true or false. - if (!validate_address_family($_POST['network'], $_POST['gateway'], $_POST['disabled'] ? true : false)) { - $input_errors[] = gettext("The gateway '{$a_gateways[$_POST['gateway']]['gateway']}' is a different Address Family than network '{$_POST['network']}'."); - } + // Note that the 3rd parameter "disabled" must be passed as explicitly true or false. + if (!validate_address_family($_POST['network'], $_POST['gateway'], $_POST['disabled'] ? true : false)) { + $input_errors[] = gettext("The gateway '{$a_gateways[$_POST['gateway']]['gateway']}' is a different Address Family than network '{$_POST['network']}'."); } } } -- cgit v1.1