예제 #1
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     $buffer = "";
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_DMRAID_ACCESS)) {
         case 'command':
             if (PSI_OS == 'FreeBSD') {
                 CommonFunctions::executeProgram("graid", "list", $buffer);
             } else {
                 CommonFunctions::executeProgram("dmraid", "-s -vv 2>&1", $buffer);
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/dmraid.txt", $buffer);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_DMRAID_ACCESS");
             break;
     }
     if (trim($buffer) != "") {
         if (PSI_OS == 'FreeBSD') {
             $this->_filecontent = preg_split("/Consumers:\r?\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
         } else {
             $this->_filecontent = preg_split("/(\r?\n\\*\\*\\* )|(\r?\n--> )/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
         }
     } else {
         $this->_filecontent = array();
     }
 }
예제 #2
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     CommonFunctions::rfts(PSI_PLUGIN_UPDATENOTIFIER_FILE, $buffer_info);
     // Remove blank lines
     $this->_filecontent = preg_split("/\n/", $buffer_info, -1, PREG_SPLIT_NO_EMPTY);
 }
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_UPDATENOTIFIER_ACCESS)) {
         case 'command':
             if (PSI_PLUGIN_UPDATENOTIFIER_UBUNTU_LANDSCAPE_FORMAT === true) {
                 CommonFunctions::executeProgram("/usr/lib/update-notifier/apt-check", "--human-readable", $buffer_info);
             } else {
                 CommonFunctions::executeProgram("/usr/lib/update-notifier/apt-check", "2>&1", $buffer_info);
             }
             break;
         case 'data':
             if (defined('PSI_PLUGIN_UPDATENOTIFIER_FILE') && is_string(PSI_PLUGIN_UPDATENOTIFIER_FILE)) {
                 CommonFunctions::rfts(PSI_PLUGIN_UPDATENOTIFIER_FILE, $buffer_info);
             } else {
                 CommonFunctions::rfts("/var/lib/update-notifier/updates-available", $buffer_info);
             }
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_UPDATENOTIFIER_ACCESS");
             break;
     }
     // Remove blank lines
     $this->_filecontent = preg_split("/\r?\n/", $buffer_info, -1, PREG_SPLIT_NO_EMPTY);
 }
예제 #4
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
         case 'command':
             if (PSI_OS == 'WINNT') {
                 try {
                     $objLocator = new COM("WbemScripting.SWbemLocator");
                     $wmi = $objLocator->ConnectServer();
                     $os_wmi = $wmi->InstancesOf('Win32_OperatingSystem');
                     foreach ($os_wmi as $os) {
                         $memtotal = $os->TotalVisibleMemorySize * 1024;
                     }
                     $process_wmi = $wmi->InstancesOf('Win32_Process');
                     foreach ($process_wmi as $process) {
                         if (strlen(trim($process->CommandLine)) > 0) {
                             $ps = trim($process->CommandLine);
                         } else {
                             $ps = trim($process->Caption);
                         }
                         if (trim($process->ProcessId) != 0) {
                             $memusage = round(trim($process->WorkingSetSize) * 100 / $memtotal, 1);
                             //ParentProcessId
                             //Unique identifier of the process that creates a process. Process identifier numbers are reused, so they
                             //only identify a process for the lifetime of that process. It is possible that the process identified by
                             //ParentProcessId is terminated, so ParentProcessId may not refer to a running process. It is also
                             //possible that ParentProcessId incorrectly refers to a process that reuses a process identifier. You can
                             //use the CreationDate property to determine whether the specified parent was created after the process
                             //represented by this Win32_Process instance was created.
                             //=> subtrees of processes may be missing (WHAT TODO?!?)
                             $this->_filecontent[] = trim($process->ProcessId) . " " . trim($process->ParentProcessId) . " " . $memusage . " " . $ps;
                         }
                     }
                 } catch (Exception $e) {
                 }
             } else {
                 CommonFunctions::executeProgram("ps", "axo pid,ppid,pmem,args", $buffer, PSI_DEBUG);
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/ps.txt", $buffer);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_PS_ACCESS");
             break;
     }
     if (PSI_OS != 'WINNT') {
         if (trim($buffer) != "") {
             $this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
             unset($this->_filecontent[0]);
         } else {
             $this->_filecontent = array();
         }
     }
 }
예제 #5
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc target encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_PSSTATUS_ACCESS)) {
         case 'command':
             if (PSI_OS == 'WINNT') {
                 try {
                     $objLocator = new COM('WbemScripting.SWbemLocator');
                     $wmi = $objLocator->ConnectServer('', 'root\\CIMv2');
                     $process_wmi = CommonFunctions::getWMI($wmi, 'Win32_Process', array('Caption', 'ProcessId'));
                     foreach ($process_wmi as $process) {
                         $this->_filecontent[] = array(strtolower(trim($process['Caption'])), trim($process['ProcessId']));
                     }
                 } catch (Exception $e) {
                 }
             } else {
                 if (defined('PSI_PLUGIN_PSSTATUS_PROCESSES') && is_string(PSI_PLUGIN_PSSTATUS_PROCESSES)) {
                     if (preg_match(ARRAY_EXP, PSI_PLUGIN_PSSTATUS_PROCESSES)) {
                         $processes = eval(PSI_PLUGIN_PSSTATUS_PROCESSES);
                     } else {
                         $processes = array(PSI_PLUGIN_PSSTATUS_PROCESSES);
                     }
                     if (defined('PSI_PLUGIN_PSSTATUS_USE_REGEX') && PSI_PLUGIN_PSSTATUS_USE_REGEX === true) {
                         foreach ($processes as $process) {
                             CommonFunctions::executeProgram("pgrep", "-n -x " . $process, $buffer, PSI_DEBUG);
                             if (strlen($buffer) > 0) {
                                 $this->_filecontent[] = array($process, $buffer);
                             }
                         }
                     } else {
                         foreach ($processes as $process) {
                             CommonFunctions::executeProgram("pidof", "-s " . $process, $buffer, PSI_DEBUG);
                             if (strlen($buffer) > 0) {
                                 $this->_filecontent[] = array($process, $buffer);
                             }
                         }
                     }
                 }
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/psstatus.txt", $buffer);
             $processes = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($processes as $process) {
                 $ps = preg_split("/[\\s]?\\|[\\s]?/", $process, -1, PREG_SPLIT_NO_EMPTY);
                 if (count($ps) == 2) {
                     $this->_filecontent[] = array(trim($ps[0]), trim($ps[1]));
                 }
             }
             break;
         default:
             $this->global_error->addError("switch(PSI_PLUGIN_PSSTATUS_ACCESS)", "Bad psstatus configuration in phpsysinfo.ini");
             break;
     }
 }
