From c9e04cd59054cf839af96cdf71cfc4cf58ccabaf Mon Sep 17 00:00:00 2001 From: jim-p Date: Tue, 10 Apr 2012 16:42:49 -0400 Subject: Add alias support to static routes (needs some testing) Ticket #2239 --- usr/local/www/system_routes_edit.php | 96 +++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 23 deletions(-) (limited to 'usr/local/www') diff --git a/usr/local/www/system_routes_edit.php b/usr/local/www/system_routes_edit.php index 3ca0de9..8415c36 100755 --- a/usr/local/www/system_routes_edit.php +++ b/usr/local/www/system_routes_edit.php @@ -92,7 +92,7 @@ if ($_POST) { do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - if (($_POST['network'] && !is_ipaddr($_POST['network']))) { + if (($_POST['network'] && !is_ipaddr($_POST['network']) && !is_alias($_POST['network']))) { $input_errors[] = gettext("A valid destination network must be specified."); } if (($_POST['network_subnet'] && !is_numeric($_POST['network_subnet']))) { @@ -104,38 +104,63 @@ if ($_POST) { } /* check for overlaps */ - $osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet']; - foreach ($a_routes as $route) { - if (isset($id) && ($a_routes[$id]) && ($a_routes[$id] === $route)) - continue; + $current_targets = get_staticroutes(true); + $new_targets = array(); + if (is_ipaddr($_POST['network'])) { + $osn = gen_subnet($_POST['network'], $_POST['network_subnet']) . "/" . $_POST['network_subnet']; + $new_targets[] = $osn; + } elseif (is_alias($_POST['network'])) { + $osn = $_POST['network']; + foreach (filter_expand_alias_array($_POST['network']) as $tgt) { + if (is_ipaddr($tgt)) + $tgt .= "/32"; + if (!is_subnet($tgt)) + continue; + $new_targets[] = $tgt; + } + } - if ($route['network'] == $osn) { - $input_errors[] = gettext("A route to this destination network already exists."); - break; + if (!isset($id)) + $id = count($a_routes); + $oroute = $a_routes[$id]; + if (!empty($oroute)) { + $old_targets = array(); + if (is_alias($oroute['network'])) { + foreach (filter_expand_alias_array($oroute['network']) as $tgt) { + if (is_ipaddr($tgt)) + $tgt .= "/32"; + if (!is_subnet($tgt)) + continue; + $old_targets[] = $tgt; + } + } else { + $old_targets[] = $oroute['network']; } } + $overlaps = array_intersect($current_targets, $new_targets); + $overlaps = array_diff($overlaps, $old_targets); + if (count($overlaps)) { + $input_errors[] = gettext("A route to these destination networks already exists") . ": " . implode(", ", $overlaps); + } + if (!$input_errors) { $route = array(); $route['network'] = $osn; $route['gateway'] = $_POST['gateway']; $route['descr'] = $_POST['descr']; - if (!isset($id)) - $id = count($a_routes); - if (file_exists("{$g['tmp_path']}/.system_routes.apply")) - $toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply")); - else - $toapplylist = array(); - $oroute = $a_routes[$id]; - + if (file_exists("{$g['tmp_path']}/.system_routes.apply")) + $toapplylist = unserialize(file_get_contents("{$g['tmp_path']}/.system_routes.apply")); + else + $toapplylist = array(); $a_routes[$id] = $route; if (!empty($oroute)) { - $osn = explode('/', $oroute['network']); - $sn = explode('/', $route['network']); - if ($oroute['network'] <> $route['network']) - $toapplylist[] = "/sbin/route delete {$oroute['network']}"; + $delete_targets = array_diff($old_targets, $new_targets); + if (count($delete_targets)) + foreach ($delete_targets as $dts) + $toapplylist[] = "/sbin/route delete {$dts}"; } file_put_contents("{$g['tmp_path']}/.system_routes.apply", serialize($toapplylist)); staticroutes_sort(); @@ -151,11 +176,14 @@ if ($_POST) { $pgtitle = array(gettext("System"),gettext("Static Routes"),gettext("Edit route")); include("head.inc"); - ?> - + + +
@@ -165,7 +193,7 @@ include("head.inc");
- + /