Subversion Repositories ALCASAR

Rev

Rev 3179 | 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
        }
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
            $virtstring = "";
285
            foreach ($virt as $virtkey=>$virtvalue) if ($virtvalue) {
3287 rexy 286
                if ($virtstring !== "") {
3037 rexy 287
                    $virtstring .= ", ";
288
                }
289
                if ($virtkey === 'microsoft') {
3287 rexy 290
                    if (!isset($virt["wsl"]) || !$virt["wsl"]) {
291
                        $virtstring .= 'hyper-v';
292
                    }
3037 rexy 293
                } elseif ($virtkey === 'kvm') {
294
                    $virtstring .= 'qemu-kvm';
295
                } elseif ($virtkey === 'oracle') {
296
                    $virtstring .= 'virtualbox';
297
                } elseif ($virtkey === 'zvm') {
298
                    $virtstring .= 'z/vm';
3179 rexy 299
                } elseif ($virtkey === 'sre') {
300
                    $virtstring .= 'lmhs sre';
3037 rexy 301
                } else {
302
                    $virtstring .= $virtkey;
303
                }
304
            }
305
            if ($virtstring !== "") {
306
                $hardware->addAttribute('Virtualizer', $virtstring);
307
            }
308
        }
309
 
2976 rexy 310
        $cpu = null;
311
        $vendortab = null;
312
        foreach ($this->_sys->getCpus() as $oneCpu) {
313
            if ($cpu === null) $cpu = $hardware->addChild('CPU');
314
            $tmp = $cpu->addChild('CpuCore');
315
            $tmp->addAttribute('Model', $oneCpu->getModel());
3037 rexy 316
            if ($oneCpu->getVoltage() > 0) {
317
                $tmp->addAttribute('Voltage', $oneCpu->getVoltage());
2976 rexy 318
            }
3037 rexy 319
            if ($oneCpu->getCpuSpeed() > 0) {
320
                $tmp->addAttribute('CpuSpeed', $oneCpu->getCpuSpeed());
321
            } elseif ($oneCpu->getCpuSpeed() == -1) {
322
                $tmp->addAttribute('CpuSpeed', 0); // core stopped
323
            }
324
            if ($oneCpu->getCpuSpeedMax() > 0) {
2976 rexy 325
                $tmp->addAttribute('CpuSpeedMax', $oneCpu->getCpuSpeedMax());
326
            }
3037 rexy 327
            if ($oneCpu->getCpuSpeedMin() > 0) {
2976 rexy 328
                $tmp->addAttribute('CpuSpeedMin', $oneCpu->getCpuSpeedMin());
329
            }
330
/*
331
            if ($oneCpu->getTemp() !== null) {
332
                $tmp->addAttribute('CpuTemp', $oneCpu->getTemp());
333
            }
334
*/
335
            if ($oneCpu->getBusSpeed() !== null) {
336
                $tmp->addAttribute('BusSpeed', $oneCpu->getBusSpeed());
337
            }
338
            if ($oneCpu->getCache() !== null) {
339
                $tmp->addAttribute('Cache', $oneCpu->getCache());
340
            }
341
            if ($oneCpu->getVirt() !== null) {
342
                $tmp->addAttribute('Virt', $oneCpu->getVirt());
343
            }
344
            if ($oneCpu->getVendorId() !== null) {
345
                if ($vendortab === null) $vendortab = @parse_ini_file(PSI_APP_ROOT."/data/cpus.ini", true);
3037 rexy 346
                $shortvendorid = $oneCpu->getVendorId();
2976 rexy 347
                if ($vendortab && ($shortvendorid != "") && isset($vendortab['manufacturer'][$shortvendorid])) {
348
                    $tmp->addAttribute('Manufacturer', $vendortab['manufacturer'][$shortvendorid]);
349
                }
350
            }
351
            if ($oneCpu->getBogomips() !== null) {
352
                $tmp->addAttribute('Bogomips', $oneCpu->getBogomips());
353
            }
354
            if ($oneCpu->getLoad() !== null) {
355
                $tmp->addAttribute('Load', $oneCpu->getLoad());
356
            }
357
        }
358
        $mem = null;