예제 #6
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc target encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (PSI_PLUGIN_SMART_ACCESS) {
         case 'command':
             $disks = preg_split('/([\\s]+)?,([\\s]+)?/', PSI_PLUGIN_SMART_DEVICES, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($disks as $disk) {
                 $buffer = "";
                 if (CommonFunctions::executeProgram('smartctl', '--all' . (PSI_PLUGIN_SMART_DEVICE ? ' --device ' . PSI_PLUGIN_SMART_DEVICE : '') . ' ' . $disk, $buffer, PSI_DEBUG)) {
                     $this->_filecontent[$disk] = $buffer;
                 }
             }
             $fullIds = preg_split('/([\\s]+)?,([\\s]+)?/', PSI_PLUGIN_SMART_IDS, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($fullIds as $fullId) {
                 $arrFullId = preg_split('/-/', $fullId);
                 $this->_ids[intval($arrFullId[0])] = strtolower($arrFullId[1]);
                 if (!empty($arrFullId[2])) {
                     $this->_ids[intval($arrFullId[2])] = "#replace-" . intval($arrFullId[0]);
                 }
             }
             break;
         case 'data':
             $disks = preg_split('/([\\s]+)?,([\\s]+)?/', PSI_PLUGIN_SMART_DEVICES, -1, PREG_SPLIT_NO_EMPTY);
             $dn = 0;
             foreach ($disks as $disk) {
                 $buffer = "";
                 if (CommonFunctions::rfts(APP_ROOT . "/data/SMART{$dn}.txt", $buffer) && !empty($buffer)) {
                     $this->_filecontent[$disk] = $buffer;
                 }
                 $dn++;
             }
             $fullIds = preg_split('/([\\s]+)?,([\\s]+)?/', PSI_PLUGIN_SMART_IDS, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($fullIds as $fullId) {
                 $arrFullId = preg_split('/-/', $fullId);
                 $this->_ids[intval($arrFullId[0])] = strtolower($arrFullId[1]);
                 if (!empty($arrFullId[2])) {
                     $this->_ids[intval($arrFullId[2])] = "#replace-" . intval($arrFullId[0]);
                 }
             }
             break;
         default:
             $this->global_error->addError("switch(PSI_PLUGIN_SMART_ACCESS)", "Bad SMART configuration in SMART.config.php");
             break;
     }
 }
예제 #7
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (PSI_PLUGIN_BAT_ACCESS) {
         case 'command':
             CommonFunctions::rfts('/proc/acpi/battery/' . PSI_PLUGIN_BAT_DEVICE . '/info', $buffer_info);
             CommonFunctions::rfts('/proc/acpi/battery/' . PSI_PLUGIN_BAT_DEVICE . '/state', $buffer_state);
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/bat_info.txt", $buffer_info);
             CommonFunctions::rfts(APP_ROOT . "/data/bat_state.txt", $buffer_state);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_BAT_ACCESS");
             break;
     }
     $this->_filecontent['info'] = preg_split("/\n/", $buffer_info, -1, PREG_SPLIT_NO_EMPTY);
     $this->_filecontent['state'] = preg_split("/\n/", $buffer_state, -1, PREG_SPLIT_NO_EMPTY);
 }
예제 #8
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     $buffer = "";
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_MDSTATUS_ACCESS)) {
         case 'file':
             CommonFunctions::rfts("/proc/mdstat", $buffer);
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/mdstat.txt", $buffer);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_MDSTATUS_ACCESS");
             break;
     }
     if (trim($buffer) != "") {
         $this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
     } else {
         $this->_filecontent = array();
     }
 }
예제 #9
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc target encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (PSI_PLUGIN_QUOTAS_ACCESS) {
         case 'command':
             CommonFunctions::executeProgram("repquota", "-au", $buffer, PSI_DEBUG);
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/quotas.txt", $buffer);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_QUOTAS_ACCESS");
             break;
     }
     if (trim($buffer) != "") {
         $this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
         unset($this->_filecontent[0]);
     } else {
         $this->_filecontent = array();
     }
 }
예제 #10
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc target encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (PSI_PLUGIN_PSSTATUS_ACCESS) {
         case 'command':
             if (PHP_OS == 'WINNT') {
                 $objLocator = new COM("WbemScripting.SWbemLocator");
                 $wmi = $objLocator->ConnectServer();
                 $process_wmi = $wmi->InstancesOf('Win32_Process');
                 foreach ($process_wmi as $process) {
                     $this->_filecontent[] = array(trim($process->Caption), trim($process->ProcessId));
                 }
             } else {
                 $processes = preg_split("/([\\s]+)?,([\\s]+)?/", PSI_PLUGIN_PSSTATUS_PROCESSES, -1, PREG_SPLIT_NO_EMPTY);
                 foreach ($processes as $process) {
                     CommonFunctions::executeProgram("pidof", "-s " . $process, $buffer, PSI_DEBUG);
                     if (strlen(trim($buffer)) > 0) {
                         $this->_filecontent[] = array($process, trim($buffer));
                     }
                 }
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/psstatus.txt", $buffer);
             $processes = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($processes as $process) {
                 $ps = preg_split("/[\\s]?\\|[\\s]?/", $process, -1, PREG_SPLIT_NO_EMPTY);
                 if (count($ps) == 2) {
                     $this->_filecontent[] = array(trim($ps[0]), trim($ps[1]));
                 }
             }
             break;
         default:
             $this->global_error->addError("switch(PSI_PLUGIN_PSSTATUS_ACCESS)", "Bad psstatus configuration in psstatus.config.php");
             break;
     }
 }
