From 01da41cf8a21a07734e25a5bce4c2d35f81a0134 Mon Sep 17 00:00:00 2001 From: Bill Marquette Date: Sat, 14 Mar 2009 01:25:46 -0500 Subject: Sajax is no more, long live Prototype This eliminates one AJAX library, but not all "non-Prototype" AJAX code --- usr/local/www/getstats.php | 40 +++++ usr/local/www/head.inc | 10 +- usr/local/www/includes/sajax.class.php | 266 -------------------------------- usr/local/www/index.php | 106 +++++-------- usr/local/www/javascript/index/ajax.js | 154 ++++++++++++++++++ usr/local/www/javascript/index/sajax.js | 148 ------------------ usr/local/www/sajax/index.sajax.php | 14 -- 7 files changed, 237 insertions(+), 501 deletions(-) create mode 100644 usr/local/www/getstats.php delete mode 100644 usr/local/www/includes/sajax.class.php create mode 100644 usr/local/www/javascript/index/ajax.js delete mode 100644 usr/local/www/javascript/index/sajax.js delete mode 100755 usr/local/www/sajax/index.sajax.php (limited to 'usr') diff --git a/usr/local/www/getstats.php b/usr/local/www/getstats.php new file mode 100644 index 0000000..1de82b2 --- /dev/null +++ b/usr/local/www/getstats.php @@ -0,0 +1,40 @@ + \ No newline at end of file diff --git a/usr/local/www/head.inc b/usr/local/www/head.inc index bbb3b5c..0d48fa2 100755 --- a/usr/local/www/head.inc +++ b/usr/local/www/head.inc @@ -73,14 +73,6 @@ $pagetitle = gentitle( $pgtitle ); } } - if ($oSajax): -?> - - - - -"; ?> diff --git a/usr/local/www/includes/sajax.class.php b/usr/local/www/includes/sajax.class.php deleted file mode 100644 index dc070bd..0000000 --- a/usr/local/www/includes/sajax.class.php +++ /dev/null @@ -1,266 +0,0 @@ -sajax_remote_uri = $this->sajax_get_my_uri(); - } - - - /** - * PHP 4 Constructor - * - * @param string $remoteURI - */ - function sajax($remoteURI = NULL) - { - $this->__construct($$remoteURI); - } - - - /** - * - * - */ - function sajax_get_my_uri() - { - global $REQUEST_URI; - - return $REQUEST_URI; - } - - - - function sajax_handle_client_request() { - - $mode = ""; - - if (! empty($_GET["rs"])) - $mode = "get"; - - if (!empty($_POST["rs"])) - $mode = "post"; - - if (empty($mode)) - return; - - if ($mode == "get") { - // Bust cache in the head - header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past - header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); - // always modified - header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 - header ("Pragma: no-cache"); // HTTP/1.0 - $func_name = $_GET["rs"]; - if (! empty($_GET["rsargs"])) - $args = $_GET["rsargs"]; - else - $args = array(); - } - else { - $func_name = $_POST["rs"]; - if (! empty($_POST["rsargs"])) - $args = $_POST["rsargs"]; - else - $args = array(); - } - - if (! in_array($func_name, $this->sajax_export_list)) - echo "-:$func_name not callable"; - else { - echo "+:"; - $result = call_user_func_array($func_name, $args); - echo $result; - } - exit; - } // End sajax_handle_client_request() function ... - - - function sajax_get_common_js() { - - $t = strtoupper($this->sajax_request_type); - if ($t != "GET" && $t != "POST") - return "// Invalid type: $t.. \n\n"; - - ob_start(); - ?> - - sajax_get_common_js(); - } - - - function sajax_esc($val) - { - return str_replace('"', '\\\\"', $val); - } - - - /** - * sajax_get_one_stub - * - * @param string $func_name - */ - function sajax_get_one_stub($func_name) - { - ob_start(); - ?> - - // wrapper for - - function x_() { - sajax_do_call("", - x_.arguments); - } - - sajax_export_list[] = func_get_arg($i); - } - } - - - function sajax_get_javascript() - { - $html = ""; - if (! $this->sajax_js_has_been_shown) { - $html .= $this->sajax_get_common_js(); - $this->sajax_js_has_been_shown = 1; - } - foreach ($this->sajax_export_list as $func) { - $html .= $this->sajax_get_one_stub($func); - } - return $html; - } - - - function sajax_show_javascript() - { - echo $this->sajax_get_javascript(); - } - - -} // End sajax class - - -?> \ No newline at end of file diff --git a/usr/local/www/index.php b/usr/local/www/index.php index 198211b..ac2dc68 100755 --- a/usr/local/www/index.php +++ b/usr/local/www/index.php @@ -59,20 +59,6 @@ ## Load Functions Files require_once('includes/functions.inc.php'); - - ## Load AJAX, Initiate Class ############################################### - require_once('includes/sajax.class.php'); - - ## Initiate Class and Set location of ajax file containing - ## the information that we need for this page. Also set functions - ## that SAJAX will be using. - $oSajax = new sajax(); - $oSajax->sajax_remote_uri = 'sajax/index.sajax.php'; - $oSajax->sajax_request_type = 'POST'; - $oSajax->sajax_export("get_stats"); - $oSajax->sajax_handle_client_request(); - ############################################################################ - ## Check to see if we have a swap space, ## if true, display, if false, hide it ... @@ -551,69 +537,61 @@ echo $jscriptstr; } if ($config['widgets'] && $pconfig['sequence'] != ""){ - if ($displayarray[$widgetcounter] == "show"){ - $divdisplay = "block"; - $display = "block"; - $inputdisplay = "show"; - $showWidget = "none"; - $mindiv = "inline"; - } - else if ($displayarray[$widgetcounter] == "hide") { - $divdisplay = "block"; - $display = "none"; - $inputdisplay = "hide"; - $showWidget = "inline"; - $mindiv = "none"; - } - else if ($displayarray[$widgetcounter] == "close"){ - $divdisplay = "none"; - $display = "block"; - $inputdisplay = "close"; - $showWidget = "none"; - $mindiv = "inline"; - } - else{ - $divdisplay = "none"; - $display = "block"; - $inputdisplay = "none"; - $showWidget = "none"; - $mindiv = "inline"; - } - } - else - { - if ($firstprint == false){ - $divdisplay = "block"; - $display = "block"; - $inputdisplay = "show"; - $showWidget = "none"; - $mindiv = "inline"; - $firstprint = true; - } - else - { - if ($widget == "interfaces.widget.php") - { + switch($displayarray[$widgetcounter]){ + case "show": $divdisplay = "block"; $display = "block"; $inputdisplay = "show"; $showWidget = "none"; $mindiv = "inline"; - } - else if ($widget == "traffic_graphs.widget.php") - { + break; + case "hide": $divdisplay = "block"; + $display = "none"; + $inputdisplay = "hide"; + $showWidget = "inline"; + $mindiv = "none"; + berak; + case "close": + $divdisplay = "none"; $display = "block"; - $inputdisplay = "show"; + $inputdisplay = "close"; $showWidget = "none"; $mindiv = "inline"; - } - else { + break; + default: $divdisplay = "none"; $display = "block"; - $inputdisplay = "close"; + $inputdisplay = "none"; $showWidget = "none"; $mindiv = "inline"; + break; + } + } else { + if ($firstprint == false){ + $divdisplay = "block"; + $display = "block"; + $inputdisplay = "show"; + $showWidget = "none"; + $mindiv = "inline"; + $firstprint = true; + } else { + switch ($widget) { + case "interfaces.widget.php": + case "traffic_graphs.widget.php": + $divdisplay = "block"; + $display = "block"; + $inputdisplay = "show"; + $showWidget = "none"; + $mindiv = "inline"; + break; + default: + $divdisplay = "none"; + $display = "block"; + $inputdisplay = "close"; + $showWidget = "none"; + $mindiv = "inline"; + break; } } } diff --git a/usr/local/www/javascript/index/ajax.js b/usr/local/www/javascript/index/ajax.js new file mode 100644 index 0000000..79bd898 --- /dev/null +++ b/usr/local/www/javascript/index/ajax.js @@ -0,0 +1,154 @@ + +/* Most widgets update their backend data every 10 seconds. 11 seconds + * will ensure that we update the GUI right after the stats are updated. + * Seconds * 1000 = value + */ +var update_interval = 11000; + +function updateMeters() { + url = '/getstats.php' + + new Ajax.Request(url, { + method: 'get', + onSuccess: function(transport) { + stats(transport.responseText); + } + }); + setTimeout('updateMeters()', update_interval); +} + +function stats(x) { + var values = x.split("|"); + if (values.find(function(value){ + if (value == 'undefined' || value == null) + return true; + else + return false; + })) + return; + + updateCPU(values[0]); + updateMemory(values[1]); + updateUptime(values[2]); + updateState(values[3]); + updateTemp(values[4]); + updateDateTime(values[5]); + updateInterfaceStats(values[6]); + updateInterfaces(values[7]); + updateGatewayStats(values[8]); +} + +function updateMemory(x) { + if($('memusagemeter')) + $("memusagemeter").value = x + '%'; + if($('memwidtha')) + $("memwidtha").style.width = x + 'px'; + if($('memwidthb')) + $("memwidthb").style.width = (100 - x) + 'px'; +} + +function updateCPU(x) { + if($('cpumeter')) + $("cpumeter").value = x + '%'; + if($('cpuwidtha')) + $("cpuwidtha").style.width = x + 'px'; + if($('cpuwidthb')) + $("cpuwidthb").style.width = (100 - x) + 'px'; + /* Load CPU Graph widget if enabled */ + if(typeof GraphValue == 'function') { + GraphValue(graph[0], x); + } +} + +function updateTemp(x) { + if($("tempmeter")) { + $("tempmeter").value = x + 'C'; + $("tempwidtha").style.width = x + 'px'; + $("tempwidthb").style.width = (100 - x) + 'px'; + } +} + +function updateDateTime(x) { + if($('datetime')) + $("datetime").firstChild.data = x; +} + +function updateUptime(x) { + if($('uptime')) + $("uptime").value = x; +} + +function updateState(x) { + if($('pfstate')) + $("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 -- cgit v1.1