Subversion Repositories ALCASAR

Rev

Rev 2770 | Rev 3037 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2770 Rev 2976
Line 25... Line 25...
25
     * fill the private content var
25
     * fill the private content var
26
     */
26
     */
27
    public function __construct()
27
    public function __construct()
28
    {
28
    {
29
        parent::__construct();
29
        parent::__construct();
30
        if (PSI_OS == 'WINNT') {
30
        switch (defined('PSI_SENSOR_THERMALZONE_ACCESS')?strtolower(PSI_SENSOR_THERMALZONE_ACCESS):'command') {
31
            $_wmi = null;
31
        case 'command':
32
            try {
-
 
33
                // initialize the wmi object
32
            if ((PSI_OS == 'WINNT') || defined('PSI_EMU_HOSTNAME')) {
34
                $objLocator = new COM('WbemScripting.SWbemLocator');
33
                if (defined('PSI_EMU_HOSTNAME') || CommonFunctions::isAdmin()) {
35
                $_wmi = $objLocator->ConnectServer('', 'root\WMI');
34
                    $_wmi = CommonFunctions::initWMI('root\WMI', true);
36
            } catch (Exception $e) {
35
                    if ($_wmi) {
-
 
36
                        $this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
-
 
37
                    }
-
 
38
                } else {
37
                $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for ThermalZone data.");
39
                    $this->error->addError("Error reading data from thermalzone sensor", "Allowed only for systems with administrator privileges (run as administrator)");
-
 
40
                }
38
            }
41
            }
39
            if ($_wmi) {
42
            break;
-
 
43
        case 'data':
40
                $this->_buf = CommonFunctions::getWMI($_wmi, 'MSAcpi_ThermalZoneTemperature', array('InstanceName', 'CriticalTripPoint', 'CurrentTemperature'));
44
            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"
-
 
45
                $lines = trim(preg_replace('/[\x00-\x09\x0b-\x1F]/', '', $lines));
-
 
46
                $lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
-
 
47
                if ((($clines=count($lines)) > 1) && preg_match("/CriticalTripPoint\s+CurrentTemperature\s+InstanceName/i", $lines[0])) for ($i = 1; $i < $clines; $i++) {
-
 
48
                    $values = preg_split("/\s+/", trim($lines[$i]), -1, PREG_SPLIT_NO_EMPTY);
-
 
49
                    if (count($values)==3) {
-
 
50
                        $this->_buf[] = array('CriticalTripPoint'=>trim($values[0]), 'CurrentTemperature'=>trim($values[1]), 'InstanceName'=>trim($values[2]));
-
 
51
                    }
-
 
52
                }
41
            }
53
            }
-
 
54
            break;
-
 
55
        default:
-
 
56
            $this->error->addConfigError('__construct()', '[sensor_thermalzone] ACCESS');
-
 
57
            break;
42
        }
58
        }
43
    }
59
    }
44
 
60
 
45
    /**
61
    /**
46
     * get temperature information
62
     * get temperature information
47
     *
63
     *
48
     * @return void
64
     * @return void
49
     */
65
     */
50
    private function _temperature()
66
    private function _temperature()
51
    {
67
    {
-
 
68
        $mode = defined('PSI_SENSOR_THERMALZONE_ACCESS')?strtolower(PSI_SENSOR_THERMALZONE_ACCESS):'command';
-
 
69
        if ((($mode == 'command') && ((PSI_OS == 'WINNT') || defined('PSI_EMU_HOSTNAME')))
52
        if (PSI_OS == 'WINNT') {
70
           || (($mode == 'data') && !defined('PSI_EMU_HOSTNAME'))) {
53
            if ($this->_buf) foreach ($this->_buf as $buffer) {
71
            if ($this->_buf) foreach ($this->_buf as $buffer) {
54
                if (isset($buffer['CurrentTemperature']) && (($value = ($buffer['CurrentTemperature'] - 2732)/10) > -100)) {
72
                if (isset($buffer['CurrentTemperature']) && (($value = ($buffer['CurrentTemperature'] - 2732)/10) > -100)) {
55
                    $dev = new SensorDevice();
73
                    $dev = new SensorDevice();
56
                    if (isset($buffer['InstanceName']) && preg_match("/([^\\\\ ]+)$/", $buffer['InstanceName'], $outbuf)) {
74
                    if (isset($buffer['InstanceName']) && preg_match("/([^\\\\ ]+)$/", $buffer['InstanceName'], $outbuf)) {
57
                        $dev->setName('ThermalZone '.$outbuf[1]);
75
                        $dev->setName('ThermalZone '.$outbuf[1]);
Line 63... Line 81...
63
                        $dev->setMax($maxvalue);
81
                        $dev->setMax($maxvalue);
64
                    }
82
                    }
65
                    $this->mbinfo->setMbTemp($dev);
83
                    $this->mbinfo->setMbTemp($dev);
66
                }
84
                }
67
            }
85
            }
68
        } else {
86
        } elseif (($mode == 'command') && (PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME')) {
69
            $notwas = true;
87
            $notwas = true;
70
            $thermalzones = glob('/sys/class/thermal/thermal_zone*/');
88
            $thermalzones = glob('/sys/class/thermal/thermal_zone*/');
71
            if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
89
            if (is_array($thermalzones) && (count($thermalzones) > 0)) foreach ($thermalzones as $thermalzone) {
72
                $thermalzonetemp = $thermalzone.'temp';
90
                $thermalzonetemp = $thermalzone.'temp';
73
                $temp = null;
91
                $temp = null;