first commit

This commit is contained in:
renjianbo
2026-01-07 11:40:41 +08:00
parent 2b5d784e31
commit 8f2ed2c108
6466 changed files with 1431506 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?php
/**
* coretemp sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.Coretemp.inc.php 263 2009-06-22 13:01:52Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting hardware temperature information through sysctl
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author William Johansson <radar@radhuset.org>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Coretemp extends Sensors
{
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
$smp = 1;
CommonFunctions::executeProgram('sysctl', '-n kern.smp.cpus', $smp);
for ($i = 0; $i < $smp; $i++) {
$temp = 0;
if (CommonFunctions::executeProgram('sysctl', '-n dev.cpu.'.$i.'.temperature', $temp)) {
$dev = new SensorDevice();
$dev->setName("CPU ".($i + 1));
$dev->setValue($temp);
$dev->setMax(70);
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
}
}
?>

View File

@@ -0,0 +1,136 @@
<?php
/**
* hddtemp sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.HDDTemp.inc.php 337 2009-10-05 07:37:32Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from hddtemp
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author T.A. van Roermund <timo@van-roermund.nl>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class HDDTemp extends Sensors
{
/**
* get the temperature information from hddtemp
* access is available through tcp or command
*
* @return array temperatures in array
*/
private function _temperature()
{
$ar_buf = array();
switch (PSI_HDD_TEMP) {
case "tcp":
$lines = '';
// Timo van Roermund: connect to the hddtemp daemon, use a 5 second timeout.
$fp = @fsockopen('localhost', 7634, $errno, $errstr, 5);
// if connected, read the output of the hddtemp daemon
if ($fp) {
while (!feof($fp)) {
$lines .= fread($fp, 1024);
}
fclose($fp);
} else {
$this->error->addError("HDDTemp error", $errno.", ".$errstr);
}
$lines = str_replace("||", "|\n|", $lines);
$ar_buf = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
case "command":
$strDrives = "";
$strContent = "";
$hddtemp_value = "";
if (CommonFunctions::rfts("/proc/diskstats", $strContent, 0, 4096, false)) {
$arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrContent as $strLine) {
preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
if (! empty($arrSplit[2])) {
$strDrive = '/dev/'.$arrSplit[2];
if (file_exists($strDrive)) {
$strDrives = $strDrives.$strDrive.' ';
}
}
}
} else {
if (CommonFunctions::rfts("/proc/partitions", $strContent, 0, 4096, false)) {
$arrContent = preg_split("/\n/", $strContent, -1, PREG_SPLIT_NO_EMPTY);
foreach ($arrContent as $strLine) {
if (!preg_match("/^\s(.*)\s([\/a-z0-9]*(\/disc))\s(.*)/", $strLine, $arrSplit)) {
preg_match("/^\s(.*)\s([a-z]*)\s(.*)/", $strLine, $arrSplit);
}
if (! empty($arrSplit[2])) {
$strDrive = '/dev/'.$arrSplit[2];
if (file_exists($strDrive)) {
$strDrives = $strDrives.$strDrive.' ';
}
}
}
}
}
if (trim($strDrives) == "") {
break;
}
if (CommonFunctions::executeProgram("hddtemp", $strDrives, $hddtemp_value)) {
$hddtemp_value = preg_split("/\n/", $hddtemp_value, -1, PREG_SPLIT_NO_EMPTY);
foreach ($hddtemp_value as $line) {
$temp = preg_split("/:\s/", $line, 3);
if (count($temp) == 3 && preg_match("/^[0-9]/", $temp[2])) {
preg_match("/^([0-9]*)(.*)/", $temp[2], $ar_temp);
$temp[2] = trim($ar_temp[1]);
$temp[3] = trim($ar_temp[2]);
array_push($ar_buf, "|".implode("|", $temp)."|");
}
}
}
break;
default:
$this->error->addConfigError("temperature()", "PSI_HDD_TEMP");
break;
}
// Timo van Roermund: parse the info from the hddtemp daemon.
foreach ($ar_buf as $line) {
$data = array();
if (ereg("\|(.*)\|(.*)\|(.*)\|(.*)\|", $line, $data)) {
if (trim($data[3]) != "ERR") {
// get the info we need
$dev = new SensorDevice();
$dev->setName($data[1] . ' (' . $data[2] . ')');
if (is_numeric($data[3])) {
$dev->setValue($data[3]);
}
$dev->setMax(60);
$this->mbinfo->setMbTemp($dev);
}
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
}
}
?>

