From d44d26c13ea8e1bc13657f0a186c3cfda7b28d47 Mon Sep 17 00:00:00 2001 From: Ermal Date: Fri, 1 Oct 2010 16:08:45 +0000 Subject: Fix the problem of not saving data when most of the information is not being posted. Also do not disable any field anymore to allow people to choose static gateways for dynamic interfaces. Also do not save any information when the user Clicks save but has not posted any information not known already. Do not prevent to post a dynamic value for gateway on an interface that is configured with static ip. --- usr/local/www/system_gateways_edit.php | 143 +++++++++++++++------------------ 1 file changed, 66 insertions(+), 77 deletions(-) (limited to 'usr/local/www/system_gateways_edit.php') diff --git a/usr/local/www/system_gateways_edit.php b/usr/local/www/system_gateways_edit.php index dd08e64..3e5c916 100755 --- a/usr/local/www/system_gateways_edit.php +++ b/usr/local/www/system_gateways_edit.php @@ -68,18 +68,15 @@ if (isset($id) && $a_gateways[$id]) { $pconfig['weight'] = $a_gateways[$id]['weight']; $pconfig['interface'] = $a_gateways[$id]['interface']; $pconfig['friendlyiface'] = $a_gateways[$id]['friendlyiface']; - if ($a_gateways[$id]['gateway'] == "dynamic" || $a_gateway_item[$id]['gateway'] == "dynamic") - $pconfig['gateway'] = gettext("dynamic"); - else - $pconfig['gateway'] = $a_gateways[$id]['gateway']; + if (isset($a_gateways[$id]['dynamic'])) + $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']; - if (isset($a_gateways[$id]['dynamic'])) - $pconfig['dynamic'] = true; $pconfig['monitor'] = $a_gateways[$id]['monitor']; $pconfig['descr'] = $a_gateways[$id]['descr']; $pconfig['attribute'] = $a_gateways[$id]['attribute']; @@ -95,8 +92,8 @@ if ($_POST) { unset($input_errors); /* input validation */ - $reqdfields = explode(" ", "name"); - $reqdfieldsn = array(gettext("Name")); + $reqdfields = explode(" ", "name interface"); + $reqdfieldsn = array(gettext("Name"), gettext("Interface")); do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); @@ -111,7 +108,11 @@ if ($_POST) { $input_errors[] = gettext("A valid gateway IP address must be specified."); } - if ($_POST['gateway'] && (is_ipaddr($_POST['gateway'])) && ($pconfig['attribute'] != "system") && !$_REQUEST['isAjax']) { + if ($_POST['gateway'] && (is_ipaddr($_POST['gateway'])) && !$_REQUEST['isAjax']) { + if (!empty($config['interfaces'][$_POST['interface']]['ipaddr'])) { + if (is_ipaddr($config['interfaces'][$_POST['interface']]['ipaddr']) && $_POST['gateway'] == "dynamic") + $input_errors[] = gettext("Dynamic gateway values cannot be specified for interfaces with a static ip configuration."); + } $parent_ip = get_interface_ip($_POST['interface']); if (is_ipaddr($parent_ip)) { $parent_sn = get_interface_subnet($_POST['interface']); @@ -192,65 +193,63 @@ if ($_POST) { } if (!$input_errors) { + if (!(($_POST['weight'] && $_POST['weight'] > 1) || $_POST['latencylow'] || $_POST['latencyhigh'] || + $_POST['losslow'] || $_POST['losshigh'] || $_POST['down'] || $_POST['defaultgw'] || + ($_POST['gateway'] && $_POST['gateway'] != "dynamic") || + ($_POST['monitorip'] && $_POST['monitor'] != "dynamic"))) { + header("Location: system_gateways.php"); + exit; + } + + $reloadif = false; - $save = false; - if (($_POST['weight'] && $_POST['weight'] > 1) || - $_POST['latencylow'] || $_POST['latencyhigh'] || $_POST['losslow'] || $_POST['losshigh'] || $_POST['down'] || - $_POST['defaultgw'] || ($_POST['gateway'] && $_POST['gateway'] != "dynamic")) - $save = true; - /* if we are processing a system gateway only save the monitorip */ - if (!$save && (empty($_POST['gateway']) || $_POST['gateway'] == "dynamic")) { - /* when dynamic gateway is not anymore a default the entry is no more needed. */ - if (isset($id) && $a_gateway_item[$id]) - unset($a_gateway_item[$id]); - } else { - - /* Manual gateways are handled differently */ - /* rebuild the array with the manual entries only */ - - $gateway = array(); + $gateway = array(); + + if (empty($_POST['interface'])) + $gateway['interface'] = $pconfig['friendlyiface']; + else $gateway['interface'] = $_POST['interface']; - if (is_ipaddr($_POST['gateway'])) - $gateway['gateway'] = $_POST['gateway']; - else - $gateway['gateway'] = "dynamic"; - $gateway['name'] = $_POST['name']; - $gateway['weight'] = $_POST['weight']; - $gateway['descr'] = $_POST['descr']; - if (is_ipaddr($_POST['monitor'])) - $gateway['monitor'] = $_POST['monitor']; - - if ($_POST['defaultgw'] == "yes" || $_POST['defaultgw'] == "on") { - $i = 0; - foreach($a_gateway_item as $gw) { - unset($config['gateways']['gateway_item'][$i]['defaultgw']); - $i++; - } - $gateway['defaultgw'] = true; - $reloadif = true; + if (is_ipaddr($_POST['gateway'])) + $gateway['gateway'] = $_POST['gateway']; + else + $gateway['gateway'] = "dynamic"; + $gateway['name'] = $_POST['name']; + $gateway['weight'] = $_POST['weight']; + $gateway['descr'] = $_POST['descr']; + if (is_ipaddr($_POST['monitor'])) + $gateway['monitor'] = $_POST['monitor']; + + if ($_POST['defaultgw'] == "yes" || $_POST['defaultgw'] == "on") { + $i = 0; + foreach($a_gateway_item as $gw) { + unset($config['gateways']['gateway_item'][$i]['defaultgw']); + $i++; } - - if ($_POST['latencylow']) - $gateway['latencylow'] = $_POST['latencylow']; - if ($_POST['latencyhigh']) - $gateway['latencyhigh'] = $_POST['latencyhigh']; - if ($_POST['losslow']) - $gateway['losslow'] = $_POST['losslow']; - if ($_POST['losshigh']) - $gateway['losshigh'] = $_POST['losshigh']; - if ($_POST['down']) - $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; - else - $a_gateway_item[] = $gateway; + $gateway['defaultgw'] = true; + $reloadif = true; } + + if ($_POST['latencylow']) + $gateway['latencylow'] = $_POST['latencylow']; + if ($_POST['latencyhigh']) + $gateway['latencyhigh'] = $_POST['latencyhigh']; + if ($_POST['losslow']) + $gateway['losslow'] = $_POST['losslow']; + if ($_POST['losshigh']) + $gateway['losshigh'] = $_POST['losshigh']; + if ($_POST['down']) + $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; + else + $a_gateway_item[] = $gateway; + mark_subsystem_dirty('staticroutes'); - + write_config(); - + if($_REQUEST['isAjax']) { echo $_POST['name']; exit; @@ -277,15 +276,6 @@ include("head.inc");