예제 #11
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (PSI_PLUGIN_SNMPPINFO_ACCESS) {
         case 'command':
             $printers = preg_split('/([\\s]+)?,([\\s]+)?/', PSI_PLUGIN_SNMPPINFO_DEVICES, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($printers as $printer) {
                 CommonFunctions::executeProgram("snmpwalk", "-On -c public -v 1 " . $printer . " 1.3.6.1.2.1.1.5", $buffer, PSI_DEBUG);
                 if (strlen(trim($buffer)) > 0) {
                     $this->_filecontent[$printer] = $buffer;
                     CommonFunctions::executeProgram("snmpwalk", "-On -c public -v 1 " . $printer . " 1.3.6.1.2.1.43.11.1.1", $buffer2, PSI_DEBUG);
                     if (strlen(trim($buffer2)) > 0) {
                         $this->_filecontent[$printer] = $buffer . "\n" . $buffer2;
                     } else {
                         $this->_filecontent[$printer] = $buffer;
                     }
                 }
             }
             break;
         case 'php-snmp':
             snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
             snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
             $printers = preg_split('/([\\s]+)?,([\\s]+)?/', PSI_PLUGIN_SNMPPINFO_DEVICES, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($printers as $printer) {
                 if (!PSI_DEBUG) {
                     restore_error_handler();
                 }
                 $bufferarr = snmprealwalk($printer, "public", "1.3.6.1.2.1.1.5");
                 if (!PSI_DEBUG) {
                     set_error_handler('errorHandlerPsi');
                 }
                 if (!empty($bufferarr)) {
                     $buffer = "";
                     foreach ($bufferarr as $id => $string) {
                         $buffer = $buffer . $id . " = " . $string . "\n";
                     }
                     if (!PSI_DEBUG) {
                         restore_error_handler();
                     }
                     $bufferarr2 = snmprealwalk($printer, "public", "1.3.6.1.2.1.43.11.1.1");
                     if (!PSI_DEBUG) {
                         set_error_handler('errorHandlerPsi');
                     }
                     if (!empty($bufferarr2)) {
                         foreach ($bufferarr2 as $id => $string) {
                             $buffer = $buffer . $id . " = " . $string . "\n";
                         }
                     }
                     if (strlen(trim($buffer)) > 0) {
                         $this->_filecontent[$printer] = $buffer;
                     }
                 }
             }
             break;
         case 'data':
             $printers = preg_split('/([\\s]+)?,([\\s]+)?/', PSI_PLUGIN_SNMPPINFO_DEVICES, -1, PREG_SPLIT_NO_EMPTY);
             $pn = 0;
             foreach ($printers as $printer) {
                 $buffer = "";
                 if (CommonFunctions::rfts(APP_ROOT . "/data/SNMPPInfo{$pn}.txt", $buffer) && !empty($buffer)) {
                     $this->_filecontent[$printer] = $buffer;
                 }
                 $pn++;
             }
             break;
         default:
             $this->global_error->addError("switch(PSI_PLUGIN_SNMPPINFO_ACCESS)", "Bad SNMPPInfo configuration in SNMPPInfo.config.php");
             break;
     }
 }
예제 #12
0
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     $this->_lines = array();
 }
