Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 2976 → Rev 3037

/web/acc/phpsysinfo/includes/mb/class.thermalzone.inc.php
30,18 → 30,24
switch (defined('PSI_SENSOR_THERMALZONE_ACCESS')?strtolower(PSI_SENSOR_THERMALZONE_ACCESS):'command') {
case 'command':
if ((PSI_OS == 'WINNT') || defined('PSI_EMU_HOSTNAME')) {
if (defined('PSI_EMU_HOSTNAME') || CommonFunctions::isAdmin()) {
$_wmi = CommonFunctions::initWMI('root\WMI', true);
if (defined('PSI_EMU_HOSTNAME') || WINNT::isAdmin()) {
$_wmi = WINNT::initWMI('root\WMI', true);
if ($_wmi) {
$this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
$this->_buf = WINNT::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
}
} else {
$this->error->addError("Error reading data from thermalzone sensor", "Allowed only for systems with administrator privileges (run as administrator)");
$_wmi = WINNT::getcimv2wmi();
if ($_wmi) {
$this->_buf = WINNT::getWMI($_wmi, 'Win32_PerfFormattedData_Counters_ThermalZoneInformation', array('Name', 'HighPrecisionTemperature', 'Temperature'));
}
if (!$this->_buf || PSI_DEBUG) {
$this->error->addError("Error reading data from thermalzone sensor", "Allowed only for systems with administrator privileges (run as administrator)");
}
}
}
break;
case 'data':
if (!defined('PSI_EMU_HOSTNAME') && CommonFunctions::rfts(PSI_APP_ROOT.'/data/thermalzone.txt', $lines, 0, 4096, false)) { //output of "wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CriticalTripPoint,CurrentTemperature,InstanceName"
if (!defined('PSI_EMU_HOSTNAME') && CommonFunctions::rftsdata('thermalzone.tmp', $lines)) { //output of "wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CriticalTripPoint,CurrentTemperature,InstanceName"
$lines = trim(preg_replace('/[\x00-\x09\x0b-\x1F]/', '', $lines));
$lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
if ((($clines=count($lines)) > 1) && preg_match("/CriticalTripPoint\s+CurrentTemperature\s+InstanceName/i", $lines[0])) for ($i = 1; $i < $clines; $i++) {
54,7 → 60,6
break;
default:
$this->error->addConfigError('__construct()', '[sensor_thermalzone] ACCESS');
break;
}
}
 
81,15 → 86,27
$dev->setMax($maxvalue);
}
$this->mbinfo->setMbTemp($dev);
} else {
if ((isset($buffer['HighPrecisionTemperature']) && (($value = ($buffer['HighPrecisionTemperature'] - 2732)/10) > -100))
|| (isset($buffer['Temperature']) && (($value = ($buffer['Temperature'] - 273)) > -100))) {
$dev = new SensorDevice();
if (isset($buffer['Name']) && preg_match("/([^\\\\\. ]+)$/", $buffer['Name'], $outbuf)) {
$dev->setName('ThermalZone '.$outbuf[1]);
} else {
$dev->setName('ThermalZone THM0');
}
$dev->setValue($value);
$this->mbinfo->setMbTemp($dev);
}
}
}
} elseif (($mode == 'command') && (PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME')) {
$notwas = true;
$thermalzones = glob('/sys/class/thermal/thermal_zone*/');
$thermalzones = CommonFunctions::findglob('/sys/class/thermal/thermal_zone*/');
if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
$thermalzonetemp = $thermalzone.'temp';
$temp = null;
if (CommonFunctions::rfts($thermalzonetemp, $temp, 1, 4096, false) && !is_null($temp) && (($temp = trim($temp)) != "")) {
if (CommonFunctions::rfts($thermalzonetemp, $temp, 1, 4096, false) && ($temp !== null) && (($temp = trim($temp)) != "")) {
if ($temp >= 1000) {
$div = 1000;
} elseif ($temp >= 200) {
104,7 → 121,7
$dev->setValue($temp);
 
$temp_type = null;
if (CommonFunctions::rfts($thermalzone.'type', $temp_type, 1, 4096, false) && !is_null($temp_type) && (($temp_type = trim($temp_type)) != "")) {
if (CommonFunctions::rfts($thermalzone.'type', $temp_type, 1, 4096, false) && ($temp_type !== null) && (($temp_type = trim($temp_type)) != "")) {
$dev->setName($temp_type);
} else {
$dev->setName("ThermalZone");
111,7 → 128,7
}
 
$temp_max = null;
if (CommonFunctions::rfts($thermalzone.'trip_point_0_temp', $temp_max, 1, 4096, false) && !is_null($temp_max) && (($temp_max = trim($temp_max)) != "") && ($temp_max > -40)) {
if (CommonFunctions::rfts($thermalzone.'trip_point_0_temp', $temp_max, 1, 4096, false) && ($temp_max !== null) && (($temp_max = trim($temp_max)) != "") && ($temp_max > -40)) {
$temp_max = $temp_max / $div;
if (($temp_max != 0) || ($temp != 0)) { // if non-zero values
$dev->setMax($temp_max);
125,10 → 142,10
}
}
if ($notwas) {
$thermalzones = glob('/proc/acpi/thermal_zone/TH*/temperature');
$thermalzones = (PSI_ROOT_FILESYSTEM.'/proc/acpi/thermal_zone/TH*/temperature');
if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
$temp = null;
if (CommonFunctions::rfts($thermalzone, $temp, 1, 4096, false) && !is_null($temp) && (($temp = trim($temp)) != "")) {
if (CommonFunctions::rfts($thermalzone, $temp, 1, 4096, false) && ($temp !== null) && (($temp = trim($temp)) != "")) {
$dev = new SensorDevice();
if (preg_match("/^\/proc\/acpi\/thermal_zone\/(.+)\/temperature$/", $thermalzone, $name)) {
$dev->setName("ThermalZone ".$name[1]);
148,7 → 165,7
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
* @return void
*/
public function build()
{