Fix an issue that changes wrong gateway entry when items are hidden

This commit is contained in:
Renato Botelho 2013-11-21 09:36:50 -02:00
parent 186ab4ea1a
commit 1ad6ad279f
2 changed files with 19 additions and 14 deletions

View File

@ -372,10 +372,13 @@ function return_gateways_array($disabled = false, $localhost = false) {
$interfaces_v4 = array();
$interfaces_v6 = array();
$i = 0;
$i = -1;
/* Process/add all the configured gateways. */
if (is_array($config['gateways']['gateway_item'])) {
foreach ($config['gateways']['gateway_item'] as $gateway) {
/* Increment it here to do not skip items */
$i++;
if (empty($config['interfaces'][$gateway['interface']]))
continue;
$wancfg = $config['interfaces'][$gateway['interface']];
@ -445,7 +448,6 @@ function return_gateways_array($disabled = false, $localhost = false) {
$gateway['attribute'] = $i;
$gateways_arr[$gateway['name']] = $gateway;
$i++;
}
}
unset($gateway);

View File

@ -75,11 +75,11 @@ if (isset($id) && $a_gateways[$id]) {
$pconfig['dynamic'] = true;
$pconfig['gateway'] = $a_gateways[$id]['gateway'];
$pconfig['defaultgw'] = isset($a_gateways[$id]['defaultgw']);
$pconfig['latencylow'] = $a_gateway_item[$id]['latencylow'];
$pconfig['latencyhigh'] = $a_gateway_item[$id]['latencyhigh'];
$pconfig['losslow'] = $a_gateway_item[$id]['losslow'];
$pconfig['losshigh'] = $a_gateway_item[$id]['losshigh'];
$pconfig['down'] = $a_gateway_item[$id]['down'];
$pconfig['latencylow'] = $a_gateways[$id]['latencylow'];
$pconfig['latencyhigh'] = $a_gateways[$id]['latencyhigh'];
$pconfig['losslow'] = $a_gateways[$id]['losslow'];
$pconfig['losshigh'] = $a_gateways[$id]['losshigh'];
$pconfig['down'] = $a_gateways[$id]['down'];
$pconfig['monitor'] = $a_gateways[$id]['monitor'];
$pconfig['monitor_disable'] = isset($a_gateways[$id]['monitor_disable']);
$pconfig['descr'] = $a_gateways[$id]['descr'];
@ -91,6 +91,9 @@ if (isset($_GET['dup'])) {
unset($pconfig['attribute']);
}
if (isset($id) && $a_gateways[$id])
$realid = $a_gateways[$id]['attribute'];
if ($_POST) {
unset($input_errors);
@ -386,12 +389,12 @@ if ($_POST) {
$gateway['monitor_disable'] = true;
else if (is_ipaddr($_POST['monitor'])) {
/* NOTE: If monitor ip is changed need to cleanup the old static route */
if ($_POST['monitor'] != "dynamic" && !empty($a_gateway_item[$id]) && is_ipaddr($a_gateway_item[$id]['monitor']) &&
$_POST['monitor'] != $a_gateway_item[$id]['monitor'] && $gateway['gateway'] != $a_gateway_item[$id]['monitor']) {
if (is_ipaddrv4($a_gateway_item[$id]['monitor']))
mwexec("/sbin/route delete " . escapeshellarg($a_gateway_item[$id]['monitor']));
if ($_POST['monitor'] != "dynamic" && !empty($a_gateway_item[$realid]) && is_ipaddr($a_gateway_item[$realid]['monitor']) &&
$_POST['monitor'] != $a_gateway_item[$realid]['monitor'] && $gateway['gateway'] != $a_gateway_item[$realid]['monitor']) {
if (is_ipaddrv4($a_gateway_item[$realid]['monitor']))
mwexec("/sbin/route delete " . escapeshellarg($a_gateway_item[$realid]['monitor']));
else
mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateway_item[$id]['monitor']));
mwexec("/sbin/route delete -inet6 " . escapeshellarg($a_gateway_item[$realid]['monitor']));
}
$gateway['monitor'] = $_POST['monitor'];
}
@ -422,8 +425,8 @@ if ($_POST) {
$gateway['down'] = $_POST['down'];
/* when saving the manual gateway we use the attribute which has the corresponding id */
if (isset($id) && $a_gateway_item[$id])
$a_gateway_item[$id] = $gateway;
if (isset($realid) && $a_gateway_item[$realid])
$a_gateway_item[$realid] = $gateway;
else
$a_gateway_item[] = $gateway;