Subversion Repositories ALCASAR

Rev

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

Rev 325 Rev 2770
Line 1... Line 1...
1
<?php 
1
<?php
2
 
2
/**
3
// phpSysInfo - A PHP System Information Script
3
 * hwsensors sensor class, getting information from hwsensors
-
 
4
 *
4
// http://phpsysinfo.sourceforge.net/
5
 * PHP version 5
5
 
6
 *
6
// This program is free software; you can redistribute it and/or
7
 * @category  PHP
7
// modify it under the terms of the GNU General Public License
8
 * @package   PSI_Sensor
8
// as published by the Free Software Foundation; either version 2
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
9
// of the License, or (at your option) any later version.
10
 * @copyright 2009 phpSysInfo
10
 
-
 
11
// This program is distributed in the hope that it will be useful,
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * @version   Release: 3.0
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * @link      http://phpsysinfo.sourceforge.net
-
 
14
 */
14
// GNU General Public License for more details.
15
class HWSensors extends Sensors
15
 
16
{
-
 
17
    /**
16
// You should have received a copy of the GNU General Public License
18
     * content to parse
-
 
19
     *
17
// along with this program; if not, write to the Free Software
20
     * @var array
-
 
21
     */
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
    private $_lines = array();
19
 
23
 
-
 
24
    /**
20
// $Id: class.hwsensors.inc.php,v 1.4 2006/05/20 17:01:07 bigmichi1 Exp $
25
     * fill the private content var through command
21
 
-
 
22
class mbinfo {
26
     */
23
    var $lines;
27
    public function __construct()
24
 
28
    {
-
 
29
        parent::__construct();
25
    function mbinfo() {
30
        $lines = "";
26
        $this->lines = execute_program('sysctl', '-w hw.sensors');
31
//        CommonFunctions::executeProgram('sysctl', '-w hw.sensors', $lines);
-
 
32
        CommonFunctions::executeProgram('sysctl', 'hw.sensors', $lines);
27
	$this->lines = explode("\n", $this->lines);
33
        $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
28
    }
34
    }
29
 
35
 
-
 
36
    /**
30
    function temperature() {
37
     * get temperature information
-
 
38
     *
31
	$ar_buf = array();
39
     * @return void
-
 
40
     */
32
	$results = array();
41
    private function _temperature()
33
 
42
    {
34
        foreach( $this->lines as $line ) {
43
        foreach ($this->_lines as $line) {
-
 
44
            if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+temp,\s+([0-9\.]+)\s+degC.*$/', $line, $ar_buf)) {
35
    	    $ar_buf = preg_split("/[\s,]+/", $line);
45
                $dev = new SensorDevice();
-
 
46
                $dev->setName($ar_buf[1]);
36
	    if( isset( $ar_buf[3] ) && $ar_buf[2] == 'temp') {
47
                $dev->setValue($ar_buf[2]);
-
 
48
                $this->mbinfo->setMbTemp($dev);
-
 
49
            } elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+degC$/', $line, $ar_buf)) {
-
 
50
                $dev = new SensorDevice();
37
    		$results[$j]['label'] = $ar_buf[1];
51
                $dev->setName($ar_buf[1]);
-
 
52
                $dev->setValue($ar_buf[2]);
-
 
53
                $this->mbinfo->setMbTemp($dev);
-
 
54
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+degC\s+\((.*)\)$/', $line, $ar_buf)) {
-
 
55
                $dev = new SensorDevice();
38
    		$results[$j]['value'] = $ar_buf[3];
56
                $dev->setName($ar_buf[3]);
-
 
57
                $dev->setValue($ar_buf[2]);
39
    		$results[$j]['limit'] = '70.0';
58
                $this->mbinfo->setMbTemp($dev);
40
    		$results[$j]['percent'] = $results[$j]['value'] * 100 / $results[$j]['limit'];
59
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+degC$/', $line, $ar_buf)) {
-
 
60
                $dev = new SensorDevice();
-
 
61
                $dev->setName($ar_buf[1]);
-
 
62
                $dev->setValue($ar_buf[2]);
-
 
63
                $this->mbinfo->setMbTemp($dev);
41
    		$j++;
64
            }
42
	    }
65
        }
43
	}
-
 
44
	return $results;
-
 
45
    }
66
    }
46
 
67
 
-
 
68
    /**
47
    function fans() {
69
     * get fan information
-
 
70
     *
48
	$ar_buf = array();
71
     * @return void
-
 
72
     */
49
	$results = array();
73
    private function _fans()
50
 
