This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * XML Generation class |
||
4 | * |
||
5 | * PHP version 5 |
||
6 | * |
||
7 | * @category PHP |
||
8 | * @package PSI_XML |
||
9 | * @author Michael Cramer <[email protected]> |
||
10 | * @copyright 2009 phpSysInfo |
||
11 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
||
12 | * @version SVN: $Id: class.XML.inc.php 699 2012-09-15 11:57:13Z namiltd $ |
||
13 | * @link http://phpsysinfo.sourceforge.net |
||
14 | */ |
||
15 | /** |
||
16 | * class for generation of the xml |
||
17 | * |
||
18 | * @category PHP |
||
19 | * @package PSI_XML |
||
20 | * @author Michael Cramer <[email protected]> |
||
21 | * @copyright 2009 phpSysInfo |
||
22 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
||
23 | * @version Release: 3.0 |
||
24 | * @link http://phpsysinfo.sourceforge.net |
||
25 | */ |
||
26 | class XML |
||
0 ignored issues
–
show
|
|||
27 | { |
||
28 | /** |
||
29 | * Sysinfo object where the information retrieval methods are included |
||
30 | * |
||
31 | * @var PSI_Interface_OS |
||
32 | */ |
||
33 | private $_sysinfo; |
||
34 | |||
35 | /** |
||
36 | * @var System |
||
37 | */ |
||
38 | private $_sys = null; |
||
39 | |||
40 | /** |
||
41 | * xml object with the xml content |
||
42 | * |
||
43 | * @var SimpleXMLExtended |
||
44 | */ |
||
45 | private $_xml; |
||
46 | |||
47 | /** |
||
48 | * object for error handling |
||
49 | * |
||
50 | * @var Error |
||
51 | */ |
||
52 | private $_errors; |
||
53 | |||
54 | /** |
||
55 | * array with all enabled plugins (name) |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | private $_plugins; |
||
60 | |||
61 | /** |
||
62 | * plugin name if pluginrequest |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | private $_plugin = ''; |
||
67 | |||
68 | /** |
||
69 | * generate a xml for a plugin or for the main app |
||
70 | * |
||
71 | * @var boolean |
||
72 | */ |
||
73 | private $_plugin_request = false; |
||
74 | |||
75 | /** |
||
76 | * generate the entire xml with all plugins or only a part of the xml (main or plugin) |
||
77 | * |
||
78 | * @var boolean |
||
79 | */ |
||
80 | private $_complete_request = false; |
||
81 | |||
82 | /** |
||
83 | * doing some initial tasks |
||
84 | * - generate the xml structure with the right header elements |
||
85 | * - get the error object for error output |
||
86 | * - get a instance of the sysinfo object |
||
87 | * |
||
88 | * @param boolean $complete generate xml with all plugins or not |
||
89 | * @param string $pluginname name of the plugin |
||
90 | * |
||
91 | * @return void |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Adding a
@return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.
Adding a Please refer to the PHP core documentation on constructors. ![]() |
|||
92 | */ |
||
93 | public function __construct($complete = false, $pluginname = "") |
||
94 | { |
||
95 | $this->_errors = PSI_Error::singleton(); |
||
0 ignored issues
–
show
Are you sure the assignment to
$this->_errors is correct as \PSI_Error::singleton() (which targets PSI_Error::singleton() ) seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
96 | if ($pluginname == "") { |
||
97 | $this->_plugin_request = false; |
||
98 | $this->_plugin = ''; |
||
99 | } else { |
||
100 | $this->_plugin_request = true; |
||
101 | $this->_plugin = $pluginname; |
||
102 | } |
||
103 | if ($complete) { |
||
104 | $this->_complete_request = true; |
||
105 | } else { |
||
106 | $this->_complete_request = false; |
||
107 | } |
||
108 | $os = PSI_OS; |
||
109 | $this->_sysinfo = new $os(); |
||
110 | $this->_plugins = CommonFunctions::getPlugins(); |
||
111 | $this->_xmlbody(); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * generate common information |
||
116 | * |
||
117 | * @return void |
||
118 | */ |
||
119 | private function _buildVitals() |
||
120 | { |
||
121 | $vitals = $this->_xml->addChild('Vitals'); |
||
122 | $vitals->addAttribute('Hostname', $this->_sys->getHostname()); |
||
123 | $vitals->addAttribute('IPAddr', $this->_sys->getIp()); |
||
124 | $vitals->addAttribute('Kernel', $this->_sys->getKernel()); |
||
125 | $vitals->addAttribute('Distro', $this->_sys->getDistribution()); |
||
126 | $vitals->addAttribute('Distroicon', $this->_sys->getDistributionIcon()); |
||
127 | $vitals->addAttribute('Uptime', $this->_sys->getUptime()); |
||
128 | $vitals->addAttribute('Users', $this->_sys->getUsers()); |
||
129 | $vitals->addAttribute('LoadAvg', $this->_sys->getLoad()); |
||
130 | if ($this->_sys->getLoadPercent() !== null) { |
||
131 | $vitals->addAttribute('CPULoad', $this->_sys->getLoadPercent()); |
||
132 | } |
||
133 | if ($this->_sysinfo->getLanguage() !== null) { |
||
134 | $vitals->addAttribute('SysLang', $this->_sysinfo->getLanguage()); |
||
135 | } |
||
136 | if ($this->_sysinfo->getEncoding() !== null) { |
||
137 | $vitals->addAttribute('CodePage', $this->_sysinfo->getEncoding()); |
||
138 | } |
||
139 | |||
140 | //processes |
||
141 | if (($procss = $this->_sys->getProcesses()) !== null) { |
||
142 | if (isset($procss['*']) && (($procall = $procss['*']) > 0)) { |
||
143 | $vitals->addAttribute('Processes', $procall); |
||
144 | if (!isset($procss[' ']) || !($procss[' '] > 0)) { // not unknown |
||
145 | $procsum = 0; |
||
146 | if (isset($procss['R']) && (($proctmp = $procss['R']) > 0)) { |
||
147 | $vitals->addAttribute('ProcessesRunning', $proctmp); |
||
148 | $procsum += $proctmp; |
||
149 | } |
||
150 | if (isset($procss['S']) && (($proctmp = $procss['S']) > 0)) { |
||
151 | $vitals->addAttribute('ProcessesSleeping', $proctmp); |
||
152 | $procsum += $proctmp; |
||
153 | } |
||
154 | if (isset($procss['T']) && (($proctmp = $procss['T']) > 0)) { |
||
155 | $vitals->addAttribute('ProcessesStopped', $proctmp); |
||
156 | $procsum += $proctmp; |
||
157 | } |
||
158 | if (isset($procss['Z']) && (($proctmp = $procss['Z']) > 0)) { |
||
159 | $vitals->addAttribute('ProcessesZombie', $proctmp); |
||
160 | $procsum += $proctmp; |
||
161 | } |
||
162 | if (isset($procss['D']) && (($proctmp = $procss['D']) > 0)) { |
||
163 | $vitals->addAttribute('ProcessesWaiting', $proctmp); |
||
164 | $procsum += $proctmp; |
||
165 | } |
||
166 | if (($proctmp = $procall - $procsum) > 0) { |
||
167 | $vitals->addAttribute('ProcessesOther', $proctmp); |
||
168 | } |
||
169 | } |
||
170 | } |
||
171 | } |
||
172 | $vitals->addAttribute('OS', PSI_OS); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * generate the network information |
||
177 | * |
||
178 | * @return void |
||
179 | */ |
||
180 | private function _buildNetwork() |
||
181 | { |
||
182 | $hideDevices = array(); |
||
183 | $network = $this->_xml->addChild('Network'); |
||
184 | View Code Duplication | if (defined('PSI_HIDE_NETWORK_INTERFACE')) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
185 | if (is_string(PSI_HIDE_NETWORK_INTERFACE)) { |
||
186 | if (preg_match(ARRAY_EXP, PSI_HIDE_NETWORK_INTERFACE)) { |
||
187 | $hideDevices = eval(PSI_HIDE_NETWORK_INTERFACE); |
||
0 ignored issues
–
show
It is generally not recommended to use
eval unless absolutely required.
On one hand, ![]() |
|||
188 | } else { |
||
189 | $hideDevices = array(PSI_HIDE_NETWORK_INTERFACE); |
||
190 | } |
||
191 | } elseif (PSI_HIDE_NETWORK_INTERFACE === true) { |
||
192 | return; |
||
193 | } |
||
194 | } |
||
195 | foreach ($this->_sys->getNetDevices() as $dev) { |
||
196 | if (!in_array(trim($dev->getName()), $hideDevices)) { |
||
197 | $device = $network->addChild('NetDevice'); |
||
198 | $device->addAttribute('Name', $dev->getName()); |
||
199 | $device->addAttribute('RxBytes', $dev->getRxBytes()); |
||
200 | $device->addAttribute('TxBytes', $dev->getTxBytes()); |
||
201 | $device->addAttribute('Err', $dev->getErrors()); |
||
202 | $device->addAttribute('Drops', $dev->getDrops()); |
||
203 | if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS && $dev->getInfo()) |
||
204 | $device->addAttribute('Info', $dev->getInfo()); |
||
205 | } |
||
206 | } |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * generate the hardware information |
||
211 | * |
||
212 | * @return void |
||
213 | */ |
||
214 | private function _buildHardware() |
||
215 | { |
||
216 | $dev = new HWDevice(); |
||
217 | $hardware = $this->_xml->addChild('Hardware'); |
||
218 | if ($this->_sys->getMachine() != "") { |
||
219 | $hardware->addAttribute('Name', $this->_sys->getMachine()); |
||
220 | } |
||
221 | $pci = null; |
||
222 | View Code Duplication | foreach (System::removeDupsAndCount($this->_sys->getPciDevices()) as $dev) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
223 | if ($pci === null) $pci = $hardware->addChild('PCI'); |
||
224 | $tmp = $pci->addChild('Device'); |
||
225 | $tmp->addAttribute('Name', $dev->getName()); |
||
226 | $tmp->addAttribute('Count', $dev->getCount()); |
||
227 | } |
||
228 | $usb = null; |
||
229 | View Code Duplication | foreach (System::removeDupsAndCount($this->_sys->getUsbDevices()) as $dev) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
230 | if ($usb === null) $usb = $hardware->addChild('USB'); |
||
231 | $tmp = $usb->addChild('Device'); |
||
232 | $tmp->addAttribute('Name', $dev->getName()); |
||
233 | $tmp->addAttribute('Count', $dev->getCount()); |
||
234 | } |
||
235 | $ide = null; |
||
236 | View Code Duplication | foreach (System::removeDupsAndCount($this->_sys->getIdeDevices()) as $dev) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
237 | if ($ide === null) $ide = $hardware->addChild('IDE'); |
||
238 | $tmp = $ide->addChild('Device'); |
||
239 | $tmp->addAttribute('Name', $dev->getName()); |
||
240 | $tmp->addAttribute('Count', $dev->getCount()); |
||
241 | if ($dev->getCapacity() !== null) { |
||
242 | $tmp->addAttribute('Capacity', $dev->getCapacity()); |
||
243 | } |
||
244 | } |
||
245 | $scsi = null; |
||
246 | View Code Duplication | foreach (System::removeDupsAndCount($this->_sys->getScsiDevices()) as $dev) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
247 | if ($scsi === null) $scsi = $hardware->addChild('SCSI'); |
||
248 | $tmp = $scsi->addChild('Device'); |
||
249 | $tmp->addAttribute('Name', $dev->getName()); |
||
250 | $tmp->addAttribute('Count', $dev->getCount()); |
||
251 | if ($dev->getCapacity() !== null) { |
||
252 | $tmp->addAttribute('Capacity', $dev->getCapacity()); |
||
253 | } |
||
254 | } |
||
255 | $tb = null; |
||
256 | View Code Duplication | foreach (System::removeDupsAndCount($this->_sys->getTbDevices()) as $dev) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
257 | if ($tb === null) $tb = $hardware->addChild('TB'); |
||
258 | $tmp = $tb->addChild('Device'); |
||
259 | $tmp->addAttribute('Name', $dev->getName()); |
||
260 | $tmp->addAttribute('Count', $dev->getCount()); |
||
261 | } |
||
262 | $i2c = null; |
||
263 | View Code Duplication | foreach (System::removeDupsAndCount($this->_sys->getI2cDevices()) as $dev) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
264 | if ($i2c === null) $i2c = $hardware->addChild('I2C'); |
||
265 | $tmp = $i2c->addChild('Device'); |
||
266 | $tmp->addAttribute('Name', $dev->getName()); |
||
267 | $tmp->addAttribute('Count', $dev->getCount()); |
||
268 | } |
||
269 | |||
270 | $cpu = null; |
||
271 | foreach ($this->_sys->getCpus() as $oneCpu) { |
||
272 | if ($cpu === null) $cpu = $hardware->addChild('CPU'); |
||
273 | $tmp = $cpu->addChild('CpuCore'); |
||
274 | $tmp->addAttribute('Model', $oneCpu->getModel()); |
||
275 | if ($oneCpu->getCpuSpeed() !== 0) { |
||
276 | $tmp->addAttribute('CpuSpeed', $oneCpu->getCpuSpeed()); |
||
277 | } |
||
278 | if ($oneCpu->getCpuSpeedMax() !== 0) { |
||
279 | $tmp->addAttribute('CpuSpeedMax', $oneCpu->getCpuSpeedMax()); |
||
280 | } |
||
281 | if ($oneCpu->getCpuSpeedMin() !== 0) { |
||
282 | $tmp->addAttribute('CpuSpeedMin', $oneCpu->getCpuSpeedMin()); |
||
283 | } |
||
284 | if ($oneCpu->getTemp() !== null) { |
||
285 | $tmp->addAttribute('CpuTemp', $oneCpu->getTemp()); |
||
286 | } |
||
287 | if ($oneCpu->getBusSpeed() !== null) { |
||
288 | $tmp->addAttribute('BusSpeed', $oneCpu->getBusSpeed()); |
||
289 | } |
||
290 | if ($oneCpu->getCache() !== null) { |
||
291 | $tmp->addAttribute('Cache', $oneCpu->getCache()); |
||
292 | } |
||
293 | if ($oneCpu->getVirt() !== null) { |
||
294 | $tmp->addAttribute('Virt', $oneCpu->getVirt()); |
||
295 | } |
||
296 | if ($oneCpu->getBogomips() !== null) { |
||
297 | $tmp->addAttribute('Bogomips', $oneCpu->getBogomips()); |
||
298 | } |
||
299 | if ($oneCpu->getLoad() !== null) { |
||
300 | $tmp->addAttribute('Load', $oneCpu->getLoad()); |
||
301 | } |
||
302 | } |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * generate the memory information |
||
307 | * |
||
308 | * @return void |
||
309 | */ |
||
310 | private function _buildMemory() |
||
311 | { |
||
312 | $memory = $this->_xml->addChild('Memory'); |
||
313 | $memory->addAttribute('Free', $this->_sys->getMemFree()); |
||
314 | $memory->addAttribute('Used', $this->_sys->getMemUsed()); |
||
315 | $memory->addAttribute('Total', $this->_sys->getMemTotal()); |
||
316 | $memory->addAttribute('Percent', $this->_sys->getMemPercentUsed()); |
||
317 | if (($this->_sys->getMemApplication() !== null) || ($this->_sys->getMemBuffer() !== null) || ($this->_sys->getMemCache() !== null)) { |
||
318 | $details = $memory->addChild('Details'); |
||
319 | if ($this->_sys->getMemApplication() !== null) { |
||
320 | $details->addAttribute('App', $this->_sys->getMemApplication()); |
||
321 | $details->addAttribute('AppPercent', $this->_sys->getMemPercentApplication()); |
||
322 | } |
||
323 | if ($this->_sys->getMemBuffer() !== null) { |
||
324 | $details->addAttribute('Buffers', $this->_sys->getMemBuffer()); |
||
325 | $details->addAttribute('BuffersPercent', $this->_sys->getMemPercentBuffer()); |
||
326 | } |
||
327 | if ($this->_sys->getMemCache() !== null) { |
||
328 | $details->addAttribute('Cached', $this->_sys->getMemCache()); |
||
329 | $details->addAttribute('CachedPercent', $this->_sys->getMemPercentCache()); |
||
330 | } |
||
331 | } |
||
332 | if (count($this->_sys->getSwapDevices()) > 0) { |
||
333 | $swap = $memory->addChild('Swap'); |
||
334 | $swap->addAttribute('Free', $this->_sys->getSwapFree()); |
||
335 | $swap->addAttribute('Used', $this->_sys->getSwapUsed()); |
||
336 | $swap->addAttribute('Total', $this->_sys->getSwapTotal()); |
||
337 | $swap->addAttribute('Percent', $this->_sys->getSwapPercentUsed()); |
||
338 | $i = 1; |
||
339 | foreach ($this->_sys->getSwapDevices() as $dev) { |
||
340 | $swapMount = $swap->addChild('Mount'); |
||
341 | $this->_fillDevice($swapMount, $dev, $i++); |
||
342 | } |
||
343 | } |
||
344 | } |
||
345 | |||
346 | /** |
||
347 | * fill a xml element with atrributes from a disk device |
||
348 | * |
||
349 | * @param SimpleXmlExtended $mount Xml-Element |
||
350 | * @param DiskDevice $dev DiskDevice |
||
351 | * @param Integer $i counter |
||
352 | * |
||
353 | * @return Void |
||
354 | */ |
||
355 | private function _fillDevice(SimpleXMLExtended $mount, DiskDevice $dev, $i) |
||
356 | { |
||
357 | $mount->addAttribute('MountPointID', $i); |
||
358 | if ($dev->getFsType()!=="") $mount->addAttribute('FSType', $dev->getFsType()); |
||
359 | $mount->addAttribute('Name', $dev->getName()); |
||
360 | $mount->addAttribute('Free', sprintf("%.0f", $dev->getFree())); |
||
361 | $mount->addAttribute('Used', sprintf("%.0f", $dev->getUsed())); |
||
362 | $mount->addAttribute('Total', sprintf("%.0f", $dev->getTotal())); |
||
363 | $mount->addAttribute('Percent', $dev->getPercentUsed()); |
||
364 | if (PSI_SHOW_MOUNT_OPTION === true) { |
||
365 | if ($dev->getOptions() !== null) { |
||
366 | $mount->addAttribute('MountOptions', preg_replace("/,/", ", ", $dev->getOptions())); |
||
367 | } |
||
368 | } |
||
369 | if ($dev->getPercentInodesUsed() !== null) { |
||
370 | $mount->addAttribute('Inodes', $dev->getPercentInodesUsed()); |
||
371 | } |
||
372 | if (PSI_SHOW_MOUNT_POINT === true) { |
||
373 | $mount->addAttribute('MountPoint', $dev->getMountPoint()); |
||
374 | } |
||
375 | } |
||
376 | |||
377 | /** |
||
378 | * generate the filesysteminformation |
||
379 | * |
||
380 | * @return void |
||
381 | */ |
||
382 | private function _buildFilesystems() |
||
383 | { |
||
384 | $hideMounts = $hideFstypes = $hideDisks = array(); |
||
385 | $i = 1; |
||
386 | View Code Duplication | if (defined('PSI_HIDE_MOUNTS') && is_string(PSI_HIDE_MOUNTS)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
387 | if (preg_match(ARRAY_EXP, PSI_HIDE_MOUNTS)) { |
||
388 | $hideMounts = eval(PSI_HIDE_MOUNTS); |
||
0 ignored issues
–
show
It is generally not recommended to use
eval unless absolutely required.
On one hand, ![]() |
|||
389 | } else { |
||
390 | $hideMounts = array(PSI_HIDE_MOUNTS); |
||
391 | } |
||
392 | } |
||
393 | View Code Duplication | if (defined('PSI_HIDE_FS_TYPES') && is_string(PSI_HIDE_FS_TYPES)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
394 | if (preg_match(ARRAY_EXP, PSI_HIDE_FS_TYPES)) { |
||
395 | $hideFstypes = eval(PSI_HIDE_FS_TYPES); |
||
0 ignored issues
–
show
It is generally not recommended to use
eval unless absolutely required.
On one hand, ![]() |
|||
396 | } else { |
||
397 | $hideFstypes = array(PSI_HIDE_FS_TYPES); |
||
398 | } |
||
399 | } |
||
400 | View Code Duplication | if (defined('PSI_HIDE_DISKS')) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
401 | if (is_string(PSI_HIDE_DISKS)) { |
||
402 | if (preg_match(ARRAY_EXP, PSI_HIDE_DISKS)) { |
||
403 | $hideDisks = eval(PSI_HIDE_DISKS); |
||
0 ignored issues
–
show
It is generally not recommended to use
eval unless absolutely required.
On one hand, ![]() |
|||
404 | } else { |
||
405 | $hideDisks = array(PSI_HIDE_DISKS); |
||
406 | } |
||
407 | } elseif (PSI_HIDE_DISKS === true) { |
||
408 | return; |
||
409 | } |
||
410 | } |
||
411 | $fs = $this->_xml->addChild('FileSystem'); |
||
412 | foreach ($this->_sys->getDiskDevices() as $disk) { |
||
413 | if (!in_array($disk->getMountPoint(), $hideMounts, true) && !in_array($disk->getFsType(), $hideFstypes, true) && !in_array($disk->getName(), $hideDisks, true)) { |
||
414 | $mount = $fs->addChild('Mount'); |
||
415 | $this->_fillDevice($mount, $disk, $i++); |
||
416 | } |
||
417 | } |
||
418 | } |
||
419 | |||
420 | /** |
||
421 | * generate the motherboard information |
||
422 | * |
||
423 | * @return void |
||
424 | */ |
||
425 | private function _buildMbinfo() |
||
426 | { |
||
427 | $mbinfo = $this->_xml->addChild('MBInfo'); |
||
428 | $temp = $fan = $volt = $power = $current = null; |
||
429 | |||
430 | if (sizeof(unserialize(PSI_MBINFO))>0) { |
||
431 | foreach (unserialize(PSI_MBINFO) as $mbinfoclass) { |
||
432 | $mbinfo_data = new $mbinfoclass(); |
||
433 | $mbinfo_detail = $mbinfo_data->getMBInfo(); |
||
434 | |||
435 | View Code Duplication | foreach ($mbinfo_detail->getMbTemp() as $dev) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
436 | if ($temp == null) { |
||
437 | $temp = $mbinfo->addChild('Temperature'); |
||
438 | } |
||
439 | $item = $temp->addChild('Item'); |
||
440 | $item->addAttribute('Label', $dev->getName()); |
||
441 | $item->addAttribute('Value', $dev->getValue()); |
||
442 | if ($dev->getMax() !== null) { |
||
443 | $item->addAttribute('Max', $dev->getMax()); |
||
444 | } |
||
445 | if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") { |
||
446 | $item->addAttribute('Event', $dev->getEvent()); |
||
447 | } |
||
448 | } |
||
449 | |||
450 | View Code Duplication | foreach ($mbinfo_detail->getMbFan() as $dev) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
451 | if ($fan == null) { |
||
452 | $fan = $mbinfo->addChild('Fans'); |
||
453 | } |
||
454 | $item = $fan->addChild('Item'); |
||
455 | $item->addAttribute('Label', $dev->getName()); |
||
456 | $item->addAttribute('Value', $dev->getValue()); |
||
457 | if ($dev->getMin() !== null) { |
||
458 | $item->addAttribute('Min', $dev->getMin()); |
||
459 | } |
||
460 | if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") { |
||
461 | $item->addAttribute('Event', $dev->getEvent()); |
||
462 | } |
||
463 | } |
||
464 | |||
465 | foreach ($mbinfo_detail->getMbVolt() as $dev) { |
||
466 | if ($volt == null) { |
||
467 | $volt = $mbinfo->addChild('Voltage'); |
||
468 | } |
||
469 | $item = $volt->addChild('Item'); |
||
470 | $item->addAttribute('Label', $dev->getName()); |
||
471 | $item->addAttribute('Value', $dev->getValue()); |
||
472 | if ($dev->getMin() !== null) { |
||
473 | $item->addAttribute('Min', $dev->getMin()); |
||
474 | } |
||
475 | if ($dev->getMax() !== null) { |
||
476 | $item->addAttribute('Max', $dev->getMax()); |
||
477 | } |
||
478 | if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") { |
||
479 | $item->addAttribute('Event', $dev->getEvent()); |
||
480 | } |
||
481 | } |
||
482 | |||
483 | View Code Duplication | foreach ($mbinfo_detail->getMbPower() as $dev) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
484 | if ($power == null) { |
||
485 | $power = $mbinfo->addChild('Power'); |
||
486 | } |
||
487 | $item = $power->addChild('Item'); |
||
488 | $item->addAttribute('Label', $dev->getName()); |
||
489 | $item->addAttribute('Value', $dev->getValue()); |
||
490 | if ($dev->getMax() !== null) { |
||
491 | $item->addAttribute('Max', $dev->getMax()); |
||
492 | } |
||
493 | if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") { |
||
494 | $item->addAttribute('Event', $dev->getEvent()); |
||
495 | } |
||
496 | } |
||
497 | |||
498 | View Code Duplication | foreach ($mbinfo_detail->getMbCurrent() as $dev) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
499 | if ($current == null) { |
||
500 | $current = $mbinfo->addChild('Current'); |
||
501 | } |
||
502 | $item = $current->addChild('Item'); |
||
503 | $item->addAttribute('Label', $dev->getName()); |
||
504 | $item->addAttribute('Value', $dev->getValue()); |
||
505 | if ($dev->getMax() !== null) { |
||
506 | $item->addAttribute('Max', $dev->getMax()); |
||
507 | } |
||
508 | if (defined('PSI_SENSOR_EVENTS') && PSI_SENSOR_EVENTS && $dev->getEvent() !== "") { |
||
509 | $item->addAttribute('Event', $dev->getEvent()); |
||
510 | } |
||
511 | } |
||
512 | } |
||
513 | } |
||
514 | } |
||
515 | |||
516 | /** |
||
517 | * generate the ups information |
||
518 | * |
||
519 | * @return void |
||
520 | */ |
||
521 | private function _buildUpsinfo() |
||
522 | { |
||
523 | $upsinfo = $this->_xml->addChild('UPSInfo'); |
||
524 | if (defined('PSI_UPS_APCUPSD_CGI_ENABLE') && PSI_UPS_APCUPSD_CGI_ENABLE) { |
||
525 | $upsinfo->addAttribute('ApcupsdCgiLinks', true); |
||
0 ignored issues
–
show
true is of type boolean , but the function expects a string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
526 | } |
||
527 | if (sizeof(unserialize(PSI_UPSINFO))>0) { |
||
528 | foreach (unserialize(PSI_UPSINFO) as $upsinfoclass) { |
||
529 | $upsinfo_data = new $upsinfoclass(); |
||
530 | $upsinfo_detail = $upsinfo_data->getUPSInfo(); |
||
531 | foreach ($upsinfo_detail->getUpsDevices() as $ups) { |
||
532 | $item = $upsinfo->addChild('UPS'); |
||
533 | $item->addAttribute('Name', $ups->getName()); |
||
534 | if ($ups->getModel() !== "") { |
||
535 | $item->addAttribute('Model', $ups->getModel()); |
||
536 | } |
||
537 | $item->addAttribute('Mode', $ups->getMode()); |
||
538 | if ($ups->getStartTime() !== "") { |
||
539 | $item->addAttribute('StartTime', $ups->getStartTime()); |
||
540 | } |
||
541 | $item->addAttribute('Status', $ups->getStatus()); |
||
542 | if ($ups->getTemperatur() !== null) { |
||
543 | $item->addAttribute('Temperature', $ups->getTemperatur()); |
||
544 | } |
||
545 | if ($ups->getOutages() !== null) { |
||
546 | $item->addAttribute('OutagesCount', $ups->getOutages()); |
||
547 | } |
||
548 | if ($ups->getLastOutage() !== null) { |
||
549 | $item->addAttribute('LastOutage', $ups->getLastOutage()); |
||
550 | } |
||
551 | if ($ups->getLastOutageFinish() !== null) { |
||
552 | $item->addAttribute('LastOutageFinish', $ups->getLastOutageFinish()); |
||
553 | } |
||
554 | if ($ups->getLineVoltage() !== null) { |
||
555 | $item->addAttribute('LineVoltage', $ups->getLineVoltage()); |
||
556 | } |
||
557 | if ($ups->getLineFrequency() !== null) { |
||
558 | $item->addAttribute('LineFrequency', $ups->getLineFrequency()); |
||
559 | } |
||
560 | if ($ups->getLoad() !== null) { |
||
561 | $item->addAttribute('LoadPercent', $ups->getLoad()); |
||
562 | } |
||
563 | if ($ups->getBatteryDate() !== null) { |
||
564 | $item->addAttribute('BatteryDate', $ups->getBatteryDate()); |
||
565 | } |
||
566 | if ($ups->getBatteryVoltage() !== null) { |
||
567 | $item->addAttribute('BatteryVoltage', $ups->getBatteryVoltage()); |
||
568 | } |
||
569 | if ($ups->getBatterCharge() !== null) { |
||
570 | $item->addAttribute('BatteryChargePercent', $ups->getBatterCharge()); |
||
571 | } |
||
572 | if ($ups->getTimeLeft() !== null) { |
||
573 | $item->addAttribute('TimeLeftMinutes', $ups->getTimeLeft()); |
||
574 | } |
||
575 | } |
||
576 | } |
||
577 | } |
||
578 | } |
||
579 | |||
580 | /** |
||
581 | * generate the xml document |
||
582 | * |
||
583 | * @return void |
||
584 | */ |
||
585 | private function _buildXml() |
||
586 | { |
||
587 | if (!$this->_plugin_request || $this->_complete_request) { |
||
588 | if (version_compare("5.2", PHP_VERSION, ">")) { |
||
589 | $this->_errors->addError("ERROR", "PHP 5.2 or greater is required, some things may not work correctly"); |
||
590 | } |
||
591 | if ($this->_sys === null) { |
||
592 | if (PSI_DEBUG === true) { |
||
593 | // unstable version check |
||
594 | if (!is_numeric(substr(PSI_VERSION, -1))) { |
||
595 | $this->_errors->addError("WARN", "This is an unstable version of phpSysInfo, some things may not work correctly"); |
||
596 | } |
||
597 | |||
598 | // Safe mode check |
||
599 | $safe_mode = @ini_get("safe_mode") ? true : false; |
||
600 | if ($safe_mode) { |
||
601 | $this->_errors->addError("WARN", "PhpSysInfo requires to set off 'safe_mode' in 'php.ini'"); |
||
602 | } |
||
603 | // Include path check |
||
604 | $include_path = @ini_get("include_path"); |
||
605 | if ($include_path && ($include_path!="")) { |
||
606 | $include_path = preg_replace("/(:)|(;)/", "\n", $include_path); |
||
607 | if (preg_match("/^\.$/m", $include_path)) { |
||
608 | $include_path = "."; |
||
609 | } |
||
610 | } |
||
611 | if ($include_path != ".") { |
||
612 | $this->_errors->addError("WARN", "PhpSysInfo requires '.' inside the 'include_path' in php.ini"); |
||
613 | } |
||
614 | // popen mode check |
||
615 | if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN === true) { |
||
616 | $this->_errors->addError("WARN", "Installed version of PHP does not support proc_open() function, popen() is used"); |
||
617 | } |
||
618 | } |
||
619 | $this->_sys = $this->_sysinfo->getSys(); |
||
620 | } |
||
621 | $this->_buildVitals(); |
||
622 | $this->_buildNetwork(); |
||
623 | $this->_buildHardware(); |
||
624 | $this->_buildMemory(); |
||
625 | $this->_buildFilesystems(); |
||
626 | $this->_buildMbinfo(); |
||
627 | $this->_buildUpsinfo(); |
||
628 | } |
||
629 | $this->_buildPlugins(); |
||
630 | $this->_xml->combinexml($this->_errors->errorsAddToXML($this->_sysinfo->getEncoding())); |
||
631 | } |
||
632 | |||
633 | /** |
||
634 | * get the xml object |
||
635 | * |
||
636 | * @return string |
||
0 ignored issues
–
show
|
|||
637 | */ |
||
638 | public function getXml() |
||
639 | { |
||
640 | $this->_buildXml(); |
||
641 | |||
642 | return $this->_xml->getSimpleXmlElement(); |
||
643 | } |
||
644 | |||
645 | /** |
||
646 | * include xml-trees of the plugins to the main xml |
||
647 | * |
||
648 | * @return void |
||
649 | */ |
||
650 | private function _buildPlugins() |
||
651 | { |
||
652 | $pluginroot = $this->_xml->addChild("Plugins"); |
||
653 | if (($this->_plugin_request || $this->_complete_request) && count($this->_plugins) > 0) { |
||
654 | $plugins = array(); |
||
655 | if ($this->_complete_request) { |
||
656 | $plugins = $this->_plugins; |
||
657 | } |
||
658 | if ($this->_plugin_request) { |
||
659 | $plugins = array($this->_plugin); |
||
660 | } |
||
661 | foreach ($plugins as $plugin) { |
||
662 | $object = new $plugin($this->_sysinfo->getEncoding()); |
||
663 | $object->execute(); |
||
664 | $oxml = $object->xml(); |
||
665 | if (sizeof($oxml) > 0) { |
||
666 | $pluginroot->combinexml($oxml); |
||
667 | } |
||
668 | } |
||
669 | } |
||
670 | } |
||
671 | |||
672 | /** |
||
673 | * build the xml structure where the content can be inserted |
||
674 | * |
||
675 | * @return void |
||
676 | */ |
||
677 | private function _xmlbody() |
||
678 | { |
||
679 | $dom = new DOMDocument('1.0', 'UTF-8'); |
||
680 | $root = $dom->createElement("tns:phpsysinfo"); |
||
681 | $root->setAttribute('xmlns:tns', 'http://phpsysinfo.sourceforge.net/'); |
||
682 | $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); |
||
683 | $root->setAttribute('xsi:schemaLocation', 'http://phpsysinfo.sourceforge.net/ phpsysinfo3.xsd'); |
||
684 | $dom->appendChild($root); |
||
685 | $this->_xml = new SimpleXMLExtended(simplexml_import_dom($dom), $this->_sysinfo->getEncoding()); |
||
686 | |||
687 | $generation = $this->_xml->addChild('Generation'); |
||
688 | $generation->addAttribute('version', PSI_VERSION_STRING); |
||
689 | $generation->addAttribute('timestamp', time()); |
||
690 | $options = $this->_xml->addChild('Options'); |
||
691 | $options->addAttribute('tempFormat', defined('PSI_TEMP_FORMAT') ? strtolower(PSI_TEMP_FORMAT) : 'c'); |
||
692 | $options->addAttribute('byteFormat', defined('PSI_BYTE_FORMAT') ? strtolower(PSI_BYTE_FORMAT) : 'auto_binary'); |
||
693 | if (defined('PSI_REFRESH')) { |
||
694 | if (PSI_REFRESH === false) { |
||
695 | $options->addAttribute('refresh', 0); |
||
696 | } elseif (PSI_REFRESH === true) { |
||
697 | $options->addAttribute('refresh', 1); |
||
698 | } else { |
||
699 | $options->addAttribute('refresh', PSI_REFRESH); |
||
700 | } |
||
701 | } else { |
||
702 | $options->addAttribute('refresh', 60000); |
||
703 | } |
||
704 | if (defined('PSI_FS_USAGE_THRESHOLD')) { |
||
705 | if (PSI_FS_USAGE_THRESHOLD === true) { |
||
706 | $options->addAttribute('threshold', 1); |
||
707 | } elseif ((PSI_FS_USAGE_THRESHOLD !== false) && (PSI_FS_USAGE_THRESHOLD >= 1) && (PSI_FS_USAGE_THRESHOLD <= 99)) { |
||
708 | $options->addAttribute('threshold', PSI_FS_USAGE_THRESHOLD); |
||
709 | } |
||
710 | } else { |
||
711 | $options->addAttribute('threshold', 90); |
||
712 | } |
||
713 | if (count($this->_plugins) > 0) { |
||
714 | if ($this->_plugin_request) { |
||
715 | $plug = $this->_xml->addChild('UsedPlugins'); |
||
716 | $plug->addChild('Plugin')->addAttribute('name', $this->_plugin); |
||
717 | } elseif ($this->_complete_request) { |
||
718 | $plug = $this->_xml->addChild('UsedPlugins'); |
||
719 | foreach ($this->_plugins as $plugin) { |
||
720 | $plug->addChild('Plugin')->addAttribute('name', $plugin); |
||
721 | } |
||
722 | /* |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
62% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
723 | } else { |
||
724 | $plug = $this->_xml->addChild('UnusedPlugins'); |
||
725 | foreach ($this->_plugins as $plugin) { |
||
726 | $plug->addChild('Plugin')->addAttribute('name', $plugin); |
||
727 | } |
||
728 | */ |
||
729 | } |
||
730 | } |
||
731 | } |
||
732 | } |
||
733 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.