Subversion Repositories ALCASAR

Rev

Rev 2976 | Rev 3100 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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