Subversion Repositories ALCASAR

Rev

Details | Last modification | View Log

Rev Author Line No. Line
1 root 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.lmsensors.inc.php,v 1.19 2007/02/18 19:11:31 bigmichi1 Exp $
21
if (!defined('IN_PHPSYSINFO')) {
22
    die("No Hacking");
23
}
24
 
25
require_once(APP_ROOT . "/includes/common_functions.php");
26
 
27
class mbinfo {
28
  var $lines;
29
 
30
  function mbinfo() {
31
   $lines = execute_program("sensors", "");
32
   // Martijn Stolk: Dirty fix for misinterpreted output of sensors, 
33
   // where info could come on next line when the label is too long.
34
   $lines = str_replace(":\n", ":", $lines);
35
   $lines = str_replace("\n\n", "\n", $lines);
36
   $this->lines = explode("\n", $lines);
37
  }
38
 
39
  function temperature() {
40
    $ar_buf = array();
41
    $results = array();
42
 
43
    $sensors_value = $this->lines;
44
 
45
    foreach($sensors_value as $line) {
46
      $data = array();
47
      if (ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data)) ;
48
      elseif (ereg("(.*):(.*)\((.*)=(.*)\)(.*)", $line, $data)) ;
49
      else (ereg("(.*):(.*)", $line, $data));
50
      if (count($data) > 1) {
51
        $temp = substr(trim($data[2]), -1);
52
        switch ($temp) {
53
          case "C";
54
          case "F":
55
            array_push($ar_buf, $line);
56
            break;
57
        }
58
      }
59
    }
60
 
61
    $i = 0;
62
    foreach($ar_buf as $line) {
63
      unset($data);
64
      if (ereg("(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)\)", $line, $data)) ;
65
      elseif (ereg("(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)", $line, $data)) ;
66
      elseif (ereg("(.*):(.*).C[ ]*\((.*)=(.*).C\)(.*)", $line, $data)) ;
67
      else (ereg("(.*):(.*).C", $line, $data));
68
 
69
      $results[$i]['label'] = $data[1];
70
      $results[$i]['value'] = trim($data[2]);
71
      if ( isset( $data[6] ) && trim( $data[2] ) > trim( $data[6] ) ) {
72
        $results[$i]['limit'] = "+75";
73
        $results[$i]['perce'] = "+75";
74
      } else {
75
        $results[$i]['limit'] = isset($data[4]) ? trim($data[4]) : "+75";
76
        $results[$i]['perce'] = isset($data[6]) ? trim($data[6]) : "+75";
77
      }
78
      if ($results[$i]['limit'] < $results[$i]['perce']) {	 	
79
         $results[$i]['limit'] = $results[$i]['perce'];	 	
80
       }      
81
      $i++;
82
    }
83
 
84
    asort($results);
85
    return array_values($results);
86
  }
87
 
88
  function fans() {
89
    $ar_buf = array();
90
    $results = array();
91
 
92
    $sensors_value = $this->lines;
93
 
94
    foreach($sensors_value as $line) {
95
      $data = array();
96
      if (ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data));
97
      elseif (ereg("(.*):(.*)\((.*)=(.*)\)(.*)", $line, $data));
98
      else ereg("(.*):(.*)", $line, $data);
99
 
100
      if (count($data) > 1) {
101
        $temp = explode(" ", trim($data[2]));
102
        if (count($temp) == 1)
103
          $temp = explode("\xb0", trim($data[2]));
104
	if(isset($temp[1])) {
105
          switch ($temp[1]) {
106
            case "RPM":
107
              array_push($ar_buf, $line);
108
              break;
109
          }
110
	}
111
      }
112
    }
113
 
114
    $i = 0;
115
    foreach($ar_buf as $line) {
116
      unset($data);
117
      if (ereg("(.*):(.*) RPM  \((.*)=(.*) RPM,(.*)=(.*)\)(.*)\)", $line, $data));
118
      elseif (ereg("(.*):(.*) RPM  \((.*)=(.*) RPM,(.*)=(.*)\)(.*)", $line, $data));
119
      elseif (ereg("(.*):(.*) RPM  \((.*)=(.*) RPM\)(.*)", $line, $data));
120
      else ereg("(.*):(.*) RPM", $line, $data);
121
 
122
      $results[$i]['label'] = trim($data[1]);
123
      $results[$i]['value'] = trim($data[2]);
124
      $results[$i]['min'] = isset($data[4]) ? trim($data[4]) : 0;
125
      $i++;
126
    }
127
 
128
    asort($results);
129
    return array_values($results);
130
  }
131
 
132
  function voltage() {
133
    $ar_buf = array();
134
    $results = array();
135
 
136
    $sensors_value = $this->lines;
137
 
138
    foreach($sensors_value as $line) {
139
      $data = array();
140
      if (ereg("(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)", $line, $data));
141
      else ereg("(.*):(.*)", $line, $data);
142
 
143
      if (count($data) > 1) {
144
        $temp = explode(" ", trim($data[2]));
145
        if (count($temp) == 1)
146
          $temp = explode("\xb0", trim($data[2]));
147
        if (isset($temp[1])) {
148
          switch ($temp[1]) {
149
            case "V":
150
              array_push($ar_buf, $line);
151
              break;
152
	  }
153
        }
154
      }
155
    }
156
 
157
    $i = 0;
158
    foreach($ar_buf as $line) {
159
      unset($data);
160
      if (ereg("(.*):(.*) V  \((.*)=(.*) V,(.*)=(.*) V\)(.*)\)", $line, $data));
161
      elseif (ereg("(.*):(.*) V  \((.*)=(.*) V,(.*)=(.*) V\)(.*)", $line, $data));
162
      else ereg("(.*):(.*) V$", $line, $data);
163
      if(isset($data[1])) {
164
        $results[$i]['label'] = trim($data[1]);
165
        $results[$i]['value'] = trim($data[2]);
166
        $results[$i]['min'] = isset($data[4]) ? trim($data[4]) : 0;
167
        $results[$i]['max'] = isset($data[6]) ? trim($data[6]) : 0;
168
        $i++;
169
      }
170
    }
171
    return $results;
172
  }
173
}
174
 
175
?>