예제 #13
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_PS_ACCESS)) {
         case 'command':
             if (PSI_OS == 'WINNT') {
                 try {
                     $objLocator = new COM("WbemScripting.SWbemLocator");
                     $wmi = $objLocator->ConnectServer();
                     $os_wmi = $wmi->InstancesOf('Win32_OperatingSystem');
                     foreach ($os_wmi as $os) {
                         $memtotal = $os->TotalVisibleMemorySize * 1024;
                     }
                     $process_wmi = $wmi->InstancesOf('Win32_Process');
                     foreach ($process_wmi as $process) {
                         if (strlen(trim($process->CommandLine)) > 0) {
                             $ps = trim($process->CommandLine);
                         } else {
                             $ps = trim($process->Caption);
                         }
                         if (trim($process->ProcessId) != 0) {
                             $memusage = round(trim($process->WorkingSetSize) * 100 / $memtotal, 1);
                             //ParentProcessId
                             //Unique identifier of the process that creates a process. Process identifier numbers are reused, so they
                             //only identify a process for the lifetime of that process. It is possible that the process identified by
                             //ParentProcessId is terminated, so ParentProcessId may not refer to a running process. It is also
                             //possible that ParentProcessId incorrectly refers to a process that reuses a process identifier. You can
                             //use the CreationDate property to determine whether the specified parent was created after the process
                             //represented by this Win32_Process instance was created.
                             //=> subtrees of processes may be missing (WHAT TODO?!?)
                             $this->_filecontent[] = trim($process->ProcessId) . " " . trim($process->ParentProcessId) . " " . $memusage . " " . $ps;
                         }
                     }
                 } catch (Exception $e) {
                 }
             } else {
                 CommonFunctions::executeProgram("ps", "axo pid,ppid,pmem,args", $buffer, PSI_DEBUG);
                 if ((PSI_OS == 'Linux' || PSI_OS == 'Android') && !preg_match("/^[^\n]+\n.+/", $buffer)) {
                     //alternative method if no data
                     if (CommonFunctions::rfts('/proc/meminfo', $mbuf)) {
                         $bufe = preg_split("/\n/", $mbuf, -1, PREG_SPLIT_NO_EMPTY);
                         $totalmem = 0;
                         foreach ($bufe as $buf) {
                             if (preg_match('/^MemTotal:\\s+(.*)\\s*kB/i', $buf, $ar_buf)) {
                                 $totalmem = $ar_buf[1];
                                 break;
                             }
                         }
                         $buffer = "  PID  PPID %MEM COMMAND\n";
                         $processlist = glob('/proc/*/status', GLOB_NOSORT);
                         if (($total = count($processlist)) > 0) {
                             natsort($processlist);
                             //first sort
                             $prosess = array();
                             foreach ($processlist as $processitem) {
                                 //second sort
                                 $process[] = $processitem;
                             }
                             $buf = "";
                             for ($i = 0; $i < $total; $i++) {
                                 if (CommonFunctions::rfts($process[$i], $buf, 0, 4096, false)) {
                                     if ($totalmem != 0 && preg_match('/^VmRSS:\\s+(\\d+)\\s+kB/m', $buf, $tmppmem)) {
                                         $pmem = round(100 * $tmppmem[1] / $totalmem, 1);
                                     } else {
                                         $pmem = 0;
                                     }
                                     $name = null;
                                     if (CommonFunctions::rfts(substr($process[$i], 0, strlen($process[$i]) - 6) . "cmdline", $namebuf, 0, 4096, false)) {
                                         $name = str_replace(chr(0), ' ', trim($namebuf));
                                     }
                                     if (preg_match('/^Pid:\\s+(\\d+)/m', $buf, $tmppid) && preg_match('/^PPid:\\s+(\\d+)/m', $buf, $tmpppid) && preg_match('/^Name:\\s+(.+)/m', $buf, $tmpargs)) {
                                         $pid = $tmppid[1];
                                         $ppid = $tmpppid[1];
                                         $args = $tmpargs[1];
                                         if ($name !== null) {
                                             if ($name !== "") {
                                                 $args = $name;
                                             } else {
                                                 $args = "[" . $args . "]";
                                             }
                                         }
                                         $buffer .= $pid . " " . $ppid . " " . $pmem . " " . $args . "\n";
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/ps.txt", $buffer);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_PS_ACCESS");
             break;
     }
     if (PSI_OS != 'WINNT') {
         if (trim($buffer) != "") {
             $this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
             unset($this->_filecontent[0]);
         } else {
             $this->_filecontent = array();
         }
     }
 }
예제 #14
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_SNMPPINFO_ACCESS)) {
         case 'command':
             if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                 if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                     $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 } else {
                     $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 }
                 foreach ($printers as $printer) {
                     CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 " . $printer . " .1.3.6.1.2.1.1.5", $buffer, PSI_DEBUG);
                     if (strlen(trim($buffer)) > 0) {
                         $this->_filecontent[$printer] = $buffer;
                         CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 " . $printer . " .1.3.6.1.2.1.43.11.1.1", $buffer2, PSI_DEBUG);
                         if (strlen(trim($buffer2)) > 0) {
                             $this->_filecontent[$printer] = $this->_filecontent[$printer] . "\n" . $buffer2;
                         }
                         CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 " . $printer . " .1.3.6.1.2.1.43.18.1.1", $buffer3, PSI_DEBUG);
                         if (strlen(trim($buffer3)) > 0) {
                             $this->_filecontent[$printer] = $this->_filecontent[$printer] . "\n" . $buffer3;
                         }
                     }
                 }
             }
             break;
         case 'php-snmp':
             snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
             snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
             if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                 if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                     $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 } else {
                     $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 }
                 foreach ($printers as $printer) {
                     if (!PSI_DEBUG) {
                         restore_error_handler();
                         /* default error handler */
                         $old_err_rep = error_reporting();
                         error_reporting(E_ERROR);
                         /* fatal errors only */
                     }
                     $bufferarr = snmprealwalk($printer, "public", ".1.3.6.1.2.1.1.5", 1000000, 1);
                     if (!PSI_DEBUG) {
                         error_reporting($old_err_rep);
                         /* restore error level */
                         set_error_handler('errorHandlerPsi');
                         /* restore error handler */
                     }
                     if (!empty($bufferarr)) {
                         $buffer = "";
                         foreach ($bufferarr as $id => $string) {
                             $buffer = $buffer . $id . " = " . $string . "\n";
                         }
                         if (!PSI_DEBUG) {
                             restore_error_handler();
                             /* default error handler */
                             $old_err_rep = error_reporting();
                             error_reporting(E_ERROR);
                             /* fatal errors only */
                         }
                         $bufferarr2 = snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.11.1.1", 1000000, 1);
                         if (!PSI_DEBUG) {
                             error_reporting($old_err_rep);
                             /* restore error level */
                             set_error_handler('errorHandlerPsi');
                             /* restore error handler */
                         }
                         if (!empty($bufferarr2)) {
                             foreach ($bufferarr2 as $id => $string) {
                                 $buffer = $buffer . $id . " = " . $string . "\n";
                             }
                         }
                         if (!PSI_DEBUG) {
                             restore_error_handler();
                             /* default error handler */
                             $old_err_rep = error_reporting();
                             error_reporting(E_ERROR);
                             /* fatal errors only */
                         }
                         $bufferarr3 = snmprealwalk($printer, "public", ".1.3.6.1.2.1.43.18.1.1", 1000000, 1);
                         if (!PSI_DEBUG) {
                             error_reporting($old_err_rep);
                             /* restore error level */
                             set_error_handler('errorHandlerPsi');
                             /* restore error handler */
                         }
                         if (!empty($bufferarr3)) {
                             foreach ($bufferarr3 as $id => $string) {
                                 $buffer = $buffer . $id . " = " . $string . "\n";
                             }
                         }
                         if (strlen(trim($buffer)) > 0) {
                             $this->_filecontent[$printer] = $buffer;
                         }
                     }
                 }
             }
             break;
         case 'data':
             if (defined('PSI_PLUGIN_SNMPPINFO_DEVICES') && is_string(PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                 if (preg_match(ARRAY_EXP, PSI_PLUGIN_SNMPPINFO_DEVICES)) {
                     $printers = eval(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 } else {
                     $printers = array(PSI_PLUGIN_SNMPPINFO_DEVICES);
                 }
                 $pn = 0;
                 foreach ($printers as $printer) {
                     $buffer = "";
                     if (CommonFunctions::rfts(APP_ROOT . "/data/snmppinfo{$pn}.txt", $buffer) && !empty($buffer)) {
                         $this->_filecontent[$printer] = $buffer;
                     }
                     $pn++;
                 }
             }
             break;
         default:
             $this->global_error->addError("switch(PSI_PLUGIN_SNMPPINFO_ACCESS)", "Bad SNMPPInfo configuration in SNMPPInfo.config.php");
             break;
     }
 }
