summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeth Mos <seth.mos@dds.nl>2012-07-25 23:47:54 -0700
committerSeth Mos <seth.mos@dds.nl>2012-07-25 23:47:54 -0700
commit617152591ff0d0b5b3b8b6674d024880cb6bbf12 (patch)
tree875f869443e08b15e79fb390903ec6ba887109fe
parent4b957845b3dda554e13b733961a13180602619c5 (diff)
parenteb2335174c30b976d79963785c3731a937292467 (diff)
downloadpfsense-617152591ff0d0b5b3b8b6674d024880cb6bbf12.zip
pfsense-617152591ff0d0b5b3b8b6674d024880cb6bbf12.tar.gz
Merge pull request #192 from phil-davis/master
Validate advanced gateway monitoring settings
-rw-r--r--etc/inc/gwlb.inc39
-rwxr-xr-xusr/local/www/system_gateways_edit.php201
2 files changed, 168 insertions, 72 deletions
diff --git a/etc/inc/gwlb.inc b/etc/inc/gwlb.inc
index f064010..9023451 100644
--- a/etc/inc/gwlb.inc
+++ b/etc/inc/gwlb.inc
@@ -31,9 +31,20 @@
*/
require_once("config.inc");
+/* Returns an array of default values used for apinger.conf */
+function return_apinger_defaults() {
+ return array(
+ "latencylow" => "200",
+ "latencyhigh" => "500",
+ "losslow" => "10",
+ "losshigh" => "20",
+ "interval" => "1",
+ "down" => "10");
+ }
+
/*
* Creates monitoring configuration file and
- * adds apropriate static routes.
+ * adds appropriate static routes.
*/
function setup_gateways_monitor() {
global $config, $g;
@@ -46,13 +57,7 @@ function setup_gateways_monitor() {
return;
}
- /* Default settings. Probably should move to globals.inc? */
- $a_settings = array();
- $a_settings['latencylow'] = "200";
- $a_settings['latencyhigh'] = "500";
- $a_settings['losslow'] = "10";
- $a_settings['losshigh'] = "20";
-
+ $apinger_default = return_apinger_defaults();
$fd = fopen("{$g['varetc_path']}/apinger.conf", "w");
$apingerconfig = <<<EOD
@@ -72,7 +77,7 @@ pid_file "{$g['varrun_path']}/apinger.pid"
#timestamp_format "%Y%m%d%H%M%S"
status {
- ## File where the status information whould be written to
+ ## File where the status information should be written to
file "{$g['tmp_path']}/apinger.status"
## Interval between file updates
## when 0 or not set, file is written only when SIGUSR1 is received
@@ -84,7 +89,7 @@ status {
# Interval between RRD updates
rrd interval 60s;
-## These parameters can be overriden in a specific alarm configuration
+## These parameters can be overridden in a specific alarm configuration
alarm default {
command on "/usr/local/sbin/pfSctl -c 'service reload dyndnsall' -c 'service reload ipsecdns' -c 'filter reload' -c 'service reload openvpn'"
command off "/usr/local/sbin/pfSctl -c 'service reload dyndnsall' -c 'service reload ipsecdns' -c 'filter reload' -c 'service reload openvpn'"
@@ -94,28 +99,28 @@ alarm default {
## "Down" alarm definition.
## This alarm will be fired when target doesn't respond for 30 seconds.
alarm down "down" {
- time 10s
+ time {$apinger_default['down']}s
}
## "Delay" alarm definition.
## This alarm will be fired when responses are delayed more than 200ms
## it will be canceled, when the delay drops below 100ms
alarm delay "delay" {
- delay_low {$a_settings['latencylow']}ms
- delay_high {$a_settings['latencyhigh']}ms
+ delay_low {$apinger_default['latencylow']}ms
+ delay_high {$apinger_default['latencyhigh']}ms
}
## "Loss" alarm definition.
## This alarm will be fired when packet loss goes over 20%
## it will be canceled, when the loss drops below 10%
alarm loss "loss" {
- percent_low {$a_settings['losslow']}
- percent_high {$a_settings['losshigh']}
+ percent_low {$apinger_default['losslow']}
+ percent_high {$apinger_default['losshigh']}
}
target default {
## How often the probe should be sent
- interval 1s
+ interval {$apinger_default['interval']}s
## How many replies should be used to compute average delay
## for controlling "delay" alarms
@@ -971,4 +976,4 @@ function validate_address_family($ipaddr, $gwname) {
}
-?>
+?> \ No newline at end of file
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() {
<tr>
<td width="22%" valign="top" class="vncell"><?=gettext("Advanced");?></td>
<td width="78%" class="vtable">
- <?php $showbutton = (!empty($pconfig['latencylow']) || !empty($pconfig['latencyhigh']) || !empty($pconfig['losslow']) || !empty($pconfig['losshigh']) || (isset($pconfig['weight']) && $pconfig['weight'] > 1) || (isset($pconfig['interval']) && $pconfig['interval'])); ?>
+ <?php $showbutton = (!empty($pconfig['latencylow']) || !empty($pconfig['latencyhigh']) || !empty($pconfig['losslow']) || !empty($pconfig['losshigh']) || (isset($pconfig['weight']) && $pconfig['weight'] > 1) || (isset($pconfig['interval']) && ($pconfig['interval'] > $apinger_default['interval'])) || (isset($pconfig['down']) && !($pconfig['down'] == $apinger_default['down']))); ?>
<div id="showadvgatewaybox" <? if ($showbutton) echo "style='display:none'"; ?>>
<input type="button" onClick="show_advanced_gateway()" value="Advanced"></input> - Show advanced option</a>
</div>
@@ -475,7 +572,7 @@ function monitor_change() {
<?=gettext("To");?>
<input name="latencyhigh" type="text" class="formfld unknown" id="latencyhigh" size="2"
value="<?=htmlspecialchars($pconfig['latencyhigh']);?>">
- <br> <span class="vexpl"><?=gettext("These define the low and high water marks for latency in milliseconds. Default is 100/200.");?></span></td>
+ <br> <span class="vexpl"><?=gettext(sprintf("Low and high thresholds for latency in milliseconds. Default is %d/%d.", $apinger_default['latencylow'], $apinger_default['latencyhigh']));?></span></td>
</td>
</tr>
<tr>
@@ -487,7 +584,7 @@ function monitor_change() {
<?=gettext("To");?>
<input name="losshigh" type="text" class="formfld unknown" id="losshigh" size="2"
value="<?=htmlspecialchars($pconfig['losshigh']);?>">
- <br> <span class="vexpl"><?=gettext("These define the low and high water marks for packet loss in %. Default is 10/20.");?></span></td>
+ <br> <span class="vexpl"><?=gettext(sprintf("Low and high thresholds for packet loss in %%. Default is %d/%d.", $apinger_default['losslow'], $apinger_default['losshigh']));?></span></td>
</td>
</tr>
<tr>
@@ -496,7 +593,7 @@ function monitor_change() {
<input name="interval" type="text" class="formfld unknown" id="interval" size="2"
value="<?=htmlspecialchars($pconfig['interval']);?>">
<br><span class="vexpl">
- <?=gettext("This defines how often that an icmp probe will be sent in seconds. Default is 1.");?><br/><br/>
+ <?=gettext(sprintf("How often that an ICMP probe will be sent in seconds. Default is %d.", $apinger_default['interval']));?><br/><br/>
<?=gettext("NOTE: The quality graph is averaged over seconds, not intervals, so as the frequency probe is increased the accuracy of the quality graph is decreased.");?>
</span></td>
</td>
@@ -506,18 +603,12 @@ function monitor_change() {
<td width="78%" class="vtable">
<input name="down" type="text" class="formfld unknown" id="down" size="2"
value="<?=htmlspecialchars($pconfig['down']);?>">
- <br> <span class="vexpl"><?=gettext("This defines the number of bad probes before the alarm will fire. Default is 10.");?></span></td>
+ <br> <span class="vexpl"><?=gettext(sprintf("The number of seconds of failed probes before the alarm will fire. Default is %d.", $apinger_default['down']));?></span></td>
</td>
</tr>
<tr>
<td colspan="2">
- <?= gettext("NOTE: The total time before a gateway is down is the product of the Frequency Probe and the Down fields. By default this is 1*10=10 seconds."); ?><br/>
- <?php if (is_numeric($pconfig['interval']) || is_numeric($pconfig['down'])) {
- echo "<br/>";
- $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));
- } ?>
+ <?= gettext("NOTE: The Frequency Probe interval must be less than the Down time, otherwise the gateway will seem to go down then come up again at the next probe."); ?><br/>
</td>
</tr>
</table>
@@ -546,4 +637,4 @@ function monitor_change() {
monitor_change();
</script>
</body>
-</html>
+</html> \ No newline at end of file
OpenPOWER on IntegriCloud