Commit 90a31b13 authored by Ad Schellevis's avatar Ad Schellevis

(dashboard, widgets) replace thermal_sensors.widget.php

parent 53f6dace
<?php
/*
Copyright (C) 2016 Deciso B.V.
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.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS 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
AUTHOR 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.
*/
/**
* widget temperature data
*/
function temperature_api()
{
$result = array();
exec("/sbin/sysctl -a | grep temperature", $sysctlOutput);
foreach ($sysctlOutput as $sysctl) {
$parts = explode(':', $sysctl);
if (count($parts) >= 2) {
$tempItem = array();
$tempItem['device'] = $parts[0];
$tempItem['device_seq'] = filter_var($tempItem['device'], FILTER_SANITIZE_NUMBER_INT);
$tempItem['temperature'] = trim(str_replace('C', '', $parts[1]));
$tempItem['type'] = strpos($tempItem['device'], 'hw.acpi') !== false ? "zone" : "core";
$tempItem['type_translated'] = $tempItem['type'] == "zone" ? gettext("Zone") : gettext("Core");
$result[] = $tempItem;
}
}
usort($result, function ($item1, $item2) {
return strcmp(strtolower($item1['device']), strtolower($item2['device']));
});
return $result;
}
<?php
/*
$Id: thermal_sensors.inc
File location:
\usr\local\www\widgets\include\
Used by:
\usr\local\www\widgets\widgets\thermal_sensors.widget.php
*/
//set variable for custom title
$thermal_sensors_widget_title = "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 cofing in System >> Advanced >> Miscellaneous tab >> Thermal Sensors section.
function getThermalSensorsData()
{
$_gb = exec("/sbin/sysctl -a | grep temperature", $dfout);
$thermalSensorsData = join("|", $dfout);
return $thermalSensorsData;
}
/*
$Id: thermal_sensors.js
Description:
Javascript functions to get and show thermal sensors data in thermal_sensors.widget.php.
NOTE: depends on proper cofing in System >> Advanced >> Miscellaneous tab >> Thermal Sensors section.
File location:
\usr\local\www\widgets\javascript\
Used by:
\usr\local\www\widgets\widgets\thermal_sensors.widget.php
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.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS 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
AUTHOR 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.
*/
//should be called from "thermal_sensors.widget.php"
function showThermalSensorsData() {
//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();
jQuery.ajax(url, {
type: 'get',
success: function(data) {
var thermalSensorsData = data || "";
buildThermalSensorsData(thermalSensorsData);
},
error: function(jqXHR, status, error){
buildThermalSensorsDataRaw(
"Error getting data from [thermal_sensors.widget.php] - |" +
"status: [" + (status || "") + "]|" +
"error: [" + (error || "") + "]");
}
});
//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) {
buildThermalSensorsDataRaw(thermalSensorsData);
}
else {
buildThermalSensorsDataGraph(thermalSensorsData);
}
}
function buildThermalSensorsDataRaw(thermalSensorsData) {
var thermalSensorsContent = "";
if (thermalSensorsData && thermalSensorsData != "") {
thermalSensorsContent = thermalSensorsData.replace(/\|/g, "<br />");
//rawData = thermalSensorsData.split("|").join("<br />");
}
loadThermalSensorsContainer(thermalSensorsContent);
}
function loadThermalSensorsContainer (thermalSensorsContent) {
if (thermalSensorsContent && thermalSensorsContent != "") {
//load generated graph (or raw data) into thermalSensorsContainer (thermalSensorsContainer DIV defined in "thermal_sensors.widget.php")
jQuery('#thermalSensorsContainer').html(thermalSensorsContent);
} else {
jQuery('#thermalSensorsContainer').html("No Thermal Sensors data available.<br /><br />");
jQuery('<div/>').html(
"<span>* You can configure a proper Thermal Sensor / Module under <br />" +
"&nbsp;&nbsp;&nbsp;<a href='system_advanced_misc.php'>System &gt; Advanced &gt; Miscellaneous : Thermal Sensors section</a>.</span>"
).appendTo('#thermalSensorsContainer');
}
}
function buildThermalSensorsDataGraph(thermalSensorsData) {
//local constants
var normalColor = "LimeGreen";
var normalColorShadowTop = "Lime";
var normalColorShadowBottom = "Green";
var warningColor = "Orange";
var warningColorShadowBottom = "Chocolate";
var criticalColor = "Red";
var criticalColorShadowBottom = "DarkRed";
//local variables
var barBgColor = normalColor; //green/normal as default
var barBgColorShadowTop = normalColorShadowTop; //green/normal as default
var barBgColorShadowBottom = normalColorShadowBottom; //green/normal as default
var thermalSensorsArray = new Array();
if (thermalSensorsData && thermalSensorsData != ""){
thermalSensorsArray = thermalSensorsData.split("|");
}
var thermalSensorsHTMLContent = "";
var itemsToPulsate = new Array();
//generate graph for each temperature sensor and append to thermalSensorsHTMLContent string
for (var i = 0; i < thermalSensorsArray.length; i++) {
var sensorDataArray = thermalSensorsArray[i].split(":");
var sensorName = sensorDataArray[0].trim();
var thermalSensorValue = getThermalSensorValue(sensorDataArray[1]);
var pulsateTimes = 0;
var pulsateDuration = 0;
var warningTempThresholdPosition = 0;
var criticalTempThresholdPosition = 0;
//NOTE: the following variables are declared/set in "thermal_sensors.widget.php":
// thermal_sensors_widget_coreWarningTempThreshold, thermal_sensors_widget_coreCriticalTempThreshold,
// thermal_sensors_widget_zoneWarningTempThreshold, thermal_sensors_widget_zoneCriticalTempThreshold
// thermal_sensors_widget_pulsateWarning, thermal_sensors_widget_pulsateCritical
//set graph color and pulsate parameters
if (sensorName.indexOf("cpu") > -1) { //check CPU Threshold config settings
warningTempThresholdPosition = thermal_sensors_widget_coreWarningTempThreshold;
criticalTempThresholdPosition = thermal_sensors_widget_coreCriticalTempThreshold;
if (thermalSensorValue < thermal_sensors_widget_coreWarningTempThreshold) {
barBgColor = normalColor;
barBgColorShadowTop = normalColorShadowTop;
barBgColorShadowBottom = normalColorShadowBottom;
pulsateTimes = 0;
pulsateDuration = 0;
} else if (thermalSensorValue >= thermal_sensors_widget_coreWarningTempThreshold && thermalSensorValue < thermal_sensors_widget_coreCriticalTempThreshold) {
barBgColor = warningColor;
barBgColorShadowTop = warningColor;
barBgColorShadowBottom = warningColorShadowBottom;
pulsateTimes = thermal_sensors_widget_pulsateWarning ? 4 : 0;
pulsateDuration = thermal_sensors_widget_pulsateWarning ? 900 : 0;
} else { // thermalSensorValue > thermal_sensors_widget_coreCriticalTempThreshold
barBgColor = criticalColor;
barBgColorShadowTop = criticalColor;
barBgColorShadowBottom = criticalColorShadowBottom;
pulsateTimes = thermal_sensors_widget_pulsateCritical ? 7 : 0;
pulsateDuration = thermal_sensors_widget_pulsateCritical ? 900 : 0;
}
} else { //assuming sensor is for a zone, check Zone Threshold config settings
warningTempThresholdPosition = thermal_sensors_widget_zoneWarningTempThreshold;
criticalTempThresholdPosition = thermal_sensors_widget_zoneCriticalTempThreshold;
if (thermalSensorValue < thermal_sensors_widget_zoneWarningTempThreshold) {
barBgColor = normalColor;
barBgColorShadowTop = normalColorShadowTop;
barBgColorShadowBottom = normalColorShadowBottom;
pulsateTimes = 0;
pulsateDuration = 0;
} else if (thermalSensorValue >= thermal_sensors_widget_zoneWarningTempThreshold
&& thermalSensorValue < thermal_sensors_widget_zoneCriticalTempThreshold) {
barBgColor = warningColor;
barBgColorShadowTop = warningColor;
barBgColorShadowBottom = warningColorShadowBottom;
pulsateTimes = thermal_sensors_widget_pulsateWarning ? 4 : 0;
pulsateDuration = thermal_sensors_widget_pulsateWarning ? 900 : 0;
} else { // thermalSensorValue > thermal_sensors_widget_zoneCriticalTempThreshold
barBgColor = criticalColor;
barBgColorShadowTop = criticalColor;
barBgColorShadowBottom = criticalColorShadowBottom;
pulsateTimes = thermal_sensors_widget_pulsateCritical ? 7 : 0;
pulsateDuration = thermal_sensors_widget_pulsateCritical ? 900 : 0;
}
}
//NOTE: variable thermal_sensors_widget_showFullSensorName is declared/set in "thermal_sensors.widget.php"
if (!thermal_sensors_widget_showFullSensorName) {
sensorName = getSensorFriendlyName(sensorName);
}
//build temperature item/row for a sensor
//NOTE: additional styles are set in 'thermal_sensors.widget.php'
var thermalSensorRow = "<div class='thermalSensorRow' id='thermalSensorRow" + i + "' >" +
//sensor name and temperature value
" <div class='thermalSensorTextShell'><div class='thermalSensorText' id='thermalSensorText" + i + "'>" + sensorName + ": </div><div class='thermalSensorValue' id='thermalSensorValue" + i + "'>" + thermalSensorValue + " &deg;C</div></div>" +
//temperature bar
" <div class='thermalSensorBarShell' id='thermalSensorBarShell" + i + "' >" +
" <div class='thermalSensorBar' id='thermalSensorBar" + i + "' style='background-color: " + barBgColor + "; border-top-color: " + barBgColorShadowTop + "; border-bottom-color: " + barBgColorShadowBottom + "; width:" + thermalSensorValue + "%;' ></div>" +
//threshold targets (warning and critical)
" <div class='thermalSensorWarnThresh' id='thermalSensorWarnThresh" + i + "' style='left:" + warningTempThresholdPosition + "%;' ></div>" +
" <div class='thermalSensorCritThresh' id='thermalSensorCritThresh" + i + "' style='left:" + criticalTempThresholdPosition + "%;' ></div>" +
//temperature scale (max 100 C)
" <div class='thermal_sensors_widget_scale000'></div>" +
" <div class='thermal_sensors_widget_scale010'></div>" +
" <div class='thermal_sensors_widget_scale020'></div>" +
" <div class='thermal_sensors_widget_scale030'></div>" +
" <div class='thermal_sensors_widget_scale040'></div>" +
" <div class='thermal_sensors_widget_scale050'></div>" +
" <div class='thermal_sensors_widget_scale060'></div>" +
" <div class='thermal_sensors_widget_scale070'></div>" +
" <div class='thermal_sensors_widget_scale080'></div>" +
" <div class='thermal_sensors_widget_scale090'></div>" +
" <div class='thermal_sensors_widget_scale100'></div>" +
" <div class='thermal_sensors_widget_mark100'>100&deg;</div>" +
" </div>" +
"</div>";
//collect parameters for warning/critical items we need to pulsate
if (pulsateTimes > 0) {
var params = i + "|" + barBgColor + "|" + pulsateTimes + "|" + pulsateDuration;
itemsToPulsate.push(params);
}
//append HTML item
thermalSensorsHTMLContent = thermalSensorsHTMLContent + thermalSensorRow;
}
//load generated graph into thermalSensorsContainer (DIV defined in "thermal_sensors.widget.php")
loadThermalSensorsContainer(thermalSensorsHTMLContent);
if (itemsToPulsate.length > 0) {
//pulsate/flash warning/critical items we collected
pulsateThermalSensorsItems(itemsToPulsate);
}
}
function pulsateThermalSensorsItems(itemsToPulsate) {
//pulsate/flash warning/critical items we collected
for (var i = 0; i < itemsToPulsate.length; i++) {
var pulsateParams = itemsToPulsate[i].split("|");
var rowNum = parseInt(pulsateParams[0]);
//var textColor = pulsateParams[1];
var pulsateTimes = parseInt(pulsateParams[2]);
var pulsateDuration = parseInt(pulsateParams[3]);
//pulsate temp Value
var divThermalSensorValue = jQuery("#thermalSensorValue" + rowNum); //get temp value by id
divThermalSensorValue.effect("pulsate", {
times: pulsateTimes
,easing: 'linear' //'easeInExpo'
}, pulsateDuration);
////set Temp Value color
//divThermalSensorValue.css( { color: textColor } );
//pulsate temp Bar
var divThermalSensorBar = jQuery("#thermalSensorBar" + rowNum); //get temp bar by id
divThermalSensorBar.effect("pulsate", {
times: pulsateTimes
,easing: 'linear' //'easeInExpo'
}, pulsateDuration);
}
}
function getSensorFriendlyName(sensorFullName){
var rzone = /^hw\.acpi\.thermal\.tz([0-9]+)\.temperature$/;
var rcore = /^dev\.cpu\.([0-9]+)\.temperature$/;
if (rzone.test(sensorFullName))
return "Zone " + rzone.exec(sensorFullName)[1];
if (rcore.test(sensorFullName))
return "Core " + rcore.exec(sensorFullName)[1];
return sensorFullName;
}
function getThermalSensorValue(stringValue){
return (+parseFloat(stringValue) || 0).toFixed(1);
}
<?php
/*
Copyright (C) 2014 Deciso B.V.
Copyright (C) 2014-2016 Deciso B.V.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
......@@ -23,267 +22,157 @@
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.
*/
/*
Description: Thermal Sensors Widget.
NOTE: depends on proper cofing in System >> Advanced >> Miscellaneous tab >> Thermal Sensors section.
File location:
\usr\local\www\widgets\widgets\
Depends on:
\usr\local\www\widgets\javascript\thermal_sensors.js
\usr\local\www\widgets\include\thermal_sensors.inc
*/
require_once("guiconfig.inc");
require_once("widgets/include/thermal_sensors.inc");
//=========================================================================
//called by showThermalSensorsData() (jQuery Ajax call) in thermal_sensors.js
if (isset($_GET["getThermalSensorsData"])) {
//get Thermal Sensors data and return
echo getThermalSensorsData();
return;
}
//=========================================================================
const WIDGETS_CONFIG_SECTION_KEY = "widgets";
const THERMAL_SENSORS_WIDGET_SUBSECTION_KEY = "thermal_sensors_widget";
//default constants
const DEFAULT_WARNING_THRESHOLD = 70; //60 C
const DEFAULT_CRITICAL_THRESHOLD = 80; //70 C
const MIN_THRESHOLD_VALUE = 1; //deg C
const MAX_THRESHOLD_VALUE = 100; //deg C
//NOTE: keys used in $_POST and $config should match text and checkbox inputs' IDs/names in HTML code section
//=========================================================================
//save widget config settings on POST
if ($_POST) {
saveThresholdSettings($config, $_POST, "thermal_sensors_widget_zone_warning_threshold", "thermal_sensors_widget_zone_critical_threshold");
saveThresholdSettings($config, $_POST, "thermal_sensors_widget_core_warning_threshold", "thermal_sensors_widget_core_critical_threshold");
//handle checkboxes separately
saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_show_raw_output");
saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_show_full_sensor_name");
saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_pulsate_warning");
saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_pulsate_critical");
//write settings to config file
write_config("Saved thermal_sensors_widget settings via Dashboard.");
header("Location: ../../index.php");
}
function saveThresholdSettings(&$configArray, &$postArray, $warningValueKey, $criticalValueKey)
function validate_temp_value($value)
{
$warningValue = 0;
$criticalValue = 0;
if (isset($postArray[$warningValueKey])) {
$warningValue = (int) $postArray[$warningValueKey];
}
if (isset($postArray[$criticalValueKey])) {
$criticalValue = (int) $postArray[$criticalValueKey];
}
if (($warningValue >= MIN_THRESHOLD_VALUE && $warningValue <= MAX_THRESHOLD_VALUE) &&
($criticalValue >= MIN_THRESHOLD_VALUE && $criticalValue <= MAX_THRESHOLD_VALUE) &&
($warningValue < $criticalValue)
) {
//all validated ok, save to config array
$configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$warningValueKey] = $warningValue;
$configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$criticalValueKey] = $criticalValue;
if (is_numeric($value) && (int)$value == $value && $value >= 0 and $value <= 100) {
return true;
} else {
return false;
}
}
function saveGraphDisplaySettings(&$configArray, &$postArray, $valueKey)
{
$configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$valueKey] = isset($postArray[$valueKey]) ? 1 : 0;
}
//=========================================================================
//get Threshold settings from config (apply defaults if missing)
$thermal_sensors_widget_zoneWarningTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_zone_warning_threshold", DEFAULT_WARNING_THRESHOLD);
$thermal_sensors_widget_zoneCriticalTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_zone_critical_threshold", DEFAULT_CRITICAL_THRESHOLD);
$thermal_sensors_widget_coreWarningTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_core_warning_threshold", DEFAULT_WARNING_THRESHOLD);
$thermal_sensors_widget_coreCriticalTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_core_critical_threshold", DEFAULT_CRITICAL_THRESHOLD);
//get display settings from config (apply defaults if missing)
$thermal_sensors_widget_showRawOutput = getBoolValueFromConfig($config, "thermal_sensors_widget_show_raw_output", false);
$thermal_sensors_widget_showFullSensorName = getBoolValueFromConfig($config, "thermal_sensors_widget_show_full_sensor_name", false);
$thermal_sensors_widget_pulsateWarning = getBoolValueFromConfig($config, "thermal_sensors_widget_pulsate_warning", true);
$thermal_sensors_widget_pulsateCritical = getBoolValueFromConfig($config, "thermal_sensors_widget_pulsate_critical", true);
function getThresholdValueFromConfig(&$configArray, $valueKey, $defaultValue)
{
$thresholdValue = $defaultValue;
if (isset($configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$valueKey])) {
$thresholdValue = (int) $configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$valueKey];
$fieldnames = array('thermal_sensors_widget_zone_warning_threshold', 'thermal_sensors_widget_zone_critical_threshold',
'thermal_sensors_widget_core_warning_threshold', 'thermal_sensors_widget_core_critical_threshold');
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$pconfig = array();
foreach ($fieldnames as $fieldname) {
$defaultValue = strpos($fieldname, 'critical') !== false ? 80 : 70;
$pconfig[$fieldname] = !empty($config['widgets']['thermal_sensors_widget'][$fieldname]) ? $config['widgets']['thermal_sensors_widget'][$fieldname] : $defaultValue;
}
if ($thresholdValue < MIN_THRESHOLD_VALUE || $thresholdValue > MAX_THRESHOLD_VALUE) {
//set to default if not in allowed range
$thresholdValue = $defaultValue;
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
// save widget config
if (empty($config['widgets']['thermal_sensors_widget']) || !is_array($config['widgets']['thermal_sensors_widget'])) {
$config['widgets']['thermal_sensors_widget'] = array();
}
return $thresholdValue;
}
function getBoolValueFromConfig(&$configArray, $valueKey, $defaultValue)
{
$boolValue = false;
if (isset($configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$valueKey])) {
$boolValue = (bool) $configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$valueKey];
} else {
//set to default if not in allowed range
$boolValue = $defaultValue;
foreach ($fieldnames as $fieldname) {
$defaultValue = strpos($fieldname, 'critical') !== false ? 80 : 70;
$newValue = !empty($_POST[$fieldname]) ? $_POST[$fieldname] : "";
$config['widgets']['thermal_sensors_widget'][$fieldname] = validate_temp_value($newValue) ? $newValue : $defaultValue;
}
return $boolValue;
write_config("Thermal sensors widget saved via Dashboard.");
header("Location: /index.php");
die;
}
//=========================================================================
?>
<script type="text/javascript">
//<![CDATA[
//set Thresholds, to be used in thermal_sensors.js
var thermal_sensors_widget_zoneWarningTempThreshold = <?= $thermal_sensors_widget_zoneWarningTempThreshold; ?>;
var thermal_sensors_widget_zoneCriticalTempThreshold = <?= $thermal_sensors_widget_zoneCriticalTempThreshold; ?>;
var thermal_sensors_widget_coreWarningTempThreshold = <?= $thermal_sensors_widget_coreWarningTempThreshold; ?>;
var thermal_sensors_widget_coreCriticalTempThreshold = <?= $thermal_sensors_widget_coreCriticalTempThreshold; ?>;
//set Graph display settings, to be used in thermal_sensors.js
var thermal_sensors_widget_showRawOutput = <?= $thermal_sensors_widget_showRawOutput ? "true" : "false"; ?>;
var thermal_sensors_widget_showFullSensorName = <?= $thermal_sensors_widget_showFullSensorName ? "true" : "false"; ?>;
var thermal_sensors_widget_pulsateWarning = <?= $thermal_sensors_widget_pulsateWarning ? "true" : "false"; ?>;
var thermal_sensors_widget_pulsateCritical = <?= $thermal_sensors_widget_pulsateCritical ? "true" : "false"; ?>;
//start showing temp data
//NOTE: the refresh interval will be reset to a proper value in showThermalSensorsData() (thermal_sensors.js).
jQuery(document).ready(function() {
showThermalSensorsData();
function thermal_sensors_widget_update(sender, data)
{
data.map(function(sensor) {
var tempIntValue = parseInt(sensor['temperature']);
var progressbar = $("#thermal_sensors_widget_progress_bar").html();
var tbody = sender.find('tbody');
var tr_id = "thermal_sensors_widget_" + sensor['device'].replace(/\./g, '_');
if (tbody.find("#"+tr_id).length == 0) {
var tr_content = [];
tr_content.push('<tr id="'+tr_id+'">');
tr_content.push('<td>'+progressbar+'</td>');
tr_content.push('</tr>');
tbody.append(tr_content.join(''));
}
// probe warning / danger temp
if (sensor['type'] == 'core') {
danger_temp = parseInt($("#thermal_sensors_widget_core_critical_threshold").val());
warning_temp = parseInt($("#thermal_sensors_widget_core_warning_threshold").val());
} else {
danger_temp = parseInt($("#thermal_sensors_widget_zone_critical_threshold").val());
warning_temp = parseInt($("#thermal_sensors_widget_zone_warning_threshold").val());
}
// progress bar style
if (tempIntValue > danger_temp) {
$("#"+tr_id + " .progress-bar").removeClass('progress-bar-success')
.removeClass('progress-bar-warning')
.removeClass('progress-bar-danger')
.addClass('progress-bar-danger');
} else if (tempIntValue > warning_temp) {
$("#"+tr_id + " .progress-bar").removeClass('progress-bar-success')
.removeClass('progress-bar-warning')
.removeClass('progress-bar-danger')
.addClass('progress-bar-warning');
} else {
$("#"+tr_id + " .progress-bar").removeClass('progress-bar-success')
.removeClass('progress-bar-warning')
.removeClass('progress-bar-danger')
.addClass('progress-bar-success');
}
// update bar
$("#"+tr_id + " .progress-bar").html(sensor['temperature'] + ' &deg;C');
$("#"+tr_id + " .progress-bar").css("width", tempIntValue + "%").attr("aria-valuenow", tempIntValue + "%");
// update label
$("#"+tr_id + " .info").html(sensor['type_translated'] + " " + sensor['device_seq'] + " <small>("+sensor['device']+")<small>");
});
//]]>
}
</script>
<input type="hidden" id="thermal_sensors-config" name="thermal_sensors-config" value="" />
<div id="thermal_sensors-settings" class="widgetconfigdiv" style="display:none;">
<form action="/widgets/widgets/thermal_sensors.widget.php" method="post" id="iform_thermal_sensors_settings" name="iform_thermal_sensors_settings">
<table class="table table-striped" width="100%" border="0" summary="thermal sensors widget">
<table class="table table-striped">
<thead>
<tr>
<td align="left" colspan="2">
<span style="font-weight: bold" ><?= gettext('Thresholds in &deg;C (1 to 100):') ?></span>
</td>
<td align="right" colspan="1">
<span style="font-weight: bold" ><?= gettext('Display settings:') ?></span>
</td>
<th colspan="2"><?= gettext('Thresholds in &deg;C (1 to 100):') ?></th>
</tr>
</thead>
<tbody>
<tr>
<td><?= gettext('Zone Warning:') ?></td>
<td>
<?= gettext('Zone Warning:') ?>
</td>
<td>
<input type="text" maxlength="3" size="3" class="formfld unknown"
name="thermal_sensors_widget_zone_warning_threshold"
id="thermal_sensors_widget_zone_warning_threshold"
value="<?= $thermal_sensors_widget_zoneWarningTempThreshold; ?>" />
</td>
<td>
<label for="thermal_sensors_widget_show_raw_output"><?= gettext('Show raw output (no graph):') ?> </label>
<input type="checkbox"
id="thermal_sensors_widget_show_raw_output"
name="thermal_sensors_widget_show_raw_output"
value="<?= $thermal_sensors_widget_showRawOutput;
?>" <?= ($thermal_sensors_widget_showRawOutput) ? " checked='checked'" : ""; ?> />
<input type="text" id="thermal_sensors_widget_zone_warning_threshold" name="thermal_sensors_widget_zone_warning_threshold" value="<?= $pconfig['thermal_sensors_widget_zone_warning_threshold']; ?>" />
</td>
</tr>
<tr>
<td><?= gettext('Zone Critical:') ?></td>
<td>
<?= gettext('Zone Critical:') ?>
</td>
<td>
<input type="text" maxlength="3" size="3" class="formfld unknown"
name="thermal_sensors_widget_zone_critical_threshold"
id="thermal_sensors_widget_zone_critical_threshold"
value="<?= $thermal_sensors_widget_zoneCriticalTempThreshold; ?>" />
</td>
<td>
<label for="thermal_sensors_widget_show_full_sensor_name"><?= gettext('Show full sensor name:') ?> </label>
<input type="checkbox"
id="thermal_sensors_widget_show_full_sensor_name"
name="thermal_sensors_widget_show_full_sensor_name"
value="<?= $thermal_sensors_widget_showFullSensorName;
?>" <?= ($thermal_sensors_widget_showFullSensorName) ? " checked='checked'" : ""; ?> />
<input type="text" id="thermal_sensors_widget_zone_critical_threshold" name="thermal_sensors_widget_zone_critical_threshold" value="<?= $pconfig['thermal_sensors_widget_zone_critical_threshold']; ?>" />
</td>
</tr>
<tr>
<td><?= gettext('Core Warning:') ?></td>
<td>
<?= gettext('Core Warning:') ?>
</td>
<td>
<input type="text" maxlength="3" size="3" class="formfld unknown"
name="thermal_sensors_widget_core_warning_threshold"
id="thermal_sensors_widget_core_warning_threshold"
value="<?= $thermal_sensors_widget_coreWarningTempThreshold ?>" />
</td>
<td>
<label for="thermal_sensors_widget_pulsate_warning"><?= gettext('Pulsate Warning:') ?> </label>
<input type="checkbox"
id="thermal_sensors_widget_pulsate_warning"
name="thermal_sensors_widget_pulsate_warning"
value="<?= $thermal_sensors_widget_pulsateWarning;
?>" <?= ($thermal_sensors_widget_pulsateWarning) ? " checked='checked'" : ""; ?> />
<input type="text" id="thermal_sensors_widget_core_warning_threshold" name="thermal_sensors_widget_core_warning_threshold" value="<?= $pconfig['thermal_sensors_widget_core_warning_threshold']; ?>" />
</td>
</tr>
<tr>
<td><?= gettext('Core Critical:') ?></td>
<td>
<?= gettext('Core Critical:') ?>
</td>
<td>
<input type="text" maxlength="3" size="3" class="formfld unknown"
name="thermal_sensors_widget_core_critical_threshold"
id="thermal_sensors_widget_core_critical_threshold"
value="<?= $thermal_sensors_widget_coreCriticalTempThreshold ?>" />
</td>
<td>
<label for="thermal_sensors_widget_pulsate_critical"><?= gettext('Pulsate Critical:') ?> </label>
<input type="checkbox"
id="thermal_sensors_widget_pulsate_critical"
name="thermal_sensors_widget_pulsate_critical"
value="<?= $thermal_sensors_widget_pulsateCritical;
?>" <?= ($thermal_sensors_widget_pulsateCritical) ? " checked='checked'" : ""; ?> />
<input type="text" id="thermal_sensors_widget_core_critical_threshold" name="thermal_sensors_widget_core_critical_threshold" value="<?= $pconfig['thermal_sensors_widget_core_critical_threshold']; ?>" />
</td>
</tr>
<tr>
<td colspan="3">
<td colspan="2">
<input type="submit" id="thermal_sensors_widget_submit" name="thermal_sensors_widget_submit" class="btn btn-primary formbtn" value="<?= gettext('Save') ?>" />
</td>
</tr>
<tr>
<td colspan="3">
<td colspan="2">
<span>* <?= sprintf(gettext('You can configure a proper Thermal Sensor / Module %shere%s.'),'<a href="system_advanced_misc.php">','</a>') ?></span>
</td>
</tr>
</tbody>
</table>
</form>
</div>
<div style="padding: 5px">
<div id="thermalSensorsContainer" class="listr">
(<?= gettext('Updating...') ?>)<br /><br />
<!-- template progress bar used for all constructed items in thermal_sensors_widget_update() -->
<div style="display:none" id="thermal_sensors_widget_progress_bar">
<div class="progress">
<div class="progress-bar progress-bar-striped progress-bar-success active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%"></div>
</div>
<span class="info">
</span>
</div>
<table class="table table-striped table-condensed" data-plugin="temperature" data-callback="thermal_sensors_widget_update">
<tbody>
</tbody>
</table>
<!-- needed to display the widget settings menu -->
<script type="text/javascript">
//<![CDATA[
textlink = jQuery("#thermal_sensors-configure");
textlink.css({display: "inline"});
$("#thermal_sensors-configure").css({display: "inline"});
//]]>
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment