Subversion Repositories ALCASAR

Rev

Rev 325 | Rev 2976 | Go to most recent revision | Show entire file | Regard 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
 * hddtemp sensor class, getting information from hddtemp
-
 
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
 * @author    T.A. van Roermund <timo@van-roermund.nl>
10
 
-
 
11
// This program is distributed in the hope that it will be useful,
11
 * @copyright 2009 phpSysInfo
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * @version   Release: 3.0
14
// GNU General Public License for more details.
14
 * @link      http://phpsysinfo.sourceforge.net
15
 
15
 */
16
// You should have received a copy of the GNU General Public License
-
 
17
// along with this program; if not, write to the Free Software
16
class HDDTemp extends Sensors
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
 
19
 
17
{
-
 
18
    /**
20
// $Id: class.hddtemp.inc.php,v 1.7 2007/01/21 13:17:20 bigmichi1 Exp $
19
     * get the temperature information from hddtemp
-
 
20
     * access is available through tcp or command
21
 
21
     *
22
class hddtemp {
22
     * @return void
23
	
23
     */
24
	function temperature($hddtemp_avail) {
24
    private function _temperature()
-
 
25
    {
25
		$ar_buf = array();
26
        $ar_buf = array();
26
		$results = array();
-
 
27
		switch ($hddtemp_avail) {
27
        switch (defined('PSI_SENSOR_HDDTEMP_ACCESS')?strtolower(PSI_SENSOR_HDDTEMP_ACCESS):'command') {
28
			case "tcp":
28
        case 'tcp':
-
 
29
            $lines = '';
29
				// Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout.
30
            // Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout.
30
				$fp = fsockopen('localhost', 7634, $errno, $errstr, 5);
31
            $fp = @fsockopen('localhost', 7634, $errno, $errstr, 5);
31
				// if connected, read the output of the hddtemp daemon
32
            // if connected, read the output of the hddtemp daemon
32
				if ($fp) {
33
            if ($fp) {
33
					// read output of the daemon
-
 
34
					$lines = '';
-
 
35
					while (!feof($fp)) {
34
                while (!feof($fp)) {
36
						$lines .= fread($fp, 1024);
35
                    $lines .= fread($fp, 1024);
37
					}
36
                }
38
					// close the connection
-
 
39
					fclose($fp);
37
                fclose($fp);
40
				} else {
38
            } else {
41
					die("HDDTemp error: " . $errno . ", " . $errstr);
39
                $this->error->addError("HDDTemp error", $errno.", ".$errstr);
42
				}
40
            }
43
				$lines = str_replace("||", "|\n|", $lines);
41
            $lines = str_replace("||", "|\n|", $lines);
44
				$ar_buf = explode("\n", $lines);
42
            $ar_buf = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
45
				break;
43
            break;
46
			case "suid":
44
        case 'command':
47
				$strDrives = "";
45
            $strDrives = "";
48
				$strContent = rfts( "/proc/diskstats", 0, 4096, false );
46
            $strContent = "";
49
				if( $strContent != "ERROR" ) {
47
            $hddtemp_value = "";
-
 
48
            if (CommonFunctions::rfts("/proc/diskstats", $strContent, 0, 4096, false)) {
50
					$arrContent = explode( "\n", $strContent );
49
                $arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
51
					foreach( $arrContent as $strLine ) {
50
                foreach ($arrContent as $strLine) {
52
						preg_match( "/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit );
51
                    preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
53
						if( !empty( $arrSplit[2] ) ) {
52
                    if (! empty($arrSplit[2])) {
54
						    $strDrive = '/dev/' . $arrSplit[2];
53
                        $strDrive = '/dev/'.$arrSplit[2];
55
						    if( file_exists( $strDrive ) ) {
54
                        if (file_exists($strDrive)) {
56
							$strDrives = $strDrives . $strDrive . ' ';
55
                            $strDrives = $strDrives.$strDrive.' ';
57
						    }							
56
                        }
58
						}
57
                    }
59
					}
58
                }
60
				} else {
59
            } else {
61
				    $strContent = rfts( "/proc/partitions", 0, 4096, false );
60
                if (CommonFunctions::rfts("/proc/partitions", $strContent, 0, 4096, false)) {
62
				    if( $strContent != "ERROR" ) {
-
 
63
					$arrContent = explode( "\n", $strContent );
61
                    $arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
64
					foreach( $arrContent as $strLine ) {
62
                    foreach ($arrContent as $strLine) {
65
						if( !preg_match( "/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit ) ) {
63
                        if (!preg_match("/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit)) {
66
						    preg_match( "/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit );
64
                            preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
67
						}
65
                        }
68
						if( !empty( $arrSplit[2] ) ) {
66
                        if (! empty($arrSplit[2])) {
Line 72... Line 70...
72
						    }
70
                            }
73
						}
71
                        }
74
					}
72
                    }
75
				    }
73
                }
76
				}
74
            }
77
				
-
 
78
				if( trim( $strDrives ) == "" ) {
75
            if (trim($strDrives) == "") {
79
					return array();
76
                break;
80
				}
77
            }
81
 
-
 
82
				$hddtemp_value = execute_program("hddtemp", $strDrives);
78
            if (CommonFunctions::executeProgram("hddtemp", $strDrives, $hddtemp_value, PSI_DEBUG)) {
83
				$hddtemp_value = explode("\n", $hddtemp_value);
79
                $hddtemp_value = preg_split("/\n/", $hddtemp_value, -1, PREG_SPLIT_NO_EMPTY);
84
				foreach($hddtemp_value as $line) {
80
                foreach ($hddtemp_value as $line) {
85
					$temp = preg_split("/:\s/", $line, 3);
81
                    $temp = preg_split("/:\s/", $line, 3);
86
					if(count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) {
82
                    if (count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) {
-
 
83
                        preg_match("/^([0-9]*)(.*)/", $temp[2], $ar_temp);
-
 
84
                        $temp[2] = trim($ar_temp[1]);
87
						list($temp[2], $temp[3]) = (preg_split("/\s/", $temp[2]));
85
                        $temp[3] = trim($ar_temp[2]);
88
						array_push( $ar_buf, "|" . implode("|", $temp) . "|");
86
                        array_push($ar_buf, "|".implode("|", $temp)."|");
89
					}
87
                    }
90
				}
88
                }
-
 
89
            }
91
				break;
90
            break;
92
			default:
91
        default:
93
				die("Bad hddtemp configuration in config.php");
92
            $this->error->addConfigError("temperature()", "[sensor_hddtemp] ACCESS");
-
 
93
            break;
94
		}
94
        }
95
		
-
 
96
		// Timo van Roermund: parse the info from the hddtemp daemon.
95
        // Timo van Roermund: parse the info from the hddtemp daemon.
97
		$i = 0;
-
 
98
		foreach($ar_buf as $line) {
96
        foreach ($ar_buf as $line) {
99
			$data = array();
97
            $data = array();
100
			if (ereg("\|(.*)\|(.*)\|(.*)\|(.*)\|", $line, $data)) {
98
            if (preg_match("/\|(.*)\|(.*)\|(.*)\|(.*)\|/", $line, $data)) {
101
				if( trim($data[3]) != "ERR" ) {
99
                if (trim($data[3]) != "ERR") {
102
					// get the info we need
100
                    // get the info we need
-
 
101
                    $dev = new SensorDevice();
-
 
102
                    $dev->setName($data[1] . ' (' . (strpos($data[2], "  ")?substr($data[2], 0, strpos($data[2], "  ")):$data[2]) . ')');
103
					$results[$i]['label'] = $data[1];
103
                    if (is_numeric($data[3])) {
104
					$results[$i]['value'] = $data[3];
104
                        $dev->setValue($data[3]);
-
 
105
                    }
105
					$results[$i]['model'] = $data[2];
106
//                    $dev->setMax(60);
-
 
107
                    $this->mbinfo->setMbTemp($dev);
106
					$i++;
108
                }
107
				}
109
            }
108
			}
110
        }
109
		}
111
    }
110
		
112
 
-
 
113
    /**
-
 
114
     * get the information
-
 
115
     *
-
 
116
     * @see PSI_Interface_Sensor::build()
-
 
117
     *
111
		return $results;
118
     * @return Void
-
 
119
     */
-
 
120
    public function build()
-
 
121
    {
-
 
122
        $this->_temperature();
112
	}
123
    }
113
}
124
}
114
?>
-