From 4fc5400000a74382267b0955fdaf6b699ef2fc96 Mon Sep 17 00:00:00 2001 From: 01101001c <01101001c@gmail.com> Date: Mon, 18 Mar 2013 17:08:01 -0700 Subject: Thermal Sensors Widget (for pfSense v2.1-BETA1 and up). Original post: http://forum.pfsense.org/index.php/topic,59193.0.html --- .../www/widgets/widgets/thermal_sensors.widget.php | 316 +++++++++++++++++++++ 1 file changed, 316 insertions(+) create mode 100644 usr/local/www/widgets/widgets/thermal_sensors.widget.php (limited to 'usr/local/www/widgets/widgets/thermal_sensors.widget.php') diff --git a/usr/local/www/widgets/widgets/thermal_sensors.widget.php b/usr/local/www/widgets/widgets/thermal_sensors.widget.php new file mode 100644 index 0000000..7fa4a2b --- /dev/null +++ b/usr/local/www/widgets/widgets/thermal_sensors.widget.php @@ -0,0 +1,316 @@ +> 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 + + 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. + */ + +$nocsrf = true; + +require_once("guiconfig.inc"); +require_once("/usr/local/www/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 = 60; //60 C +const DEFAULT_CRITICAL_THRESHOLD = 70; //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) { + $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; + } +} + +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]; + } + + if ($thresholdValue < MIN_THRESHOLD_VALUE || $thresholdValue > MAX_THRESHOLD_VALUE) { + //set to default if not in allowed range + $thresholdValue = $defaultValue; + } + 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; + } + return $boolValue; +} + +//========================================================================= +?> + + + + + + + + + +
+
+ (Updating...)

+
+
+ + + -- cgit v1.1