initial commit of file from CVS for smeserver-phpsysinfo on Sat Sep 7 20:53:46 AEST 2024

This commit is contained in:
Trevor Batley
2024-09-07 20:53:46 +10:00
parent 8f9c36d1f5
commit 9552652292
693 changed files with 86806 additions and 2 deletions

View File

@@ -0,0 +1,145 @@
<?php
/**
* Apcupsd class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @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.apcupsd.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from apcupsd program
*
* @category PHP
* @package PSI_UPS
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
* @author Artem Volk <artvolk@mail.ru>
* @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 Apcupsd extends UPS
{
/**
* internal storage for all gathered data
*
* @var Array
*/
private $_output = array();
/**
* get all information from all configured ups in phpsysinfo.ini and store output in internal array
*/
public function __construct()
{
parent::__construct();
if (defined('PSI_UPS_APCUPSD_LIST') && is_string(PSI_UPS_APCUPSD_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_APCUPSD_LIST)) {
$upses = eval(PSI_UPS_APCUPSD_LIST);
} else {
$upses = array(PSI_UPS_APCUPSD_LIST);
}
foreach ($upses as $ups) {
CommonFunctions::executeProgram('apcaccess', 'status '.trim($ups), $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
} else { //use default if address and port not defined
CommonFunctions::executeProgram('apcaccess', 'status', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return Void
*/
private function _info()
{
foreach ($this->_output as $ups) {
$dev = new UPSDevice();
// General info
if (preg_match('/^UPSNAME\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setName(trim($data[1]));
}
if (preg_match('/^MODEL\s*:\s*(.*)$/m', $ups, $data)) {
$model=trim($data[1]);
if (preg_match('/^APCMODEL\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setModel($model.' ('.trim($data[1]).')');
} else {
$dev->setModel($model);
}
}
if (preg_match('/^UPSMODE\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setMode(trim($data[1]));
}
if (preg_match('/^STARTTIME\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setStartTime(trim($data[1]));
}
if (preg_match('/^STATUS\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setStatus(trim($data[1]));
}
if (preg_match('/^ITEMP\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setTemperatur(trim($data[1]));
}
// Outages
if (preg_match('/^NUMXFERS\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setOutages(trim($data[1]));
}
if (preg_match('/^LASTXFER\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setLastOutage(trim($data[1]));
}
if (preg_match('/^XOFFBATT\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setLastOutageFinish(trim($data[1]));
}
// Line
if (preg_match('/^LINEV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setLineVoltage(trim($data[1]));
}
if (preg_match('/^LINEFREQ\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setLineFrequency(trim($data[1]));
}
if (preg_match('/^LOADPCT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setLoad(trim($data[1]));
}
// Battery
if (preg_match('/^BATTDATE\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setBatteryDate(trim($data[1]));
}
if (preg_match('/^BATTV\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setBatteryVoltage(trim($data[1]));
}
if (preg_match('/^BCHARGE\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setBatterCharge(trim($data[1]));
}
if (preg_match('/^TIMELEFT\s*:\s*(\d*\.\d*)(.*)$/m', $ups, $data)) {
$dev->setTimeLeft(trim($data[1]));
}
$this->upsinfo->setUpsDevices($dev);
}
}
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}

View File

@@ -0,0 +1,142 @@
<?php
/**
* Nut class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Artem Volk <artvolk@mail.ru>
* @author Anders Häggström <hagge@users.sourceforge.net>
* @copyright 2009 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.nut.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from upsc program
*
* @category PHP
* @package PSI_UPS
* @author Artem Volk <artvolk@mail.ru>
* @author Anders Häggström <hagge@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 Nut extends UPS
{
/**
* internal storage for all gathered data
*
* @var array
*/
private $_output = array();
/**
* get all information from all configured ups and store output in internal array
*/
public function __construct()
{
parent::__construct();
if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
$upses = eval(PSI_UPS_NUT_LIST);
} else {
$upses = array(PSI_UPS_NUT_LIST);
}
foreach ($upses as $ups) {
CommonFunctions::executeProgram('upsc', '-l '.trim($ups), $output);
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
CommonFunctions::executeProgram('upsc', trim($ups_name).'@'.trim($ups), $temp);
if (! empty($temp)) {
$this->_output[trim($ups_name).'@'.trim($ups)] = $temp;
}
}
}
} else { //use default if address and port not defined
CommonFunctions::executeProgram('upsc', '-l', $output);
$ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
foreach ($ups_names as $ups_name) {
CommonFunctions::executeProgram('upsc', trim($ups_name), $temp);
if (! empty($temp)) {
$this->_output[trim($ups_name)] = $temp;
}
}
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return array
*/
private function _info()
{
if (! empty($this->_output)) {
foreach ($this->_output as $name=>$value) {
$temp = preg_split("/\n/", $value, -1, PREG_SPLIT_NO_EMPTY);
$ups_data = array();
foreach ($temp as $value) {
$line = preg_split('/: /', $value, 2);
$ups_data[$line[0]] = isset($line[1]) ? trim($line[1]) : '';
}
$dev = new UPSDevice();
//General
$dev->setName($name);
if (isset($ups_data['ups.model'])) {
$dev->setModel($ups_data['ups.model']);
}
if (isset($ups_data['driver.name'])) {
$dev->setMode($ups_data['driver.name']);
}
if (isset($ups_data['ups.status'])) {
$dev->setStatus($ups_data['ups.status']);
}
//Line
if (isset($ups_data['input.voltage'])) {
$dev->setLineVoltage($ups_data['input.voltage']);
}
if (isset($ups_data['input.frequency'])) {
$dev->setLineFrequency($ups_data['input.frequency']);
}
if (isset($ups_data['ups.load'])) {
$dev->setLoad($ups_data['ups.load']);
}
//Battery
if (isset($ups_data['battery.voltage'])) {
$dev->setBatteryVoltage($ups_data['battery.voltage']);
}
if (isset($ups_data['battery.charge'])) {
$dev->setBatterCharge($ups_data['battery.charge']);
}
if (isset($ups_data['battery.runtime'])) {
$dev->setTimeLeft(round($ups_data['battery.runtime']/60, 2));
}
//Temperature
if (isset($ups_data['ups.temperature'])) {
$dev->setTemperatur($ups_data['ups.temperature']);
}
$this->upsinfo->setUpsDevices($dev);
}
}
}
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* Pmset class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Robert Pelletier <drizzt@menzonet.org>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.nut.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from pmset program
*
* @category PHP
* @package PSI_UPS
* @author Robert Pelletier <drizzt@menzonet.org>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class Pmset extends UPS
{
/**
* internal storage for all gathered data
*
* @var array
*/
private $_output = array();
/**
* get all information from all configured ups and store output in internal array
*/
public function __construct()
{
parent::__construct();
CommonFunctions::executeProgram('pmset', '-g batt', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return array
*/
private function _info()
{
$model = array();
$percCharge = array();
$lines = explode(PHP_EOL, implode($this->_output));
$dev = new UPSDevice();
$model = explode('FW:', $lines[1]);
if (strpos($model[0], 'InternalBattery') === false) {
$percCharge = explode(';', $lines[1]);
$dev->setName('UPS');
if ($model !== false) {
$dev->setModel(substr(trim($model[0]), 1));
}
if ($percCharge !== false) {
$dev->setBatterCharge(trim(substr($percCharge[0], -4, 3)));
$dev->setStatus(trim($percCharge[1]));
if (isset($percCharge[2])) {
$time = explode(':', $percCharge[2]);
$hours = $time[0];
$minutes = $hours*60+substr($time[1], 0, 2);
$dev->setTimeLeft($minutes);
}
}
$this->upsinfo->setUpsDevices($dev);
}
}
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* PowerSoftPlus class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version SVN: $Id: class.powersoftplus.inc.php 661 2014-06-13 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* getting ups information from powersoftplus program
*
* @category PHP
* @package PSI_UPS
* @author Mieczyslaw Nalewaj <namiltd@users.sourceforge.net>
* @copyright 2014 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @version Release: 3.0
* @link http://phpsysinfo.sourceforge.net
*/
class PowerSoftPlus extends UPS
{
/**
* internal storage for all gathered data
*
* @var Array
*/
private $_output = array();
/**
* get all information from all configured ups in phpsysinfo.ini and store output in internal array
*/
public function __construct()
{
parent::__construct();
CommonFunctions::executeProgram('powersoftplus', '-p', $temp);
if (! empty($temp)) {
$this->_output[] = $temp;
}
}
/**
* parse the input and store data in resultset for xml generation
*
* @return Void
*/
private function _info()
{
foreach ($this->_output as $ups) {
$dev = new UPSDevice();
// General info
$dev->setName("EVER");
$dev->setMode("PowerSoftPlus");
$maxpwr = 0;
$load = null;
if (preg_match('/^Identifier: UPS Model\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setModel(trim($data[1]));
if (preg_match('/\s(\d*)[^\d]*$/', trim($data[1]), $number)) {
$maxpwr=$number[1]*0.65;
}
}
if (preg_match('/^Current UPS state\s*:\s*(.*)$/m', $ups, $data)) {
$dev->setStatus(trim($data[1]));
}
if (preg_match('/^Output load\s*:\s*(.*)\s\[\%\]$/m', $ups, $data)) {
$load = trim($data[1]);
}
//wrong Output load issue
if (($load == 0) && ($maxpwr != 0) && preg_match('/^Effective power\s*:\s*(.*)\s\[W\]$/m', $ups, $data)) {
$load = 100.0*trim($data[1])/$maxpwr;
}
if ($load != null) {
$dev->setLoad($load);
}
// Battery
if (preg_match('/^Battery voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
$dev->setBatteryVoltage(trim($data[1]));
}
if (preg_match('/^Battery state\s*:\s*(.*)$/m', $ups, $data)) {
if (preg_match('/^At full capacity$/', trim($data[1]))) {
$dev->setBatterCharge(100);
} elseif (preg_match('/^(Discharged)|(Depleted)$/', trim($data[1]))) {
$dev->setBatterCharge(0);
}
}
// Line
if (preg_match('/^Input voltage\s*:\s*(.*)\s\[Volt\]$/m', $ups, $data)) {
$dev->setLineVoltage(trim($data[1]));
}
if (preg_match('/^Input frequency\s*:\s*(.*)\s\[Hz\]$/m', $ups, $data)) {
$dev->setLineFrequency(trim($data[1]));
}
$this->upsinfo->setUpsDevices($dev);
}
}
/**
* get the information
*
* @see PSI_Interface_UPS::build()
*
* @return Void
*/
public function build()
{
$this->_info();
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Basic UPS Class
*
* PHP version 5
*
* @category PHP
* @package PSI_UPS
* @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.ups.inc.php 661 2012-08-27 11:26:39Z namiltd $
* @link http://phpsysinfo.sourceforge.net
*/
/**
* Basic UPS functions for all UPS classes
*
* @category PHP
* @package PSI_UPS
* @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 UPS implements PSI_Interface_UPS
{
/**
* object for error handling
*
* @var Error
*/
protected $error;
/**
* main object for ups information
*
* @var UPSInfo
*/
protected $upsinfo;
/**
* build the global Error object
*/
public function __construct()
{
$this->error = Error::singleton();
$this->upsinfo = new UPSInfo();
}
/**
* build and return the ups information
*
* @see PSI_Interface_UPS::getUPSInfo()
*
* @return UPSInfo
*/
final public function getUPSInfo()
{
$this->build();
return $this->upsinfo;
}
}