View File

@@ -0,0 +1,123 @@
<?php
/**
* hwsensors sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.HWSensors.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from hwsensors
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class HWSensors extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through tcp or file access
*/
function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'tcp':
$lines = "";
CommonFunctions::executeProgram('sysctl', '-w hw.sensors', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
$ar_buf = preg_split("/[\s,]+/", $line);
if (isset($ar_buf[3]) && $ar_buf[2] == 'temp') {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[3]);
$dev->setMax(70);
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
foreach ($this->_lines as $line) {
$ar_buf = preg_split("/[\s,]+/", $line);
if (isset($ar_buf[3]) && $ar_buf[2] == 'fanrpm') {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[3]);
$this->mbinfo->setMbFan($dev);
}
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
foreach ($this->_lines as $line) {
$ar_buf = preg_split("/[\s,]+/", $line);
if (isset($ar_buf[3]) && $ar_buf[2] == 'volts_dc') {
$dev = new SensorDevice();
$dev->setName($ar_buf[1]);
$dev->setValue($ar_buf[3]);
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
}
}
?>

View File

@@ -0,0 +1,155 @@
<?php
/**
* healthd sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.Healthd.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from healthd
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Healthd extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through tcp or file access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
$lines = "";
CommonFunctions::executeProgram('healthdc', '-t', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
$ar_buf = preg_split("/\t+/", $this->_lines);
$dev1 = new SensorDevice();
$dev1->setName('temp1');
$dev1->setValue($ar_buf[1]);
$dev1->setMax(70);
$this->mbinfo->setMbTemp($dev1);
$dev2 = new SensorDevice();
$dev2->setName('temp1');
$dev2->setValue($ar_buf[2]);
$dev2->setMax(70);
$this->mbinfo->setMbTemp($dev2);
$dev3 = new SensorDevice();
$dev3->setName('temp1');
$dev3->setValue($ar_buf[3]);
$dev3->setMax(70);
$this->mbinfo->setMbTemp($dev3);
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
$ar_buf = preg_split("/\t+/", $this->_lines);
$dev1 = new SensorDevice();
$dev1->setName('fan1');
$dev1->setValue($ar_buf[4]);
$dev1->setMin(3000);
$this->mbinfo->setMbFan($dev1);
$dev2 = new SensorDevice();
$dev2->setName('fan2');
$dev2->setValue($ar_buf[5]);
$dev2->setMin(3000);
$this->mbinfo->setMbFan($dev2);
$dev3 = new SensorDevice();
$dev3->setName('fan3');
$dev3->setValue($ar_buf[6]);
$dev3->setMin(3000);
$this->mbinfo->setMbFan($dev3);
}
/**
* get voltage information
*
* @return array voltage in array with lable
*/
private function _voltage()
{
$ar_buf = preg_split("/\t+/", $this->_lines);
$dev1 = new SensorDevice();
$dev1->setName('Vcore1');
$dev1->setValue($ar_buf[7]);
$this->mbinfo->setMbVolt($dev1);
$dev2 = new SensorDevice();
$dev2->setName('Vcore2');
$dev2->setValue($ar_buf[8]);
$this->mbinfo->setMbVolt($dev2);
$dev3 = new SensorDevice();
$dev3->setName('3volt');
$dev3->setValue($ar_buf[9]);
$this->mbinfo->setMbVolt($dev3);
$dev4 = new SensorDevice();
$dev4->setName('+5Volt');
$dev4->setValue($ar_buf[10]);
$this->mbinfo->setMbVolt($dev4);
$dev5 = new SensorDevice();
$dev5->setName('+12Volt');
$dev5->setValue($ar_buf[11]);
$this->mbinfo->setMbVolt($dev5);
$dev6 = new SensorDevice();
$dev6->setName('-12Volt');
$dev6->setValue($ar_buf[12]);
$this->mbinfo->setMbVolt($dev6);
$dev7 = new SensorDevice();
$dev7->setName('-5Volt');
$dev7->setValue($ar_buf[13]);
$this->mbinfo->setMbVolt($dev7);
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
$this->_fans();
$this->_voltage();
}
}
?>

