rfts() public static method

read a file and return the content as a string
public static rfts ( string $strFileName, &$strRet, integer $intLines, integer $intBytes = 4096, boolean $booErrorRep = true ) : boolean
$strFileName string name of the file which should be read
$intLines integer control how many lines should be read
$intBytes integer control how many bytes of each line should be read
$booErrorRep boolean en- or disables the reporting of errors which should be logged
return boolean command successfull or not
Ejemplo n.º 1
0
 public function __construct()
 {
     parent::__construct();
     switch (defined('PSI_SENSOR_SPEEDFAN_ACCESS') ? strtolower(PSI_SENSOR_SPEEDFAN_ACCESS) : 'command') {
         case 'command':
             if (CommonFunctions::executeProgram("SpeedFanGet.exe", "", $buffer, PSI_DEBUG) && strlen($buffer) > 0) {
                 if (preg_match("/^Temperatures:\\s+(.+)\$/m", $buffer, $out)) {
                     $this->_filecontent["temp"] = $out[1];
                 }
                 if (preg_match("/^Fans:\\s+(.+)\$/m", $buffer, $out)) {
                     $this->_filecontent["fans"] = $out[1];
                 }
                 if (preg_match("/^Voltages:\\s+(.+)\$/m", $buffer, $out)) {
                     $this->_filecontent["volt"] = $out[1];
                 }
             }
             break;
         case 'data':
             if (CommonFunctions::rfts(APP_ROOT . '/data/speedfan.txt', $buffer) && strlen($buffer) > 0) {
                 if (preg_match("/^Temperatures:\\s+(.+)\$/m", $buffer, $out)) {
                     $this->_filecontent["temp"] = $out[1];
                 }
                 if (preg_match("/^Fans:\\s+(.+)\$/m", $buffer, $out)) {
                     $this->_filecontent["fans"] = $out[1];
                 }
                 if (preg_match("/^Voltages:\\s+(.+)\$/m", $buffer, $out)) {
                     $this->_filecontent["volt"] = $out[1];
                 }
             }
             break;
         default:
             $this->error->addConfigError('__construct()', 'PSI_SENSOR_SPEEDFAN_ACCESS');
             break;
     }
 }
Ejemplo n.º 2
0
 /**
  * fill the private content var through command or data access
  */
 public function __construct()
 {
     parent::__construct();
     switch (defined('PSI_SENSOR_LMSENSORS_ACCESS') ? strtolower(PSI_SENSOR_LMSENSORS_ACCESS) : 'command') {
         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 'data':
             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_LMSENSORS_ACCESS');
             break;
     }
 }
 /**
  * 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);
 }
Ejemplo n.º 4
0
 /**
  * fill the private content var through tcp, command or data access
  */
 public function __construct()
 {
     parent::__construct();
     switch (defined('PSI_SENSOR_MBMON_ACCESS') ? strtolower(PSI_SENSOR_MBMON_ACCESS) : 'command') {
         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, PSI_DEBUG);
             $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             break;
         case 'data':
             if (CommonFunctions::rfts(APP_ROOT . '/data/mbmon.txt', $lines)) {
                 $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             }
             break;
         default:
             $this->error->addConfigError('__construct()', 'PSI_SENSOR_MBMON_ACCESS');
             break;
     }
 }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
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();
     }
 }
