2770 |
rexy |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* XML Generation class
|
|
|
4 |
*
|
|
|
5 |
* PHP version 5
|
|
|
6 |
*
|
|
|
7 |
* @category PHP
|
|
|
8 |
* @package PSI_XML
|
|
|
9 |
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
|
|
10 |
* @copyright 2009 phpSysInfo
|
|
|
11 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
12 |
* @version SVN: $Id: class.XML.inc.php 699 2012-09-15 11:57:13Z namiltd $
|
|
|
13 |
* @link http://phpsysinfo.sourceforge.net
|
|
|
14 |
*/
|
|
|
15 |
/**
|
|
|
16 |
* class for generation of the xml
|
|
|
17 |
*
|
|
|
18 |
* @category PHP
|
|
|
19 |
* @package PSI_XML
|
|
|
20 |
* @author Michael Cramer <BigMichi1@users.sourceforge.net>
|
|
|
21 |
* @copyright 2009 phpSysInfo
|
|
|
22 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
23 |
* @version Release: 3.0
|
|
|
24 |
* @link http://phpsysinfo.sourceforge.net
|
|
|
25 |
*/
|
|
|
26 |
class XML
|
|
|
27 |
{
|
|
|
28 |
/**
|
|
|
29 |
* Sysinfo object where the information retrieval methods are included
|
|
|
30 |
*
|
|
|
31 |
* @var PSI_Interface_OS
|
|
|
32 |
*/
|
|
|
33 |
private $_sysinfo;
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* @var System
|
|
|
37 |
*/
|
|
|
38 |
private $_sys = null;
|
|
|
39 |
|
|
|
40 |
/**
|
|
|
41 |
* xml object with the xml content
|
|
|
42 |
*
|
|
|
43 |
* @var SimpleXMLExtended
|
|
|
44 |
*/
|
|
|
45 |
private $_xml;
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
* object for error handling
|
|
|
49 |
*
|
|
|
50 |
* @var PSI_Error
|
|
|
51 |
*/
|
|
|
52 |
private $_errors;
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* array with all enabled plugins (name)
|
|
|
56 |
*
|
|
|
57 |
* @var array
|
|
|
58 |
*/
|
|
|
59 |
private $_plugins;
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* plugin name if pluginrequest
|
|
|
63 |
*
|
|
|
64 |
* @var string
|
|
|
65 |
*/
|
|
|
66 |
private $_plugin = '';
|
|
|
67 |
|
|
|
68 |
/**
|
|
|
69 |
* generate the entire xml with all plugins or only a part of the xml (main or plugin)
|
|
|
70 |
*
|
|
|
71 |
* @var boolean
|
|
|
72 |
*/
|
|
|
73 |
private $_complete_request = false;
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* doing some initial tasks
|
|
|
77 |
* - generate the xml structure with the right header elements
|
|
|
78 |
* - get the error object for error output
|
|
|
79 |
* - get a instance of the sysinfo object
|
|
|
80 |
*
|
|
|
81 |
* @param boolean $complete generate xml with all plugins or not
|
|
|
82 |
* @param string $pluginname name of the plugin
|
|
|
83 |
*
|
|
|
84 |
* @return void
|
|
|
85 |
*/
|
|
|
86 |
public function __construct($complete = false, $pluginname = "", $blockname = false)
|
|
|
87 |
{
|
|
|
88 |
$this->_errors = PSI_Error::singleton();
|
2976 |
rexy |
89 |
$this->_plugin = $pluginname;
|
2770 |
rexy |
90 |
if ($complete) {
|
|
|
91 |
$this->_complete_request = true;
|
|
|
92 |
} else {
|
|
|
93 |
$this->_complete_request = false;
|
|
|
94 |
}
|
3100 |
rexy |
95 |
if (defined('PSI_EMU_PORT')) {
|
|
|
96 |
$os = 'SSH';
|
|
|
97 |
} elseif (defined('PSI_EMU_HOSTNAME')) {
|
2976 |
rexy |
98 |
$os = 'WINNT';
|
|
|
99 |
} else {
|
|
|
100 |
$os = PSI_OS;
|
|
|
101 |
}
|
2770 |
rexy |
102 |
$this->_sysinfo = new $os($blockname);
|
|
|
103 |
$this->_plugins = CommonFunctions::getPlugins();
|
|
|
104 |
$this->_xmlbody();
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
/**
|
|
|
108 |
* generate common information
|
|
|
109 |
*
|
|
|
110 |
* @return void
|
|
|
111 |
*/
|
|
|
112 |
private function _buildVitals()
|
|
|
113 |
{
|
|
|
114 |
$vitals = $this->_xml->addChild('Vitals');
|
|
|
115 |
$vitals->addAttribute('Hostname', $this->_sys->getHostname());
|
|
|
116 |
$vitals->addAttribute('IPAddr', $this->_sys->getIp());
|
|
|
117 |
$vitals->addAttribute('Kernel', $this->_sys->getKernel());
|
|
|
118 |
$vitals->addAttribute('Distro', $this->_sys->getDistribution());
|
|
|
119 |
$vitals->addAttribute('Distroicon', $this->_sys->getDistributionIcon());
|
|
|
120 |
$vitals->addAttribute('Uptime', $this->_sys->getUptime());
|
|
|
121 |
$vitals->addAttribute('Users', $this->_sys->getUsers());
|
|
|
122 |
$vitals->addAttribute('LoadAvg', $this->_sys->getLoad());
|
|
|
123 |
if ($this->_sys->getLoadPercent() !== null) {
|
|
|
124 |
$vitals->addAttribute('CPULoad', $this->_sys->getLoadPercent());
|
|
|
125 |
}
|
|
|
126 |
if ($this->_sysinfo->getLanguage() !== null) {
|
|
|
127 |
$vitals->addAttribute('SysLang', $this->_sysinfo->getLanguage());
|
|
|
128 |
}
|
|
|
129 |
if ($this->_sysinfo->getEncoding() !== null) {
|
|
|
130 |
$vitals->addAttribute('CodePage', $this->_sysinfo->getEncoding());
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
//processes
|
|
|
134 |
if (($procss = $this->_sys->getProcesses()) !== null) {
|
|
|
135 |
if (isset($procss['*']) && (($procall = $procss['*']) > 0)) {
|
|
|
136 |
$vitals->addAttribute('Processes', $procall);
|
|
|
137 |
if (!isset($procss[' ']) || !($procss[' '] > 0)) { // not unknown
|
|
|
138 |
$procsum = 0;
|
|
|
139 |
if (isset($procss['R']) && (($proctmp = $procss['R']) > 0)) {
|
|
|
140 |
$vitals->addAttribute('ProcessesRunning', $proctmp);
|
|
|
141 |
$procsum += $proctmp;
|
|
|
142 |
}
|
|
|
143 |
if (isset($procss['S']) && (($proctmp = $procss['S']) > 0)) {
|
|
|
144 |
$vitals->addAttribute('ProcessesSleeping', $proctmp);
|
|
|
145 |
$procsum += $proctmp;
|
|
|
146 |
}
|
|
|
147 |
if (isset($procss['T']) && (($proctmp = $procss['T']) > 0)) {
|
|
|
148 |
$vitals->addAttribute('ProcessesStopped', $proctmp);
|
|
|
149 |
$procsum += $proctmp;
|
|
|
150 |
}
|
|
|
151 |
if (isset($procss['Z']) && (($proctmp = $procss['Z']) > 0)) {
|
|
|
152 |
$vitals->addAttribute('ProcessesZombie', $proctmp);
|
|
|
153 |
$procsum += $proctmp;
|
|
|
154 |
}
|
|
|
155 |
if (isset($procss['D']) && (($proctmp = $procss['D']) > 0)) {
|
|
|
156 |
$vitals->addAttribute('ProcessesWaiting', $proctmp);
|
|
|
157 |
$procsum += $proctmp;
|
|
|
158 |
}
|
|
|
159 |
if (($proctmp = $procall - $procsum) > 0) {
|
|
|
160 |
$vitals->addAttribute('ProcessesOther', $proctmp);
|
|
|
161 |
}
|
|
|
162 |
}
|
|
|
163 |
}
|
|
|
164 |
}
|
2976 |
rexy |
165 |
|
3100 |
rexy |
166 |
if (($os = $this->_sys->getOS()) == 'Android') {
|
|
|
167 |
$vitals->addAttribute('OS', 'Linux');
|
|
|
168 |
} elseif ($os == 'GNU') {
|
|
|
169 |
$vitals->addAttribute('OS', 'Hurd');
|
2976 |
rexy |
170 |
} else {
|
3100 |
rexy |
171 |
$vitals->addAttribute('OS', $os);
|
2976 |
rexy |
172 |
}
|
2770 |
rexy |
173 |
}
|
|
|
174 |
|
|
|
175 |
/**
|
|
|
176 |
* generate the network information
|
|
|
177 |
*
|
|
|
178 |
* @return void
|
|
|
179 |
*/
|
|
|
180 |
private function _buildNetwork()
|
|
|
181 |
{
|
|
|
182 |
$hideDevices = array();
|
|
|
183 |
$network = $this->_xml->addChild('Network');
|
|
|
184 |
if (defined('PSI_HIDE_NETWORK_INTERFACE')) {
|
|
|
185 |
if (is_string(PSI_HIDE_NETWORK_INTERFACE)) {
|
|
|
186 |
if (preg_match(ARRAY_EXP, PSI_HIDE_NETWORK_INTERFACE)) {
|
|
|
187 |
$hideDevices = eval(PSI_HIDE_NETWORK_INTERFACE);
|
|
|
188 |
} else {
|
|
|
189 |
$hideDevices = array(PSI_HIDE_NETWORK_INTERFACE);
|
|
|
190 |
}
|
|
|
191 |
} elseif (PSI_HIDE_NETWORK_INTERFACE === true) {
|
|
|
192 |
return;
|
|
|
193 |
}
|
|
|
194 |
}
|
|
|
195 |
foreach ($this->_sys->getNetDevices() as $dev) {
|
3037 |
rexy |
196 |
if (defined('PSI_HIDE_NETWORK_INTERFACE_REGEX') && PSI_HIDE_NETWORK_INTERFACE_REGEX) {
|
|
|
197 |
$hide = false;
|
|
|
198 |
foreach ($hideDevices as $hidedev) {
|
|
|
199 |
if (preg_match('/^'.$hidedev.'$/', trim($dev->getName()))) {
|
|
|
200 |
$hide = true;
|
|
|
201 |
break;
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
} else {
|
|
|
205 |
$hide =in_array(trim($dev->getName()), $hideDevices);
|
|
|
206 |
}
|
|
|
207 |
if (!$hide) {
|
2770 |
rexy |
208 |
$device = $network->addChild('NetDevice');
|
|
|
209 |
$device->addAttribute('Name', $dev->getName());
|
3100 |
rexy |
210 |
$rxbytes = $dev->getRxBytes();
|
|
|
211 |
$txbytes = $dev->getTxBytes();
|
|
|
212 |
$device->addAttribute('RxBytes', $rxbytes);
|
|
|
213 |
$device->addAttribute('TxBytes', $txbytes);
|
|
|
214 |
if (defined('PSI_SHOW_NETWORK_ACTIVE_SPEED') && PSI_SHOW_NETWORK_ACTIVE_SPEED) {
|
|
|
215 |
if (($rxbytes == 0) && ($txbytes == 0)) {
|
|
|
216 |
$rxrate = $dev->getRxRate();
|
|
|
217 |
$txrate = $dev->getTxRate();
|
|
|
218 |
if (($rxrate !== null) || ($txrate !== null)) {
|
|
|
219 |
if ($rxrate !== null) {
|
|
|
220 |
$device->addAttribute('RxRate', $rxrate);
|
|
|
221 |
} else {
|
|
|
222 |
$device->addAttribute('RxRate', 0);
|
|
|
223 |
}
|
|
|
224 |
if ($txrate !== null) {
|
|
|
225 |
$device->addAttribute('TxRate', $txrate);
|
|
|
226 |
} else {
|
|
|
227 |
$device->addAttribute('TxRate', 0);
|
|
|
228 |
}
|
|
|
229 |
}
|
|
|
230 |
}
|
|
|
231 |
}
|
2770 |
rexy |
232 |
$device->addAttribute('Err', $dev->getErrors());
|
|
|
233 |
$device->addAttribute('Drops', $dev->getDrops());
|
3179 |
rexy |
234 |
if (defined('PSI_SHOW_NETWORK_BRIDGE') && PSI_SHOW_NETWORK_BRIDGE && $dev->getBridge()) {
|
|
|
235 |
$device->addAttribute('Bridge', $dev->getBridge());
|
|
|
236 |
}
|
|
|
237 |
if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS && $dev->getInfo()) {
|
2770 |
rexy |
238 |
$device->addAttribute('Info', $dev->getInfo());
|
3179 |
rexy |
239 |
}
|
2770 |
rexy |
240 |
}
|
|
|
241 |
}
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
/**
|
|
|
245 |
* generate the hardware information
|
|
|
246 |
*
|
|
|
247 |
* @return void
|
|
|
248 |
*/
|
|
|
249 |
private function _buildHardware()
|
|
|
250 |
{
|
|
|
251 |
$hardware = $this->_xml->addChild('Hardware');
|
3037 |
rexy |
252 |
if (($machine = $this->_sys->getMachine()) != "") {
|
3100 |
rexy |
253 |
$machine = trim(preg_replace("/\s+/", " ", preg_replace("/^\s*[\/,]*/", "", preg_replace("/\/\s+,/", "/,", $machine)))); // remove leading slash or comma and unnecessary spaces
|
|
|
254 |
if (preg_match('/, BIOS .*$/', $machine, $mbuf, PREG_OFFSET_CAPTURE)) {
|
|
|
255 |
$comapos = $mbuf[0][1];
|
|
|
256 |
$endstr = $mbuf[0][0];
|
|
|
257 |
$offset = 0;
|
|
|
258 |
while (($offset < $comapos)
|
|
|
259 |
&& (($slashpos = strpos($machine, "/", $offset)) !== false)
|
|
|
260 |
&& ($slashpos < $comapos)) {
|
|
|
261 |
$len1 = $comapos - $slashpos - 1;
|
|
|
262 |
$str1 = substr($machine, $slashpos + 1, $len1);
|
|
|
263 |
$begstr = substr($machine, 0, $slashpos);
|
|
|
264 |
if ($len1 > 0) { // no empty
|
|
|
265 |
$str2 = substr($begstr, -$len1 - 1);
|
|
|
266 |
} else {
|
|
|
267 |
$str2 = " ";
|
|
|
268 |
}
|
|
|
269 |
if ((" ".$str1 === $str2) || ($str1 === $begstr)) { // duplicates
|
|
|
270 |
$machine = $begstr.$endstr;
|
|
|
271 |
break;
|
|
|
272 |
}
|
|
|
273 |
$offset = $slashpos + 1;
|
|
|
274 |
}
|
3037 |
rexy |
275 |
}
|
|
|
276 |
|
|
|
277 |
if ($machine != "") {
|
|
|
278 |
$hardware->addAttribute('Name', $machine);
|
|
|
279 |
}
|
2770 |
rexy |
280 |
}
|
3037 |
rexy |
281 |
|
|
|
282 |
if (defined('PSI_SHOW_VIRTUALIZER_INFO') && PSI_SHOW_VIRTUALIZER_INFO) {
|
|
|
283 |
$virt = $this->_sys->getVirtualizer();
|
|
|
284 |
$first = true;
|
|
|
285 |
$virtstring = "";
|
|
|
286 |
foreach ($virt as $virtkey=>$virtvalue) if ($virtvalue) {
|
|
|
287 |
if ($first) {
|
|
|
288 |
$first = false;
|
|
|
289 |
} else {
|
|
|
290 |
$virtstring .= ", ";
|
|
|
291 |
}
|
|
|
292 |
if ($virtkey === 'microsoft') {
|
|
|
293 |
$virtstring .= 'hyper-v';
|
|
|
294 |
} elseif ($virtkey === 'kvm') {
|
|
|
295 |
$virtstring .= 'qemu-kvm';
|
|
|
296 |
} elseif ($virtkey === 'oracle') {
|
|
|
297 |
$virtstring .= 'virtualbox';
|
|
|
298 |
} elseif ($virtkey === 'zvm') {
|
|
|
299 |
$virtstring .= 'z/vm';
|
3179 |
rexy |
300 |
} elseif ($virtkey === 'sre') {
|
|
|
301 |
$virtstring .= 'lmhs sre';
|
3037 |
rexy |
302 |
} else {
|
|
|
303 |
$virtstring .= $virtkey;
|
|
|
304 |
}
|
|
|
305 |
}
|
|
|
306 |
if ($virtstring !== "") {
|
|
|
307 |
$hardware->addAttribute('Virtualizer', $virtstring);
|
|
|
308 |
}
|
|
|
309 |
}
|
|
|
310 |
|
2976 |
rexy |
311 |
$cpu = null;
|
|
|
312 |
$vendortab = null;
|
|
|
313 |
foreach ($this->_sys->getCpus() as $oneCpu) {
|
|
|
314 |
if ($cpu === null) $cpu = $hardware->addChild('CPU');
|
|
|
315 |
$tmp = $cpu->addChild('CpuCore');
|
|
|
316 |
$tmp->addAttribute('Model', $oneCpu->getModel());
|
3037 |
rexy |
317 |
if ($oneCpu->getVoltage() > 0) {
|
|
|
318 |
$tmp->addAttribute('Voltage', $oneCpu->getVoltage());
|
2976 |
rexy |
319 |
}
|
3037 |
rexy |
320 |
if ($oneCpu->getCpuSpeed() > 0) {
|
|
|
321 |
$tmp->addAttribute('CpuSpeed', $oneCpu->getCpuSpeed());
|
|
|
322 |
} elseif ($oneCpu->getCpuSpeed() == -1) {
|
|
|
323 |
$tmp->addAttribute('CpuSpeed', 0); // core stopped
|
|
|
324 |
}
|
|
|
325 |
if ($oneCpu->getCpuSpeedMax() > 0) {
|
2976 |
rexy |
326 |
$tmp->addAttribute('CpuSpeedMax', $oneCpu->getCpuSpeedMax());
|
|
|
327 |
}
|
3037 |
rexy |
328 |
if ($oneCpu->getCpuSpeedMin() > 0) {
|
2976 |
rexy |
329 |
$tmp->addAttribute('CpuSpeedMin', $oneCpu->getCpuSpeedMin());
|
|
|
330 |
}
|
|
|
331 |
/*
|
|
|
332 |
if ($oneCpu->getTemp() !== null) {
|
|
|
333 |
$tmp->addAttribute('CpuTemp', $oneCpu->getTemp());
|
|
|
334 |
}
|
|
|
335 |
*/
|
|
|
336 |
if ($oneCpu->getBusSpeed() !== null) {
|
|
|
337 |
$tmp->addAttribute('BusSpeed', $oneCpu->getBusSpeed());
|
|
|
338 |
}
|
|
|
339 |
if ($oneCpu->getCache() !== null) {
|
|
|
340 |
$tmp->addAttribute('Cache', $oneCpu->getCache());
|
|
|
341 |
}
|
|
|
342 |
if ($oneCpu->getVirt() !== null) {
|
|
|
343 |
$tmp->addAttribute('Virt', $oneCpu->getVirt());
|
|
|
344 |
}
|
|
|
345 |
if ($oneCpu->getVendorId() !== null) {
|
|
|
346 |
if ($vendortab === null) $vendortab = @parse_ini_file(PSI_APP_ROOT."/data/cpus.ini", true);
|
3037 |
rexy |
347 |
$shortvendorid = $oneCpu->getVendorId();
|
2976 |
rexy |
348 |
if ($vendortab && ($shortvendorid != "") && isset($vendortab['manufacturer'][$shortvendorid])) {
|
|
|
349 |
$tmp->addAttribute('Manufacturer', $vendortab['manufacturer'][$shortvendorid]);
|
|
|
350 |
}
|
|
|
351 |
}
|
|
|
352 |
if ($oneCpu->getBogomips() !== null) {
|
|
|
353 |
$tmp->addAttribute('Bogomips', $oneCpu->getBogomips());
|
|
|
354 |
}
|
|
|
355 |
if ($oneCpu->getLoad() !== null) {
|
|
|
356 |
$tmp->addAttribute('Load', $oneCpu->getLoad());
|
|
|
357 |
}
|
|
|
358 |
}
|
|
|
359 |
$mem = null;
|
|
|
360 |
foreach (System::removeDupsAndCount($this->_sys->getMemDevices()) as $dev) {
|
|
|
361 |
if ($mem === null) $mem = $hardware->addChild('MEM');
|
|
|
362 |
$tmp = $mem->addChild('Chip');
|
2770 |
rexy |
363 |
$tmp->addAttribute('Name', $dev->getName());
|
|
|
364 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
2976 |
rexy |
365 |
if ($dev->getCapacity() !== null) {
|
|
|
366 |
$tmp->addAttribute('Capacity', $dev->getCapacity());
|
|
|
367 |
}
|
2770 |
rexy |
368 |
if ($dev->getManufacturer() !== null) {
|
|
|
369 |
$tmp->addAttribute('Manufacturer', $dev->getManufacturer());
|
|
|
370 |
}
|
|
|
371 |
if ($dev->getProduct() !== null) {
|
|
|
372 |
$tmp->addAttribute('Product', $dev->getProduct());
|
|
|
373 |
}
|
2976 |
rexy |
374 |
if ($dev->getSpeed() !== null) {
|
|
|
375 |
$tmp->addAttribute('Speed', $dev->getSpeed());
|
|
|
376 |
}
|
|
|
377 |
if ($dev->getVoltage() !== null) {
|
|
|
378 |
$tmp->addAttribute('Voltage', $dev->getVoltage());
|
|
|
379 |
}
|
|
|
380 |
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
|
|
|
381 |
$tmp->addAttribute('Serial', $dev->getSerial());
|
|
|
382 |
}
|
2770 |
rexy |
383 |
}
|
|
|
384 |
if ($dev->getCount() > 1) {
|
|
|
385 |
$tmp->addAttribute('Count', $dev->getCount());
|
|
|
386 |
}
|
|
|
387 |
}
|
2976 |
rexy |
388 |
$pci = null;
|
|
|
389 |
foreach (System::removeDupsAndCount($this->_sys->getPciDevices()) as $dev) {
|
|
|
390 |
if ($pci === null) $pci = $hardware->addChild('PCI');
|
|
|
391 |
$tmp = $pci->addChild('Device');
|
2770 |
rexy |
392 |
$tmp->addAttribute('Name', $dev->getName());
|
|
|
393 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
|
|
394 |
if ($dev->getManufacturer() !== null) {
|
|
|
395 |
$tmp->addAttribute('Manufacturer', $dev->getManufacturer());
|
|
|
396 |
}
|
|
|
397 |
if ($dev->getProduct() !== null) {
|
|
|
398 |
$tmp->addAttribute('Product', $dev->getProduct());
|
|
|
399 |
}
|
|
|
400 |
}
|
|
|
401 |
if ($dev->getCount() > 1) {
|
|
|
402 |
$tmp->addAttribute('Count', $dev->getCount());
|
|
|
403 |
}
|
|
|
404 |
}
|
|
|
405 |
$ide = null;
|
|
|
406 |
foreach (System::removeDupsAndCount($this->_sys->getIdeDevices()) as $dev) {
|
|
|
407 |
if ($ide === null) $ide = $hardware->addChild('IDE');
|
|
|
408 |
$tmp = $ide->addChild('Device');
|
|
|
409 |
$tmp->addAttribute('Name', $dev->getName());
|
|
|
410 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
|
|
411 |
if ($dev->getCapacity() !== null) {
|
|
|
412 |
$tmp->addAttribute('Capacity', $dev->getCapacity());
|
|
|
413 |
}
|
|
|
414 |
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
|
|
|
415 |
$tmp->addAttribute('Serial', $dev->getSerial());
|
|
|
416 |
}
|
|
|
417 |
}
|
|
|
418 |
if ($dev->getCount() > 1) {
|
|
|
419 |
$tmp->addAttribute('Count', $dev->getCount());
|
|
|
420 |
}
|
|
|
421 |
}
|
|
|
422 |
$scsi = null;
|
|
|
423 |
foreach (System::removeDupsAndCount($this->_sys->getScsiDevices()) as $dev) {
|
|
|
424 |
if ($scsi === null) $scsi = $hardware->addChild('SCSI');
|
|
|
425 |
$tmp = $scsi->addChild('Device');
|
|
|
426 |
$tmp->addAttribute('Name', $dev->getName());
|
|
|
427 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
|
|
428 |
if ($dev->getCapacity() !== null) {
|
|
|
429 |
$tmp->addAttribute('Capacity', $dev->getCapacity());
|
|
|
430 |
}
|
|
|
431 |
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
|
|
|
432 |
$tmp->addAttribute('Serial', $dev->getSerial());
|
|
|
433 |
}
|
|
|
434 |
}
|
|
|
435 |
if ($dev->getCount() > 1) {
|
|
|
436 |
$tmp->addAttribute('Count', $dev->getCount());
|
|
|
437 |
}
|
|
|
438 |
}
|
|
|
439 |
$nvme = null;
|
|
|
440 |
foreach (System::removeDupsAndCount($this->_sys->getNvmeDevices()) as $dev) {
|
|
|
441 |
if ($nvme === null) $nvme = $hardware->addChild('NVMe');
|
|
|
442 |
$tmp = $nvme->addChild('Device');
|
|
|
443 |
$tmp->addAttribute('Name', $dev->getName());
|
|
|
444 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
|
|
445 |
if ($dev->getCapacity() !== null) {
|
|
|
446 |
$tmp->addAttribute('Capacity', $dev->getCapacity());
|
|
|
447 |
}
|
|
|
448 |
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
|
|
|
449 |
$tmp->addAttribute('Serial', $dev->getSerial());
|
|
|
450 |
}
|
|
|
451 |
}
|
|
|
452 |
if ($dev->getCount() > 1) {
|
|
|
453 |
$tmp->addAttribute('Count', $dev->getCount());
|
|
|
454 |
}
|
|
|
455 |
}
|
2976 |
rexy |
456 |
$usb = null;
|
|
|
457 |
foreach (System::removeDupsAndCount($this->_sys->getUsbDevices()) as $dev) {
|
|
|
458 |
if ($usb === null) $usb = $hardware->addChild('USB');
|
|
|
459 |
$tmp = $usb->addChild('Device');
|
|
|
460 |
$tmp->addAttribute('Name', $dev->getName());
|
|
|
461 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
|
|
462 |
if ($dev->getManufacturer() !== null) {
|
|
|
463 |
$tmp->addAttribute('Manufacturer', $dev->getManufacturer());
|
|
|
464 |
}
|
|
|
465 |
if ($dev->getProduct() !== null) {
|
|
|
466 |
$tmp->addAttribute('Product', $dev->getProduct());
|
|
|
467 |
}
|
|
|
468 |
if ($dev->getSpeed() !== null) {
|
|
|
469 |
$tmp->addAttribute('Speed', $dev->getSpeed());
|
|
|
470 |
}
|
|
|
471 |
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
|
|
|
472 |
$tmp->addAttribute('Serial', $dev->getSerial());
|
|
|
473 |
}
|
|
|
474 |
}
|
|
|
475 |
if ($dev->getCount() > 1) {
|
|
|
476 |
$tmp->addAttribute('Count', $dev->getCount());
|
|
|
477 |
}
|
|
|
478 |
}
|
2770 |
rexy |
479 |
$tb = null;
|
|
|
480 |
foreach (System::removeDupsAndCount($this->_sys->getTbDevices()) as $dev) {
|
|
|
481 |
if ($tb === null) $tb = $hardware->addChild('TB');
|
|
|
482 |
$tmp = $tb->addChild('Device');
|
|
|
483 |
$tmp->addAttribute('Name', $dev->getName());
|
|
|
484 |
if ($dev->getCount() > 1) {
|
|
|
485 |
$tmp->addAttribute('Count', $dev->getCount());
|
|
|
486 |
}
|
|
|
487 |
}
|
|
|
488 |
$i2c = null;
|
|
|
489 |
foreach (System::removeDupsAndCount($this->_sys->getI2cDevices()) as $dev) {
|
|
|
490 |
if ($i2c === null) $i2c = $hardware->addChild('I2C');
|
|
|
491 |
$tmp = $i2c->addChild('Device');
|
|
|
492 |
$tmp->addAttribute('Name', $dev->getName());
|
|
|
493 |
if ($dev->getCount() > 1) {
|
|
|
494 |
$tmp->addAttribute('Count', $dev->getCount());
|
|
|
495 |
}
|
|
|
496 |
}
|
|
|
497 |
}
|
|
|
498 |
|
|
|
499 |
/**
|
|
|
500 |
* generate the memory information
|
|
|
501 |
*
|
|
|
502 |
* @return void
|
|
|
503 |
*/
|
|
|
504 |
private function _buildMemory()
|
|
|
505 |
{
|
|
|
506 |
$memory = $this->_xml->addChild('Memory');
|
|
|
507 |
$memory->addAttribute('Free', $this->_sys->getMemFree());
|
|
|
508 |
$memory->addAttribute('Used', $this->_sys->getMemUsed());
|
|
|
509 |
$memory->addAttribute('Total', $this->_sys->getMemTotal());
|
|
|
510 |
$memory->addAttribute('Percent', $this->_sys->getMemPercentUsed());
|
|
|
511 |
if (($this->_sys->getMemApplication() !== null) || ($this->_sys->getMemBuffer() !== null) || ($this->_sys->getMemCache() !== null)) {
|
|
|
512 |
$details = $memory->addChild('Details');
|
|
|
513 |
if ($this->_sys->getMemApplication() !== null) {
|
|
|
514 |
$details->addAttribute('App', $this->_sys->getMemApplication());
|
|
|
515 |
$details->addAttribute('AppPercent', $this->_sys->getMemPercentApplication());
|
|
|
516 |
}
|
|
|
517 |
if ($this->_sys->getMemBuffer() !== null) {
|
|
|
518 |
$details->addAttribute('Buffers', $this->_sys->getMemBuffer());
|
|
|
519 |
$details->addAttribute('BuffersPercent', $this->_sys->getMemPercentBuffer());
|
|
|
520 |
}
|
|
|
521 |
if ($this->_sys->getMemCache() !== null) {
|
|
|
522 |
$details->addAttribute('Cached', $this->_sys->getMemCache());
|
|
|
523 |
$details->addAttribute('CachedPercent', $this->_sys->getMemPercentCache());
|
|
|
524 |
}
|
|
|
525 |
}
|
|
|
526 |
if (count($this->_sys->getSwapDevices()) > 0) {
|
|
|
527 |
$swap = $memory->addChild('Swap');
|
|
|
528 |
$swap->addAttribute('Free', $this->_sys->getSwapFree());
|
|
|
529 |
$swap->addAttribute('Used', $this->_sys->getSwapUsed());
|
|
|
530 |
$swap->addAttribute('Total', $this->_sys->getSwapTotal());
|
|
|
531 |
$swap->addAttribute('Percent', $this->_sys->getSwapPercentUsed());
|
|
|
532 |
$i = 1;
|
|
|
533 |
foreach ($this->_sys->getSwapDevices() as $dev) {
|
|
|
534 |
$swapMount = $swap->addChild('Mount');
|
|
|
535 |
$this->_fillDevice($swapMount, $dev, $i++);
|
|
|
536 |
}
|
|
|
537 |
}
|
|
|
538 |
}
|
|
|
539 |
|
|
|
540 |
/**
|
|
|
541 |
* fill a xml element with atrributes from a disk device
|
|
|
542 |
*
|
|
|
543 |
* @param SimpleXmlExtended $mount Xml-Element
|
|
|
544 |
* @param DiskDevice $dev DiskDevice
|
3037 |
rexy |
545 |
* @param int $i counter
|
2770 |
rexy |
546 |
*
|
3037 |
rexy |
547 |
* @return void
|
2770 |
rexy |
548 |
*/
|
|
|
549 |
private function _fillDevice(SimpleXMLExtended $mount, DiskDevice $dev, $i)
|
|
|
550 |
{
|
|
|
551 |
$mount->addAttribute('MountPointID', $i);
|
2976 |
rexy |
552 |
if ($dev->getFsType()!=="") {
|
|
|
553 |
$mount->addAttribute('FSType', $dev->getFsType());
|
|
|
554 |
}
|
2770 |
rexy |
555 |
$mount->addAttribute('Name', $dev->getName());
|
|
|
556 |
$mount->addAttribute('Free', sprintf("%.0f", $dev->getFree()));
|
|
|
557 |
$mount->addAttribute('Used', sprintf("%.0f", $dev->getUsed()));
|
|
|
558 |
$mount->addAttribute('Total', sprintf("%.0f", $dev->getTotal()));
|
2976 |
rexy |
559 |
$percentUsed = $dev->getPercentUsed();
|
|
|
560 |
$mount->addAttribute('Percent', $percentUsed);
|
|
|
561 |
if ($dev->getPercentInodesUsed() !== null) {
|
|
|
562 |
$mount->addAttribute('Inodes', $dev->getPercentInodesUsed());
|
|
|
563 |
}
|
2770 |
rexy |
564 |
if ($dev->getIgnore() > 0) $mount->addAttribute('Ignore', $dev->getIgnore());
|
3037 |
rexy |
565 |
if (PSI_SHOW_MOUNT_OPTION) {
|
2770 |
rexy |
566 |
if ($dev->getOptions() !== null) {
|
|
|
567 |
$mount->addAttribute('MountOptions', preg_replace("/,/", ", ", $dev->getOptions()));
|
|
|
568 |
}
|
|
|
569 |
}
|
3037 |
rexy |
570 |
if (PSI_SHOW_MOUNT_POINT && ($dev->getMountPoint() !== null)) {
|
2770 |
rexy |
571 |
$mount->addAttribute('MountPoint', $dev->getMountPoint());
|
|
|
572 |
}
|
|
|
573 |
}
|
|
|
574 |
|
|
|
575 |
/**
|
|
|
576 |
* generate the filesysteminformation
|
|
|
577 |
*
|
|
|
578 |
* @return void
|
|
|
579 |
*/
|
|
|
580 |
private function _buildFilesystems()
|
|
|
581 |
{
|
2976 |
rexy |
582 |
$hideMounts = $hideFstypes = $hideDisks = $ignoreFree = $ignoreTotal = $ignoreUsage = $ignoreThreshold = array();
|
2770 |
rexy |
583 |
if (defined('PSI_HIDE_MOUNTS') && is_string(PSI_HIDE_MOUNTS)) {
|
|
|
584 |
if (preg_match(ARRAY_EXP, PSI_HIDE_MOUNTS)) {
|
|
|
585 |
$hideMounts = eval(PSI_HIDE_MOUNTS);
|
|
|
586 |
} else {
|
|
|
587 |
$hideMounts = array(PSI_HIDE_MOUNTS);
|
|
|
588 |
}
|
|
|
589 |
}
|
|
|
590 |
if (defined('PSI_HIDE_FS_TYPES') && is_string(PSI_HIDE_FS_TYPES)) {
|
|
|
591 |
if (preg_match(ARRAY_EXP, PSI_HIDE_FS_TYPES)) {
|
|
|
592 |
$hideFstypes = eval(PSI_HIDE_FS_TYPES);
|
|
|
593 |
} else {
|
|
|
594 |
$hideFstypes = array(PSI_HIDE_FS_TYPES);
|
|
|
595 |
}
|
|
|
596 |
}
|
|
|
597 |
if (defined('PSI_HIDE_DISKS')) {
|
|
|
598 |
if (is_string(PSI_HIDE_DISKS)) {
|
|
|
599 |
if (preg_match(ARRAY_EXP, PSI_HIDE_DISKS)) {
|
|
|
600 |
$hideDisks = eval(PSI_HIDE_DISKS);
|
|
|
601 |
} else {
|
|
|
602 |
$hideDisks = array(PSI_HIDE_DISKS);
|
|
|
603 |
}
|
|
|
604 |
} elseif (PSI_HIDE_DISKS === true) {
|
|
|
605 |
return;
|
|
|
606 |
}
|
|
|
607 |
}
|
|
|
608 |
if (defined('PSI_IGNORE_FREE') && is_string(PSI_IGNORE_FREE)) {
|
|
|
609 |
if (preg_match(ARRAY_EXP, PSI_IGNORE_FREE)) {
|
|
|
610 |
$ignoreFree = eval(PSI_IGNORE_FREE);
|
|
|
611 |
} else {
|
|
|
612 |
$ignoreFree = array(PSI_IGNORE_FREE);
|
|
|
613 |
}
|
|
|
614 |
}
|
2976 |
rexy |
615 |
if (defined('PSI_IGNORE_TOTAL') && is_string(PSI_IGNORE_TOTAL)) {
|
|
|
616 |
if (preg_match(ARRAY_EXP, PSI_IGNORE_TOTAL)) {
|
|
|
617 |
$ignoreTotal = eval(PSI_IGNORE_TOTAL);
|
|
|
618 |
} else {
|
|
|
619 |
$ignoreTotal = array(PSI_IGNORE_TOTAL);
|
|
|
620 |
}
|
|
|
621 |
}
|
2770 |
rexy |
622 |
if (defined('PSI_IGNORE_USAGE') && is_string(PSI_IGNORE_USAGE)) {
|
|
|
623 |
if (preg_match(ARRAY_EXP, PSI_IGNORE_USAGE)) {
|
|
|
624 |
$ignoreUsage = eval(PSI_IGNORE_USAGE);
|
|
|
625 |
} else {
|
|
|
626 |
$ignoreUsage = array(PSI_IGNORE_USAGE);
|
|
|
627 |
}
|
|
|
628 |
}
|
|
|
629 |
if (defined('PSI_IGNORE_THRESHOLD_FS_TYPES') && is_string(PSI_IGNORE_THRESHOLD_FS_TYPES)) {
|
|
|
630 |
if (preg_match(ARRAY_EXP, PSI_IGNORE_THRESHOLD_FS_TYPES)) {
|
|
|
631 |
$ignoreThreshold = eval(PSI_IGNORE_THRESHOLD_FS_TYPES);
|
|
|
632 |
} else {
|
|
|
633 |
$ignoreThreshold = array(PSI_IGNORE_THRESHOLD_FS_TYPES);
|
|
|
634 |
}
|
|
|
635 |
}
|
|
|
636 |
$fs = $this->_xml->addChild('FileSystem');
|
3037 |
rexy |
637 |
$i = 1;
|
2770 |
rexy |
638 |
foreach ($this->_sys->getDiskDevices() as $disk) {
|
|
|
639 |
if (!in_array($disk->getMountPoint(), $hideMounts, true) && !in_array($disk->getFsType(), $hideFstypes, true) && !in_array($disk->getName(), $hideDisks, true)) {
|
|
|
640 |
$mount = $fs->addChild('Mount');
|
|
|
641 |
if (in_array($disk->getFsType(), $ignoreThreshold, true)) {
|
2976 |
rexy |
642 |
$disk->setIgnore(4);
|
|
|
643 |
} elseif (in_array($disk->getMountPoint(), $ignoreUsage, true)) {
|
2770 |
rexy |
644 |
$disk->setIgnore(3);
|
2976 |
rexy |
645 |
} elseif (in_array($disk->getMountPoint(), $ignoreTotal, true)) {
|
2770 |
rexy |
646 |
$disk->setIgnore(2);
|
|
|
647 |
} elseif (in_array($disk->getMountPoint(), $ignoreFree, true)) {
|
|
|
648 |
$disk->setIgnore(1);
|
|
|
649 |
}
|
|
|
650 |
$this->_fillDevice($mount, $disk, $i++);
|
|
|
651 |
}
|
|
|
652 |
}
|
|
|
653 |
}
|
|
|
654 |
|
|
|
655 |
/**
|
|
|
656 |
* generate the motherboard information
|
|
|
657 |
*
|
|
|
658 |
* @return void
|
|
|
659 |
*/
|
|
|
660 |
private function _buildMbinfo()
|
|
|
661 |
{
|
|
|
662 |
$mbinfo = $this->_xml->addChild('MBInfo');
|
|
|
663 |
$temp = $fan = $volt = $power = $current = $other = null;
|
|
|
664 |
|
|
|
665 |
if (sizeof(unserialize(PSI_MBINFO))>0) {
|
|
|
666 |
foreach (unserialize(PSI_MBINFO) as $mbinfoclass) {
|
|
|
667 |
$mbinfo_data = new $mbinfoclass();
|
|
|
668 |
$mbinfo_detail = $mbinfo_data->getMBInfo();
|
|
|
669 |
|
|
|
670 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='temperature') foreach ($mbinfo_detail->getMbTemp() as $dev) {
|
|
|
671 |
if ($temp == null) {
|
|
|
672 |
$temp = $mbinfo->addChild('Temperature');
|
|
|
673 |
}
|
|
|
674 |
$item = $temp->addChild('Item');
|
|
|
675 |
$item->addAttribute('Label', $dev->getName());
|
|
|
676 |
$item->addAttribute('Value', $dev->getValue());
|
3037 |
rexy |
677 |
$alarm = false;
|
2770 |
rexy |
678 |
if ($dev->getMax() !== null) {
|
|
|
679 |
$item->addAttribute('Max', $dev->getMax());
|
3037 |
rexy |
680 |
$alarm = true;
|
2770 |
rexy |
681 |
}
|
3037 |
rexy |
682 |
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
|
|
|
683 |
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
|
2770 |
rexy |
684 |
}
|
|
|
685 |
}
|
|
|
686 |
|
|
|
687 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='fans') foreach ($mbinfo_detail->getMbFan() as $dev) {
|
|
|
688 |
if ($fan == null) {
|
|
|
689 |
$fan = $mbinfo->addChild('Fans');
|
|
|
690 |
}
|
|
|
691 |
$item = $fan->addChild('Item');
|
|
|
692 |
$item->addAttribute('Label', $dev->getName());
|
|
|
693 |
$item->addAttribute('Value', $dev->getValue());
|
3037 |
rexy |
694 |
$alarm = false;
|
2770 |
rexy |
695 |
if ($dev->getMin() !== null) {
|
|
|
696 |
$item->addAttribute('Min', $dev->getMin());
|
3037 |
rexy |
697 |
$alarm = true;
|
2770 |
rexy |
698 |
}
|
2976 |
rexy |
699 |
if ($dev->getUnit() !== "") {
|
|
|
700 |
$item->addAttribute('Unit', $dev->getUnit());
|
|
|
701 |
}
|
3037 |
rexy |
702 |
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
|
|
|
703 |
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
|
2770 |
rexy |
704 |
}
|
|
|
705 |
}
|
|
|
706 |
|
|
|
707 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='voltage') foreach ($mbinfo_detail->getMbVolt() as $dev) {
|
|
|
708 |
if ($volt == null) {
|
|
|
709 |
$volt = $mbinfo->addChild('Voltage');
|
|
|
710 |
}
|
|
|
711 |
$item = $volt->addChild('Item');
|
|
|
712 |
$item->addAttribute('Label', $dev->getName());
|
|
|
713 |
$item->addAttribute('Value', $dev->getValue());
|
3037 |
rexy |
714 |
$alarm = false;
|
2976 |
rexy |
715 |
if (($dev->getMin() === null) || ($dev->getMin() != 0) || ($dev->getMax() === null) || ($dev->getMax() != 0)) {
|
|
|
716 |
if ($dev->getMin() !== null) {
|
|
|
717 |
$item->addAttribute('Min', $dev->getMin());
|
3037 |
rexy |
718 |
$alarm = true;
|
2976 |
rexy |
719 |
}
|
|
|
720 |
if ($dev->getMax() !== null) {
|
|
|
721 |
$item->addAttribute('Max', $dev->getMax());
|
3037 |
rexy |
722 |
$alarm = true;
|
2976 |
rexy |
723 |
}
|
2770 |
rexy |
724 |
}
|
3037 |
rexy |
725 |
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
|
|
|
726 |
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
|
2770 |
rexy |
727 |
}
|
|
|
728 |
}
|
|
|
729 |
|
|
|
730 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='power') foreach ($mbinfo_detail->getMbPower() as $dev) {
|
|
|
731 |
if ($power == null) {
|
|
|
732 |
$power = $mbinfo->addChild('Power');
|
|
|
733 |
}
|
|
|
734 |
$item = $power->addChild('Item');
|
|
|
735 |
$item->addAttribute('Label', $dev->getName());
|
|
|
736 |
$item->addAttribute('Value', $dev->getValue());
|
3037 |
rexy |
737 |
$alarm = false;
|
2770 |
rexy |
738 |
if ($dev->getMax() !== null) {
|
|
|
739 |
$item->addAttribute('Max', $dev->getMax());
|
3037 |
rexy |
740 |
$alarm = true;
|
2770 |
rexy |
741 |
}
|
3037 |
rexy |
742 |
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
|
|
|
743 |
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
|
2770 |
rexy |
744 |
}
|
|
|
745 |
}
|
|
|
746 |
|
|
|
747 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='current') foreach ($mbinfo_detail->getMbCurrent() as $dev) {
|
|
|
748 |
if ($current == null) {
|
|
|
749 |
$current = $mbinfo->addChild('Current');
|
|
|
750 |
}
|
|
|
751 |
$item = $current->addChild('Item');
|
|
|
752 |
$item->addAttribute('Label', $dev->getName());
|
|
|
753 |
$item->addAttribute('Value', $dev->getValue());
|
3037 |
rexy |
754 |
$alarm = false;
|
2976 |
rexy |
755 |
if (($dev->getMin() === null) || ($dev->getMin() != 0) || ($dev->getMax() === null) || ($dev->getMax() != 0)) {
|
|
|
756 |
if ($dev->getMin() !== null) {
|
|
|
757 |
$item->addAttribute('Min', $dev->getMin());
|
3037 |
rexy |
758 |
$alarm = true;
|
2976 |
rexy |
759 |
}
|
|
|
760 |
if ($dev->getMax() !== null) {
|
|
|
761 |
$item->addAttribute('Max', $dev->getMax());
|
3037 |
rexy |
762 |
$alarm = true;
|
2976 |
rexy |
763 |
}
|
2770 |
rexy |
764 |
}
|
3037 |
rexy |
765 |
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
|
|
|
766 |
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
|
2770 |
rexy |
767 |
}
|
|
|
768 |
}
|
|
|
769 |
|
|
|
770 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='other') foreach ($mbinfo_detail->getMbOther() as $dev) {
|
|
|
771 |
if ($other == null) {
|
|
|
772 |
$other = $mbinfo->addChild('Other');
|
|
|
773 |
}
|
|
|
774 |
$item = $other->addChild('Item');
|
|
|
775 |
$item->addAttribute('Label', $dev->getName());
|
|
|
776 |
$item->addAttribute('Value', $dev->getValue());
|
2976 |
rexy |
777 |
if ($dev->getUnit() !== "") {
|
|
|
778 |
$item->addAttribute('Unit', $dev->getUnit());
|
|
|
779 |
}
|
2770 |
rexy |
780 |
if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") {
|
3037 |
rexy |
781 |
$item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
|
2770 |
rexy |
782 |
}
|
|
|
783 |
}
|
|
|
784 |
}
|
|
|
785 |
}
|
|
|
786 |
}
|
|
|
787 |
|
|
|
788 |
/**
|
|
|
789 |
* generate the ups information
|
|
|
790 |
*
|
|
|
791 |
* @return void
|
|
|
792 |
*/
|
|
|
793 |
private function _buildUpsinfo()
|
|
|
794 |
{
|
|
|
795 |
$upsinfo = $this->_xml->addChild('UPSInfo');
|
3037 |
rexy |
796 |
if (!defined('PSI_EMU_HOSTNAME') && defined('PSI_UPS_APCUPSD_CGI_ENABLE') && PSI_UPS_APCUPSD_CGI_ENABLE) {
|
2770 |
rexy |
797 |
$upsinfo->addAttribute('ApcupsdCgiLinks', true);
|
|
|
798 |
}
|
|
|
799 |
if (sizeof(unserialize(PSI_UPSINFO))>0) {
|
|
|
800 |
foreach (unserialize(PSI_UPSINFO) as $upsinfoclass) {
|
|
|
801 |
$upsinfo_data = new $upsinfoclass();
|
|
|
802 |
$upsinfo_detail = $upsinfo_data->getUPSInfo();
|
|
|
803 |
foreach ($upsinfo_detail->getUpsDevices() as $ups) {
|
|
|
804 |
$item = $upsinfo->addChild('UPS');
|
|
|
805 |
$item->addAttribute('Name', $ups->getName());
|
|
|
806 |
if ($ups->getModel() !== "") {
|
|
|
807 |
$item->addAttribute('Model', $ups->getModel());
|
|
|
808 |
}
|
|
|
809 |
if ($ups->getMode() !== "") {
|
|
|
810 |
$item->addAttribute('Mode', $ups->getMode());
|
|
|
811 |
}
|
|
|
812 |
if ($ups->getStartTime() !== "") {
|
|
|
813 |
$item->addAttribute('StartTime', $ups->getStartTime());
|
|
|
814 |
}
|
|
|
815 |
$item->addAttribute('Status', $ups->getStatus());
|
3037 |
rexy |
816 |
if ($ups->getBeeperStatus() !== null) {
|
|
|
817 |
$item->addAttribute('BeeperStatus', $ups->getBeeperStatus());
|
|
|
818 |
}
|
2770 |
rexy |
819 |
if ($ups->getTemperatur() !== null) {
|
|
|
820 |
$item->addAttribute('Temperature', $ups->getTemperatur());
|
|
|
821 |
}
|
|
|
822 |
if ($ups->getOutages() !== null) {
|
|
|
823 |
$item->addAttribute('OutagesCount', $ups->getOutages());
|
|
|
824 |
}
|
|
|
825 |
if ($ups->getLastOutage() !== null) {
|
|
|
826 |
$item->addAttribute('LastOutage', $ups->getLastOutage());
|
|
|
827 |
}
|
|
|
828 |
if ($ups->getLastOutageFinish() !== null) {
|
|
|
829 |
$item->addAttribute('LastOutageFinish', $ups->getLastOutageFinish());
|
|
|
830 |
}
|
|
|
831 |
if ($ups->getLineVoltage() !== null) {
|
|
|
832 |
$item->addAttribute('LineVoltage', $ups->getLineVoltage());
|
|
|
833 |
}
|
|
|
834 |
if ($ups->getLineFrequency() !== null) {
|
|
|
835 |
$item->addAttribute('LineFrequency', $ups->getLineFrequency());
|
|
|
836 |
}
|
|
|
837 |
if ($ups->getLoad() !== null) {
|
|
|
838 |
$item->addAttribute('LoadPercent', $ups->getLoad());
|
|
|
839 |
}
|
|
|
840 |
if ($ups->getBatteryDate() !== null) {
|
|
|
841 |
$item->addAttribute('BatteryDate', $ups->getBatteryDate());
|
|
|
842 |
}
|
|
|
843 |
if ($ups->getBatteryVoltage() !== null) {
|
|
|
844 |
$item->addAttribute('BatteryVoltage', $ups->getBatteryVoltage());
|
|
|
845 |
}
|
|
|
846 |
if ($ups->getBatterCharge() !== null) {
|
|
|
847 |
$item->addAttribute('BatteryChargePercent', $ups->getBatterCharge());
|
|
|
848 |
}
|
|
|
849 |
if ($ups->getTimeLeft() !== null) {
|
|
|
850 |
$item->addAttribute('TimeLeftMinutes', $ups->getTimeLeft());
|
|
|
851 |
}
|
|
|
852 |
}
|
|
|
853 |
}
|
|
|
854 |
}
|
|
|
855 |
}
|
|
|
856 |
|
|
|
857 |
/**
|
|
|
858 |
* generate the xml document
|
|
|
859 |
*
|
|
|
860 |
* @return void
|
|
|
861 |
*/
|
|
|
862 |
private function _buildXml()
|
|
|
863 |
{
|
2976 |
rexy |
864 |
if (($this->_plugin == '') || $this->_complete_request) {
|
2770 |
rexy |
865 |
if ($this->_sys === null) {
|
3037 |
rexy |
866 |
if (PSI_DEBUG) {
|
2770 |
rexy |
867 |
// unstable version check
|
|
|
868 |
if (!is_numeric(substr(PSI_VERSION, -1))) {
|
3037 |
rexy |
869 |
$this->_errors->addWarning("This is an unstable version of phpSysInfo, some things may not work correctly");
|
2770 |
rexy |
870 |
}
|
|
|
871 |
|
|
|
872 |
// Safe mode check
|
|
|
873 |
$safe_mode = @ini_get("safe_mode") ? true : false;
|
|
|
874 |
if ($safe_mode) {
|
|
|
875 |
$this->_errors->addError("WARN", "PhpSysInfo requires to set off 'safe_mode' in 'php.ini'");
|
|
|
876 |
}
|
|
|
877 |
// Include path check
|
|
|
878 |
$include_path = @ini_get("include_path");
|
|
|
879 |
if ($include_path && ($include_path!="")) {
|
|
|
880 |
$include_path = preg_replace("/(:)|(;)/", "\n", $include_path);
|
|
|
881 |
if (preg_match("/^\.$/m", $include_path)) {
|
|
|
882 |
$include_path = ".";
|
|
|
883 |
}
|
|
|
884 |
}
|
|
|
885 |
if ($include_path != ".") {
|
|
|
886 |
$this->_errors->addError("WARN", "PhpSysInfo requires '.' inside the 'include_path' in php.ini");
|
|
|
887 |
}
|
|
|
888 |
// popen mode check
|
3037 |
rexy |
889 |
if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
|
2770 |
rexy |
890 |
$this->_errors->addError("WARN", "Installed version of PHP does not support proc_open() function, popen() is used");
|
|
|
891 |
}
|
|
|
892 |
}
|
|
|
893 |
$this->_sys = $this->_sysinfo->getSys();
|
|
|
894 |
}
|
|
|
895 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='vitals') $this->_buildVitals();
|
|
|
896 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='network') $this->_buildNetwork();
|
|
|
897 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='hardware') $this->_buildHardware();
|
|
|
898 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='memory') $this->_buildMemory();
|
|
|
899 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='filesystem') $this->_buildFilesystems();
|
|
|
900 |
if (!$this->_sysinfo->getBlockName() || in_array($this->_sysinfo->getBlockName(), array('voltage','current','temperature','fans','power','other'))) $this->_buildMbinfo();
|
|
|
901 |
if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='ups') $this->_buildUpsinfo();
|
|
|
902 |
}
|
|
|
903 |
if (!$this->_sysinfo->getBlockName()) $this->_buildPlugins();
|
|
|
904 |
$this->_xml->combinexml($this->_errors->errorsAddToXML($this->_sysinfo->getEncoding()));
|
|
|
905 |
}
|
|
|
906 |
|
|
|
907 |
/**
|
|
|
908 |
* get the xml object
|
|
|
909 |
*
|
|
|
910 |
* @return SimpleXmlElement
|
|
|
911 |
*/
|
|
|
912 |
public function getXml()
|
|
|
913 |
{
|
|
|
914 |
$this->_buildXml();
|
|
|
915 |
|
|
|
916 |
return $this->_xml->getSimpleXmlElement();
|
|
|
917 |
}
|
|
|
918 |
|
|
|
919 |
/**
|
|
|
920 |
* include xml-trees of the plugins to the main xml
|
|
|
921 |
*
|
|
|
922 |
* @return void
|
|
|
923 |
*/
|
|
|
924 |
private function _buildPlugins()
|
|
|
925 |
{
|
|
|
926 |
$pluginroot = $this->_xml->addChild("Plugins");
|
2976 |
rexy |
927 |
if ((($this->_plugin != '') || $this->_complete_request) && count($this->_plugins) > 0) {
|
2770 |
rexy |
928 |
$plugins = array();
|
|
|
929 |
if ($this->_complete_request) {
|
|
|
930 |
$plugins = $this->_plugins;
|
|
|
931 |
}
|
2976 |
rexy |
932 |
if (($this->_plugin != '')) {
|
2770 |
rexy |
933 |
$plugins = array($this->_plugin);
|
|
|
934 |
}
|
|
|
935 |
foreach ($plugins as $plugin) {
|
3179 |
rexy |
936 |
if (!$this->_complete_request ||
|
|
|
937 |
(!defined('PSI_PLUGIN_'.strtoupper($plugin).'_SSH_HOSTNAME') && !defined('PSI_PLUGIN_'.strtoupper($plugin).'_WMI_HOSTNAME')) ||
|
|
|
938 |
(defined('PSI_SSH_HOSTNAME') && (PSI_SSH_HOSTNAME == constant('PSI_PLUGIN_'.strtoupper($plugin).'_SSH_HOSTNAME'))) ||
|
2976 |
rexy |
939 |
(defined('PSI_WMI_HOSTNAME') && (PSI_WMI_HOSTNAME == constant('PSI_PLUGIN_'.strtoupper($plugin).'_WMI_HOSTNAME')))) {
|
|
|
940 |
$object = new $plugin($this->_sysinfo->getEncoding());
|
|
|
941 |
$object->execute();
|
|
|
942 |
$oxml = $object->xml();
|
|
|
943 |
if (sizeof($oxml) > 0) {
|
|
|
944 |
$pluginroot->combinexml($oxml);
|
|
|
945 |
}
|
2770 |
rexy |
946 |
}
|
|
|
947 |
}
|
|
|
948 |
}
|
|
|
949 |
}
|
|
|
950 |
|
|
|
951 |
/**
|
|
|
952 |
* build the xml structure where the content can be inserted
|
|
|
953 |
*
|
|
|
954 |
* @return void
|
|
|
955 |
*/
|
|
|
956 |
private function _xmlbody()
|
|
|
957 |
{
|
|
|
958 |
$dom = new DOMDocument('1.0', 'UTF-8');
|
|
|
959 |
$root = $dom->createElement("tns:phpsysinfo");
|
|
|
960 |
$root->setAttribute('xmlns:tns', 'http://phpsysinfo.sourceforge.net/');
|
|
|
961 |
$root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
|
|
|
962 |
$root->setAttribute('xsi:schemaLocation', 'http://phpsysinfo.sourceforge.net/ phpsysinfo3.xsd');
|
|
|
963 |
$dom->appendChild($root);
|
|
|
964 |
$this->_xml = new SimpleXMLExtended(simplexml_import_dom($dom), $this->_sysinfo->getEncoding());
|
|
|
965 |
|
|
|
966 |
$generation = $this->_xml->addChild('Generation');
|
|
|
967 |
$generation->addAttribute('version', PSI_VERSION_STRING);
|
|
|
968 |
$generation->addAttribute('timestamp', time());
|
|
|
969 |
$options = $this->_xml->addChild('Options');
|
|
|
970 |
$options->addAttribute('tempFormat', defined('PSI_TEMP_FORMAT') ? strtolower(PSI_TEMP_FORMAT) : 'c');
|
|
|
971 |
$options->addAttribute('byteFormat', defined('PSI_BYTE_FORMAT') ? strtolower(PSI_BYTE_FORMAT) : 'auto_binary');
|
|
|
972 |
$options->addAttribute('datetimeFormat', defined('PSI_DATETIME_FORMAT') ? strtolower(PSI_DATETIME_FORMAT) : 'utc');
|
|
|
973 |
if (defined('PSI_REFRESH')) {
|
3037 |
rexy |
974 |
$options->addAttribute('refresh', max(intval(PSI_REFRESH), 0));
|
2770 |
rexy |
975 |
} else {
|
|
|
976 |
$options->addAttribute('refresh', 60000);
|
|
|
977 |
}
|
|
|
978 |
if (defined('PSI_FS_USAGE_THRESHOLD')) {
|
|
|
979 |
if ((($fsut = intval(PSI_FS_USAGE_THRESHOLD)) >= 1) && ($fsut <= 99)) {
|
|
|
980 |
$options->addAttribute('threshold', $fsut);
|
|
|
981 |
}
|
|
|
982 |
} else {
|
|
|
983 |
$options->addAttribute('threshold', 90);
|
|
|
984 |
}
|
|
|
985 |
if (count($this->_plugins) > 0) {
|
2976 |
rexy |
986 |
if (($this->_plugin != '')) {
|
2770 |
rexy |
987 |
$plug = $this->_xml->addChild('UsedPlugins');
|
|
|
988 |
$plug->addChild('Plugin')->addAttribute('name', $this->_plugin);
|
|
|
989 |
} elseif ($this->_complete_request) {
|
|
|
990 |
$plug = $this->_xml->addChild('UsedPlugins');
|
|
|
991 |
foreach ($this->_plugins as $plugin) {
|
|
|
992 |
$plug->addChild('Plugin')->addAttribute('name', $plugin);
|
|
|
993 |
}
|
|
|
994 |
/*
|
|
|
995 |
} else {
|
|
|
996 |
$plug = $this->_xml->addChild('UnusedPlugins');
|
|
|
997 |
foreach ($this->_plugins as $plugin) {
|
|
|
998 |
$plug->addChild('Plugin')->addAttribute('name', $plugin);
|
|
|
999 |
}
|
|
|
1000 |
*/
|
|
|
1001 |
}
|
|
|
1002 |
}
|
|
|
1003 |
}
|
|
|
1004 |
}
|