From 3dfa6a5214276556ce089a17e597ac4a345fe319 Mon Sep 17 00:00:00 2001 From: Scott Ullrich Date: Wed, 11 Mar 2009 17:28:17 -0400 Subject: Add ajax mojo to gateway status widget --- usr/local/www/includes/functions.inc.php | 41 ++++++++++++++++++++-- usr/local/www/includes/javascript.inc.php | 1 - usr/local/www/includes/sajax.class.php | 2 +- usr/local/www/javascript/index/sajax.js | 14 +++++++- usr/local/www/sajax/index.sajax.php | 2 +- .../www/widgets/include/interface_statistics.inc | 2 -- usr/local/www/widgets/widgets/gateways.widget.php | 17 ++++++--- 7 files changed, 65 insertions(+), 14 deletions(-) (limited to 'usr/local/www') diff --git a/usr/local/www/includes/functions.inc.php b/usr/local/www/includes/functions.inc.php index 8f549d6..218f732 100644 --- a/usr/local/www/includes/functions.inc.php +++ b/usr/local/www/includes/functions.inc.php @@ -6,7 +6,6 @@ if(Connection_Aborted()) { require_once("config.inc"); - function get_stats() { $stats['cpu'] = cpu_usage(); $stats['mem'] = mem_usage(); @@ -16,12 +15,48 @@ function get_stats() { $stats['datetime'] = update_date_time(); $stats['interfacestatistics'] = get_interfacestats(); $stats['interfacestatus'] = get_interfacestatus(); - + $stats['gateways'] = get_gatewaystats(); $stats = join("|", $stats); - return $stats; } +function get_gatewaystats() { + $gateways_status = array(); + $gateways_status = return_gateways_status(); + $data = ""; + $isfirst = true; + foreach($gateways_status as $gw) { + if(!$isfirst) + $data .= ","; + $isfirst = false; + $data .= $gw['name'] . ","; + $data .= $gw['gateway'] . ","; + $data .= $gw['delay'] . ","; + $data .= $gw['loss'] . ","; + switch($gw['status']) { + case "None": + $online = "Online"; + $bgcolor = "lightgreen"; + break; + case "\"down\"": + $online = "Offline"; + $bgcolor = "lightcoral"; + break; + case "\"delay\"": + $online = "Warning, Latency"; + $bgcolor = "khaki"; + break; + case "\"loss\"": + $online = "Warning, Packetloss"; + $bgcolor = "khaki"; + break; + default: + $online = "No data"; + } + $data .= " $online "; + } + return $data; +} function get_uptime() { $boottime = ""; diff --git a/usr/local/www/includes/javascript.inc.php b/usr/local/www/includes/javascript.inc.php index d1acf17..3cbb64e 100644 --- a/usr/local/www/includes/javascript.inc.php +++ b/usr/local/www/includes/javascript.inc.php @@ -10,7 +10,6 @@ $top_javascript_files = array(); $bottom_javascript_files = array(); - $top_javascript_files['firewall_rules_edit.php'][] = 'autosuggest.js'; $top_javascript_files['firewall_rules_edit.php'][] = 'suggestions.js'; $top_javascript_files['firewall_rules_edit.php'][] = 'firewall_rules_edit.js'; diff --git a/usr/local/www/includes/sajax.class.php b/usr/local/www/includes/sajax.class.php index 58e9393..ee38add 100644 --- a/usr/local/www/includes/sajax.class.php +++ b/usr/local/www/includes/sajax.class.php @@ -261,4 +261,4 @@ class sajax { } // End sajax class -?> +?> \ No newline at end of file diff --git a/usr/local/www/javascript/index/sajax.js b/usr/local/www/javascript/index/sajax.js index c195cf0..c8f31f5 100644 --- a/usr/local/www/javascript/index/sajax.js +++ b/usr/local/www/javascript/index/sajax.js @@ -27,7 +27,8 @@ function stats(x) { updateDateTime(values[5]); updateInterfaceStats(values[6]); updateInterfaces(values[7]); - + updateGatewayStats(values[8]); + } function updateMemory(x) @@ -81,6 +82,17 @@ function updateState(x) document.getElementById("pfstate").value = x; } +function updateGatewayStats(x){ + if (widgetActive("gateways")){ + gateways_split = x.split(","); + var counter = 1; + for (var y=0; ysajax_export("get_stats"); $oSajax->sajax_handle_client_request(); -?> +?> \ No newline at end of file diff --git a/usr/local/www/widgets/include/interface_statistics.inc b/usr/local/www/widgets/include/interface_statistics.inc index 781a018..c789418 100644 --- a/usr/local/www/widgets/include/interface_statistics.inc +++ b/usr/local/www/widgets/include/interface_statistics.inc @@ -2,6 +2,4 @@ //set variable for custom title $interface_statistics_title = "Interface Statistics"; $interface_statistics_title_link = "status_interfaces.php"; - - ?> \ No newline at end of file diff --git a/usr/local/www/widgets/widgets/gateways.widget.php b/usr/local/www/widgets/widgets/gateways.widget.php index 68567df..2af3ea3 100644 --- a/usr/local/www/widgets/widgets/gateways.widget.php +++ b/usr/local/www/widgets/widgets/gateways.widget.php @@ -35,6 +35,8 @@ $a_gateways = return_gateways_array(); $gateways_status = array(); $gateways_status = return_gateways_status(); +$counter = 1; + ?> @@ -52,17 +54,21 @@ $gateways_status = return_gateways_status(); } ?> - - - - -- cgit v1.1
+ + + + + + + + @@ -91,7 +97,8 @@ $gateways_status = return_gateways_status(); default: $online = "No data"; } - echo ""; + echo ""; + $counter++; ?>
$online
$online