Ejemplo n.º 7
0
 /**
  * get temperature information
  *
  * @return void
  */
 private function _temperature()
 {
     if (PSI_OS == 'Linux') {
         $hwpaths = glob("/sys/devices/platform/coretemp.*/", GLOB_NOSORT);
         if (($totalh = count($hwpaths)) > 0) {
             $buf = "";
             for ($h = 0; $h < $totalh; $h++) {
                 $tempsensor = glob($hwpaths[$h] . "temp*_input", GLOB_NOSORT);
                 if (($total = count($tempsensor)) > 0) {
                     $buf = "";
                     for ($i = 0; $i < $total; $i++) {
                         if (CommonFunctions::rfts($tempsensor[$i], $buf, 1, 4096, false) && trim($buf) != "") {
                             $dev = new SensorDevice();
                             $dev->setValue(trim($buf) / 1000);
                             $label = preg_replace("/_input\$/", "_label", $tempsensor[$i]);
                             $crit = preg_replace("/_input\$/", "_crit", $tempsensor[$i]);
                             $max = preg_replace("/_input\$/", "_max", $tempsensor[$i]);
                             $crit_alarm = preg_replace("/_input\$/", "_crit_alarm", $tempsensor[$i]);
                             if (CommonFunctions::fileexists($label) && CommonFunctions::rfts($label, $buf, 1, 4096, false) && trim($buf) != "") {
                                 $dev->setName(trim($buf));
                             } else {
                                 $labelname = trim(preg_replace("/_input\$/", "", pathinfo($tempsensor[$i], PATHINFO_BASENAME)));
                                 if ($labelname !== "") {
                                     $dev->setName($labelname);
                                 } else {
                                     $dev->setName('unknown');
                                 }
                             }
                             if (CommonFunctions::fileexists($crit) && CommonFunctions::rfts($crit, $buf, 1, 4096, false) && trim($buf) != "") {
                                 $dev->setMax(trim($buf) / 1000);
                                 if (CommonFunctions::fileexists($crit_alarm) && CommonFunctions::rfts($crit_alarm, $buf, 1, 4096, false) && trim($buf) === "1") {
                                     $dev->setEvent("Critical Alarm");
                                 }
                             } elseif (CommonFunctions::fileexists($max) && CommonFunctions::rfts($max, $buf, 1, 4096, false) && trim($buf) != "") {
                                 $dev->setMax(trim($buf) / 1000);
                             }
                             $this->mbinfo->setMbTemp($dev);
                         }
                     }
                 }
             }
         }
     } else {
         $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)) {
                 $temp = preg_replace('/C/', '', $temp);
                 $dev = new SensorDevice();
                 $dev->setName("CPU " . ($i + 1));
                 $dev->setValue($temp);
                 //                    $dev->setMax(70);
                 $this->mbinfo->setMbTemp($dev);
             }
         }
     }
 }
Ejemplo n.º 8
0
 /**
  * read the MBM5.csv file and fill the private arrays
  */
 public function __construct()
 {
     parent::__construct();
     $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);
 }
Ejemplo n.º 9
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_PS_ACCESS) {
         case 'command':
             if (PHP_OS == 'WINNT') {
                 $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;
                     }
                 }
             } 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 (PHP_OS != 'WINNT') {
         if (trim($buffer) != "") {
             $this->_filecontent = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
             unset($this->_filecontent[0]);
         } else {
             $this->_filecontent = array();
         }
     }
 }
Ejemplo n.º 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 (strtolower(PSI_PLUGIN_PSSTATUS_ACCESS)) {
         case 'command':
             if (PSI_OS == 'WINNT') {
                 try {
                     $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));
                     }
                 } 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);
                     }
                     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;
     }
 }
Ejemplo n.º 11
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;
     }
 }
Ejemplo n.º 12
0
 /**
  * fill the private content var through tcp or file access
  */
 public function __construct()
 {
     parent::__construct();
     switch (strtolower(PSI_SENSOR_ACCESS)) {
         case 'command':
             CommonFunctions::executeProgram('ipmiutil', 'sensor -stw', $lines);
             $this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             break;
         case 'file':
             if (CommonFunctions::rfts(APP_ROOT . '/data/ipmiutil.txt', $lines)) {
                 $this->_lines = preg_split("/\r?\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             }
             break;
         default:
             $this->error->addConfigError('__construct()', 'PSI_SENSOR_ACCESS');
             break;
     }
 }
Ejemplo n.º 13
0
 /**
  * fill the private content var through command or data access
  */
 public function __construct()
 {
     parent::__construct();
     switch (defined('PSI_SENSOR_FREEIPMI_ACCESS') ? strtolower(PSI_SENSOR_FREEIPMI_ACCESS) : 'command') {
         case 'command':
             CommonFunctions::executeProgram('ipmi-sensors', '--output-sensor-thresholds', $lines);
             $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             break;
         case 'data':
             if (CommonFunctions::rfts(APP_ROOT . '/data/freeipmi.txt', $lines)) {
                 $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             }
             break;
         default:
             $this->error->addConfigError('__construct()', 'PSI_SENSOR_FREEIPMI_ACCESS');
             break;
     }
 }
Ejemplo n.º 14
0
 /**
  * fill the private array
  */
 public function __construct()
 {
     parent::__construct();
     switch (defined('PSI_SENSOR_K8TEMP_ACCESS') ? strtolower(PSI_SENSOR_K8TEMP_ACCESS) : 'command') {
         case 'command':
             $lines = "";
             CommonFunctions::executeProgram('k8temp', '', $lines);
             $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             break;
         case 'data':
             if (CommonFunctions::rfts(APP_ROOT . '/data/k8temp.txt', $lines)) {
                 $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             }
             break;
         default:
             $this->error->addConfigError('__construct()', 'PSI_SENSOR_K8TEMP_ACCESS');
             break;
     }
 }
Ejemplo n.º 15
0
 /**
  * read the MBM5.csv file and fill the private arrays
  */
 public 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;
     }
 }