359
        foreach (System::removeDupsAndCount($this->_sys->getMemDevices()) as $dev) {
360
            if ($mem === null) $mem = $hardware->addChild('MEM');
361
            $tmp = $mem->addChild('Chip');
2770 rexy 362
            $tmp->addAttribute('Name', $dev->getName());
363
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
2976 rexy 364
                if ($dev->getCapacity() !== null) {
365
                    $tmp->addAttribute('Capacity', $dev->getCapacity());
366
                }
2770 rexy 367
                if ($dev->getManufacturer() !== null) {
368
                    $tmp->addAttribute('Manufacturer', $dev->getManufacturer());
369
                }
370
                if ($dev->getProduct() !== null) {
371
                    $tmp->addAttribute('Product', $dev->getProduct());
372
                }
2976 rexy 373
                if ($dev->getSpeed() !== null) {
374
                    $tmp->addAttribute('Speed', $dev->getSpeed());
375
                }
376
                if ($dev->getVoltage() !== null) {
377
                    $tmp->addAttribute('Voltage', $dev->getVoltage());
378
                }
379
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
380
                    $tmp->addAttribute('Serial', $dev->getSerial());
381
                }
2770 rexy 382
            }
383
            if ($dev->getCount() > 1) {
384
                $tmp->addAttribute('Count', $dev->getCount());
385
            }
386
        }
2976 rexy 387
        $pci = null;
388
        foreach (System::removeDupsAndCount($this->_sys->getPciDevices()) as $dev) {
389
            if ($pci === null) $pci = $hardware->addChild('PCI');
390
            $tmp = $pci->addChild('Device');
2770 rexy 391
            $tmp->addAttribute('Name', $dev->getName());
392
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
393
                if ($dev->getManufacturer() !== null) {
394
                    $tmp->addAttribute('Manufacturer', $dev->getManufacturer());
395
                }
396
                if ($dev->getProduct() !== null) {
397
                    $tmp->addAttribute('Product', $dev->getProduct());
398
                }
399
            }
400
            if ($dev->getCount() > 1) {
401
                $tmp->addAttribute('Count', $dev->getCount());
402
            }
403
        }
404
        $ide = null;
405
        foreach (System::removeDupsAndCount($this->_sys->getIdeDevices()) as $dev) {
406
            if ($ide === null) $ide = $hardware->addChild('IDE');
407
            $tmp = $ide->addChild('Device');
408
            $tmp->addAttribute('Name', $dev->getName());
409
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
410
                if ($dev->getCapacity() !== null) {
411
                    $tmp->addAttribute('Capacity', $dev->getCapacity());
412
                }
413
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
414
                    $tmp->addAttribute('Serial', $dev->getSerial());
415
                }
416
            }
417
            if ($dev->getCount() > 1) {
418
                $tmp->addAttribute('Count', $dev->getCount());
419
            }
420
        }
421
        $scsi = null;
422
        foreach (System::removeDupsAndCount($this->_sys->getScsiDevices()) as $dev) {
423
            if ($scsi === null) $scsi = $hardware->addChild('SCSI');
424
            $tmp = $scsi->addChild('Device');
425
            $tmp->addAttribute('Name', $dev->getName());
426
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
427
                if ($dev->getCapacity() !== null) {
428
                    $tmp->addAttribute('Capacity', $dev->getCapacity());
429
                }
430
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
431
                    $tmp->addAttribute('Serial', $dev->getSerial());
432
                }
433
            }
434
            if ($dev->getCount() > 1) {
435
                $tmp->addAttribute('Count', $dev->getCount());
436
            }
437
        }
438
        $nvme = null;
439
        foreach (System::removeDupsAndCount($this->_sys->getNvmeDevices()) as $dev) {
440
            if ($nvme === null) $nvme = $hardware->addChild('NVMe');
441
            $tmp = $nvme->addChild('Device');
442
            $tmp->addAttribute('Name', $dev->getName());
443
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
444
                if ($dev->getCapacity() !== null) {
445
                    $tmp->addAttribute('Capacity', $dev->getCapacity());
446
                }
447
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
448
                    $tmp->addAttribute('Serial', $dev->getSerial());
449
                }
450
            }
451
            if ($dev->getCount() > 1) {
452
                $tmp->addAttribute('Count', $dev->getCount());
453
            }
454
        }
2976 rexy 455
        $usb = null;
456
        foreach (System::removeDupsAndCount($this->_sys->getUsbDevices()) as $dev) {
457
            if ($usb === null) $usb = $hardware->addChild('USB');
458
            $tmp = $usb->addChild('Device');
459
            $tmp->addAttribute('Name', $dev->getName());
460
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
461
                if ($dev->getManufacturer() !== null) {
462
                    $tmp->addAttribute('Manufacturer', $dev->getManufacturer());
463
                }
464
                if ($dev->getProduct() !== null) {
465
                    $tmp->addAttribute('Product', $dev->getProduct());
466
                }
467
                if ($dev->getSpeed() !== null) {
468
                    $tmp->addAttribute('Speed', $dev->getSpeed());
469
                }
470
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL && ($dev->getSerial() !== null)) {
471
                    $tmp->addAttribute('Serial', $dev->getSerial());
472
                }
473
            }
