From eb2335174c30b976d79963785c3731a937292467 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 25 Jul 2012 21:57:27 +0545 Subject: Validate advanced gateway monitoring settings Use the default values from return_apinger_defaults. Validate values - low less than high, probe interval less than "down" time, values are positive numeric. Update descriptions on the UI to show the defaults used. --- usr/local/www/system_gateways_edit.php | 201 ++++++++++++++++++++++++--------- 1 file changed, 146 insertions(+), 55 deletions(-) (limited to 'usr') diff --git a/usr/local/www/system_gateways_edit.php b/usr/local/www/system_gateways_edit.php index 033b3e6..b7762d5 100755 --- a/usr/local/www/system_gateways_edit.php +++ b/usr/local/www/system_gateways_edit.php @@ -53,6 +53,7 @@ if (!is_array($config['gateways']['gateway_item'])) $config['gateways']['gateway_item'] = array(); $a_gateway_item = &$config['gateways']['gateway_item']; +$apinger_default = return_apinger_defaults(); $id = $_GET['id']; if (isset($_POST['id'])) @@ -75,10 +76,10 @@ if (isset($id) && $a_gateways[$id]) { $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['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['monitor'] = $a_gateways[$id]['monitor']; $pconfig['monitor_disable'] = isset($a_gateways[$id]['monitor_disable']); $pconfig['descr'] = $a_gateways[$id]['descr']; @@ -198,45 +199,141 @@ if ($_POST) { } } - /* input validation */ - if($_POST['latencylow']) { - if (! is_numeric($_POST['latencylow'])) { - $input_errors[] = gettext("The low latency watermark needs to be a numeric value."); - } - } - - if($_POST['latencyhigh']) { - if (! is_numeric($_POST['latencyhigh'])) { - $input_errors[] = gettext("The high latency watermark needs to be a numeric value."); - } - } - if($_POST['losslow']) { - if (! is_numeric($_POST['losslow'])) { - $input_errors[] = gettext("The low loss watermark needs to be a numeric value."); - } - } - if($_POST['losshigh']) { - if (! is_numeric($_POST['losshigh'])) { - $input_errors[] = gettext("The high loss watermark needs to be a numeric value."); - } - } - - if(($_POST['latencylow']) && ($_POST['latencyhigh'])){ - if(($_POST['latencylow'] > $_POST['latencyhigh'])) { - $input_errors[] = gettext("The High latency watermark needs to be higher then the low latency watermark"); - } - } - - if(($_POST['losslow']) && ($_POST['losshigh'])){ - if($_POST['losslow'] > $_POST['losshigh']) { - $input_errors[] = gettext("The High packet loss watermark needs to be higher then the low packet loss watermark"); - } - } + /* input validation of apinger advanced parameters */ + if($_POST['latencylow']) { + if (! is_numeric($_POST['latencylow'])) { + $input_errors[] = gettext("The low latency threshold needs to be a numeric value."); + } else { + if ($_POST['latencylow'] < 1) { + $input_errors[] = gettext("The low latency threshold needs to be positive."); + } + } + } + + if($_POST['latencyhigh']) { + if (! is_numeric($_POST['latencyhigh'])) { + $input_errors[] = gettext("The high latency threshold needs to be a numeric value."); + } else { + if ($_POST['latencyhigh'] < 1) { + $input_errors[] = gettext("The high latency threshold needs to be positive."); + } + } + } + + if($_POST['losslow']) { + if (! is_numeric($_POST['losslow'])) { + $input_errors[] = gettext("The low Packet Loss threshold needs to be a numeric value."); + } else { + if ($_POST['losslow'] < 1) { + $input_errors[] = gettext("The low Packet Loss threshold needs to be positive."); + } + if ($_POST['losslow'] >= 100) { + $input_errors[] = gettext("The low Packet Loss threshold needs to be less than 100."); + } + } + } + + if($_POST['losshigh']) { + if (! is_numeric($_POST['losshigh'])) { + $input_errors[] = gettext("The high Packet Loss threshold needs to be a numeric value."); + } else { + if ($_POST['losshigh'] < 1) { + $input_errors[] = gettext("The high Packet Loss threshold needs to be positive."); + } + if ($_POST['losshigh'] > 100) { + $input_errors[] = gettext("The high Packet Loss threshold needs to be 100 or less."); + } + } + } + + if(($_POST['latencylow']) && ($_POST['latencyhigh'])) { + if ((is_numeric($_POST['latencylow'])) && (is_numeric($_POST['latencyhigh']))) { + if(($_POST['latencylow'] > $_POST['latencyhigh'])) { + $input_errors[] = gettext("The high latency threshold needs to be higher than the low latency threshold"); + } + } + } else { + if($_POST['latencylow']){ + if (is_numeric($_POST['latencylow'])) { + if($_POST['latencylow'] > $apinger_default['latencyhigh']) { + $input_errors[] = gettext(sprintf("The low latency threshold needs to be less than the default high latency threshold (%d)", $apinger_default['latencyhigh'])); + } + } + } + if($_POST['latencyhigh']){ + if (is_numeric($_POST['latencyhigh'])) { + if($_POST['latencyhigh'] < $apinger_default['latencylow']) { + $input_errors[] = gettext(sprintf("The high latency threshold needs to be higher than the default low latency threshold (%d)", $apinger_default['latencylow'])); + } + } + } + } + + if(($_POST['losslow']) && ($_POST['losshigh'])){ + if ((is_numeric($_POST['losslow'])) && (is_numeric($_POST['losshigh']))) { + if($_POST['losslow'] > $_POST['losshigh']) { + $input_errors[] = gettext("The high Packet Loss threshold needs to be higher than the low Packet Loss threshold"); + } + } + } else { + if($_POST['losslow']){ + if (is_numeric($_POST['losslow'])) { + if($_POST['losslow'] > $apinger_default['losshigh']) { + $input_errors[] = gettext(sprintf("The low Packet Loss threshold needs to be less than the default high Packet Loss threshold (%d)", $apinger_default['losshigh'])); + } + } + } + if($_POST['losshigh']){ + if (is_numeric($_POST['losshigh'])) { + if($_POST['losshigh'] < $apinger_default['losslow']) { + $input_errors[] = gettext(sprintf("The high Packet Loss threshold needs to be higher than the default low Packet Loss threshold (%d)", $apinger_default['losslow'])); + } + } + } + } + + if($_POST['interval']) { + if (! is_numeric($_POST['interval'])) { + $input_errors[] = gettext("The frequency probe interval needs to be a numeric value."); + } else { + if ($_POST['interval'] < 1) { + $input_errors[] = gettext("The frequency probe interval needs to be positive."); + } + } + } + if($_POST['down']) { - if (! is_numeric($_POST['down']) || $_POST['down'] < 1) { - $input_errors[] = gettext("The low latency watermark needs to be a numeric value."); - } - } + if (! is_numeric($_POST['down'])) { + $input_errors[] = gettext("The down time setting needs to be a numeric value."); + } else { + if ($_POST['down'] < 1) { + $input_errors[] = gettext("The down time setting needs to be positive."); + } + } + } + + if(($_POST['interval']) && ($_POST['down'])){ + if ((is_numeric($_POST['interval'])) && (is_numeric($_POST['down']))) { + if($_POST['interval'] > $_POST['down']) { + $input_errors[] = gettext("The Frequency Probe interval needs to be less than the down time setting."); + } + } + } else { + if($_POST['interval']){ + if (is_numeric($_POST['interval'])) { + if($_POST['interval'] > $apinger_default['down']) { + $input_errors[] = gettext(sprintf("The Frequency Probe interval needs to be less than the default down time setting (%d)", $apinger_default['down'])); + } + } + } + if($_POST['down']){ + if (is_numeric($_POST['down'])) { + if($_POST['down'] < $apinger_default['interval']) { + $input_errors[] = gettext(sprintf("The down time setting needs to be higher than the default Frequency Probe interval (%d)", $apinger_default['interval'])); + } + } + } + } if (!$input_errors) { $reloadif = ""; @@ -444,7 +541,7 @@ function monitor_change() { - 1) || (isset($pconfig['interval']) && $pconfig['interval'])); ?> + 1) || (isset($pconfig['interval']) && ($pconfig['interval'] > $apinger_default['interval'])) || (isset($pconfig['down']) && !($pconfig['down'] == $apinger_default['down']))); ?>
> - Show advanced option
@@ -475,7 +572,7 @@ function monitor_change() { -
+
@@ -487,7 +584,7 @@ function monitor_change() { -
+
@@ -496,7 +593,7 @@ function monitor_change() {
-

+

@@ -506,18 +603,12 @@ function monitor_change() { -
+
-
- "; - $interval = is_numeric($pconfig['interval']) ? $pconfig['interval'] : 1; - $down = is_numeric($pconfig['down']) ? $pconfig['down'] : 10; - echo gettext(sprintf("With the current configuration, the total time before this gateway would be considered down would be: %d*%d=%d seconds.", $interval, $down, $interval*$down)); - } ?> +
@@ -546,4 +637,4 @@ function monitor_change() { monitor_change(); - + \ No newline at end of file -- cgit v1.1