Ejemplo n.º 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 (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);
 }
Ejemplo n.º 17
0
 public function execute()
 {
     $this->_lines = array();
     switch (strtolower(PSI_PLUGIN_IPTABLES_ACCESS)) {
         case 'command':
             $lines = "";
             if (CommonFunctions::executeProgram('iptables-save', "", $lines) && !empty($lines)) {
                 $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             }
             break;
         case 'data':
             if (CommonFunctions::rfts(APP_ROOT . "/data/iptables.txt", $lines) && !empty($lines)) {
                 $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             }
             break;
         default:
             $this->error->addConfigError('__construct()', 'PSI_PLUGIN_IPTABLES_ACCESS');
             break;
     }
 }
Ejemplo n.º 18
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();
     }
 }
Ejemplo n.º 19
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();
     }
 }
Ejemplo n.º 20
0
 public function execute()
 {
     $this->_lines = array();
     switch (strtolower(PSI_PLUGIN_UPRECORDS_ACCESS)) {
         case 'command':
             $lines = "";
             $oldtz = getenv("TZ");
             putenv("TZ=GMT");
             if (CommonFunctions::executeProgram('uprecords', '-a -w', $lines) && !empty($lines)) {
                 $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             }
             putenv("TZ=" . $oldtz);
             break;
         case 'data':
             if (CommonFunctions::rfts(APP_ROOT . "/data/uprecords.txt", $lines) && !empty($lines)) {
                 $this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
             }
             break;
         default:
             $this->error->addConfigError('__construct()', 'PSI_PLUGIN_UPRECORDS_ACCESS');
             break;
     }
 }
Ejemplo n.º 21
0
 /**
  * get CPU information
  *
  * @return void
  */
 protected function cpuinfo()
 {
     $dev = new CpuDevice();
     if (CommonFunctions::executeProgram('hostinfo', '| grep "Processor type"', $buf, PSI_DEBUG)) {
         $dev->setModel(preg_replace('/Processor type: /', '', $buf));
         $buf = $this->grabkey('hw.model');
         if (!is_null($buf) && trim($buf) != "") {
             $this->sys->setMachine(trim($buf));
             if (CommonFunctions::rfts(APP_ROOT . '/data/ModelTranslation.txt', $buffer)) {
                 $buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
                 foreach ($buffer as $line) {
                     $ar_buf = preg_split("/:/", $line, 3);
                     if (trim($buf) === trim($ar_buf[0])) {
                         $dev->setModel(trim($ar_buf[2]));
                         $this->sys->setMachine($this->sys->getMachine() . ' - ' . trim($ar_buf[1]));
                         break;
                     }
                 }
             }
         }
         $buf = $this->grabkey('machdep.cpu.brand_string');
         if (!is_null($buf) && trim($buf) != "" && (trim($buf) != "i486 (Intel 80486)" || $dev->getModel() == "")) {
             $dev->setModel(trim($buf));
         }
         $buf = $this->grabkey('machdep.cpu.features');
         if (!is_null($buf) && trim($buf) != "") {
             if (preg_match("/ VMX/", $buf)) {
                 $dev->setVirt("vmx");
             } elseif (preg_match("/ SVM/", $buf)) {
                 $dev->setVirt("svm");
             }
         }
     }
     $dev->setCpuSpeed(round($this->grabkey('hw.cpufrequency') / 1000000));
     $dev->setBusSpeed(round($this->grabkey('hw.busfrequency') / 1000000));
     $bufn = $this->grabkey('hw.cpufrequency_min');
     $bufx = $this->grabkey('hw.cpufrequency_max');
     if (!is_null($bufn) && trim($bufn) != "" && !is_null($bufx) && trim($bufx) != "" && $bufn != $bufx) {
         $dev->setCpuSpeedMin(round($bufn / 1000000));
         $dev->setCpuSpeedMax(round($bufx / 1000000));
     }
     $buf = $this->grabkey('hw.l2cachesize');
     if (!is_null($buf) && trim($buf) != "") {
         $dev->setCache(round($buf));
     }
     $ncpu = $this->grabkey('hw.ncpu');
     if (is_null($ncpu) || trim($ncpu) == "" || !($ncpu >= 1)) {
         $ncpu = 1;
     }
     for ($ncpu; $ncpu > 0; $ncpu--) {
         $this->sys->setCpus($dev);
     }
 }