474
            if ($dev->getCount() > 1) {
475
                $tmp->addAttribute('Count', $dev->getCount());
476
            }
477
        }
2770 rexy 478
        $tb = null;
479
        foreach (System::removeDupsAndCount($this->_sys->getTbDevices()) as $dev) {
480
            if ($tb === null) $tb = $hardware->addChild('TB');
481
            $tmp = $tb->addChild('Device');
482
            $tmp->addAttribute('Name', $dev->getName());
483
            if ($dev->getCount() > 1) {
484
                $tmp->addAttribute('Count', $dev->getCount());
485
            }
486
        }
487
        $i2c = null;
488
        foreach (System::removeDupsAndCount($this->_sys->getI2cDevices()) as $dev) {
489
            if ($i2c === null) $i2c = $hardware->addChild('I2C');
490
            $tmp = $i2c->addChild('Device');
491
            $tmp->addAttribute('Name', $dev->getName());
492
            if ($dev->getCount() > 1) {
493
                $tmp->addAttribute('Count', $dev->getCount());
494
            }
495
        }
496
    }
497
 
498
    /**
499
     * generate the memory information
500
     *
501
     * @return void
502
     */
503
    private function _buildMemory()
504
    {
505
        $memory = $this->_xml->addChild('Memory');
506
        $memory->addAttribute('Free', $this->_sys->getMemFree());
507
        $memory->addAttribute('Used', $this->_sys->getMemUsed());
508
        $memory->addAttribute('Total', $this->_sys->getMemTotal());
509
        $memory->addAttribute('Percent', $this->_sys->getMemPercentUsed());
510
        if (($this->_sys->getMemApplication() !== null) || ($this->_sys->getMemBuffer() !== null) || ($this->_sys->getMemCache() !== null)) {
511
            $details = $memory->addChild('Details');
512
            if ($this->_sys->getMemApplication() !== null) {
513
                $details->addAttribute('App', $this->_sys->getMemApplication());
514
                $details->addAttribute('AppPercent', $this->_sys->getMemPercentApplication());
515
            }
516
            if ($this->_sys->getMemBuffer() !== null) {
517
                $details->addAttribute('Buffers', $this->_sys->getMemBuffer());
518
                $details->addAttribute('BuffersPercent', $this->_sys->getMemPercentBuffer());
519
            }
520
            if ($this->_sys->getMemCache() !== null) {
521
                $details->addAttribute('Cached', $this->_sys->getMemCache());
522
                $details->addAttribute('CachedPercent', $this->_sys->getMemPercentCache());
523
            }
524
        }
525
        if (count($this->_sys->getSwapDevices()) > 0) {
526
            $swap = $memory->addChild('Swap');
527
            $swap->addAttribute('Free', $this->_sys->getSwapFree());
528
            $swap->addAttribute('Used', $this->_sys->getSwapUsed());
529
            $swap->addAttribute('Total', $this->_sys->getSwapTotal());
530
            $swap->addAttribute('Percent', $this->_sys->getSwapPercentUsed());
531
            $i = 1;
532
            foreach ($this->_sys->getSwapDevices() as $dev) {
533
                $swapMount = $swap->addChild('Mount');
534
                $this->_fillDevice($swapMount, $dev, $i++);
535
            }
536
        }
537
    }
538
 
539
    /**
540
     * fill a xml element with atrributes from a disk device
541
     *
542
     * @param SimpleXmlExtended $mount Xml-Element
543
     * @param DiskDevice        $dev   DiskDevice
3037 rexy 544
     * @param int               $i     counter
2770 rexy 545
     *
3037 rexy 546
     * @return void
2770 rexy 547
     */
548
    private function _fillDevice(SimpleXMLExtended $mount, DiskDevice $dev, $i)
549
    {
550
        $mount->addAttribute('MountPointID', $i);
2976 rexy 551
        if ($dev->getFsType()!=="") {
552
            $mount->addAttribute('FSType', $dev->getFsType());
553
        }
2770 rexy 554
        $mount->addAttribute('Name', $dev->getName());
555
        $mount->addAttribute('Free', sprintf("%.0f", $dev->getFree()));
556
        $mount->addAttribute('Used', sprintf("%.0f", $dev->getUsed()));
557
        $mount->addAttribute('Total', sprintf("%.0f", $dev->getTotal()));
2976 rexy 558
        $percentUsed = $dev->getPercentUsed();
559
        $mount->addAttribute('Percent', $percentUsed);
560
        if ($dev->getPercentInodesUsed() !== null) {
561
            $mount->addAttribute('Inodes', $dev->getPercentInodesUsed());
562
        }
2770 rexy 563
        if ($dev->getIgnore() > 0) $mount->addAttribute('Ignore', $dev->getIgnore());
3037 rexy 564
        if (PSI_SHOW_MOUNT_OPTION) {
2770 rexy 565
            if ($dev->getOptions() !== null) {
566
                $mount->addAttribute('MountOptions', preg_replace("/,/", ", ", $dev->getOptions()));
567
            }
568
        }
3037 rexy 569
        if (PSI_SHOW_MOUNT_POINT && ($dev->getMountPoint() !== null)) {
2770 rexy 570
            $mount->addAttribute('MountPoint', $dev->getMountPoint());
571
        }
572
    }
