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 | * NetBSD System Class |
||
4 | * |
||
5 | * PHP version 5 |
||
6 | * |
||
7 | * @category PHP |
||
8 | * @package PSI NetBSD 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.NetBSD.inc.php 287 2009-06-26 12:11:59Z bigmichi1 $ |
||
13 | * @link http://phpsysinfo.sourceforge.net |
||
14 | */ |
||
15 | /** |
||
16 | * NetBSD sysinfo class |
||
17 | * get all the required information from NetBSD systems |
||
18 | * |
||
19 | * @category PHP |
||
20 | * @package PSI NetBSD 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 NetBSD extends BSDCommon |
||
0 ignored issues
–
show
|
|||
28 | { |
||
29 | /** |
||
30 | * define the regexp for log parser |
||
31 | */ |
||
32 | View Code Duplication | public function __construct() |
|
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. ![]() |
|||
33 | { |
||
34 | parent::__construct(); |
||
35 | $this->setCPURegExp1("/^cpu(.*)\, (.*) MHz/"); |
||
36 | $this->setCPURegExp2("/user = (.*), nice = (.*), sys = (.*), intr = (.*), idle = (.*)/"); |
||
37 | $this->setSCSIRegExp1("/^(.*) at scsibus.*: <(.*)> .*/"); |
||
38 | $this->setSCSIRegExp2("/^(da[0-9]+): (.*)MB /"); |
||
39 | $this->setPCIRegExp1("/(.*) at pci[0-9]+ dev [0-9]* function [0-9]*: (.*)$/"); |
||
40 | $this->setPCIRegExp2("/\"(.*)\" (.*).* at [.0-9]+ irq/"); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * UpTime |
||
45 | * time the system is running |
||
46 | * |
||
47 | * @return void |
||
48 | */ |
||
49 | private function _uptime() |
||
50 | { |
||
51 | $a = $this->grabkey('kern.boottime'); |
||
52 | $this->sys->setUptime(time() - $a); |
||
0 ignored issues
–
show
time() - $a is of type integer|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);
![]() |
|||
53 | } |
||
54 | |||
55 | /** |
||
56 | * get network information |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | 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. ![]() |
|||
61 | { |
||
62 | CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_b); |
||
63 | CommonFunctions::executeProgram('netstat', '-ndi | cut -c1-25,44- | grep "^[a-z]*[0-9][ \t].*Link"', $netstat_n); |
||
64 | $lines_b = preg_split("/\n/", $netstat_b, -1, PREG_SPLIT_NO_EMPTY); |
||
65 | $lines_n = preg_split("/\n/", $netstat_n, -1, PREG_SPLIT_NO_EMPTY); |
||
66 | for ($i = 0, $max = sizeof($lines_b); $i < $max; $i++) { |
||
67 | $ar_buf_b = preg_split("/\s+/", $lines_b[$i]); |
||
68 | $ar_buf_n = preg_split("/\s+/", $lines_n[$i]); |
||
69 | if (!empty($ar_buf_b[0]) && (!empty($ar_buf_n[3]) || ($ar_buf_n[3] === "0"))) { |
||
70 | $dev = new NetDevice(); |
||
71 | $dev->setName($ar_buf_b[0]); |
||
72 | $dev->setTxBytes($ar_buf_b[4]); |
||
73 | $dev->setRxBytes($ar_buf_b[3]); |
||
74 | $dev->setDrops($ar_buf_n[8]); |
||
75 | $dev->setErrors($ar_buf_n[4] + $ar_buf_n[6]); |
||
76 | if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf_b[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) { |
||
77 | $speedinfo = ""; |
||
78 | $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY); |
||
79 | foreach ($bufe2 as $buf2) { |
||
80 | if (preg_match('/^\s+address:\s+(\S+)/i', $buf2, $ar_buf2)) |
||
81 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1]))); |
||
82 | elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) |
||
83 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]); |
||
84 | elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2) |
||
85 | || preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2)) |
||
86 | && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) |
||
87 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1])); |
||
88 | elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) { |
||
89 | if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") { |
||
90 | $unit = "G"; |
||
91 | } else { |
||
92 | $unit = "M"; |
||
93 | } |
||
94 | if (preg_match('/\s(\S+)-duplex/i', $buf2, $ar_buf3)) |
||
95 | $speedinfo = $ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]); |
||
96 | else |
||
97 | $speedinfo = $ar_buf2[1].$unit.'b/s'; |
||
98 | } |
||
99 | } |
||
100 | if ($speedinfo != "") $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$speedinfo); |
||
101 | } |
||
102 | $this->sys->setNetDevices($dev); |
||
103 | } |
||
104 | } |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * IDE information |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | protected function ide() |
||
113 | { |
||
114 | foreach ($this->readdmesg() as $line) { |
||
115 | if (preg_match('/^(.*) at (pciide|wdc|atabus|atapibus)[0-9]+ (.*): <(.*)>/', $line, $ar_buf)) { |
||
116 | $dev = new HWDevice(); |
||
117 | $dev->setName($ar_buf[1]); |
||
118 | // now loop again and find the capacity |
||
119 | foreach ($this->readdmesg() as $line2) { |
||
120 | if (preg_match("/^(".$ar_buf[1]."): (.*), (.*), (.*)MB, .*$/", $line2, $ar_buf_n)) { |
||
121 | $dev->setCapacity($ar_buf_n[4] * 2048 * 1.049); |
||
122 | View Code Duplication | } elseif (preg_match("/^(".$ar_buf[1]."): (.*) MB, (.*), (.*), .*$/", $line2, $ar_buf_n)) { |
|
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. ![]() |
|||
123 | $dev->setCapacity($ar_buf_n[2] * 2048); |
||
124 | } |
||
125 | } |
||
126 | $this->sys->setIdeDevices($dev); |
||
127 | } |
||
128 | } |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * get icon name |
||
133 | * |
||
134 | * @return void |
||
135 | */ |
||
136 | private function _distroicon() |
||
137 | { |
||
138 | $this->sys->setDistributionIcon('NetBSD.png'); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Processes |
||
143 | * |
||
144 | * @return void |
||
145 | */ |
||
146 | View Code Duplication | protected function _processes() |
|
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. ![]() |
|||
147 | { |
||
148 | if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) { |
||
149 | $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
||
150 | $processes['*'] = 0; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$processes was never initialized. Although not strictly required by PHP, it is generally a good practice to add $processes = 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. ![]() |
|||
151 | foreach ($lines as $line) { |
||
152 | if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) { |
||
153 | $processes['*']++; |
||
154 | $state = $ar_buf[1]; |
||
155 | if ($state == 'O') $state = 'R'; //linux format |
||
156 | elseif ($state == 'I') $state = 'S'; |
||
157 | if (isset($processes[$state])) { |
||
158 | $processes[$state]++; |
||
159 | } else { |
||
160 | $processes[$state] = 1; |
||
161 | } |
||
162 | } |
||
163 | } |
||
164 | if ($processes['*'] > 0) { |
||
165 | $this->sys->setProcesses($processes); |
||
166 | } |
||
167 | } |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * get the information |
||
172 | * |
||
173 | * @see BSDCommon::build() |
||
174 | * |
||
175 | * @return Void |
||
176 | */ |
||
177 | public function build() |
||
178 | { |
||
179 | parent::build(); |
||
180 | $this->_distroicon(); |
||
181 | $this->_network(); |
||
182 | $this->_uptime(); |
||
183 | $this->_processes(); |
||
184 | } |
||
185 | } |
||
186 |
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.