Ejemplo n.º 22
0
 /**
  * read /var/run/dmesg.boot, but only if we haven't already
  *
  * @return array
  */
 protected function readdmesg()
 {
     if (count($this->_dmesg) === 0) {
         if (PHP_OS != "Darwin") {
             if (CommonFunctions::rfts('/var/run/dmesg.boot', $buf)) {
                 $parts = preg_split("/rebooting/", $buf, -1, PREG_SPLIT_NO_EMPTY);
                 $this->_dmesg = preg_split("/\n/", $parts[count($parts) - 1], -1, PREG_SPLIT_NO_EMPTY);
             }
         }
     }
     return $this->_dmesg;
 }
Ejemplo n.º 23
0
 /**
  * Distribution
  *
  * @return void
  */
 private function _distro()
 {
     $list = @parse_ini_file(APP_ROOT . "/data/distros.ini", true);
     if (!$list) {
         return;
     }
     // We have the '2> /dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
     if (CommonFunctions::executeProgram('lsb_release', '-a 2> /dev/null', $distro_info, PSI_DEBUG)) {
         $distro_tmp = preg_split("/\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($distro_tmp as $info) {
             $info_tmp = preg_split('/:/', $info, 2);
             $distro[$info_tmp[0]] = trim($info_tmp[1]);
             if (isset($distro['Distributor ID']) && isset($list[$distro['Distributor ID']]['Image'])) {
                 $this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']);
             }
             if (isset($distro['Description'])) {
                 $this->sys->setDistribution($distro['Description']);
             }
         }
     } else {
         // Fall back in case 'lsb_release' does not exist ;)
         foreach ($list as $section => $distribution) {
             if (!isset($distribution["Files"])) {
                 continue;
             } else {
                 foreach (preg_split("/;/", $distribution["Files"], -1, PREG_SPLIT_NO_EMPTY) as $filename) {
                     if (file_exists($filename)) {
                         CommonFunctions::rfts($filename, $buf);
                         if (isset($distribution["Image"])) {
                             $this->sys->setDistributionIcon($distribution["Image"]);
                         }
                         if (isset($distribution["Name"])) {
                             if ($distribution["Name"] == 'Synology') {
                                 $this->sys->setDistribution($distribution["Name"]);
                             } else {
                                 $this->sys->setDistribution($distribution["Name"] . " " . trim($buf));
                             }
                         } else {
                             $this->sys->setDistribution(trim($buf));
                         }
                         return;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 24
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();
         }
     }
 }
Ejemplo n.º 25
0
 /**
  * get CPU information
  *
  * @return void
  */
 protected function cpuinfo()
 {
     $dev = new CpuDevice();
     if (CommonFunctions::executeProgram('hostinfo', '| grep "Processor type"', $buf, PSI_DEBUG)) {
         $dev->setModel(preg_replace('/Processor type: /', '', $buf));
         $buf = $this->grabkey('hw.model');
         if (CommonFunctions::rfts(APP_ROOT . '/data/ModelTranslation.txt', $buffer)) {
             $buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($buffer as $line) {
                 $ar_buf = preg_split("/:/", $line, 2);
                 if (trim($buf) === trim($ar_buf[0])) {
                     $dev->setModel(trim($ar_buf[1]));
                 }
             }
         }
     }
     $dev->setCpuSpeed(round($this->grabkey('hw.cpufrequency') / 1000000));
     $dev->setBusSpeed(round($this->grabkey('hw.busfrequency') / 1000000));
     $dev->setCache(round($this->grabkey('hw.l2cachesize')));
     for ($i = $this->grabkey('hw.ncpu'); $i > 0; $i--) {
         $this->sys->setCpus($dev);
     }
 }
Ejemplo n.º 26
0
 /**
  *  Physical memory information and Swap Space information
  *
  *  @return void
  */
 private function _memory()
 {
     if (CommonFunctions::rfts('/proc/meminfo', $bufr, 1, 4096, false)) {
         $ar_buf = preg_split('/\\s+/', trim($bufr));
         if (count($ar_buf) >= 5) {
             $this->sys->setMemTotal($ar_buf[0] * $ar_buf[1]);
             $this->sys->setMemFree($ar_buf[0] * $ar_buf[2]);
             $this->sys->setMemCache($ar_buf[0] * $ar_buf[4]);
             $this->sys->setMemUsed($ar_buf[0] * ($ar_buf[1] - $ar_buf[2]));
         }
     }
 }
 /**
  * Distribution
  *
  * @return void
  */
 private function _distro()
 {
     $this->sys->setDistribution("Linux");
     $list = @parse_ini_file(APP_ROOT . "/data/distros.ini", true);
     if (!$list) {
         return;
     }
     // We have the '2>/dev/null' because Ubuntu gives an error on this command which causes the distro to be unknown
     if (CommonFunctions::executeProgram('lsb_release', '-a 2>/dev/null', $distro_info, PSI_DEBUG) && strlen(trim($distro_info)) > 0) {
         $distro_tmp = preg_split("/\n/", $distro_info, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($distro_tmp as $info) {
             $info_tmp = preg_split('/:/', $info, 2);
             if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && trim($distro_tmp[0]) != "" && isset($distro_tmp[1]) && !is_null($distro_tmp[1]) && trim($distro_tmp[1]) != "") {
                 $distro[trim($info_tmp[0])] = trim($info_tmp[1]);
             }
         }
         if (!isset($distro['Distributor ID']) && !isset($distro['Description'])) {
             // Systems like StartOS
             if (isset($distro_tmp[0]) && !is_null($distro_tmp[0]) && trim($distro_tmp[0]) != "") {
                 $this->sys->setDistribution(trim($distro_tmp[0]));
                 if (preg_match('/^(\\S+)\\s*/', $distro_tmp[0], $id_buf) && isset($list[trim($id_buf[1])]['Image'])) {
                     $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
                 }
             }
         } else {
             if (isset($distro['Description']) && preg_match('/^NAME=\\s*(.+)\\s*$/', $distro['Description'], $name_tmp)) {
                 $distro['Description'] = $name_tmp[1];
             }
             if (isset($distro['Description']) && $distro['Description'] != "n/a" && !isset($distro['Distributor ID'])) {
                 $this->sys->setDistribution($distro['Description']);
             } elseif (isset($distro['Description']) && $distro['Description'] != "n/a" && isset($distro['Distributor ID']) && $distro['Distributor ID'] != "n/a" && $distro['Description'] != $distro['Distributor ID']) {
                 $this->sys->setDistribution($distro['Description']);
             } elseif (isset($distro['Distributor ID']) && $distro['Distributor ID'] != "n/a") {
                 $this->sys->setDistribution($distro['Distributor ID']);
                 if (isset($distro['Release']) && $distro['Release'] != "n/a") {
                     $this->sys->setDistribution($this->sys->getDistribution() . " " . $distro['Release']);
                 }
                 if (isset($distro['Codename']) && $distro['Codename'] != "n/a") {
                     $this->sys->setDistribution($this->sys->getDistribution() . " (" . $distro['Codename'] . ")");
                 }
             }
             if (isset($distro['Distributor ID']) && $distro['Distributor ID'] != "n/a" && isset($list[$distro['Distributor ID']]['Image'])) {
                 $this->sys->setDistributionIcon($list[$distro['Distributor ID']]['Image']);
             }
         }
     } else {
         /* default error handler */
         if (function_exists('errorHandlerPsi')) {
             restore_error_handler();
         }
         /* fatal errors only */
         $old_err_rep = error_reporting();
         error_reporting(E_ERROR);
         // Fall back in case 'lsb_release' does not exist but exist /etc/lsb-release
         if (CommonFunctions::fileexists($filename = "/etc/lsb-release") && CommonFunctions::rfts($filename, $buf, 0, 4096, false) && preg_match('/^DISTRIB_ID="?([^"\\n]+)"?/m', $buf, $id_buf)) {
             if (preg_match('/^DISTRIB_DESCRIPTION="?([^"\\n]+)"?/m', $buf, $desc_buf) && trim($desc_buf[1]) != trim($id_buf[1])) {
                 $this->sys->setDistribution(trim($desc_buf[1]));
             } else {
                 if (isset($list[trim($id_buf[1])]['Name'])) {
                     $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
                 } else {
                     $this->sys->setDistribution(trim($id_buf[1]));
                 }
                 if (preg_match('/^DISTRIB_RELEASE="?([^"\\n]+)"?/m', $buf, $vers_buf)) {
                     $this->sys->setDistribution($this->sys->getDistribution() . " " . trim($vers_buf[1]));
                 }
                 if (preg_match('/^DISTRIB_CODENAME="?([^"\\n]+)"?/m', $buf, $vers_buf)) {
                     $this->sys->setDistribution($this->sys->getDistribution() . " (" . trim($vers_buf[1]) . ")");
                 }
             }
             if (isset($list[trim($id_buf[1])]['Image'])) {
                 $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
             }
         } else {
             // otherwise find files specific for distribution
             foreach ($list as $section => $distribution) {
                 if (!isset($distribution['Files'])) {
                     continue;
                 } else {
                     foreach (preg_split("/;/", $distribution['Files'], -1, PREG_SPLIT_NO_EMPTY) as $filename) {
                         if (CommonFunctions::fileexists($filename)) {
                             $distro = $distribution;
                             if (isset($distribution['Mode']) && strtolower($distribution['Mode']) == "detection") {
                                 $buf = "";
                             } elseif (isset($distribution['Mode']) && strtolower($distribution['Mode']) == "execute") {
                                 if (!CommonFunctions::executeProgram($filename, '2>/dev/null', $buf, PSI_DEBUG)) {
                                     $buf = "";
                                 }
                             } else {
                                 if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
                                     $buf = "";
                                 } elseif (isset($distribution['Mode']) && strtolower($distribution['Mode']) == "analyse") {
                                     if (preg_match('/^(\\S+)\\s*/', preg_replace('/^Red\\s+/', 'Red', $buf), $id_buf) && isset($list[trim($id_buf[1])]['Image'])) {
                                         $distro = $list[trim($id_buf[1])];
                                     }
                                 }
                             }
                             if (isset($distro['Image'])) {
                                 $this->sys->setDistributionIcon($distro['Image']);
                             }
                             if (isset($distribution['Name'])) {
                                 if (is_null($buf) || trim($buf) == "") {
                                     $this->sys->setDistribution($distribution['Name']);
                                 } else {
                                     $this->sys->setDistribution($distribution['Name'] . " " . trim($buf));
                                 }
                             } else {
                                 if (is_null($buf) || trim($buf) == "") {
                                     $this->sys->setDistribution($section);
                                 } else {
                                     $this->sys->setDistribution(trim($buf));
                                 }
                             }
                             if (isset($distribution['Files2'])) {
                                 foreach (preg_split("/;/", $distribution['Files2'], -1, PREG_SPLIT_NO_EMPTY) as $filename2) {
                                     if (CommonFunctions::fileexists($filename2) && CommonFunctions::rfts($filename2, $buf, 0, 4096, false)) {
                                         if (preg_match('/^majorversion="?([^"\\n]+)"?/m', $buf, $maj_buf) && preg_match('/^minorversion="?([^"\\n]+)"?/m', $buf, $min_buf)) {
                                             $distr2 = $maj_buf[1] . '.' . $min_buf[1];
                                             if (preg_match('/^buildphase="?([^"\\n]+)"?/m', $buf, $pha_buf) && $pha_buf[1] !== "0") {
                                                 $distr2 .= '.' . $pha_buf[1];
                                             }
                                             if (preg_match('/^buildnumber="?([^"\\n]+)"?/m', $buf, $num_buf)) {
                                                 $distr2 .= '-' . $num_buf[1];
                                             }
                                             if (preg_match('/^builddate="?([^"\\n]+)"?/m', $buf, $dat_buf)) {
                                                 $distr2 .= ' (' . $dat_buf[1] . ')';
                                             }
                                             $this->sys->setDistribution($this->sys->getDistribution() . " " . $distr2);
                                         } else {
                                             $distr2 = trim(substr($buf, 0, strpos($buf, "\n")));
                                             if (!is_null($distr2) && $distr2 != "") {
                                                 $this->sys->setDistribution($this->sys->getDistribution() . " " . $distr2);
                                             }
                                         }
                                         break;
                                     }
                                 }
                             }
                             break 2;
                         }
                     }
                 }
             }
         }
         // if the distribution is still unknown
         if ($this->sys->getDistribution() == "Linux") {
             if (CommonFunctions::fileexists($filename = "/etc/DISTRO_SPECS") && CommonFunctions::rfts($filename, $buf, 0, 4096, false) && preg_match('/^DISTRO_NAME=\'(.+)\'/m', $buf, $id_buf)) {
                 if (isset($list[trim($id_buf[1])]['Name'])) {
                     $dist = trim($list[trim($id_buf[1])]['Name']);
                 } else {
                     $dist = trim($id_buf[1]);
                 }
                 if (preg_match('/^DISTRO_VERSION=(.+)/m', $buf, $vers_buf)) {
                     $this->sys->setDistribution(trim($dist . " " . trim($vers_buf[1])));
                 } else {
                     $this->sys->setDistribution($dist);
                 }
                 if (isset($list[trim($id_buf[1])]['Image'])) {
                     $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
                 } else {
                     if (isset($list['Puppy']['Image'])) {
                         $this->sys->setDistributionIcon($list['Puppy']['Image']);
                     }
                 }
             } elseif (CommonFunctions::fileexists($filename = "/etc/distro-release") && CommonFunctions::rfts($filename, $buf, 1, 4096, false) && !is_null($buf) && trim($buf) != "" || CommonFunctions::fileexists($filename = "/etc/system-release") && CommonFunctions::rfts($filename, $buf, 1, 4096, false) && !is_null($buf) && trim($buf) != "") {
                 $this->sys->setDistribution(trim($buf));
                 if (preg_match('/^(\\S+)\\s*/', preg_replace('/^Red\\s+/', 'Red', $buf), $id_buf) && isset($list[trim($id_buf[1])]['Image'])) {
                     $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
                 }
             } elseif (CommonFunctions::fileexists($filename = "/etc/solydxk/info") && CommonFunctions::rfts($filename, $buf, 0, 4096, false) && preg_match('/^DISTRIB_ID="?([^"\\n]+)"?/m', $buf, $id_buf)) {
                 if (preg_match('/^DESCRIPTION="?([^"\\n]+)"?/m', $buf, $desc_buf) && trim($desc_buf[1]) != trim($id_buf[1])) {
                     $this->sys->setDistribution(trim($desc_buf[1]));
                 } else {
                     if (isset($list[trim($id_buf[1])]['Name'])) {
                         $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
                     } else {
                         $this->sys->setDistribution(trim($id_buf[1]));
                     }
                     if (preg_match('/^RELEASE="?([^"\\n]+)"?/m', $buf, $vers_buf)) {
                         $this->sys->setDistribution($this->sys->getDistribution() . " " . trim($vers_buf[1]));
                     }
                     if (preg_match('/^CODENAME="?([^"\\n]+)"?/m', $buf, $vers_buf)) {
                         $this->sys->setDistribution($this->sys->getDistribution() . " (" . trim($vers_buf[1]) . ")");
                     }
                 }
                 if (isset($list[trim($id_buf[1])]['Image'])) {
                     $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
                 } else {
                     $this->sys->setDistributionIcon($list['SolydXK']['Image']);
                 }
             } elseif (CommonFunctions::fileexists($filename = "/etc/os-release") && CommonFunctions::rfts($filename, $buf, 0, 4096, false) && (preg_match('/^TAILS_VERSION_ID="?([^"\\n]+)"?/m', $buf, $tid_buf) || preg_match('/^NAME="?([^"\\n]+)"?/m', $buf, $id_buf))) {
                 if (preg_match('/^TAILS_VERSION_ID="?([^"\\n]+)"?/m', $buf, $tid_buf)) {
                     if (preg_match('/^TAILS_PRODUCT_NAME="?([^"\\n]+)"?/m', $buf, $desc_buf)) {
                         $this->sys->setDistribution(trim($desc_buf[1]) . " " . trim($tid_buf[1]));
                     } else {
                         if (isset($list['Tails']['Name'])) {
                             $this->sys->setDistribution(trim($list['Tails']['Name']) . " " . trim($tid_buf[1]));
                         } else {
                             $this->sys->setDistribution('Tails' . " " . trim($tid_buf[1]));
                         }
                     }
                     $this->sys->setDistributionIcon($list['Tails']['Image']);
                 } else {
                     if (preg_match('/^PRETTY_NAME="?([^"\\n]+)"?/m', $buf, $desc_buf) && !preg_match('/\\$/', $desc_buf[1])) {
                         //if is not defined by variable
                         $this->sys->setDistribution(trim($desc_buf[1]));
                     } else {
                         if (isset($list[trim($id_buf[1])]['Name'])) {
                             $this->sys->setDistribution(trim($list[trim($id_buf[1])]['Name']));
                         } else {
                             $this->sys->setDistribution(trim($id_buf[1]));
                         }
                         if (preg_match('/^VERSION="?([^"\\n]+)"?/m', $buf, $vers_buf)) {
                             $this->sys->setDistribution($this->sys->getDistribution() . " " . trim($vers_buf[1]));
                         } elseif (preg_match('/^VERSION_ID="?([^"\\n]+)"?/m', $buf, $vers_buf)) {
                             $this->sys->setDistribution($this->sys->getDistribution() . " " . trim($vers_buf[1]));
                         }
                     }
                     if (isset($list[trim($id_buf[1])]['Image'])) {
                         $this->sys->setDistributionIcon($list[trim($id_buf[1])]['Image']);
                     }
                 }
             } elseif (CommonFunctions::fileexists($filename = "/etc/debian_version")) {
                 if (!CommonFunctions::rfts($filename, $buf, 1, 4096, false)) {
                     $buf = "";
                 }
                 if (isset($list['Debian']['Image'])) {
                     $this->sys->setDistributionIcon($list['Debian']['Image']);
                 }
                 if (isset($list['Debian']['Name'])) {
                     if (is_null($buf) || trim($buf) == "") {
                         $this->sys->setDistribution($list['Debian']['Name']);
                     } else {
                         $this->sys->setDistribution($list['Debian']['Name'] . " " . trim($buf));
                     }
                 } else {
                     if (is_null($buf) || trim($buf) == "") {
                         $this->sys->setDistribution('Debian');
                     } else {
                         $this->sys->setDistribution(trim($buf));
                     }
                 }
             }
         }
         /* restore error level */
         error_reporting($old_err_rep);
         /* restore error handler */
         if (function_exists('errorHandlerPsi')) {
             set_error_handler('errorHandlerPsi');
         }
     }
 }
Ejemplo n.º 28
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;
     }
 }
Ejemplo n.º 29
0
 /**
  * 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 (strtolower(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, PSI_DEBUG)) {
                 $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 (preg_match("/\\|(.*)\\|(.*)\\|(.*)\\|(.*)\\|/", $line, $data)) {
             if (trim($data[3]) != "ERR") {
                 // get the info we need
                 $dev = new SensorDevice();
                 $dev->setName($data[1] . ' (' . (strpos($data[2], "  ") ? substr($data[2], 0, strpos($data[2], "  ")) : $data[2]) . ')');
                 if (is_numeric($data[3])) {
                     $dev->setValue($data[3]);
                 }
                 $dev->setMax(60);
                 $this->mbinfo->setMbTemp($dev);
             }
         }
     }
 }
Ejemplo n.º 30
-1
 private function _current()
 {
     $current = null;
     if (CommonFunctions::rfts('/sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/axp20-supplyer.28/power_supply/ac/current_now', $current, 0, 4096, false) && !is_null($current) && trim($current) != "") {
         // Banana Pi
         $dev = new SensorDevice();
         $dev->setName("Current 1");
         $dev->setValue($current / 1000000);
         $this->mbinfo->setMbCurrent($dev);
     }
 }