573
 
574
    /**
575
     * generate the filesysteminformation
576
     *
577
     * @return void
578
     */
579
    private function _buildFilesystems()
580
    {
2976 rexy 581
        $hideMounts = $hideFstypes = $hideDisks = $ignoreFree = $ignoreTotal = $ignoreUsage = $ignoreThreshold = array();
2770 rexy 582
        if (defined('PSI_HIDE_MOUNTS') && is_string(PSI_HIDE_MOUNTS)) {
583
            if (preg_match(ARRAY_EXP, PSI_HIDE_MOUNTS)) {
584
                $hideMounts = eval(PSI_HIDE_MOUNTS);
585
            } else {
586
                $hideMounts = array(PSI_HIDE_MOUNTS);
587
            }
588
        }
589
        if (defined('PSI_HIDE_FS_TYPES') && is_string(PSI_HIDE_FS_TYPES)) {
590
            if (preg_match(ARRAY_EXP, PSI_HIDE_FS_TYPES)) {
591
                $hideFstypes = eval(PSI_HIDE_FS_TYPES);
592
            } else {
593
                $hideFstypes = array(PSI_HIDE_FS_TYPES);
594
            }
595
        }
596
        if (defined('PSI_HIDE_DISKS')) {
597
            if (is_string(PSI_HIDE_DISKS)) {
598
                if (preg_match(ARRAY_EXP, PSI_HIDE_DISKS)) {
599
                    $hideDisks = eval(PSI_HIDE_DISKS);
600
                } else {
601
                    $hideDisks = array(PSI_HIDE_DISKS);
602
                }
603
            } elseif (PSI_HIDE_DISKS === true) {
604
                return;
605
            }
606
        }
607
        if (defined('PSI_IGNORE_FREE') && is_string(PSI_IGNORE_FREE)) {
608
            if (preg_match(ARRAY_EXP, PSI_IGNORE_FREE)) {
609
                $ignoreFree = eval(PSI_IGNORE_FREE);
610
            } else {
611
                $ignoreFree = array(PSI_IGNORE_FREE);
612
            }
613
        }
2976 rexy 614
        if (defined('PSI_IGNORE_TOTAL') && is_string(PSI_IGNORE_TOTAL)) {
615
            if (preg_match(ARRAY_EXP, PSI_IGNORE_TOTAL)) {
616
                $ignoreTotal = eval(PSI_IGNORE_TOTAL);
617
            } else {
618
                $ignoreTotal = array(PSI_IGNORE_TOTAL);
619
            }
620
        }
2770 rexy 621
        if (defined('PSI_IGNORE_USAGE') && is_string(PSI_IGNORE_USAGE)) {
622
            if (preg_match(ARRAY_EXP, PSI_IGNORE_USAGE)) {
623
                $ignoreUsage = eval(PSI_IGNORE_USAGE);
624
            } else {
625
                $ignoreUsage = array(PSI_IGNORE_USAGE);
626
            }
627
        }
628
        if (defined('PSI_IGNORE_THRESHOLD_FS_TYPES') && is_string(PSI_IGNORE_THRESHOLD_FS_TYPES)) {
629
            if (preg_match(ARRAY_EXP, PSI_IGNORE_THRESHOLD_FS_TYPES)) {
630
                $ignoreThreshold = eval(PSI_IGNORE_THRESHOLD_FS_TYPES);
631
            } else {
632
                $ignoreThreshold = array(PSI_IGNORE_THRESHOLD_FS_TYPES);
633
            }
634
        }
635
        $fs = $this->_xml->addChild('FileSystem');
3037 rexy 636
        $i = 1;
2770 rexy 637
        foreach ($this->_sys->getDiskDevices() as $disk) {
638
            if (!in_array($disk->getMountPoint(), $hideMounts, true) && !in_array($disk->getFsType(), $hideFstypes, true) && !in_array($disk->getName(), $hideDisks, true)) {
639
                $mount = $fs->addChild('Mount');
640
                if (in_array($disk->getFsType(), $ignoreThreshold, true)) {
2976 rexy 641
                    $disk->setIgnore(4);
642
                } elseif (in_array($disk->getMountPoint(), $ignoreUsage, true)) {
2770 rexy 643
                    $disk->setIgnore(3);
2976 rexy 644
                } elseif (in_array($disk->getMountPoint(), $ignoreTotal, true)) {
2770 rexy 645
                    $disk->setIgnore(2);
646
                } elseif (in_array($disk->getMountPoint(), $ignoreFree, true)) {
647
                    $disk->setIgnore(1);
648
                }
649
                $this->_fillDevice($mount, $disk, $i++);
650
            }
651
        }
652
    }
