Subversion Repositories ALCASAR

Rev

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