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 | * HP-UX System Class |
||
4 | * |
||
5 | * PHP version 5 |
||
6 | * |
||
7 | * @category PHP |
||
8 | * @package PSI HPUX OS class |
||
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.HPUX.inc.php 596 2012-07-05 19:37:48Z namiltd $ |
||
13 | * @link http://phpsysinfo.sourceforge.net |
||
14 | */ |
||
15 | /** |
||
16 | * HP-UX sysinfo class |
||
17 | * get all the required information from HP-UX system |
||
18 | * |
||
19 | * @category PHP |
||
20 | * @package PSI HPUX OS class |
||
21 | * @author Michael Cramer <[email protected]> |
||
22 | * @copyright 2009 phpSysInfo |
||
23 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
||
24 | * @version Release: 3.0 |
||
25 | * @link http://phpsysinfo.sourceforge.net |
||
26 | */ |
||
27 | class HPUX extends OS |
||
0 ignored issues
–
show
|
|||
28 | { |
||
29 | /** |
||
30 | * Virtual Host Name |
||
31 | * |
||
32 | * @return void |
||
33 | */ |
||
34 | View Code Duplication | private function _hostname() |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
35 | { |
||
36 | if (PSI_USE_VHOST === true) { |
||
37 | $this->sys->setHostname(getenv('SERVER_NAME')); |
||
38 | } else { |
||
39 | if (CommonFunctions::executeProgram('hostname', '', $ret)) { |
||
40 | $this->sys->setHostname($ret); |
||
41 | } |
||
42 | } |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * HP-UX Version |
||
47 | * |
||
48 | * @return void |
||
49 | */ |
||
50 | private function _kernel() |
||
51 | { |
||
52 | if (CommonFunctions::executeProgram('uname', '-srvm', $ret)) { |
||
53 | $this->sys->setKernel($ret); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * UpTime |
||
59 | * time the system is running |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | View Code Duplication | private function _uptime() |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
64 | { |
||
65 | if (CommonFunctions::executeProgram('uptime', '', $buf)) { |
||
66 | if (preg_match("/up (\d+) days,\s*(\d+):(\d+),/", $buf, $ar_buf)) { |
||
67 | $min = $ar_buf[3]; |
||
68 | $hours = $ar_buf[2]; |
||
69 | $days = $ar_buf[1]; |
||
70 | $this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60); |
||
0 ignored issues
–
show
$days * 86400 + $hours * 3600 + $min * 60 is of type double , but the function expects a object<Interger> .
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);
![]() |
|||
71 | } |
||
72 | } |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Processor Load |
||
77 | * optionally create a loadbar |
||
78 | * |
||
79 | * @return void |
||
80 | */ |
||
81 | View Code Duplication | private function _loadavg() |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
82 | { |
||
83 | if (CommonFunctions::executeProgram('uptime', '', $buf)) { |
||
84 | if (preg_match("/average: (.*), (.*), (.*)$/", $buf, $ar_buf)) { |
||
85 | $this->sys->setLoad($ar_buf[1].' '.$ar_buf[2].' '.$ar_buf[3]); |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * CPU information |
||
92 | * All of the tags here are highly architecture dependant |
||
93 | * |
||
94 | * @return void |
||
95 | */ |
||
96 | private function _cpuinfo() |
||
97 | { |
||
98 | if (CommonFunctions::rfts('/proc/cpuinfo', $bufr)) { |
||
99 | $processors = preg_split('/\s?\n\s?\n/', trim($bufr)); |
||
100 | foreach ($processors as $processor) { |
||
101 | $dev = new CpuDevice(); |
||
102 | $details = preg_split("/\n/", $processor, -1, PREG_SPLIT_NO_EMPTY); |
||
103 | foreach ($details as $detail) { |
||
104 | $arrBuff = preg_split('/\s+:\s+/', trim($detail)); |
||
105 | if (count($arrBuff) == 2) { |
||
106 | switch (strtolower($arrBuff[0])) { |
||
107 | case 'model name': |
||
108 | case 'cpu': |
||
109 | $dev->setModel($arrBuff[1]); |
||
110 | break; |
||
111 | case 'cpu mhz': |
||
112 | case 'clock': |
||
113 | $dev->setCpuSpeed($arrBuff[1]); |
||
114 | break; |
||
115 | case 'cycle frequency [hz]': |
||
116 | $dev->setCpuSpeed($arrBuff[1] / 1000000); |
||
117 | break; |
||
118 | case 'cpu0clktck': |
||
119 | $dev->setCpuSpeed(hexdec($arrBuff[1]) / 1000000); // Linux sparc64 |
||
120 | break; |
||
121 | case 'l2 cache': |
||
122 | case 'cache size': |
||
123 | $dev->setCache(preg_replace("/[a-zA-Z]/", "", $arrBuff[1]) * 1024); |
||
124 | break; |
||
125 | case 'bogomips': |
||
126 | case 'cpu0bogo': |
||
127 | $dev->setBogomips($arrBuff[1]); |
||
128 | break; |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | |||
136 | /** |
||
137 | * PCI devices |
||
138 | * |
||
139 | * @return void |
||
140 | */ |
||
141 | private function _pci() |
||
142 | { |
||
143 | if (CommonFunctions::rfts('/proc/pci', $bufr)) { |
||
144 | $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
||
145 | View Code Duplication | foreach ($bufe as $buf) { |
|
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. ![]() |
|||
146 | if (preg_match('/^\s*Bus\s/', $buf)) { |
||
147 | $device = true; |
||
148 | continue; |
||
149 | } |
||
150 | if ($device) { |
||
0 ignored issues
–
show
The variable
$device does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
151 | $dev = new HWDevice(); |
||
152 | $dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($buf))); |
||
153 | $this->sys->setPciDevices($dev); |
||
154 | /* |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
64% 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. ![]() |
|||
155 | list($key, $value) = preg_split('/: /', $buf, 2); |
||
156 | if (!preg_match('/bridge/i', $key) && !preg_match('/USB/i', $key)) { |
||
157 | $dev = new HWDevice(); |
||
158 | $dev->setName(preg_replace('/\([^\)]+\)\.$/', '', trim($value))); |
||
159 | $this->sys->setPciDevices($dev); |
||
160 | } |
||
161 | */ |
||
162 | $device = false; |
||
163 | } |
||
164 | } |
||
165 | } |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * IDE devices |
||
170 | * |
||
171 | * @return void |
||
172 | */ |
||
173 | private function _ide() |
||
174 | { |
||
175 | $bufd = CommonFunctions::gdc('/proc/ide', false); |
||
176 | foreach ($bufd as $file) { |
||
177 | if (preg_match('/^hd/', $file)) { |
||
178 | $dev = new HWDevice(); |
||
179 | $dev->setName(trim($file)); |
||
180 | View Code Duplication | if (CommonFunctions::rfts("/proc/ide/".$file."/media", $buf, 1)) { |
|
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. ![]() |
|||
181 | if (trim($buf) == 'disk') { |
||
182 | if (CommonFunctions::rfts("/proc/ide/".$file."/capacity", $buf, 1, 4096, false)) { |
||
183 | $dev->setCapacity(trim($buf) * 512 / 1024); |
||
184 | } |
||
185 | } |
||
186 | } |
||
187 | $this->sys->setIdeDevices($dev); |
||
188 | } |
||
189 | } |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * SCSI devices |
||
194 | * |
||
195 | * @return void |
||
196 | */ |
||
197 | private function _scsi() |
||
198 | { |
||
199 | $get_type = false; |
||
200 | if (CommonFunctions::rfts('/proc/scsi/scsi', $bufr, 0, 4096, PSI_DEBUG)) { |
||
201 | $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
||
202 | View Code Duplication | foreach ($bufe as $buf) { |
|
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. ![]() |
|||
203 | if (preg_match('/Vendor: (.*) Model: (.*) Rev: (.*)/i', $buf, $dev)) { |
||
204 | $get_type = true; |
||
205 | continue; |
||
206 | } |
||
207 | if ($get_type) { |
||
208 | preg_match('/Type:\s+(\S+)/i', $buf, $dev_type); |
||
209 | $dev = new HWDevice(); |
||
210 | $dev->setName($dev[1].' '.$dev[2].' ('.$dev_type[1].')'); |
||
211 | $this->sys->setScsiDevices($dev); |
||
212 | $get_type = false; |
||
213 | } |
||
214 | } |
||
215 | } |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * USB devices |
||
220 | * |
||
221 | * @return void |
||
222 | */ |
||
223 | private function _usb() |
||
224 | { |
||
225 | if (CommonFunctions::rfts('/proc/bus/usb/devices', $bufr, 0, 4096, false)) { |
||
226 | $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
||
227 | foreach ($bufe as $buf) { |
||
228 | if (preg_match('/^T/', $buf)) { |
||
229 | $devnum += 1; |
||
0 ignored issues
–
show
The variable
$devnum does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
230 | $results[$devnum] = ""; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$results was never initialized. Although not strictly required by PHP, it is generally a good practice to add $results = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
231 | } elseif (preg_match('/^S:/', $buf)) { |
||
232 | list($key, $value) = preg_split('/: /', $buf, 2); |
||
233 | list($key, $value2) = preg_split('/=/', $value, 2); |
||
234 | if (trim($key) != "SerialNumber") { |
||
235 | $results[$devnum] .= " ".trim($value2); |
||
0 ignored issues
–
show
The variable
$results does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
236 | } |
||
237 | } |
||
238 | } |
||
239 | foreach ($results as $var) { |
||
240 | $dev = new HWDevice(); |
||
241 | $dev->setName($var); |
||
242 | $this->sys->setUsbDevices($dev); |
||
243 | } |
||
244 | } |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * Network devices |
||
249 | * includes also rx/tx bytes |
||
250 | * |
||
251 | * @return void |
||
252 | */ |
||
253 | View Code Duplication | private function _network() |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
254 | { |
||
255 | if (CommonFunctions::executeProgram('netstat', '-ni | tail -n +2', $netstat)) { |
||
256 | $lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY); |
||
257 | foreach ($lines as $line) { |
||
258 | $ar_buf = preg_split("/\s+/", $line); |
||
259 | if (! empty($ar_buf[0]) && ! empty($ar_buf[3])) { |
||
260 | $dev = new NetDevice(); |
||
261 | $dev->setName($ar_buf[0]); |
||
262 | $dev->setRxBytes($ar_buf[4]); |
||
263 | $dev->setTxBytes($ar_buf[6]); |
||
264 | $dev->setErrors($ar_buf[5] + $ar_buf[7]); |
||
265 | $dev->setDrops($ar_buf[8]); |
||
266 | $this->sys->setNetDevices($dev); |
||
267 | } |
||
268 | } |
||
269 | } |
||
270 | } |
||
271 | |||
272 | /** |
||
273 | * Physical memory information and Swap Space information |
||
274 | * |
||
275 | * @return void |
||
276 | */ |
||
277 | private function _memory() |
||
278 | { |
||
279 | if (CommonFunctions::rfts('/proc/meminfo', $bufr)) { |
||
280 | $bufe = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
||
281 | foreach ($bufe as $buf) { |
||
282 | if (preg_match('/Mem:\s+(.*)$/', $buf, $ar_buf)) { |
||
283 | $ar_buf = preg_split('/\s+/', $ar_buf[1], 6); |
||
284 | $this->sys->setMemTotal($ar_buf[0]); |
||
285 | $this->sys->setMemUsed($ar_buf[1]); |
||
286 | $this->sys->setMemFree($ar_buf[2]); |
||
287 | $this->sys->setMemApplication($ar_buf[3]); |
||
288 | $this->sys->setMemBuffer($ar_buf[4]); |
||
289 | $this->sys->setMemCache($ar_buf[5]); |
||
290 | } |
||
291 | // Get info on individual swap files |
||
292 | if (CommonFunctions::rfts('/proc/swaps', $swaps)) { |
||
293 | $swapdevs = preg_split("/\n/", $swaps, -1, PREG_SPLIT_NO_EMPTY); |
||
294 | for ($i = 1, $max = (sizeof($swapdevs) - 1); $i < $max; $i++) { |
||
295 | $ar_buf = preg_split('/\s+/', $swapdevs[$i], 6); |
||
296 | $dev = new DiskDevice(); |
||
297 | $dev->setMountPoint($ar_buf[0]); |
||
298 | $dev->setName("SWAP"); |
||
299 | $dev->setFsType('swap'); |
||
300 | $dev->setTotal($ar_buf[2] * 1024); |
||
301 | $dev->setUsed($ar_buf[3] * 1024); |
||
302 | $dev->setFree($dev->getTotal() - $dev->getUsed()); |
||
303 | $this->sys->setSwapDevices($dev); |
||
304 | } |
||
305 | } |
||
306 | } |
||
307 | } |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * filesystem information |
||
312 | * |
||
313 | * @return void |
||
314 | */ |
||
315 | View Code Duplication | private function _filesystems() |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
316 | { |
||
317 | if (CommonFunctions::executeProgram('df', '-kP', $df, PSI_DEBUG)) { |
||
318 | $mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY); |
||
319 | if (CommonFunctions::executeProgram('mount', '-v', $s, PSI_DEBUG)) { |
||
320 | $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); |
||
321 | while (list(, $line) = each($lines)) { |
||
322 | $a = preg_split('/ /', $line, -1, PREG_SPLIT_NO_EMPTY); |
||
323 | $fsdev[$a[0]] = $a[4]; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$fsdev was never initialized. Although not strictly required by PHP, it is generally a good practice to add $fsdev = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
324 | } |
||
325 | } |
||
326 | foreach ($mounts as $mount) { |
||
327 | $ar_buf = preg_split("/\s+/", $mount, 6); |
||
328 | $dev = new DiskDevice(); |
||
329 | $dev->setName($ar_buf[0]); |
||
330 | $dev->setTotal($ar_buf[1] * 1024); |
||
331 | $dev->setUsed($ar_buf[2] * 1024); |
||
332 | $dev->setFree($ar_buf[3] * 1024); |
||
333 | $dev->setMountPoint($ar_buf[5]); |
||
334 | if (isset($fsdev[$ar_buf[0]])) { |
||
335 | $dev->setFsType($fsdev[$ar_buf[0]]); |
||
336 | } |
||
337 | $this->sys->setDiskDevices($dev); |
||
338 | } |
||
339 | } |
||
340 | } |
||
341 | |||
342 | /** |
||
343 | * Distribution |
||
344 | * |
||
345 | * @return void |
||
346 | */ |
||
347 | private function _distro() |
||
348 | { |
||
349 | $this->sys->setDistribution('HP-UX'); |
||
350 | $this->sys->setDistributionIcon('HPUX.png'); |
||
351 | } |
||
352 | |||
353 | /** |
||
354 | * get the information |
||
355 | * |
||
356 | * @see PSI_Interface_OS::build() |
||
357 | * |
||
358 | * @return Void |
||
359 | */ |
||
360 | public function build() |
||
361 | { |
||
362 | $this->_distro(); |
||
363 | $this->_hostname(); |
||
364 | $this->_kernel(); |
||
365 | $this->_uptime(); |
||
366 | $this->_users(); |
||
367 | $this->_loadavg(); |
||
368 | $this->_cpuinfo(); |
||
369 | $this->_pci(); |
||
370 | $this->_ide(); |
||
371 | $this->_scsi(); |
||
372 | $this->_usb(); |
||
373 | $this->_network(); |
||
374 | $this->_memory(); |
||
375 | $this->_filesystems(); |
||
376 | } |
||
377 | } |
||
378 |
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.