653
 
654
    /**
655
     * generate the motherboard information
656
     *
657
     * @return void
658
     */
659
    private function _buildMbinfo()
660
    {
661
        $mbinfo = $this->_xml->addChild('MBInfo');
662
        $temp = $fan = $volt = $power = $current = $other = null;
3287 rexy 663
        $hideSensors = array();
2770 rexy 664
 
665
        if (sizeof(unserialize(PSI_MBINFO))>0) {
3287 rexy 666
            if (defined('PSI_HIDE_SENSORS') && is_string(PSI_HIDE_SENSORS)) {
667
                 if (preg_match(ARRAY_EXP, PSI_HIDE_SENSORS)) {
668
                    $hideSensors = eval(PSI_HIDE_SENSORS);
669
                } else {
670
                    $hideSensors = array(PSI_HIDE_SENSORS);
671
                }
672
            }
2770 rexy 673
            foreach (unserialize(PSI_MBINFO) as $mbinfoclass) {
674
                $mbinfo_data = new $mbinfoclass();
675
                $mbinfo_detail = $mbinfo_data->getMBInfo();
3287 rexy 676
                if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='temperature' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbTemp() as $dev) {
677
                    $mbinfo_name = $dev->getName();
678
                    if (!in_array($mbinfo_name, $hideSensors, true)) {
679
                        if ($temp == null) {
680
                            $temp = $mbinfo->addChild('Temperature');
681
                        }
682
                        $item = $temp->addChild('Item');
683
                        $item->addAttribute('Label', $mbinfo_name);
684
                        $item->addAttribute('Value', $dev->getValue());
685
                        $alarm = false;
686
                        if ($dev->getMax() !== null) {
687
                            $item->addAttribute('Max', $dev->getMax());
688
                            $alarm = true;
689
                        }
690
                        if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
691
                            $item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
692
                        }
2770 rexy 693
                    }
694
                }
695
 
3287 rexy 696
                if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='fans' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbFan() as $dev) {
697
                    $mbinfo_name = $dev->getName();
698
                    if (!in_array($mbinfo_name, $hideSensors, true)) {
699
                        if ($fan == null) {
700
                            $fan = $mbinfo->addChild('Fans');
701
                        }
702
                        $item = $fan->addChild('Item');
703
                        $item->addAttribute('Label', $mbinfo_name);
704
                        $item->addAttribute('Value', $dev->getValue());
705
                        $alarm = false;
2976 rexy 706
                        if ($dev->getMin() !== null) {
707
                            $item->addAttribute('Min', $dev->getMin());
3037 rexy 708
                            $alarm = true;
2976 rexy 709
                        }
3287 rexy 710
                        if ($dev->getUnit() !== "") {
711
                            $item->addAttribute('Unit', $dev->getUnit());
2976 rexy 712
                        }
3287 rexy 713
                        if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
714
                            $item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
715
                        }
2770 rexy 716
                    }
717
                }
718
 
3287 rexy 719
                if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='voltage' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbVolt() as $dev) {
720
                    $mbinfo_name = $dev->getName();
721
                    if (!in_array($mbinfo_name, $hideSensors, true)) {
722
                        if ($volt == null) {
723
                            $volt = $mbinfo->addChild('Voltage');
724
                        }
725
                        $item = $volt->addChild('Item');
726
                        $item->addAttribute('Label', $mbinfo_name);
727
                        $item->addAttribute('Value', $dev->getValue());
728
                        $alarm = false;
729
                        if (($dev->getMin() === null) || ($dev->getMin() != 0) || ($dev->getMax() === null) || ($dev->getMax() != 0)) {
730
                            if ($dev->getMin() !== null) {
731
                                $item->addAttribute('Min', $dev->getMin());
732
                                $alarm = true;
733
                            }
734
                            if ($dev->getMax() !== null) {
735
                                $item->addAttribute('Max', $dev->getMax());
736
                                $alarm = true;
737
                            }
738
                        }
739
                        if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
740
                            $item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
741
                        }
2770 rexy 742
                    }
743
                }
744
 