View File

@@ -0,0 +1,105 @@
<?php
/**
* ipmi sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.IPMI.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from ipmitool
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class IPMI extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through tcp or file access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
$lines = "";
CommonFunctions::executeProgram('ipmitool', 'sensor', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temp()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/[ ]+\|[ ]+/", $line);
if ($buffer[2] == "degrees C" && $buffer[5] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
$dev->setMax($buffer[8]);
$this->mbinfo->setMbTemp($dev);
}
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
foreach ($this->_lines as $line) {
$buffer = preg_split("/[ ]+\|[ ]+/", $line);
if ($buffer[2] == "Volts" && $buffer[5] != "na") {
$dev = new SensorDevice();
$dev->setName($buffer[0]);
$dev->setValue($buffer[1]);
$dev->setMin($buffer[5]);
$dev->setMax($buffer[8]);
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temp();
$this->_voltage();
}
}
?>

View File

@@ -0,0 +1,87 @@
<?php
/**
* K8Temp sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.K8Temp.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from k8temp
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class K8Temp extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private array
*/
function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
$lines = "";
CommonFunctions::executeProgram('k8temp', '', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
if (preg_match('/(.*):\s*(\d*)/', $line, $data)) {
if ($data[2] > 0) {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setMax('70.0');
if ($data[2] < 250) {
$dev->setValue($data[2]);
}
$this->mbinfo->setMbTemp($dev);
}
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_temperature();
}
}
?>

View File

