Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
592 stephane 1
<?php
2
 
3
// phpSysInfo - A PHP System Information Script
4
// http://phpsysinfo.sourceforge.net/
5
 
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
10
 
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
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
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
 
20
// $Id: class.hddtemp.inc.php,v 1.7 2007/01/21 13:17:20 bigmichi1 Exp $
21
 
22
class hddtemp {
23
 
24
	function temperature($hddtemp_avail) {
25
		$ar_buf = array();
26
		$results = array();
27
		switch ($hddtemp_avail) {
28
			case "tcp":
29
				// Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout.
30
				$fp = fsockopen('localhost', 7634, $errno, $errstr, 5);
31
				// if connected, read the output of the hddtemp daemon
32
				if ($fp) {
33
					// read output of the daemon
34
					$lines = '';
35
					while (!feof($fp)) {
36
						$lines .= fread($fp, 1024);
37
					}
38
					// close the connection
39
					fclose($fp);
40
				} else {
41
					die("HDDTemp error: " . $errno . ", " . $errstr);
42
				}
43
				$lines = str_replace("||", "|\n|", $lines);
44
				$ar_buf = explode("\n", $lines);
45
				break;
46
			case "suid":
47
				$strDrives = "";
48
				$strContent = rfts( "/proc/diskstats", 0, 4096, false );
49
				if( $strContent != "ERROR" ) {
50
					$arrContent = explode( "\n", $strContent );
51
					foreach( $arrContent as $strLine ) {
52
						preg_match( "/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit );
53
						if( !empty( $arrSplit[2] ) ) {
54
						    $strDrive = '/dev/' . $arrSplit[2];
55
						    if( file_exists( $strDrive ) ) {
56
							$strDrives = $strDrives . $strDrive . ' ';
57
						    }							
58
						}
59
					}
60
				} else {
61
				    $strContent = rfts( "/proc/partitions", 0, 4096, false );
62
				    if( $strContent != "ERROR" ) {
63
					$arrContent = explode( "\n", $strContent );
64
					foreach( $arrContent as $strLine ) {
65
						if( !preg_match( "/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit ) ) {
66
						    preg_match( "/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit );
67
						}
68
						if( !empty( $arrSplit[2] ) ) {
69
						    $strDrive = '/dev/' . $arrSplit[2];
70
						    if( file_exists( $strDrive ) ) {
71
							$strDrives = $strDrives . $strDrive . ' ';
72
						    }
73
						}
74
					}
75
				    }
76
				}
77
 
78
				if( trim( $strDrives ) == "" ) {
79
					return array();
80
				}
81
 
82
				$hddtemp_value = execute_program("hddtemp", $strDrives);
83
				$hddtemp_value = explode("\n", $hddtemp_value);
84
				foreach($hddtemp_value as $line) {
85
					$temp = preg_split("/:\s/", $line, 3);
86
					if(count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) {
87
						list($temp[2], $temp[3]) = (preg_split("/\s/", $temp[2]));
88
						array_push( $ar_buf, "|" . implode("|", $temp) . "|");
89
					}
90
				}
91
				break;
92
			default:
93
				die("Bad hddtemp configuration in config.php");
94
		}
95
 
96
		// Timo van Roermund: parse the info from the hddtemp daemon.
97
		$i = 0;
98
		foreach($ar_buf as $line) {
99
			$data = array();
100
			if (ereg("\|(.*)\|(.*)\|(.*)\|(.*)\|", $line, $data)) {
101
				if( trim($data[3]) != "ERR" ) {
102
					// get the info we need
103
					$results[$i]['label'] = $data[1];
104
					$results[$i]['value'] = $data[3];
105
					$results[$i]['model'] = $data[2];
106
					$i++;
107
				}
108
			}
109
		}
110
 
111
		return $results;
112
	}
113
}
114
?>