3287 rexy 745
                if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='power' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbPower() as $dev) {
746
                    $mbinfo_name = $dev->getName();
747
                    if (!in_array($mbinfo_name, $hideSensors, true)) {
748
                        if ($power == null) {
749
                            $power = $mbinfo->addChild('Power');
2976 rexy 750
                        }
3287 rexy 751
                        $item = $power->addChild('Item');
752
                        $item->addAttribute('Label', $mbinfo_name);
753
                        $item->addAttribute('Value', $dev->getValue());
754
                        $alarm = false;
2976 rexy 755
                        if ($dev->getMax() !== null) {
756
                            $item->addAttribute('Max', $dev->getMax());
3037 rexy 757
                            $alarm = true;
2976 rexy 758
                        }
3287 rexy 759
                        if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
760
                            $item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
761
                        }
2770 rexy 762
                    }
3287 rexy 763
                }
764
 
765
                if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='current' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbCurrent() as $dev) {
766
                    $mbinfo_name = $dev->getName();
767
                    if (!in_array($mbinfo_name, $hideSensors, true)) {
768
                        if ($current == null) {
769
                            $current = $mbinfo->addChild('Current');
770
                        }
771
                        $item = $current->addChild('Item');
772
                        $item->addAttribute('Label', $mbinfo_name);
773
                        $item->addAttribute('Value', $dev->getValue());
774
                        $alarm = false;
775
                        if (($dev->getMin() === null) || ($dev->getMin() != 0) || ($dev->getMax() === null) || ($dev->getMax() != 0)) {
776
                            if ($dev->getMin() !== null) {
777
                                $item->addAttribute('Min', $dev->getMin());
778
                                $alarm = true;
779
                            }
780
                            if ($dev->getMax() !== null) {
781
                                $item->addAttribute('Max', $dev->getMax());
782
                                $alarm = true;
783
                            }
784
                        }
785
                        if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && ($dev->getEvent() !== "") && (((strtolower($dev->getEvent())) !== "alarm") || $alarm || ($dev->getValue() == 0))) {
786
                            $item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
787
                        }
2770 rexy 788
                    }
789
                }
790
 
3287 rexy 791
                if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='other' || $this->_sysinfo->getBlockName()==='mbinfo') foreach ($mbinfo_detail->getMbOther() as $dev) {
792
                    $mbinfo_name = $dev->getName();
793
                    if (!in_array($mbinfo_name, $hideSensors, true)) {
794
                        if ($other == null) {
795
                            $other = $mbinfo->addChild('Other');
796
                        }
797
                        $item = $other->addChild('Item');
798
                        $item->addAttribute('Label', $mbinfo_name);
799
                        $item->addAttribute('Value', $dev->getValue());
800
                        if ($dev->getUnit() !== "") {
801
                            $item->addAttribute('Unit', $dev->getUnit());
802
                        }
803
                        if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") {
804
                            $item->addAttribute('Event', ucfirst(strtolower($dev->getEvent())));
805
                        }
2770 rexy 806
                    }
807
                }
808
            }
809
        }
810
    }
811
 
812
    /**
813
     * generate the ups information
814
     *
815
     * @return void
816
     */
817
    private function _buildUpsinfo()