예제 #15
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_BAT_ACCESS)) {
         case 'command':
             if (PSI_OS == 'Android') {
                 CommonFunctions::rfts('/sys/class/power_supply/battery/uevent', $buffer_info, 0, 4096, PSI_DEBUG);
                 $buffer_state = '';
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/capacity', $buffer1, 1, 4096, false)) {
                     $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $buffer1;
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/batt_temp', $buffer1, 1, 4096, false)) {
                     $buffer_state .= 'POWER_SUPPLY_TEMP=' . $buffer1;
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/batt_vol', $buffer1, 1, 4096, false)) {
                     if ($buffer1 < 100000) {
                         // uV or mV detection
                         $buffer1 = $buffer1 * 1000;
                     }
                     $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1 . "\n";
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/voltage_max_design', $buffer1, 1, 4096, false)) {
                     if ($buffer1 < 100000) {
                         // uV or mV detection
                         $buffer1 = $buffer1 * 1000;
                     }
                     $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MAX_DESIGN=' . $buffer1 . "\n";
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/technology', $buffer1, 1, 4096, false)) {
                     $buffer_state .= 'POWER_SUPPLY_TECHNOLOGY=' . $buffer1;
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/status', $buffer1, 1, 4096, false)) {
                     $buffer_state .= 'POWER_SUPPLY_STATUS=' . $buffer1;
                 }
                 if (CommonFunctions::rfts('/sys/class/power_supply/battery/health', $buffer1, 1, 4096, false)) {
                     $buffer_state .= 'POWER_SUPPLY_HEALTH=' . $buffer1;
                 }
             } elseif (PSI_OS == 'WINNT') {
                 // don't set this params for local connection, it will not work
                 $strHostname = '';
                 $strUser = '';
                 $strPassword = '';
                 try {
                     // initialize the wmi object
                     $objLocator = new COM('WbemScripting.SWbemLocator');
                     if ($strHostname == "") {
                         $this->_wmi = $objLocator->ConnectServer();
                     } else {
                         $this->_wmi = $objLocator->ConnectServer($strHostname, 'rootcimv2', $strHostname . '\\' . $strUser, $strPassword);
                     }
                 } catch (Exception $e) {
                     $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
                 }
                 $buffer_info = '';
                 $buffer_state = '';
                 $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Battery', array('EstimatedChargeRemaining', 'DesignVoltage', 'BatteryStatus', 'Chemistry'));
                 $capacity = '';
                 if (isset($buffer[0]['EstimatedChargeRemaining'])) {
                     $capacity = $buffer[0]['EstimatedChargeRemaining'];
                 }
                 if (isset($buffer[0]['DesignVoltage'])) {
                     $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . 1000 * $buffer[0]['DesignVoltage'] . "\n";
                 }
                 if (isset($buffer[0]['BatteryStatus'])) {
                     switch ($buffer[0]['BatteryStatus']) {
                         case 1:
                             $batstat = 'Discharging';
                             break;
                         case 2:
                             $batstat = 'AC connected';
                             break;
                         case 3:
                             $batstat = 'Fully Charged';
                             break;
                         case 4:
                             $batstat = 'Low';
                             break;
                         case 5:
                             $batstat = 'Critical';
                             break;
                         case 6:
                             $batstat = 'Charging';
                             break;
                         case 7:
                             $batstat = 'Charging and High';
                             break;
                         case 8:
                             $batstat = 'Charging and Low';
                             break;
                         case 9:
                             $batstat = 'Charging and Critical';
                             break;
                         case 10:
                             $batstat = 'Undefined';
                             break;
                         case 11:
                             $batstat = 'Partially Charged';
                             break;
                         default:
                             $batstat = '';
                     }
                     if ($batstat != '') {
                         $buffer_state .= 'POWER_SUPPLY_STATUS=' . $batstat . "\n";
                     }
                 }
                 $techn = '';
                 if (isset($buffer[0]['Chemistry'])) {
                     switch ($buffer[0]['Chemistry']) {
                         case 1:
                             $techn = 'Other';
                             break;
                         case 2:
                             $techn = 'Unknown';
                             break;
                         case 3:
                             $techn = 'PbAc';
                             break;
                         case 4:
                             $techn = 'NiCd';
                             break;
                         case 5:
                             $techn = 'NiMH';
                             break;
                         case 6:
                             $techn = 'Li-ion';
                             break;
                         case 7:
                             $techn = 'Zinc-air';
                             break;
                         case 8:
                             $techn = 'Li-poly';
                             break;
                     }
                 }
                 $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PortableBattery', array('DesignVoltage', 'Chemistry', 'DesignCapacity'));
                 if (isset($buffer[0]['DesignVoltage'])) {
                     $buffer_info .= 'POWER_SUPPLY_VOLTAGE_MAX_DESIGN=' . 1000 * $buffer[0]['DesignVoltage'] . "\n";
                 }
                 // sometimes Chemistry from Win32_Battery returns 2 but Win32_PortableBattery returns e.g. 6
                 if (($techn == '' || $techn == 'Unknown') && isset($buffer[0]['Chemistry'])) {
                     switch ($buffer[0]['Chemistry']) {
                         case 1:
                             $techn = 'Other';
                             break;
                         case 2:
                             $techn = 'Unknown';
                             break;
                         case 3:
                             $techn = 'PbAc';
                             break;
                         case 4:
                             $techn = 'NiCd';
                             break;
                         case 5:
                             $techn = 'NiMH';
                             break;
                         case 6:
                             $techn = 'Li-ion';
                             break;
                         case 7:
                             $techn = 'Zinc-air';
                             break;
                         case 8:
                             $techn = 'Li-poly';
                             break;
                     }
                 }
                 if ($techn != '') {
                     $buffer_info .= 'POWER_SUPPLY_TECHNOLOGY=' . $techn . "\n";
                 }
                 if (isset($buffer[0]['DesignCapacity'])) {
                     $buffer_info .= 'design capacity:' . $buffer[0]['DesignCapacity'];
                     if ($capacity != '') {
                         $buffer_state .= 'remaining capacity:' . round($capacity * $buffer[0]['DesignCapacity'] / 100);
                     }
                 } else {
                     if ($capacity != '') {
                         $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $capacity . "\n";
                     }
                 }
             } else {
                 $rfts_bi = CommonFunctions::rfts('/proc/acpi/battery/' . PSI_PLUGIN_BAT_DEVICE . '/info', $buffer_info, 0, 4096, false);
                 $rfts_bs = CommonFunctions::rfts('/proc/acpi/battery/' . PSI_PLUGIN_BAT_DEVICE . '/state', $buffer_state, 0, 4096, false);
                 if (!$rfts_bi && !$rfts_bs) {
                     CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/uevent', $buffer_info, 0, 4096, PSI_DEBUG);
                     $buffer_state = '';
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/voltage_min_design', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/voltage_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/energy_full', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_FULL=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/energy_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/charge_full', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_FULL=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/charge_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/capacity', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/technology', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_TECHNOLOGY=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . PSI_PLUGIN_BAT_DEVICE . '/status', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_STATUS=' . $buffer1;
                     }
                 }
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/bat_info.txt", $buffer_info);
             CommonFunctions::rfts(APP_ROOT . "/data/bat_state.txt", $buffer_state);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_BAT_ACCESS");
             break;
     }
     $this->_filecontent['info'] = preg_split("/\n/", $buffer_info, -1, PREG_SPLIT_NO_EMPTY);
     $this->_filecontent['state'] = preg_split("/\n/", $buffer_state, -1, PREG_SPLIT_NO_EMPTY);
 }
