Subversion Repositories ALCASAR

Rev

Rev 3037 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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