1
|
<?php
|
2
|
/*
|
3
|
$Id: thermal_sensors.widget.php
|
4
|
Description: Thermal Sensors Widget.
|
5
|
NOTE: depends on proper cofing in System >> Advanced >> Miscellaneous tab >> Thermal Sensors section.
|
6
|
|
7
|
File location:
|
8
|
\usr\local\www\widgets\widgets\
|
9
|
Depends on:
|
10
|
\usr\local\www\widgets\javascript\thermal_sensors.js
|
11
|
\usr\local\www\widgets\include\thermal_sensors.inc
|
12
|
|
13
|
Redistribution and use in source and binary forms, with or without
|
14
|
modification, are permitted provided that the following conditions are met:
|
15
|
|
16
|
1. Redistributions of source code must retain the above copyright notice,
|
17
|
this list of conditions and the following disclaimer.
|
18
|
|
19
|
2. Redistributions in binary form must reproduce the above copyright
|
20
|
notice, this list of conditions and the following disclaimer in the
|
21
|
documentation and/or other materials provided with the distribution.
|
22
|
|
23
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
24
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
25
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
26
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
27
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
POSSIBILITY OF SUCH DAMAGE.
|
33
|
*/
|
34
|
|
35
|
require_once("guiconfig.inc");
|
36
|
require_once("/usr/local/www/widgets/include/thermal_sensors.inc");
|
37
|
|
38
|
//=========================================================================
|
39
|
//called by showThermalSensorsData() (jQuery Ajax call) in thermal_sensors.js
|
40
|
if (isset($_GET["getThermalSensorsData"])) {
|
41
|
//get Thermal Sensors data and return
|
42
|
echo getThermalSensorsData();
|
43
|
return;
|
44
|
}
|
45
|
//=========================================================================
|
46
|
|
47
|
|
48
|
const WIDGETS_CONFIG_SECTION_KEY = "widgets";
|
49
|
const THERMAL_SENSORS_WIDGET_SUBSECTION_KEY = "thermal_sensors_widget";
|
50
|
|
51
|
//default constants
|
52
|
const DEFAULT_WARNING_THRESHOLD = 60; //60 C
|
53
|
const DEFAULT_CRITICAL_THRESHOLD = 70; //70 C
|
54
|
const MIN_THRESHOLD_VALUE = 1; //deg C
|
55
|
const MAX_THRESHOLD_VALUE = 100; //deg C
|
56
|
|
57
|
//NOTE: keys used in $_POST and $config should match text and checkbox inputs' IDs/names in HTML code section
|
58
|
//=========================================================================
|
59
|
//save widget config settings on POST
|
60
|
if ($_POST) {
|
61
|
saveThresholdSettings($config, $_POST, "thermal_sensors_widget_zone_warning_threshold", "thermal_sensors_widget_zone_critical_threshold");
|
62
|
saveThresholdSettings($config, $_POST, "thermal_sensors_widget_core_warning_threshold", "thermal_sensors_widget_core_critical_threshold");
|
63
|
|
64
|
//handle checkboxes separately
|
65
|
saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_show_raw_output");
|
66
|
saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_show_full_sensor_name");
|
67
|
saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_pulsate_warning");
|
68
|
saveGraphDisplaySettings($config, $_POST, "thermal_sensors_widget_pulsate_critical");
|
69
|
|
70
|
//write settings to config file
|
71
|
write_config("Saved thermal_sensors_widget settings via Dashboard.");
|
72
|
header("Location: ../../index.php");
|
73
|
}
|
74
|
|
75
|
function saveThresholdSettings(&$configArray, &$postArray, $warningValueKey, $criticalValueKey) {
|
76
|
$warningValue = 0;
|
77
|
$criticalValue = 0;
|
78
|
|
79
|
if (isset($postArray[$warningValueKey])) {
|
80
|
$warningValue = (int) $postArray[$warningValueKey];
|
81
|
}
|
82
|
|
83
|
if (isset($postArray[$criticalValueKey])) {
|
84
|
$criticalValue = (int) $postArray[$criticalValueKey];
|
85
|
}
|
86
|
|
87
|
if (
|
88
|
($warningValue >= MIN_THRESHOLD_VALUE && $warningValue <= MAX_THRESHOLD_VALUE) &&
|
89
|
($criticalValue >= MIN_THRESHOLD_VALUE && $criticalValue <= MAX_THRESHOLD_VALUE) &&
|
90
|
($warningValue < $criticalValue)
|
91
|
) {
|
92
|
//all validated ok, save to config array
|
93
|
$configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$warningValueKey] = $warningValue;
|
94
|
$configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$criticalValueKey] = $criticalValue;
|
95
|
}
|
96
|
}
|
97
|
|
98
|
function saveGraphDisplaySettings(&$configArray, &$postArray, $valueKey) {
|
99
|
$configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$valueKey] = isset($postArray[$valueKey]) ? 1 : 0;
|
100
|
}
|
101
|
|
102
|
//=========================================================================
|
103
|
//get Threshold settings from config (apply defaults if missing)
|
104
|
$thermal_sensors_widget_zoneWarningTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_zone_warning_threshold", DEFAULT_WARNING_THRESHOLD);
|
105
|
$thermal_sensors_widget_zoneCriticalTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_zone_critical_threshold", DEFAULT_CRITICAL_THRESHOLD);
|
106
|
$thermal_sensors_widget_coreWarningTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_core_warning_threshold", DEFAULT_WARNING_THRESHOLD);
|
107
|
$thermal_sensors_widget_coreCriticalTempThreshold = getThresholdValueFromConfig($config, "thermal_sensors_widget_core_critical_threshold", DEFAULT_CRITICAL_THRESHOLD);
|
108
|
|
109
|
//get display settings from config (apply defaults if missing)
|
110
|
$thermal_sensors_widget_showRawOutput = getBoolValueFromConfig($config, "thermal_sensors_widget_show_raw_output", false);
|
111
|
$thermal_sensors_widget_showFullSensorName = getBoolValueFromConfig($config, "thermal_sensors_widget_show_full_sensor_name", false);
|
112
|
$thermal_sensors_widget_pulsateWarning = getBoolValueFromConfig($config, "thermal_sensors_widget_pulsate_warning", true);
|
113
|
$thermal_sensors_widget_pulsateCritical = getBoolValueFromConfig($config, "thermal_sensors_widget_pulsate_critical", true);
|
114
|
|
115
|
function getThresholdValueFromConfig(&$configArray, $valueKey, $defaultValue) {
|
116
|
|
117
|
$thresholdValue = $defaultValue;
|
118
|
|
119
|
if (isset($configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$valueKey])) {
|
120
|
$thresholdValue = (int) $configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$valueKey];
|
121
|
}
|
122
|
|
123
|
if ($thresholdValue < MIN_THRESHOLD_VALUE || $thresholdValue > MAX_THRESHOLD_VALUE) {
|
124
|
//set to default if not in allowed range
|
125
|
$thresholdValue = $defaultValue;
|
126
|
}
|
127
|
return $thresholdValue;
|
128
|
}
|
129
|
|
130
|
function getBoolValueFromConfig(&$configArray, $valueKey, $defaultValue) {
|
131
|
|
132
|
$boolValue = false;
|
133
|
|
134
|
if (isset($configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$valueKey])) {
|
135
|
$boolValue = (bool) $configArray[WIDGETS_CONFIG_SECTION_KEY][THERMAL_SENSORS_WIDGET_SUBSECTION_KEY][$valueKey];
|
136
|
} else {
|
137
|
//set to default if not in allowed range
|
138
|
$boolValue = $defaultValue;
|
139
|
}
|
140
|
return $boolValue;
|
141
|
}
|
142
|
|
143
|
//=========================================================================
|
144
|
?>
|
145
|
|
146
|
<script type="text/javascript">
|
147
|
//<![CDATA[
|
148
|
//set Thresholds, to be used in thermal_sensors.js
|
149
|
var thermal_sensors_widget_zoneWarningTempThreshold = <?= $thermal_sensors_widget_zoneWarningTempThreshold; ?>;
|
150
|
var thermal_sensors_widget_zoneCriticalTempThreshold = <?= $thermal_sensors_widget_zoneCriticalTempThreshold; ?>;
|
151
|
var thermal_sensors_widget_coreWarningTempThreshold = <?= $thermal_sensors_widget_coreWarningTempThreshold; ?>;
|
152
|
var thermal_sensors_widget_coreCriticalTempThreshold = <?= $thermal_sensors_widget_coreCriticalTempThreshold; ?>;
|
153
|
|
154
|
//set Graph display settings, to be used in thermal_sensors.js
|
155
|
var thermal_sensors_widget_showRawOutput = <?= $thermal_sensors_widget_showRawOutput ? "true" : "false"; ?>;
|
156
|
var thermal_sensors_widget_showFullSensorName = <?= $thermal_sensors_widget_showFullSensorName ? "true" : "false"; ?>;
|
157
|
var thermal_sensors_widget_pulsateWarning = <?= $thermal_sensors_widget_pulsateWarning ? "true" : "false"; ?>;
|
158
|
var thermal_sensors_widget_pulsateCritical = <?= $thermal_sensors_widget_pulsateCritical ? "true" : "false"; ?>;
|
159
|
|
160
|
//start showing temp data
|
161
|
//NOTE: the refresh interval will be reset to a proper value in showThermalSensorsData() (thermal_sensors.js).
|
162
|
jQuery(document).ready(function() {
|
163
|
showThermalSensorsData();
|
164
|
});
|
165
|
//]]>
|
166
|
</script>
|
167
|
|
168
|
<input type="hidden" id="thermal_sensors-config" name="thermal_sensors-config" value="" />
|
169
|
<div id="thermal_sensors-settings" class="widgetconfigdiv" style="display:none;">
|
170
|
<form action="/widgets/widgets/thermal_sensors.widget.php" method="post" id="iform_thermal_sensors_settings" name="iform_thermal_sensors_settings">
|
171
|
<table width="100%" border="0" summary="thermal sensors widget">
|
172
|
<tr>
|
173
|
<td align="left" colspan="2">
|
174
|
<span style="font-weight: bold" >Thresholds in °C (1 to 100):</span>
|
175
|
</td>
|
176
|
<td align="right" colspan="1">
|
177
|
<span style="font-weight: bold" >Display settings:</span>
|
178
|
</td>
|
179
|
</tr>
|
180
|
<tr>
|
181
|
<td align="right">
|
182
|
Zone Warning:
|
183
|
</td>
|
184
|
<td>
|
185
|
<input type="text" maxlength="3" size="3" class="formfld unknown"
|
186
|
name="thermal_sensors_widget_zone_warning_threshold"
|
187
|
id="thermal_sensors_widget_zone_warning_threshold"
|
188
|
value="<?= $thermal_sensors_widget_zoneWarningTempThreshold; ?>" />
|
189
|
</td>
|
190
|
<td align="right">
|
191
|
<label for="thermal_sensors_widget_show_raw_output">Show raw output (no graph): </label>
|
192
|
<input type="checkbox"
|
193
|
id="thermal_sensors_widget_show_raw_output"
|
194
|
name="thermal_sensors_widget_show_raw_output"
|
195
|
value="<?= $thermal_sensors_widget_showRawOutput; ?>" <?= ($thermal_sensors_widget_showRawOutput) ? " checked='checked'" : ""; ?> />
|
196
|
</td>
|
197
|
</tr>
|
198
|
<tr>
|
199
|
<td align="right">
|
200
|
Zone Critical:
|
201
|
</td>
|
202
|
<td>
|
203
|
<input type="text" maxlength="3" size="3" class="formfld unknown"
|
204
|
name="thermal_sensors_widget_zone_critical_threshold"
|
205
|
id="thermal_sensors_widget_zone_critical_threshold"
|
206
|
value="<?= $thermal_sensors_widget_zoneCriticalTempThreshold; ?>" />
|
207
|
</td>
|
208
|
<td align="right">
|
209
|
<label for="thermal_sensors_widget_show_full_sensor_name">Show full sensor name: </label>
|
210
|
<input type="checkbox"
|
211
|
id="thermal_sensors_widget_show_full_sensor_name"
|
212
|
name="thermal_sensors_widget_show_full_sensor_name"
|
213
|
value="<?= $thermal_sensors_widget_showFullSensorName; ?>" <?= ($thermal_sensors_widget_showFullSensorName) ? " checked='checked'" : ""; ?> />
|
214
|
</td>
|
215
|
</tr>
|
216
|
<tr>
|
217
|
<td align="right">
|
218
|
Core Warning:
|
219
|
</td>
|
220
|
<td>
|
221
|
<input type="text" maxlength="3" size="3" class="formfld unknown"
|
222
|
name="thermal_sensors_widget_core_warning_threshold"
|
223
|
id="thermal_sensors_widget_core_warning_threshold"
|
224
|
value="<?= $thermal_sensors_widget_coreWarningTempThreshold ?>" />
|
225
|
</td>
|
226
|
<td align="right">
|
227
|
<label for="thermal_sensors_widget_pulsate_warning">Pulsate Warning: </label>
|
228
|
<input type="checkbox"
|
229
|
id="thermal_sensors_widget_pulsate_warning"
|
230
|
name="thermal_sensors_widget_pulsate_warning"
|
231
|
value="<?= $thermal_sensors_widget_pulsateWarning; ?>" <?= ($thermal_sensors_widget_pulsateWarning) ? " checked='checked'" : ""; ?> />
|
232
|
</td>
|
233
|
</tr>
|
234
|
<tr>
|
235
|
<td align="right">
|
236
|
Core Critical:
|
237
|
</td>
|
238
|
<td>
|
239
|
<input type="text" maxlength="3" size="3" class="formfld unknown"
|
240
|
name="thermal_sensors_widget_core_critical_threshold"
|
241
|
id="thermal_sensors_widget_core_critical_threshold"
|
242
|
value="<?= $thermal_sensors_widget_coreCriticalTempThreshold ?>" />
|
243
|
</td>
|
244
|
<td align="right">
|
245
|
<label for="thermal_sensors_widget_pulsate_critical">Pulsate Critical: </label>
|
246
|
<input type="checkbox"
|
247
|
id="thermal_sensors_widget_pulsate_critical"
|
248
|
name="thermal_sensors_widget_pulsate_critical"
|
249
|
value="<?= $thermal_sensors_widget_pulsateCritical; ?>" <?= ($thermal_sensors_widget_pulsateCritical) ? " checked='checked'" : ""; ?> />
|
250
|
</td>
|
251
|
</tr>
|
252
|
<tr>
|
253
|
<td align="right" colspan="3">
|
254
|
<input type="submit" id="thermal_sensors_widget_submit" name="thermal_sensors_widget_submit" class="formbtn" value="Save" />
|
255
|
</td>
|
256
|
</tr>
|
257
|
<tr>
|
258
|
<td align="left" colspan="3">
|
259
|
<span>* You can configure a proper Thermal Sensor / Module under <br />
|
260
|
<a href="system_advanced_misc.php">System > Advanced > Miscellaneous : Thermal Sensors section</a>.</span>
|
261
|
</td>
|
262
|
</tr>
|
263
|
</table>
|
264
|
</form>
|
265
|
</div>
|
266
|
|
267
|
<div style="padding: 5px">
|
268
|
<div id="thermalSensorsContainer" class="listr">
|
269
|
(Updating...)<br /><br />
|
270
|
</div>
|
271
|
</div>
|
272
|
|
273
|
<!-- needed to display the widget settings menu -->
|
274
|
<script type="text/javascript">
|
275
|
|
276
|
textlink = jQuery("#thermal_sensors-configure");
|
277
|
textlink.css({display: "inline"});
|
278
|
|
279
|
</script>
|