예제 #16
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_BAT_ACCESS)) {
         case 'command':
             if (PSI_OS == 'WINNT') {
                 $_cim = null;
                 //root\CIMv2
                 $_wmi = null;
                 //root\WMI
                 // don't set this params for local connection, it will not work
                 $strHostname = '';
                 $strUser = '';
                 $strPassword = '';
                 try {
                     // initialize the wmi object
                     $objLocatorCIM = new COM('WbemScripting.SWbemLocator');
                     if ($strHostname == "") {
                         $_cim = $objLocatorCIM->ConnectServer();
                     } else {
                         $_cim = $objLocatorCIM->ConnectServer($strHostname, 'root\\CIMv2', $strHostname . '\\' . $strUser, $strPassword);
                     }
                     // initialize the wmi object
                     $objLocatorWMI = new COM('WbemScripting.SWbemLocator');
                     if ($strHostname == "") {
                         $_wmi = $objLocatorWMI->ConnectServer($strHostname, 'root\\WMI');
                     } else {
                         $_wmi = $objLocatorWMI->ConnectServer($strHostname, 'root\\WMI', $strHostname . '\\' . $strUser, $strPassword);
                     }
                 } catch (Exception $e) {
                     $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
                 }
                 $buffer_info = '';
                 $buffer_state = '';
                 $bufferWB = CommonFunctions::getWMI($_cim, 'Win32_Battery', array('EstimatedChargeRemaining', 'DesignVoltage', 'BatteryStatus', 'Chemistry'));
                 if (sizeof($bufferWB) > 0) {
                     $capacity = '';
                     if (isset($bufferWB[0]['EstimatedChargeRemaining'])) {
                         $capacity = $bufferWB[0]['EstimatedChargeRemaining'];
                     }
                     if (isset($bufferWB[0]['BatteryStatus'])) {
                         switch ($bufferWB[0]['BatteryStatus']) {
                             case 1:
                                 $batstat = 'Discharging';
                                 break;
                             case 2:
                                 $batstat = 'AC connected';
                                 break;
                             case 3:
                                 $batstat = 'Fully Charged';
                                 break;
                             case 4:
                                 $batstat = 'Low';
                                 break;
                             case 5:
                                 $batstat = 'Critical';
                                 break;
                             case 6:
                                 $batstat = 'Charging';
                                 break;
                             case 7:
                                 $batstat = 'Charging and High';
                                 break;
                             case 8:
                                 $batstat = 'Charging and Low';
                                 break;
                             case 9:
                                 $batstat = 'Charging and Critical';
                                 break;
                             case 10:
                                 $batstat = 'Undefined';
                                 break;
                             case 11:
                                 $batstat = 'Partially Charged';
                                 break;
                             default:
                                 $batstat = '';
                         }
                         if ($batstat != '') {
                             $buffer_state .= 'POWER_SUPPLY_STATUS=' . $batstat . "\n";
                         }
                     }
                     $techn = '';
                     if (isset($bufferWB[0]['Chemistry'])) {
                         switch ($bufferWB[0]['Chemistry']) {
                             case 1:
                                 $techn = 'Other';
                                 break;
                             case 2:
                                 $techn = 'Unknown';
                                 break;
                             case 3:
                                 $techn = 'PbAc';
                                 break;
                             case 4:
                                 $techn = 'NiCd';
                                 break;
                             case 5:
                                 $techn = 'NiMH';
                                 break;
                             case 6:
                                 $techn = 'Li-ion';
                                 break;
                             case 7:
                                 $techn = 'Zinc-air';
                                 break;
                             case 8:
                                 $techn = 'Li-poly';
                                 break;
                         }
                     }
                     $bufferWPB = CommonFunctions::getWMI($_cim, 'Win32_PortableBattery', array('DesignVoltage', 'Chemistry', 'DesignCapacity', 'FullChargeCapacity'));
                     if (isset($bufferWPB[0]['DesignVoltage'])) {
                         $buffer_info .= 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN=' . $bufferWPB[0]['DesignVoltage'] * 1000 . "\n";
                     }
                     // sometimes Chemistry from Win32_Battery returns 2 but Win32_PortableBattery returns e.g. 6
                     if (($techn == '' || $techn == 'Unknown') && isset($bufferWPB[0]['Chemistry'])) {
                         switch ($bufferWPB[0]['Chemistry']) {
                             case 1:
                                 $techn = 'Other';
                                 break;
                             case 2:
                                 $techn = 'Unknown';
                                 break;
                             case 3:
                                 $techn = 'PbAc';
                                 break;
                             case 4:
                                 $techn = 'NiCd';
                                 break;
                             case 5:
                                 $techn = 'NiMH';
                                 break;
                             case 6:
                                 $techn = 'Li-ion';
                                 break;
                             case 7:
                                 $techn = 'Zinc-air';
                                 break;
                             case 8:
                                 $techn = 'Li-poly';
                                 break;
                         }
                     }
                     if ($techn != '') {
                         $buffer_info .= 'POWER_SUPPLY_TECHNOLOGY=' . $techn . "\n";
                     }
                     $bufferBS = CommonFunctions::getWMI($_wmi, 'BatteryStatus', array('RemainingCapacity', 'Voltage'));
                     if (sizeof($bufferBS) > 0) {
                         if (isset($bufferBS[0]['RemainingCapacity']) && $bufferBS[0]['RemainingCapacity'] > 0) {
                             $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $bufferBS[0]['RemainingCapacity'] * 1000 . "\n";
                             $capacity = '';
                         }
                         if (isset($bufferBS[0]['Voltage']) && $bufferBS[0]['Voltage'] > 0) {
                             $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $bufferBS[0]['Voltage'] * 1000 . "\n";
                         } elseif (isset($bufferWB[0]['DesignVoltage'])) {
                             $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $bufferWB[0]['DesignVoltage'] * 1000 . "\n";
                         }
                     }
                     if (!isset($bufferWPB[0]['FullChargeCapacity'])) {
                         $bufferBFCC = CommonFunctions::getWMI($_wmi, 'BatteryFullChargedCapacity', array('FullChargedCapacity'));
                         if (sizeof($bufferBFCC) > 0 && isset($bufferBFCC[0]['FullChargedCapacity'])) {
                             $bufferWPB[0]['FullChargeCapacity'] = $bufferBFCC[0]['FullChargedCapacity'];
                         }
                     }
                     if (isset($bufferWPB[0]['FullChargeCapacity'])) {
                         $buffer_info .= 'POWER_SUPPLY_ENERGY_FULL=' . $bufferWPB[0]['FullChargeCapacity'] * 1000 . "\n";
                         if ($capacity != '') {
                             $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . (round($capacity * $bufferWPB[0]['FullChargeCapacity'] * 10) . "\n");
                         }
                         if (isset($bufferWPB[0]['DesignCapacity']) && $bufferWPB[0]['DesignCapacity'] != 0) {
                             $buffer_info .= 'POWER_SUPPLY_ENERGY_FULL_DESIGN=' . $bufferWPB[0]['DesignCapacity'] * 1000 . "\n";
                         }
                     } elseif (isset($bufferWPB[0]['DesignCapacity'])) {
                         $buffer_info .= 'POWER_SUPPLY_ENERGY_FULL_DESIGN=' . $bufferWPB[0]['DesignCapacity'] * 1000 . "\n";
                         if ($capacity != '') {
                             $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . (round($capacity * $bufferWPB[0]['DesignCapacity'] * 10) . "\n");
                         }
                     } else {
                         if ($capacity != '') {
                             $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $capacity . "\n";
                         }
                     }
                     $bufferBCC = CommonFunctions::getWMI($_wmi, 'BatteryCycleCount', array('CycleCount'));
                     if (sizeof($bufferBCC) > 0 && isset($bufferBCC[0]['CycleCount']) && $bufferBCC[0]['CycleCount'] > 0) {
                         $buffer_info .= 'POWER_SUPPLY_CYCLE_COUNT=' . $bufferBCC[0]['CycleCount'] . "\n";
                     }
                 }
             } elseif (PSI_OS == 'Darwin') {
                 $buffer_info = '';
                 $buffer_state = '';
                 CommonFunctions::executeProgram('ioreg', '-w0 -l -n AppleSmartBattery -r', $buffer_info, false);
             } elseif (PSI_OS == 'FreeBSD') {
                 $buffer_info = '';
                 $buffer_state = '';
                 CommonFunctions::executeProgram('acpiconf', '-i batt', $buffer_info, false);
             } else {
                 $buffer_info = '';
                 $buffer_state = '';
                 $bat_name = PSI_PLUGIN_BAT_DEVICE;
                 $rfts_bi = CommonFunctions::rfts('/proc/acpi/battery/' . $bat_name . '/info', $buffer_info, 0, 4096, false);
                 $rfts_bs = CommonFunctions::rfts('/proc/acpi/battery/' . $bat_name . '/state', $buffer_state, 0, 4096, false);
                 if (!$rfts_bi && !$rfts_bs) {
                     $buffer_info = '';
                     $buffer_state = '';
                     if (!CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/uevent', $buffer_info, 0, 4096, false)) {
                         if (CommonFunctions::rfts('/sys/class/power_supply/battery/uevent', $buffer_info, 0, 4096, false)) {
                             $bat_name = 'battery';
                         } else {
                             CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/uevent', $buffer_info, 0, 4096, PSI_DEBUG);
                             // Once again but with debug
                         }
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/voltage_min_design', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/voltage_max_design', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_MAX_DESIGN=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/voltage_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/energy_full', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_FULL=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/energy_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_ENERGY_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/charge_full', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_CHARGE_FULL=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/charge_now', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_CHARGE_NOW=' . $buffer1 . "\n";
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/capacity', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_CAPACITY=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/technology', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_TECHNOLOGY=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/status', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_STATUS=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/batt_temp', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_TEMP=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/batt_vol', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_VOLTAGE_NOW=' . $buffer1;
                     }
                     if (CommonFunctions::rfts('/sys/class/power_supply/' . $bat_name . '/health', $buffer1, 1, 4096, false)) {
                         $buffer_state .= 'POWER_SUPPLY_HEALTH=' . $buffer1;
                     }
                 }
             }
             break;
         case 'data':
             CommonFunctions::rfts(APP_ROOT . "/data/bat_info.txt", $buffer_info);
             CommonFunctions::rfts(APP_ROOT . "/data/bat_state.txt", $buffer_state);
             break;
         default:
             $this->global_error->addConfigError("__construct()", "PSI_PLUGIN_BAT_ACCESS");
             break;
     }
     $this->_filecontent['info'] = preg_split("/\n/", $buffer_info, -1, PREG_SPLIT_NO_EMPTY);
     $this->_filecontent['state'] = preg_split("/\n/", $buffer_state, -1, PREG_SPLIT_NO_EMPTY);
 }