818
    {
819
        $upsinfo = $this->_xml->addChild('UPSInfo');
3037 rexy 820
        if (!defined('PSI_EMU_HOSTNAME') && defined('PSI_UPS_APCUPSD_CGI_ENABLE') && PSI_UPS_APCUPSD_CGI_ENABLE) {
2770 rexy 821
            $upsinfo->addAttribute('ApcupsdCgiLinks', true);
822
        }
823
        if (sizeof(unserialize(PSI_UPSINFO))>0) {
824
            foreach (unserialize(PSI_UPSINFO) as $upsinfoclass) {
825
                $upsinfo_data = new $upsinfoclass();
826
                $upsinfo_detail = $upsinfo_data->getUPSInfo();
827
                foreach ($upsinfo_detail->getUpsDevices() as $ups) {
828
                    $item = $upsinfo->addChild('UPS');
829
                    $item->addAttribute('Name', $ups->getName());
830
                    if ($ups->getModel() !== "") {
831
                        $item->addAttribute('Model', $ups->getModel());
832
                    }
833
                    if ($ups->getMode() !== "") {
834
                        $item->addAttribute('Mode', $ups->getMode());
835
                    }
836
                    if ($ups->getStartTime() !== "") {
837
                        $item->addAttribute('StartTime', $ups->getStartTime());
838
                    }
839
                    $item->addAttribute('Status', $ups->getStatus());
3037 rexy 840
                    if ($ups->getBeeperStatus() !== null) {
841
                        $item->addAttribute('BeeperStatus', $ups->getBeeperStatus());
842
                    }
2770 rexy 843
                    if ($ups->getTemperatur() !== null) {
844
                        $item->addAttribute('Temperature', $ups->getTemperatur());
845
                    }
846
                    if ($ups->getOutages() !== null) {
847
                        $item->addAttribute('OutagesCount', $ups->getOutages());
848
                    }
849
                    if ($ups->getLastOutage() !== null) {
850
                        $item->addAttribute('LastOutage', $ups->getLastOutage());
851
                    }
852
                    if ($ups->getLastOutageFinish() !== null) {
853
                        $item->addAttribute('LastOutageFinish', $ups->getLastOutageFinish());
854
                    }
855
                    if ($ups->getLineVoltage() !== null) {
856
                        $item->addAttribute('LineVoltage', $ups->getLineVoltage());
857
                    }
858
                    if ($ups->getLineFrequency() !== null) {
859
                        $item->addAttribute('LineFrequency', $ups->getLineFrequency());
860
                    }
861
                    if ($ups->getLoad() !== null) {
862
                        $item->addAttribute('LoadPercent', $ups->getLoad());
863
                    }
864
                    if ($ups->getBatteryDate() !== null) {
865
                        $item->addAttribute('BatteryDate', $ups->getBatteryDate());
866
                    }
867
                    if ($ups->getBatteryVoltage() !== null) {
868
                        $item->addAttribute('BatteryVoltage', $ups->getBatteryVoltage());
869
                    }
870
                    if ($ups->getBatterCharge() !== null) {
871
                        $item->addAttribute('BatteryChargePercent', $ups->getBatterCharge());
872
                    }
873
                    if ($ups->getTimeLeft() !== null) {
874
                        $item->addAttribute('TimeLeftMinutes', $ups->getTimeLeft());
875
                    }
876
                }
877
            }
878
        }
879
    }
880
 
881
    /**
882
     * generate the xml document
883
     *
884
     * @return void
885
     */
886
    private function _buildXml()
887
    {
2976 rexy 888
        if (($this->_plugin == '') || $this->_complete_request) {
2770 rexy 889
            if ($this->_sys === null) {
3037 rexy 890
                if (PSI_DEBUG) {
2770 rexy 891
                    // unstable version check
892
                    if (!is_numeric(substr(PSI_VERSION, -1))) {
3037 rexy 893
                        $this->_errors->addWarning("This is an unstable version of phpSysInfo, some things may not work correctly");
2770 rexy 894
                    }
895
 
896
                    // Safe mode check
897
                    $safe_mode = @ini_get("safe_mode") ? true : false;
898
                    if ($safe_mode) {
899
                        $this->_errors->addError("WARN", "PhpSysInfo requires to set off 'safe_mode' in 'php.ini'");
900
                    }
901
                    // Include path check
902
                    $include_path = @ini_get("include_path");
903
                    if ($include_path && ($include_path!="")) {
904
                        $include_path = preg_replace("/(:)|(;)/", "\n", $include_path);
905
                        if (preg_match("/^\.$/m", $include_path)) {
906
                            $include_path = ".";
907
                        }
908
                    }
909
                    if ($include_path != ".") {
910
                        $this->_errors->addError("WARN", "PhpSysInfo requires '.' inside the 'include_path' in php.ini");
911
                    }
912
                    // popen mode check
3037 rexy 913
                    if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
2770 rexy 914
                        $this->_errors->addError("WARN", "Installed version of PHP does not support proc_open() function, popen() is used");
915
                    }
916
                }
917
                $this->_sys = $this->_sysinfo->getSys();
918
            }
919
            if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='vitals') $this->_buildVitals();
920
            if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='network') $this->_buildNetwork();
921
            if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='hardware') $this->_buildHardware();
922
            if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='memory') $this->_buildMemory();
923
            if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='filesystem') $this->_buildFilesystems();
3287 rexy 924
            if (!$this->_sysinfo->getBlockName() || in_array($this->_sysinfo->getBlockName(), array('mbinfo','voltage','current','temperature','fans','power','other'))) $this->_buildMbinfo();
2770 rexy 925
            if (!$this->_sysinfo->getBlockName() || $this->_sysinfo->getBlockName()==='ups') $this->_buildUpsinfo();
926
        }
927
        if (!$this->_sysinfo->getBlockName()) $this->_buildPlugins();
928
        $this->_xml->combinexml($this->_errors->errorsAddToXML($this->_sysinfo->getEncoding()));
929
    }
930
 
931
    /**
932
     * get the xml object
933
     *
934
     * @return SimpleXmlElement
935
     */
936
    public function getXml()
937
    {
938
        $this->_buildXml();
939
 
940
        return $this->_xml->getSimpleXmlElement();
941
    }
942
 
943
    /**
944
     * include xml-trees of the plugins to the main xml
945
     *
946
     * @return void
947
     */
