2780 |
rexy |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Uprecords plugin, which displays all uprecords informations available
|
|
|
4 |
*
|
|
|
5 |
* @category PHP
|
|
|
6 |
* @package PSI_Plugin_Uprecords
|
|
|
7 |
* @author Ambrus Sandor Olah <aolah76@freemail.hu>
|
|
|
8 |
* @copyright 2014 phpSysInfo
|
|
|
9 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
10 |
* @version Release: 1.0
|
|
|
11 |
* @link http://phpsysinfo.sourceforge.net
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
class uprecords extends PSI_Plugin
|
|
|
15 |
{
|
|
|
16 |
private $_lines;
|
|
|
17 |
|
|
|
18 |
public function __construct($enc)
|
|
|
19 |
{
|
|
|
20 |
parent::__construct(__CLASS__, $enc);
|
|
|
21 |
|
|
|
22 |
$this->_lines = array();
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* get uprecords information
|
|
|
27 |
*
|
|
|
28 |
* @return array uprecords in array with label
|
|
|
29 |
*/
|
|
|
30 |
|
|
|
31 |
private function getUprecords()
|
|
|
32 |
{
|
|
|
33 |
$result = array();
|
|
|
34 |
$i = 0;
|
|
|
35 |
|
|
|
36 |
foreach ($this->_lines as $line) {
|
|
|
37 |
if (($i > 1) and (strpos($line, '---') === false)) {
|
|
|
38 |
$buffer = preg_split("/\s*[ |]\s+/", ltrim(ltrim($line, '->'), ' '));
|
|
|
39 |
if (defined('PSI_PLUGIN_UPRECORDS_SHORT_MODE') &&
|
|
|
40 |
(PSI_PLUGIN_UPRECORDS_SHORT_MODE === true) &&
|
|
|
41 |
!is_numeric($buffer[0])) {
|
|
|
42 |
break;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
if (strpos($line, '->') !== false) {
|
|
|
46 |
if (defined('PSI_PLUGIN_UPRECORDS_DENOTE_BY_ASTERISK') && (PSI_PLUGIN_UPRECORDS_DENOTE_BY_ASTERISK === true)) {
|
|
|
47 |
$buffer[0] .= ' *';
|
|
|
48 |
} else {
|
|
|
49 |
$buffer[0] = '-> '.$buffer[0];
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
if (count($buffer) > 4) {
|
|
|
54 |
$buffer[3] = $buffer[3].' '.$buffer[4];
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
$result[$i]['hash'] = $buffer[0];
|
|
|
58 |
$result[$i]['Uptime'] = $buffer[1];
|
|
|
59 |
$result[$i]['System'] = $buffer[2];
|
|
|
60 |
//Date formating
|
|
|
61 |
$result[$i]['Bootup'] = preg_replace("/^(\S+)(\s+)/", "$1,$2", preg_replace("/^(\S+\s+\S+\s+)(\d)(\s+)/", "$1 0$2$3", trim($buffer[3])." GMT"));
|
|
|
62 |
}
|
|
|
63 |
$i++;
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
return $result;
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
public function execute()
|
|
|
70 |
{
|
|
|
71 |
$this->_lines = array();
|
|
|
72 |
switch (strtolower(PSI_PLUGIN_UPRECORDS_ACCESS)) {
|
|
|
73 |
case 'command':
|
|
|
74 |
$lines = "";
|
|
|
75 |
$options = "";
|
|
|
76 |
if (defined('PSI_PLUGIN_UPRECORDS_MAX_ENTRIES')) {
|
|
|
77 |
if (($ment = max(intval(PSI_PLUGIN_UPRECORDS_MAX_ENTRIES), 0)) != 10) {
|
|
|
78 |
$options=" -m ".$ment;
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
if (defined('PSI_PLUGIN_UPRECORDS_SHORT_MODE') && (PSI_PLUGIN_UPRECORDS_SHORT_MODE === true)) {
|
|
|
82 |
$options .= " -s";
|
|
|
83 |
}
|
|
|
84 |
if (CommonFunctions::executeProgram('TZ=GMT uprecords', '-a -w'.$options, $lines) && !empty($lines))
|
|
|
85 |
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
86 |
break;
|
|
|
87 |
case 'data':
|
|
|
88 |
if (CommonFunctions::rfts(PSI_APP_ROOT."/data/uprecords.txt", $lines) && !empty($lines))
|
|
|
89 |
$this->_lines = preg_split("/\n/", $lines, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
90 |
break;
|
|
|
91 |
default:
|
|
|
92 |
$this->global_error->addConfigError("execute()", "[uprecords] ACCESS");
|
|
|
93 |
break;
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
public function xml()
|
|
|
98 |
{
|
|
|
99 |
if (empty($this->_lines))
|
|
|
100 |
return $this->xml->getSimpleXmlElement();
|
|
|
101 |
|
|
|
102 |
$arrBuff = $this->getUprecords();
|
|
|
103 |
if (sizeof($arrBuff) > 0) {
|
|
|
104 |
$uprecords = $this->xml->addChild("Uprecords");
|
|
|
105 |
foreach ($arrBuff as $arrValue) {
|
|
|
106 |
$item = $uprecords->addChild('Item');
|
|
|
107 |
$item->addAttribute('hash', $arrValue['hash']);
|
|
|
108 |
$item->addAttribute('Uptime', $arrValue['Uptime']);
|
|
|
109 |
$item->addAttribute('System', $arrValue['System']);
|
|
|
110 |
$item->addAttribute('Bootup', $arrValue['Bootup']);
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
return $this->xml->getSimpleXmlElement();
|
|
|
115 |
}
|
|
|
116 |
}
|