예제 #17
0
 /**
  * read the data into an internal array and also call the parent constructor
  *
  * @param String $enc target encoding
  */
 public function __construct($enc)
 {
     parent::__construct(__CLASS__, $enc);
     switch (strtolower(PSI_PLUGIN_SMART_ACCESS)) {
         case 'command':
             if (defined('PSI_PLUGIN_SMART_DEVICES') && is_string(PSI_PLUGIN_SMART_DEVICES)) {
                 if (preg_match(ARRAY_EXP, PSI_PLUGIN_SMART_DEVICES)) {
                     $disks = eval(PSI_PLUGIN_SMART_DEVICES);
                 } else {
                     $disks = array(PSI_PLUGIN_SMART_DEVICES);
                 }
                 foreach ($disks as $disk) {
                     if (trim($disk) != "") {
                         $diskdev = "";
                         if (preg_match("/\\s*\\(([^\\(\\(]*)\\)\\s*(.*)/", $disk, $devdisk)) {
                             $diskname = trim($devdisk[2]);
                             if (trim($devdisk[1]) != "") {
                                 $diskdev = "--device " . preg_replace('/\\./', ',', trim($devdisk[1]));
                             }
                         } else {
                             $diskname = trim($disk);
                         }
                         $buffer = "";
                         if (trim($diskname != "") && CommonFunctions::executeProgram('smartctl', '--all' . ' ' . $diskdev . ' ' . $diskname, $buffer, PSI_DEBUG)) {
                             $this->_filecontent[trim($disk)] = $buffer;
                         }
                     }
                 }
             }
             if (defined('PSI_PLUGIN_SMART_IDS') && is_string(PSI_PLUGIN_SMART_IDS)) {
                 if (preg_match(ARRAY_EXP, PSI_PLUGIN_SMART_IDS)) {
                     $fullIds = eval(PSI_PLUGIN_SMART_IDS);
                 } else {
                     $fullIds = array(PSI_PLUGIN_SMART_IDS);
                 }
                 foreach ($fullIds as $fullId) {
                     $arrFullId = preg_split('/-/', $fullId);
                     $this->_ids[intval($arrFullId[0])] = strtolower($arrFullId[1]);
                     if (!empty($arrFullId[2])) {
                         $this->_ids[intval($arrFullId[2])] = "#replace-" . intval($arrFullId[0]);
                     }
                 }
             }
             break;
         case 'data':
             if (defined('PSI_PLUGIN_SMART_DEVICES') && is_string(PSI_PLUGIN_SMART_DEVICES)) {
                 if (preg_match(ARRAY_EXP, PSI_PLUGIN_SMART_DEVICES)) {
                     $disks = eval(PSI_PLUGIN_SMART_DEVICES);
                 } else {
                     $disks = array(PSI_PLUGIN_SMART_DEVICES);
                 }
                 $dn = 0;
                 foreach ($disks as $disk) {
                     $buffer = "";
                     if (CommonFunctions::rfts(APP_ROOT . "/data/smart{$dn}.txt", $buffer) && !empty($buffer)) {
                         $this->_filecontent[$disk] = $buffer;
                     }
                     $dn++;
                 }
             }
             if (defined('PSI_PLUGIN_SMART_IDS') && is_string(PSI_PLUGIN_SMART_IDS)) {
                 if (preg_match(ARRAY_EXP, PSI_PLUGIN_SMART_IDS)) {
                     $fullIds = eval(PSI_PLUGIN_SMART_IDS);
                 } else {
                     $fullIds = array(PSI_PLUGIN_SMART_IDS);
                 }
                 foreach ($fullIds as $fullId) {
                     $arrFullId = preg_split('/-/', $fullId);
                     $this->_ids[intval($arrFullId[0])] = strtolower($arrFullId[1]);
                     if (!empty($arrFullId[2])) {
                         $this->_ids[intval($arrFullId[2])] = "#replace-" . intval($arrFullId[0]);
                     }
                 }
             }
             break;
         default:
             $this->global_error->addError("switch(PSI_PLUGIN_SMART_ACCESS)", "Bad SMART configuration in SMART.config.php");
             break;
     }
 }