summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Beaver <sbeaver@netgate.com>2017-08-15 16:40:11 -0400
committerSteve Beaver <sbeaver@netgate.com>2017-08-15 16:40:53 -0400
commit3b940f030f24f9b07a774b1b5daa87a9cccdbfc4 (patch)
tree3615ccbd00a4ec1831983ecda7af5751c942f06c
parentdf8d3033b60da87fcb1d1bf2441335165af55dee (diff)
downloadpfsense-3b940f030f24f9b07a774b1b5daa87a9cccdbfc4.zip
pfsense-3b940f030f24f9b07a774b1b5daa87a9cccdbfc4.tar.gz
COnvert thermal sensor widget to central refresh system
(cherry picked from commit 032f6a8963a51195946b6a823967d31af5fffbe0)
-rw-r--r--src/usr/local/www/widgets/include/thermal_sensors.inc71
-rw-r--r--src/usr/local/www/widgets/javascript/thermal_sensors.js27
-rw-r--r--src/usr/local/www/widgets/widgets/thermal_sensors.widget.php45
3 files changed, 40 insertions, 103 deletions
diff --git a/src/usr/local/www/widgets/include/thermal_sensors.inc b/src/usr/local/www/widgets/include/thermal_sensors.inc
deleted file mode 100644
index e9f4137..0000000
--- a/src/usr/local/www/widgets/include/thermal_sensors.inc
+++ /dev/null
@@ -1,71 +0,0 @@
-<?php
-/*
- * thermal_sensors.inc
- *
- * part of pfSense (https://www.pfsense.org)
- * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- *
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- *
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgment:
- * "This product includes software developed by the pfSense Project
- * for use in the pfSense® software distribution. (http://www.pfsense.org/).
- *
- * 4. The names "pfSense" and "pfSense Project" must not be used to
- * endorse or promote products derived from this software without
- * prior written permission. For written permission, please contact
- * coreteam@pfsense.org.
- *
- * 5. Products derived from this software may not be called "pfSense"
- * nor may "pfSense" appear in their names without prior written
- * permission of the Electric Sheep Fencing, LLC.
- *
- * 6. Redistributions of any form whatsoever must retain the following
- * acknowledgment:
- *
- * "This product includes software developed by the pfSense Project
- * for use in the pfSense software distribution (http://www.pfsense.org/).
- *
- * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
- * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
- * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-//set variable for custom title
-$thermal_sensors_widget_title = gettext("Thermal Sensors");
-//$thermal_sensors_widget_link = "thermal_sensors.php";
-
-
-//returns core temp data (from coretemp.ko or amdtemp.ko driver) as "|"-delimited string.
-//NOTE: depends on proper config in System >> Advanced >> Miscellaneous tab >> Thermal Sensors section.
-function getThermalSensorsData() {
-
- $_gb = exec("/sbin/sysctl -a | grep temperature", $dfout);
- $dfout_filtered = array_filter($dfout, function($v) {
- return strpos($negsign, ' -') === false;
- });
- return join("|", $dfout_filtered);
-
-}
-?>
diff --git a/src/usr/local/www/widgets/javascript/thermal_sensors.js b/src/usr/local/www/widgets/javascript/thermal_sensors.js
index a00dd92..7766a2a 100644
--- a/src/usr/local/www/widgets/javascript/thermal_sensors.js
+++ b/src/usr/local/www/widgets/javascript/thermal_sensors.js
@@ -54,33 +54,6 @@ warningTemp = 9999;
criticalTemp = 100;
ajaxBusy = false;
-//should be called from "thermal_sensors.widget.php"
-function showThermalSensorsData() {
- if (!ajaxBusy) {
- ajaxBusy = true;
- //get data from thermal_sensors.widget.php
- url = "/widgets/widgets/thermal_sensors.widget.php?getThermalSensorsData=1"
- //IE fix to disable cache when using http:// , just append timespan
- + new Date().getTime();
-
- $.ajax(url, {
- type: 'get',
- success: function(data) {
- var thermalSensorsData = data || "";
- buildThermalSensorsData(thermalSensorsData);
- },
- error: function(jqXHR, status, error) {
- warningTemp = 9999;
- buildThermalSensorsDataRaw('<span class="alert-danger">Temperature data could not be read.</span>');
- }
- });
-
- ajaxBusy = false;
- }
- //call itself in 11 seconds
- window.setTimeout(showThermalSensorsData, 11000);
-}
-
function buildThermalSensorsData(thermalSensorsData) {
//NOTE: variable thermal_sensors_widget_showRawOutput is declared/set in "thermal_sensors.widget.php"
if (thermal_sensors_widget_showRawOutput) {
diff --git a/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php b/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php
index cac502b..8dfb085 100644
--- a/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php
+++ b/src/usr/local/www/widgets/widgets/thermal_sensors.widget.php
@@ -52,14 +52,23 @@
*/
require_once("guiconfig.inc");
-require_once("/usr/local/www/widgets/include/thermal_sensors.inc");
+
+//set variable for custom title
+$thermal_sensors_widget_title = gettext("Thermal Sensors");
//=========================================================================
//called by showThermalSensorsData() (jQuery Ajax call) in thermal_sensors.js
-if (isset($_GET["getThermalSensorsData"])) {
+if (isset($_REQUEST["getThermalSensorsData"])) {
//get Thermal Sensors data and return
- echo getThermalSensorsData();
- return;
+ $_gb = exec("/sbin/sysctl -a | grep temperature", $dfout);
+ $dfout_filtered = array_filter($dfout, function($v) {
+ return strpos($negsign, ' -') === false;
+ });
+
+ print(join("|", $dfout_filtered));
+
+ exit;
+
}
//=========================================================================
@@ -177,7 +186,33 @@ function getBoolValueFromConfig(&$configArray, $valueKey, $defaultValue) {
//start showing temp data
//NOTE: the refresh interval will be reset to a proper value in showThermalSensorsData() (thermal_sensors.js).
events.push(function(){
- showThermalSensorsData();
+ // --------------------- Centralized widget refresh system ------------------------------
+
+ // Callback function called by refresh system when data is retrieved
+ function ts_callback(s) {
+ var thermalSensorsData = s || "";
+ buildThermalSensorsData(thermalSensorsData);
+ }
+
+ // POST data to send via AJAX
+ var postdata = {
+ ajax: "ajax",
+ getThermalSensorsData : "1"
+ };
+
+ // Create an object defining the widget refresh AJAX call
+ var tsObject = new Object();
+ tsObject.name = "Gateways";
+ tsObject.url = "/widgets/widgets/thermal_sensors.widget.php";
+ tsObject.callback = ts_callback;
+ tsObject.parms = postdata;
+ tsObject.freq = 4;
+
+ // Register the AJAX object
+ register_ajax(tsObject);
+
+ // ---------------------------------------------------------------------------------------------------
+ //showThermalSensorsData();
});
//]]>
</script>
OpenPOWER on IntegriCloud