Subversion Repositories ALCASAR

Rev

Rev 325 | Rev 2976 | 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
 * hddtemp sensor class, getting information from hddtemp
4
// http://phpsysinfo.sourceforge.net/
4
 *
5
 
5
 * PHP version 5
6
// This program is free software; you can redistribute it and/or
6
 *
7
// modify it under the terms of the GNU General Public License
7
 * @category  PHP
8
// as published by the Free Software Foundation; either version 2
8
 * @package   PSI_Sensor
9
// of the License, or (at your option) any later version.
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
10
 
10
 * @author    T.A. van Roermund <timo@van-roermund.nl>
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
16
class HDDTemp extends Sensors
17
// along with this program; if not, write to the Free Software
17
{
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
    /**
19
 
19
     * get the temperature information from hddtemp
20
// $Id: class.hddtemp.inc.php,v 1.7 2007/01/21 13:17:20 bigmichi1 Exp $
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
		$ar_buf = array();
25
    {
26
		$results = array();
26
        $ar_buf = 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
				// Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout.
29
            $lines = '';
30
				$fp = fsockopen('localhost', 7634, $errno, $errstr, 5);
30
            // Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout.
31
				// if connected, read the output of the hddtemp daemon
31
            $fp = @fsockopen('localhost', 7634, $errno, $errstr, 5);
32
				if ($fp) {
32
            // if connected, read the output of the hddtemp daemon
33
					// read output of the daemon
33
            if ($fp) {
34
					$lines = '';
34
                while (!feof($fp)) {
35
					while (!feof($fp)) {
35
                    $lines .= fread($fp, 1024);
36
						$lines .= fread($fp, 1024);
36
                }
37
					}
37
                fclose($fp);
38
					// close the connection
38
            } else {
39
					fclose($fp);
39
                $this->error->addError("HDDTemp error", $errno.", ".$errstr);
40
				} else {
40
            }
41
					die("HDDTemp error: " . $errno . ", " . $errstr);
41
            $lines = str_replace("||", "|\n|", $lines);
42
				}
42
            $ar_buf = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
43
				$lines = str_replace("||", "|\n|", $lines);
43
            break;
44
				$ar_buf = explode("\n", $lines);
44
        case 'command':
45
				break;
45
            $strDrives = "";
46
			case "suid":
46
            $strContent = "";
47
				$strDrives = "";
47
            $hddtemp_value = "";
48
				$strContent = rfts( "/proc/diskstats", 0, 4096, false );
48
            if (CommonFunctions::rfts("/proc/diskstats", $strContent, 0, 4096, false)) {
49
				if( $strContent != "ERROR" ) {
49
                $arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
50
					$arrContent = explode( "\n", $strContent );
50
                foreach ($arrContent as $strLine) {
51
					foreach( $arrContent as $strLine ) {
51
                    preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
52
						preg_match( "/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit );
52
                    if (! empty($arrSplit[2])) {
53
						if( !empty( $arrSplit[2] ) ) {
53
                        $strDrive = '/dev/'.$arrSplit[2];
54
						    $strDrive = '/dev/' . $arrSplit[2];
54
                        if (file_exists($strDrive)) {
55
						    if( file_exists( $strDrive ) ) {
55
                            $strDrives = $strDrives.$strDrive.' ';
56
							$strDrives = $strDrives . $strDrive . ' ';
56
                        }
57
						    }							
57
                    }
58
						}
58
                }
59
					}
59
            } else {
60
				} else {
60
                if (CommonFunctions::rfts("/proc/partitions", $strContent, 0, 4096, false)) {
61
				    $strContent = rfts( "/proc/partitions", 0, 4096, false );
61
                    $arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
62
				    if( $strContent != "ERROR" ) {
62
                    foreach ($arrContent as $strLine) {
63
					$arrContent = explode( "\n", $strContent );
63
                        if (!preg_match("/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit)) {
64
					foreach( $arrContent as $strLine ) {
64
                            preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
65
						if( !preg_match( "/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit ) ) {
65
                        }
66
						    preg_match( "/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit );
66
                        if (! empty($arrSplit[2])) {
67
						}
67
                            $strDrive = '/dev/'.$arrSplit[2];
68
						if( !empty( $arrSplit[2] ) ) {
68
                            if (file_exists($strDrive)) {
69
						    $strDrive = '/dev/' . $arrSplit[2];
69
                                $strDrives = $strDrives.$strDrive.' ';
70
						    if( file_exists( $strDrive ) ) {
70
                            }
71
							$strDrives = $strDrives . $strDrive . ' ';
71
                        }
72
						    }
72
                    }
73
						}
73
                }
74
					}
74
            }
75
				    }
75
            if (trim($strDrives) == "") {
76
				}
76
                break;
77
				
77
            }
78
				if( trim( $strDrives ) == "" ) {
78
            if (CommonFunctions::executeProgram("hddtemp", $strDrives, $hddtemp_value, PSI_DEBUG)) {
79
					return array();
79
                $hddtemp_value = preg_split("/\n/", $hddtemp_value, -1, PREG_SPLIT_NO_EMPTY);
80
				}
80
                foreach ($hddtemp_value as $line) {
81
 
81
                    $temp = preg_split("/:\s/", $line, 3);
82
				$hddtemp_value = execute_program("hddtemp", $strDrives);
82
                    if (count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) {
83
				$hddtemp_value = explode("\n", $hddtemp_value);
83
                        preg_match("/^([0-9]*)(.*)/", $temp[2], $ar_temp);
84
				foreach($hddtemp_value as $line) {
84
                        $temp[2] = trim($ar_temp[1]);
85
					$temp = preg_split("/:\s/", $line, 3);
85
                        $temp[3] = trim($ar_temp[2]);
86
					if(count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) {
86
                        array_push($ar_buf, "|".implode("|", $temp)."|");
87
						list($temp[2], $temp[3]) = (preg_split("/\s/", $temp[2]));
87
                    }
88
						array_push( $ar_buf, "|" . implode("|", $temp) . "|");
88
                }
89
					}
89
            }
90
				}
90
            break;
91
				break;
91
        default:
92
			default:
92
            $this->error->addConfigError("temperature()", "[sensor_hddtemp] ACCESS");
93
				die("Bad hddtemp configuration in config.php");
93
            break;
94
		}
94
        }
95
		
95
        // Timo van Roermund: parse the info from the hddtemp daemon.
96
		// Timo van Roermund: parse the info from the hddtemp daemon.
96
        foreach ($ar_buf as $line) {
97
		$i = 0;
97
            $data = array();
98
		foreach($ar_buf as $line) {
98
            if (preg_match("/\|(.*)\|(.*)\|(.*)\|(.*)\|/", $line, $data)) {
99
			$data = array();
99
                if (trim($data[3]) != "ERR") {
100
			if (ereg("\|(.*)\|(.*)\|(.*)\|(.*)\|", $line, $data)) {
100
                    // get the info we need
101
				if( trim($data[3]) != "ERR" ) {
101
                    $dev = new SensorDevice();
102
					// get the info we need
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
					$results[$i]['model'] = $data[2];
105
                    }
106
					$i++;
106
//                    $dev->setMax(60);
107
				}
107
                    $this->mbinfo->setMbTemp($dev);
108
			}
108
                }
109
		}
109
            }
110
		
110
        }
111
		return $results;
111
    }
112
	}
112
 
-
 
113
    /**
-
 
114
     * get the information
-
 
115
     *
-
 
116
     * @see PSI_Interface_Sensor::build()
-
 
117
     *
-
 
118
     * @return Void
-
 
119
     */
-
 
120
    public function build()
-
 
121
    {
-
 
122
        $this->_temperature();
-
 
123
    }
113
}
124
}
114
?>
-