74
    {
51
	foreach( $this->lines as $line ) {
75
        foreach ($this->_lines as $line) {
-
 
76
            if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+fanrpm,\s+([0-9\.]+)\s+RPM.*$/', $line, $ar_buf)) {
52
	    $ar_buf = preg_split("/[\s,]+/", $line );
77
                $dev = new SensorDevice();
-
 
78
                $dev->setName($ar_buf[1]);
53
	    if( isset( $ar_buf[3] ) && $ar_buf[2] == 'fanrpm') {
79
                $dev->setValue($ar_buf[2]);
-
 
80
                $this->mbinfo->setMbFan($dev);
-
 
81
            } elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+RPM$/', $line, $ar_buf)) {
-
 
82
                $dev = new SensorDevice();
54
    		$results[$j]['label'] = $ar_buf[1];
83
                $dev->setName($ar_buf[1]);
-
 
84
                $dev->setValue($ar_buf[2]);
-
 
85
                $this->mbinfo->setMbFan($dev);
-
 
86
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+RPM\s+\((.*)\)$/', $line, $ar_buf)) {
-
 
87
                $dev = new SensorDevice();
55
    		$results[$j]['value'] = $ar_buf[3];
88
                $dev->setName($ar_buf[3]);
-
 
89
                $dev->setValue($ar_buf[2]);
-
 
90
                $this->mbinfo->setMbFan($dev);
-
 
91
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+RPM$/', $line, $ar_buf)) {
-
 
92
                $dev = new SensorDevice();
-
 
93
                $dev->setName($ar_buf[1]);
-
 
94
                $dev->setValue($ar_buf[2]);
-
 
95
                $this->mbinfo->setMbFan($dev);
56
    		$j++;
96
            }
57
    	    }
97
        }
58
	}
-
 
59
	return $results;
-
 
60
    }
98
    }
61
 
99
 
-
 
100
    /**
-
 
101
     * get voltage information
-
 
102
     *
-
 
103
     * @return void
-
 
104
     */
62
    function voltage() {
105
    private function _voltage()
-
 
106
    {
-
 
107
        foreach ($this->_lines as $line) {
-
 
108
            if (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+volts_dc,\s+([0-9\.]+)\s+V.*$/', $line, $ar_buf)) {
-
 
109
                $dev = new SensorDevice();
-
 
110
                $dev->setName($ar_buf[1]);
-
 
111
                $dev->setValue($ar_buf[2]);
-
 
112
                $this->mbinfo->setMbVolt($dev);
-
 
113
            } elseif (preg_match('/^hw\.sensors\.[0-9]+=[^\s,]+,\s+([^,]+),\s+([0-9\.]+)\s+V\sDC$/', $line, $ar_buf)) {
-
 
114
                $dev = new SensorDevice();
-
 
115
                $dev->setName($ar_buf[1]);
-
 
116
                $dev->setValue($ar_buf[2]);
-
 
117
                $this->mbinfo->setMbVolt($dev);
-
 
118
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+VDC\s+\((.*)\)$/', $line, $ar_buf)) {
-
 
119
                $dev = new SensorDevice();
-
 
120
                $dev->setName($ar_buf[3]);
-
 
121
                $dev->setValue($ar_buf[2]);
-
 
122
                $this->mbinfo->setMbVolt($dev);
-
 
123
            } elseif (preg_match('/^hw\.sensors\.[^\.]+\.(.*)=([0-9\.]+)\s+VDC$/', $line, $ar_buf)) {
-
 
124
                $dev = new SensorDevice();
-
 
125
                $dev->setName($ar_buf[1]);
-
 
126
                $dev->setValue($ar_buf[2]);
-
 
127
                $this->mbinfo->setMbVolt($dev);
63
	$ar_buf = array();
128
            }
64
	$results = array();
129
        }
-
 
130
    }
65
 
131
 
66
	foreach( $this->lines as $line ) {
132
    /**
67
	    $ar_buf = preg_split("/[\s,]+/", $line );
133
     * get the information
68
    	    if ( isset( $ar_buf[3] ) && $ar_buf[2] == 'volts_dc') {
-
 
69
    		$results[$j]['label'] = $ar_buf[1];
134
     *
70
    		$results[$j]['value'] = $ar_buf[3];
135
     * @see PSI_Interface_Sensor::build()
71
		$results[$j]['min'] = '0.00';
136
     *
72
    		$results[$j]['max'] = '0.00';
137
     * @return Void
73
    		$j++;
138
     */
74
    	    }
139
    public function build()
75
	}
140
    {
-
 
141
        $this->_temperature();
-
 
142
        $this->_voltage();
76
	return $results;
143
        $this->_fans();
77
    }
144
    }
78
}
145
}
79
 
-
 
80
?>
-