@@ -0,0 +1,253 @@
<?php
/**
* lmsensor sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.LMSensors.inc.php 316 2009-09-03 08:09:18Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from lmsensor
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class LMSensors extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through tcp or file access
*/
function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'command':
if (CommonFunctions::executeProgram("sensors", "", $lines)) {
// Martijn Stolk: Dirty fix for misinterpreted output of sensors,
// where info could come on next line when the label is too long.
$lines = str_replace(":\n", ":", $lines);
$lines = str_replace("\n\n", "\n", $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
case 'file':
if (CommonFunctions::rfts(APP_ROOT.'/data/lmsensors.txt', $lines)) {
$lines = str_replace(":\n", ":", $lines);
$lines = str_replace("\n\n", "\n", $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\((.*)=(.*)\)(.*)/", $line, $data)) {
;
} else {
(preg_match("/(.*):(.*)/", $line, $data));
}
if (count($data) > 1) {
$temp = substr(trim($data[2]), -1);
switch ($temp) {
case "C":
case "F":
array_push($ar_buf, $line);
}
}
}
foreach ($ar_buf as $line) {
$data = array();
if (preg_match("/(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*).C[ ]*\((.*)=(.*).C,(.*)=(.*).C\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*).C[ ]*\((.*)=(.*).C\)(.*)/", $line, $data)) {
;
} else {
(preg_match("/(.*):(.*).C/", $line, $data));
}
foreach ($data as $key=>$value) {
if (preg_match("/^\+?([0-9\.]+).?$/", trim($value), $newvalue)) {
$data[$key] = trim($newvalue[1]);
} else {
$data[$key] = trim($value);
}
}
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
$limit = 0;
$perce = 0;
if (isset($data[6]) && $data[2] > $data[6]) {
$limit = 75;
$perce = 75;
} else {
$limit = isset($data[4]) ? $data[4] : 75;
$perce = isset($data[6]) ? $data[6] : 75;
}
if ($limit < $perce) {
$dev->setMax($perce);
} else {
$dev->setMax($limit);
}
$this->mbinfo->setMbTemp($dev);
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*)\((.*)=(.*)\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = preg_split("/ /", trim($data[2]));
if (count($temp) == 1) {
$temp = preg_split("/\xb0/", trim($data[2]));
}
if (isset($temp[1])) {
switch ($temp[1]) {
case "RPM":
array_push($ar_buf, $line);
}
}
}
}
foreach ($ar_buf as $line) {
$data = array();
if (preg_match("/(.*):(.*) RPM \((.*)=(.*) RPM,(.*)=(.*)\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) RPM \((.*)=(.*) RPM,(.*)=(.*)\)(.*)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) RPM \((.*)=(.*) RPM\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*) RPM/", $line, $data);
}
$dev = new SensorDevice();
$dev->setName(trim($data[1]));
$dev->setValue(trim($data[2]));
if (isset($data[4])) {
$dev->setMin(trim($data[4]));
}
$this->mbinfo->setMbFan($dev);
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
$ar_buf = array();
foreach ($this->_lines as $line) {
$data = array();
if (preg_match("/(.*):(.*)\((.*)=(.*),(.*)=(.*)\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*)/", $line, $data);
}
if (count($data) > 1) {
$temp = preg_split("/ /", trim($data[2]));
if (count($temp) == 1) {
$temp = preg_split("/\xb0/", trim($data[2]));
}
if (isset($temp[1])) {
switch ($temp[1]) {
case "V":
array_push($ar_buf, $line);
}
}
}
}
foreach ($ar_buf as $line) {
$data = array();
if (preg_match("/(.*)\:(.*) V \((.*)=(.*) V,(.*)=(.*) V\)(.*)\)/", $line, $data)) {
;
} elseif (preg_match("/(.*):(.*) V \((.*)=(.*) V,(.*)=(.*) V\)(.*)/", $line, $data)) {
;
} else {
preg_match("/(.*):(.*) V$/", $line, $data);
}
foreach ($data as $key=>$value) {
if (preg_match("/^\+?([0-9\.]+)$/", trim($value), $newvalue)) {
$data[$key] = trim($newvalue[1]);
} else {
$data[$key] = trim($value);
}
}
if (isset($data[1])) {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
if (isset($data[4])) {
$dev->setMin($data[4]);
}
if (isset($data[6])) {
$dev->setMax($data[6]);
}
$this->mbinfo->setMbVolt($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
}
}
?>

View File

@@ -0,0 +1,140 @@
<?php
/**
* MBM5 sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.MBM5.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from Motherboard Monitor 5
* information retrival through csv file
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class MBM5 extends Sensors
{
/**
* array with the names of the labels
*
* @var array
*/
private $_buf_label = array();
/**
* array withe the values
*
* @var array
*/
private $_buf_value = array();
/**
* read the MBM5.csv file and fill the private arrays
*/
function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'file':
$delim = "/;/";
CommonFunctions::rfts(APP_ROOT."/data/MBM5.csv", $buffer);
if (strpos($buffer, ";") === false) {
$delim = "/,/";
}
$buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
$this->_buf_label = preg_split($delim, substr($buffer[0], 0, -2), -1, PREG_SPLIT_NO_EMPTY);
$this->_buf_value = preg_split($delim, substr($buffer[1], 0, -2), -1, PREG_SPLIT_NO_EMPTY);
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
for ($intPosi = 3; $intPosi < 6; $intPosi++) {
if ($this->_buf_value[$intPosi] == 0) {
continue;
}
preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
$dev = new SensorDevice();
$dev->setName($this->_buf_label[$intPosi]);
$dev->setValue($hits[0]);
$dev->setMax(70);
$this->mbinfo->setMbTemp($dev);
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
for ($intPosi = 13; $intPosi < 16; $intPosi++) {
if (!isset($this->_buf_value[$intPosi])) {
continue;
}
preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
$dev = new SensorDevice();
$dev->setName($this->_buf_label[$intPosi]);
$dev->setValue($hits[0]);
$dev->setMin(3000);
$this->mbinfo->setMbFan($dev);
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
for ($intPosi = 6; $intPosi < 13; $intPosi++) {
if ($this->_buf_value[$intPosi] == 0) {
continue;
}
preg_match("/([0-9\.])*/", str_replace(",", ".", $this->_buf_value[$intPosi]), $hits);
$dev = new SensorDevice();
$dev->setName($this->_buf_label[$intPosi]);
$dev->setValue($hits[0]);
$this->mbinfo->setMbVolt($dev);
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return Void
*/
public function build()
{
$this->_fans();
$this->_temperature();
$this->_voltage();
}
}
?>

View File

@@ -0,0 +1,139 @@
<?php
/**
* mbmon sensor class
*
* PHP version 5
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.MBMon.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting information from mbmon
*
* @category PHP
* @package PSI_Sensor
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class MBMon extends Sensors
{
/**
* content to parse
*
* @var array
*/
private $_lines = array();
/**
* fill the private content var through tcp or file access
*/
public function __construct()
{
parent::__construct();
switch (strtolower(PSI_SENSOR_ACCESS)) {
case 'tcp':
$fp = fsockopen("localhost", 411, $errno, $errstr, 5);
if ($fp) {
$lines = "";
while (!feof($fp)) {
$lines .= fread($fp, 1024);
}
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
} else {
$this->error->addError("fsockopen()", $errno." ".$errstr);
}
break;
case 'command':
CommonFunctions::executeProgram('mbmon', '-c 1 -r', $lines);
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
default:
$this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
break;
}
}
/**
* get temperature information
*
* @return void
*/
private function _temperature()
{
foreach ($this->_lines as $line) {
if (preg_match('/^(TEMP\d*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2] <> '0') {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setMax(70);
if ($data[2] < 250) {
$dev->setValue($data[2]);
}
$this->mbinfo->setMbTemp($dev);
}
}
}
}
/**
* get fan information
*
* @return void
*/
private function _fans()
{
foreach ($this->_lines as $line) {
if (preg_match('/^(FAN\d*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2] <> '0') {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
$dev->setMax(3000);
$this->mbinfo->setMbFan($dev);
}
}
}
}
/**
* get voltage information
*
* @return void
*/
private function _voltage()
{
foreach ($this->_lines as $line) {
if (preg_match('/^(V.*)\s*:\s*(.*)$/D', $line, $data)) {
if ($data[2] <> '+0.00') {
$dev = new SensorDevice();
$dev->setName($data[1]);
$dev->setValue($data[2]);
$this->mbinfo->setMbVolt($dev);
}
}
}
}
/**
* get the information
*
* @see PSI_Interface_Sensor::build()
*
* @return void
*/
public function build()
{
$this->_temperature();
$this->_voltage();
$this->_fans();
}
}
?>

View File

@@ -0,0 +1,64 @@
<?php
/**
* Basic OS Class
*
* PHP version 5
*
* @category PHP
* @package PSI_OS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.Sensors.inc.php 263 2009-06-22 13:01:52Z bigmichi1 $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Basic OS functions for all OS classes
*
* @category PHP
* @package PSI_OS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
abstract class Sensors implements PSI_Interface_Sensor
{
/**
* object for error handling
*
* @var Error
*/
protected $error;
/**
* object for the information
*
* @var MBInfo
*/
protected $mbinfo;
/**
* build the global Error object
*/
public function __construct()
{
$this->error = Error::singleton();
$this->mbinfo = new MBInfo();
}
/**
* get the filled or unfilled (with default values) MBInfo object
*
* @see PSI_Interface_Sensor::getMBInfo()
*
* @return MBInfo
*/
public final function getMBInfo()
{
$this->build();
return $this->mbinfo;
}
}
?>