948
    private function _buildPlugins()
949
    {
950
        $pluginroot = $this->_xml->addChild("Plugins");
2976 rexy 951
        if ((($this->_plugin != '') || $this->_complete_request) && count($this->_plugins) > 0) {
2770 rexy 952
            $plugins = array();
953
            if ($this->_complete_request) {
954
                $plugins = $this->_plugins;
955
            }
2976 rexy 956
            if (($this->_plugin != '')) {
2770 rexy 957
                $plugins = array($this->_plugin);
958
            }
959
            foreach ($plugins as $plugin) {
3179 rexy 960
                if (!$this->_complete_request ||
961
                   (!defined('PSI_PLUGIN_'.strtoupper($plugin).'_SSH_HOSTNAME') && !defined('PSI_PLUGIN_'.strtoupper($plugin).'_WMI_HOSTNAME')) ||
962
                   (defined('PSI_SSH_HOSTNAME') && (PSI_SSH_HOSTNAME == constant('PSI_PLUGIN_'.strtoupper($plugin).'_SSH_HOSTNAME'))) ||
2976 rexy 963
                   (defined('PSI_WMI_HOSTNAME') && (PSI_WMI_HOSTNAME == constant('PSI_PLUGIN_'.strtoupper($plugin).'_WMI_HOSTNAME')))) {
964
                    $object = new $plugin($this->_sysinfo->getEncoding());
965
                    $object->execute();
966
                    $oxml = $object->xml();
967
                    if (sizeof($oxml) > 0) {
968
                        $pluginroot->combinexml($oxml);
969
                    }
2770 rexy 970
                }
971
            }
972
        }
973
    }
974
 
975
    /**
976
     * build the xml structure where the content can be inserted
977
     *
978
     * @return void
979
     */
980
    private function _xmlbody()
981
    {
982
        $dom = new DOMDocument('1.0', 'UTF-8');
983
        $root = $dom->createElement("tns:phpsysinfo");
984
        $root->setAttribute('xmlns:tns', 'http://phpsysinfo.sourceforge.net/');
985
        $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
986
        $root->setAttribute('xsi:schemaLocation', 'http://phpsysinfo.sourceforge.net/ phpsysinfo3.xsd');
987
        $dom->appendChild($root);
988
        $this->_xml = new SimpleXMLExtended(simplexml_import_dom($dom), $this->_sysinfo->getEncoding());
989
 
990
        $generation = $this->_xml->addChild('Generation');
991
        $generation->addAttribute('version', PSI_VERSION_STRING);
992
        $generation->addAttribute('timestamp', time());
993
        $options = $this->_xml->addChild('Options');
994
        $options->addAttribute('tempFormat', defined('PSI_TEMP_FORMAT') ? strtolower(PSI_TEMP_FORMAT) : 'c');
995
        $options->addAttribute('byteFormat', defined('PSI_BYTE_FORMAT') ? strtolower(PSI_BYTE_FORMAT) : 'auto_binary');
996
        $options->addAttribute('datetimeFormat', defined('PSI_DATETIME_FORMAT') ? strtolower(PSI_DATETIME_FORMAT) : 'utc');
997
        if (defined('PSI_REFRESH')) {
3037 rexy 998
            $options->addAttribute('refresh', max(intval(PSI_REFRESH), 0));
2770 rexy 999
        } else {
1000
            $options->addAttribute('refresh', 60000);
1001
        }
1002
        if (defined('PSI_FS_USAGE_THRESHOLD')) {
1003
            if ((($fsut = intval(PSI_FS_USAGE_THRESHOLD)) >= 1) && ($fsut <= 99)) {
1004
                $options->addAttribute('threshold', $fsut);
1005
            }
1006
        } else {
1007
            $options->addAttribute('threshold', 90);
1008
        }
1009
        if (count($this->_plugins) > 0) {
2976 rexy 1010
            if (($this->_plugin != '')) {
2770 rexy 1011
                $plug = $this->_xml->addChild('UsedPlugins');
1012
                $plug->addChild('Plugin')->addAttribute('name', $this->_plugin);
1013
            } elseif ($this->_complete_request) {
1014
                $plug = $this->_xml->addChild('UsedPlugins');
1015
                foreach ($this->_plugins as $plugin) {
1016
                    $plug->addChild('Plugin')->addAttribute('name', $plugin);
1017
                }
1018
/*
1019
            } else {
1020
                $plug = $this->_xml->addChild('UnusedPlugins');
1021
                foreach ($this->_plugins as $plugin) {
1022
                    $plug->addChild('Plugin')->addAttribute('name', $plugin);
1023
                }
1024
*/
1025
            }
1026
        }
1027
    }
1028
}