1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
<?php
/**
* Viewer Plugin, which displays custom informations
*
* @category PHP
* @package PSI_Plugin_Viewer
* @author erpomata
* @copyright 2016 phpSysInfo
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
* @version Release: 1.0
* @link http://phpsysinfo.sourceforge.net
*/
class Viewer extends PSI_Plugin
{
private $_lines;
private $name = "";
public function __construct($enc)
{
parent::__construct(__CLASS__, $enc);
$this->_lines = array();
}
/**
* get viewer information
*
* @return array viewer in array with label
*/
private function getViewer()
{
$result = array();
$i = 0;
foreach ($this->_lines as $line) {
$result[$i]['line'] = $line;
$i++;
}
return $result;
}
public function execute()
{
$this->_lines = array();
if (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) switch (strtolower(PSI_PLUGIN_VIEWER_ACCESS)) {
case 'command':
if (defined('PSI_PLUGIN_VIEWER_COMMAND') && is_string(PSI_PLUGIN_VIEWER_COMMAND)) {
if (defined('PSI_PLUGIN_VIEWER_PARAMS') && is_string(PSI_PLUGIN_VIEWER_PARAMS)) {
$params = PSI_PLUGIN_VIEWER_PARAMS;
} else {
$params = "";
}
$this->name = trim(PSI_PLUGIN_VIEWER_COMMAND." ".$params);
$lines = "";
if ((PSI_OS == 'WINNT') && ($cp = CommonFunctions::getcp())) {
if (CommonFunctions::executeProgram('cmd', '/c chcp '.$cp.' >nul & '.$this->name, $lines) && !empty($lines))
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
} else {
if (CommonFunctions::executeProgram(PSI_PLUGIN_VIEWER_COMMAND, $params, $lines) && !empty($lines))
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
}
} else {
$this->global_error->addConfigError("execute()", "[viewer] COMMAND");
}
break;
case 'data':
if (!defined('PSI_EMU_HOSTNAME') && CommonFunctions::rftsdata("viewer.tmp", $lines) && !empty($lines))
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
break;
default:
$this->global_error->addConfigError("execute()", "[viewer] ACCESS");
}
}
public function xml()
{
if (empty($this->_lines))
return $this->xml->getSimpleXmlElement();
$arrBuff = $this->getViewer();
if (sizeof($arrBuff) > 0) {
$viewer = $this->xml->addChild("Viewer");
$viewer->addAttribute("Name", $this->name);
foreach ($arrBuff as $arrValue) {
$item = $viewer->addChild('Item');
$item->addAttribute('Line', $arrValue['line']);
}
}
return $this->xml->getSimpleXmlElement();
}
}
|