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 | * Darwin System Class |
||
4 | * |
||
5 | * PHP version 5 |
||
6 | * |
||
7 | * @category PHP |
||
8 | * @package PSI Darwin 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.Darwin.inc.php 638 2012-08-24 09:40:48Z namiltd $ |
||
13 | * @link http://phpsysinfo.sourceforge.net |
||
14 | */ |
||
15 | /** |
||
16 | * Darwin sysinfo class |
||
17 | * get all the required information from Darwin system |
||
18 | * information may be incomplete |
||
19 | * |
||
20 | * @category PHP |
||
21 | * @package PSI Darwin OS class |
||
22 | * @author Michael Cramer <[email protected]> |
||
23 | * @copyright 2009 phpSysInfo |
||
24 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
||
25 | * @version Release: 3.0 |
||
26 | * @link http://phpsysinfo.sourceforge.net |
||
27 | */ |
||
28 | class Darwin extends BSDCommon |
||
0 ignored issues
–
show
|
|||
29 | { |
||
30 | /** |
||
31 | * define the regexp for log parser |
||
32 | */ |
||
33 | /* public function __construct() |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
68% 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. ![]() |
|||
34 | { |
||
35 | parent::__construct(); |
||
36 | $this->error->addWarning("The Darwin version of phpSysInfo is a work in progress, some things currently don't work!"); |
||
37 | $this->setCPURegExp1("/CPU: (.*) \((.*)-MHz (.*)\)/"); |
||
38 | $this->setCPURegExp2("/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/"); |
||
39 | $this->setSCSIRegExp1("/^(.*): <(.*)> .*SCSI.*device/"); |
||
40 | } */ |
||
41 | |||
42 | /** |
||
43 | * get a value from sysctl command |
||
44 | * |
||
45 | * @param string $key key of the value to get |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | protected function grabkey($key) |
||
50 | { |
||
51 | if (CommonFunctions::executeProgram('sysctl', $key, $s, PSI_DEBUG)) { |
||
52 | $s = preg_replace('/'.$key.': /', '', $s); |
||
53 | $s = preg_replace('/'.$key.' = /', '', $s); |
||
54 | |||
55 | return $s; |
||
56 | } else { |
||
57 | return ''; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * get a value from ioreg command |
||
63 | * |
||
64 | * @param string $key key of the value to get |
||
65 | * |
||
66 | * @return string |
||
67 | */ |
||
68 | private function _grabioreg($key) |
||
69 | { |
||
70 | if (CommonFunctions::executeProgram('ioreg', '-c "'.$key.'"', $s, PSI_DEBUG)) { |
||
71 | /* delete newlines */ |
||
72 | $s = preg_replace("/\s+/", " ", $s); |
||
73 | /* new newlines */ |
||
74 | $s = preg_replace("/[\|\t ]*\+\-o/", "\n", $s); |
||
75 | /* combine duplicate whitespaces and some chars */ |
||
76 | $s = preg_replace("/[\|\t ]+/", " ", $s); |
||
77 | |||
78 | $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); |
||
79 | $out = ""; |
||
80 | foreach ($lines as $line) { |
||
81 | if (preg_match('/^([^<]*) <class '.$key.',/', $line)) { |
||
82 | $out .= $line."\n"; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | return $out; |
||
87 | } else { |
||
88 | return ''; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * UpTime |
||
94 | * time the system is running |
||
95 | * |
||
96 | * @return void |
||
97 | */ |
||
98 | private function _uptime() |
||
99 | { |
||
100 | if (CommonFunctions::executeProgram('sysctl', '-n kern.boottime', $a, PSI_DEBUG)) { |
||
101 | $tmp = explode(" ", $a); |
||
102 | if ($tmp[0]=="{") { /* kern.boottime= { sec = 1096732600, usec = 885425 } Sat Oct 2 10:56:40 2004 */ |
||
103 | $data = trim($tmp[3], ","); |
||
104 | $this->sys->setUptime(time() - $data); |
||
0 ignored issues
–
show
time() - $data 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);
![]() |
|||
105 | } else { /* kern.boottime= 1096732600 */ |
||
106 | $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);
![]() |
|||
107 | } |
||
108 | } |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * get CPU information |
||
113 | * |
||
114 | * @return void |
||
115 | */ |
||
116 | protected function cpuinfo() |
||
117 | { |
||
118 | $dev = new CpuDevice(); |
||
119 | if (CommonFunctions::executeProgram('hostinfo', '| grep "Processor type"', $buf, PSI_DEBUG)) { |
||
120 | $dev->setModel(preg_replace('/Processor type: /', '', $buf)); |
||
121 | $buf=$this->grabkey('hw.model'); |
||
122 | if (!is_null($buf) && (trim($buf) != "")) { |
||
123 | $this->sys->setMachine(trim($buf)); |
||
0 ignored issues
–
show
trim($buf) is of type string , 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);
![]() |
|||
124 | if (CommonFunctions::rfts(APP_ROOT.'/data/ModelTranslation.txt', $buffer)) { |
||
125 | $buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY); |
||
126 | foreach ($buffer as $line) { |
||
127 | $ar_buf = preg_split("/:/", $line, 3); |
||
128 | if (trim($buf) === trim($ar_buf[0])) { |
||
129 | $dev->setModel(trim($ar_buf[2])); |
||
130 | $this->sys->setMachine($this->sys->getMachine().' - '.trim($ar_buf[1])); |
||
0 ignored issues
–
show
$this->sys->getMachine()... - ' . trim($ar_buf[1]) is of type string , 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);
![]() |
|||
131 | break; |
||
132 | } |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | $buf=$this->grabkey('machdep.cpu.brand_string'); |
||
137 | if (!is_null($buf) && (trim($buf) != "") && |
||
138 | ((trim($buf) != "i486 (Intel 80486)") || ($dev->getModel() == ""))) { |
||
139 | $dev->setModel(trim($buf)); |
||
140 | } |
||
141 | $buf=$this->grabkey('machdep.cpu.features'); |
||
142 | if (!is_null($buf) && (trim($buf) != "")) { |
||
143 | View Code Duplication | if (preg_match("/ VMX/", $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. ![]() |
|||
144 | $dev->setVirt("vmx"); |
||
145 | } elseif (preg_match("/ SVM/", $buf)) { |
||
146 | $dev->setVirt("svm"); |
||
147 | } |
||
148 | } |
||
149 | } |
||
150 | $dev->setCpuSpeed(round($this->grabkey('hw.cpufrequency') / 1000000)); |
||
151 | $dev->setBusSpeed(round($this->grabkey('hw.busfrequency') / 1000000)); |
||
152 | $bufn=$this->grabkey('hw.cpufrequency_min'); |
||
153 | $bufx=$this->grabkey('hw.cpufrequency_max'); |
||
154 | if (!is_null($bufn) && (trim($bufn) != "") && !is_null($bufx) && (trim($bufx) != "") && ($bufn != $bufx)) { |
||
155 | $dev->setCpuSpeedMin(round($bufn / 1000000)); |
||
156 | $dev->setCpuSpeedMax(round($bufx / 1000000)); |
||
157 | } |
||
158 | $buf=$this->grabkey('hw.l2cachesize'); |
||
159 | if (!is_null($buf) && (trim($buf) != "")) { |
||
160 | $dev->setCache(round($buf)); |
||
161 | } |
||
162 | $ncpu = $this->grabkey('hw.ncpu'); |
||
163 | View Code Duplication | if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 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. ![]() |
|||
164 | $ncpu = 1; |
||
165 | for ($ncpu ; $ncpu > 0 ; $ncpu--) { |
||
166 | $this->sys->setCpus($dev); |
||
0 ignored issues
–
show
$dev is of type object<CpuDevice> , but the function expects a object<Cpu> .
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);
![]() |
|||
167 | } |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * get the pci device information out of ioreg |
||
172 | * |
||
173 | * @return void |
||
174 | */ |
||
175 | protected function pci() |
||
176 | { |
||
177 | if (!$arrResults = Parser::lspci(false)) { //no lspci port |
||
178 | $s = $this->_grabioreg('IOPCIDevice'); |
||
179 | $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); |
||
180 | foreach ($lines as $line) { |
||
181 | $dev = new HWDevice(); |
||
182 | if (!preg_match('/"IOName" = "([^"]*)"/', $line, $ar_buf)) { |
||
183 | $ar_buf = preg_split("/[\s@]+/", $line, 19); |
||
184 | } |
||
185 | if (preg_match('/"model" = <?"([^"]*)"/', $line, $ar_buf2)) { |
||
186 | $dev->setName(trim($ar_buf[1]). ": ".trim($ar_buf2[1])); |
||
187 | } else { |
||
188 | $dev->setName(trim($ar_buf[1])); |
||
189 | } |
||
190 | $this->sys->setPciDevices($dev); |
||
191 | } |
||
192 | } else { |
||
193 | foreach ($arrResults as $dev) { |
||
194 | $this->sys->setPciDevices($dev); |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * get the ide device information out of ioreg |
||
201 | * |
||
202 | * @return void |
||
203 | */ |
||
204 | protected function ide() |
||
205 | { |
||
206 | $s = $this->_grabioreg('IOATABlockStorageDevice'); |
||
207 | $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); |
||
208 | foreach ($lines as $line) { |
||
209 | $dev = new HWDevice(); |
||
210 | if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf)) |
||
211 | $ar_buf = preg_split("/[\s@]+/", $line, 19); |
||
212 | $dev->setName(trim($ar_buf[1])); |
||
213 | $this->sys->setIdeDevices($dev); |
||
214 | } |
||
215 | |||
216 | $s = $this->_grabioreg('IOAHCIBlockStorageDevice'); |
||
217 | $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); |
||
218 | foreach ($lines as $line) { |
||
219 | $dev = new HWDevice(); |
||
220 | if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf)) |
||
221 | $ar_buf = preg_split("/[\s@]+/", $line, 19); |
||
222 | $dev->setName(trim($ar_buf[1])); |
||
223 | $this->sys->setIdeDevices($dev); |
||
224 | } |
||
225 | } |
||
226 | |||
227 | /** |
||
228 | * get the usb device information out of ioreg |
||
229 | * |
||
230 | * @return void |
||
231 | */ |
||
232 | View Code Duplication | protected function usb() |
|
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. ![]() |
|||
233 | { |
||
234 | $s = $this->_grabioreg('IOUSBDevice'); |
||
235 | $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); |
||
236 | foreach ($lines as $line) { |
||
237 | $dev = new HWDevice(); |
||
238 | if (!preg_match('/"USB Product Name" = "([^"]*)"/', $line, $ar_buf)) |
||
239 | $ar_buf = preg_split("/[\s@]+/", $line, 19); |
||
240 | $dev->setName(trim($ar_buf[1])); |
||
241 | $this->sys->setUsbDevices($dev); |
||
242 | } |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * get the scsi device information out of ioreg |
||
247 | * |
||
248 | * @return void |
||
249 | */ |
||
250 | View Code Duplication | protected function scsi() |
|
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. ![]() |
|||
251 | { |
||
252 | $s = $this->_grabioreg('IOBlockStorageServices'); |
||
253 | $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); |
||
254 | foreach ($lines as $line) { |
||
255 | $dev = new HWDevice(); |
||
256 | if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf)) |
||
257 | $ar_buf = preg_split("/[\s@]+/", $line, 19); |
||
258 | $dev->setName(trim($ar_buf[1])); |
||
259 | $this->sys->setScsiDevices($dev); |
||
260 | } |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * get memory and swap information |
||
265 | * |
||
266 | * @return void |
||
267 | */ |
||
268 | protected function memory() |
||
269 | { |
||
270 | $s = $this->grabkey('hw.memsize'); |
||
271 | if (CommonFunctions::executeProgram('vm_stat', '', $pstat, PSI_DEBUG)) { |
||
272 | // calculate free memory from page sizes (each page = 4096) |
||
273 | if (preg_match('/^Pages free:\s+(\S+)/m', $pstat, $free_buf)) { |
||
274 | if (preg_match('/^Anonymous pages:\s+(\S+)/m', $pstat, $anon_buf) |
||
275 | && preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf) |
||
276 | && preg_match('/^File-backed pages:\s+(\S+)/m', $pstat, $fileb_buf)) { |
||
277 | // OS X 10.9 or never |
||
278 | $this->sys->setMemFree($free_buf[1] * 4 * 1024); |
||
279 | $this->sys->setMemApplication(($anon_buf[1]+$wire_buf[1]) * 4 * 1024); |
||
280 | $this->sys->setMemCache($fileb_buf[1] * 4 * 1024); |
||
281 | if (preg_match('/^Pages occupied by compressor:\s+(\S+)/m', $pstat, $compr_buf)) { |
||
282 | $this->sys->setMemBuffer($compr_buf[1] * 4 * 1024); |
||
283 | } |
||
284 | } else { |
||
285 | if (preg_match('/^Pages speculative:\s+(\S+)/m', $pstat, $spec_buf)) { |
||
286 | $this->sys->setMemFree(($free_buf[1]+$spec_buf[1]) * 4 * 1024); |
||
287 | } else { |
||
288 | $this->sys->setMemFree($free_buf[1] * 4 * 1024); |
||
289 | } |
||
290 | $appMemory = 0; |
||
291 | if (preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)) { |
||
292 | $appMemory += $wire_buf[1] * 4 * 1024; |
||
293 | } |
||
294 | if (preg_match('/^Pages active:\s+(\S+)/m', $pstat, $active_buf)) { |
||
295 | $appMemory += $active_buf[1] * 4 * 1024; |
||
296 | } |
||
297 | $this->sys->setMemApplication($appMemory); |
||
298 | |||
299 | if (preg_match('/^Pages inactive:\s+(\S+)/m', $pstat, $inactive_buf)) { |
||
300 | $this->sys->setMemCache($inactive_buf[1] * 4 * 1024); |
||
301 | } |
||
302 | } |
||
303 | } else { |
||
304 | $lines = preg_split("/\n/", $pstat, -1, PREG_SPLIT_NO_EMPTY); |
||
305 | $ar_buf = preg_split("/\s+/", $lines[1], 19); |
||
306 | $this->sys->setMemFree($ar_buf[2] * 4 * 1024); |
||
307 | } |
||
308 | |||
309 | $this->sys->setMemTotal($s); |
||
310 | $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree()); |
||
311 | |||
312 | if (CommonFunctions::executeProgram('sysctl', 'vm.swapusage | colrm 1 22', $swapBuff, PSI_DEBUG)) { |
||
313 | $swap1 = preg_split('/M/', $swapBuff); |
||
314 | $swap2 = preg_split('/=/', $swap1[1]); |
||
315 | $swap3 = preg_split('/=/', $swap1[2]); |
||
316 | $dev = new DiskDevice(); |
||
317 | $dev->setName('SWAP'); |
||
318 | $dev->setMountPoint('SWAP'); |
||
319 | $dev->setFsType('swap'); |
||
320 | $dev->setTotal($swap1[0] * 1024 * 1024); |
||
321 | $dev->setUsed($swap2[1] * 1024 * 1024); |
||
322 | $dev->setFree($swap3[1] * 1024 * 1024); |
||
323 | $this->sys->setSwapDevices($dev); |
||
324 | } |
||
325 | } |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * get the thunderbolt device information out of ioreg |
||
330 | * |
||
331 | * @return void |
||
332 | */ |
||
333 | View Code Duplication | protected function _tb() |
|
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. ![]() |
|||
334 | { |
||
335 | $s = $this->_grabioreg('IOThunderboltPort'); |
||
336 | $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY); |
||
337 | foreach ($lines as $line) { |
||
338 | $dev = new HWDevice(); |
||
339 | if (!preg_match('/"Description" = "([^"]*)"/', $line, $ar_buf)) |
||
340 | $ar_buf = preg_split("/[\s@]+/", $line, 19); |
||
341 | $dev->setName(trim($ar_buf[1])); |
||
342 | $this->sys->setTbDevices($dev); |
||
343 | } |
||
344 | } |
||
345 | |||
346 | /** |
||
347 | * get network information |
||
348 | * |
||
349 | * @return void |
||
350 | */ |
||
351 | private function _network() |
||
352 | { |
||
353 | if (CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-24,42- | grep Link', $netstat, PSI_DEBUG)) { |
||
354 | $lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY); |
||
355 | foreach ($lines as $line) { |
||
356 | $ar_buf = preg_split("/\s+/", $line, 10); |
||
357 | if (!empty($ar_buf[0])) { |
||
358 | $dev = new NetDevice(); |
||
359 | $dev->setName($ar_buf[0]); |
||
360 | $dev->setTxBytes($ar_buf[8]); |
||
361 | $dev->setRxBytes($ar_buf[5]); |
||
362 | $dev->setErrors($ar_buf[4] + $ar_buf[7]); |
||
363 | if (isset($ar_buf[10])) { |
||
364 | $dev->setDrops($ar_buf[10]); |
||
365 | } |
||
366 | View Code Duplication | if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) { |
|
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. ![]() |
|||
367 | $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY); |
||
368 | foreach ($bufe2 as $buf2) { |
||
369 | if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) |
||
370 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1]))); |
||
371 | elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) |
||
372 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]); |
||
373 | elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2) |
||
374 | || preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2)) |
||
375 | && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) |
||
376 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1])); |
||
377 | elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) { |
||
378 | if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") { |
||
379 | $unit = "G"; |
||
380 | } else { |
||
381 | $unit = "M"; |
||
382 | } |
||
383 | if (preg_match('/[<\s]([^\s<]+)-duplex/i', $buf2, $ar_buf3)) |
||
384 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1])); |
||
385 | else |
||
386 | $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s'); |
||
387 | } |
||
388 | } |
||
389 | } |
||
390 | $this->sys->setNetDevices($dev); |
||
391 | } |
||
392 | } |
||
393 | } |
||
394 | } |
||
395 | |||
396 | /** |
||
397 | * get icon name |
||
398 | * |
||
399 | * @return void |
||
400 | */ |
||
401 | protected function distro() |
||
402 | { |
||
403 | $this->sys->setDistributionIcon('Darwin.png'); |
||
404 | if (!CommonFunctions::executeProgram('system_profiler', 'SPSoftwareDataType', $buffer, PSI_DEBUG)) { |
||
405 | parent::distro(); |
||
406 | } else { |
||
407 | $arrBuff = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY); |
||
408 | foreach ($arrBuff as $line) { |
||
409 | $arrLine = preg_split("/:/", $line, -1, PREG_SPLIT_NO_EMPTY); |
||
410 | if (trim($arrLine[0]) === "System Version") { |
||
411 | $distro = trim($arrLine[1]); |
||
412 | |||
413 | View Code Duplication | if (preg_match('/(^Mac OS)|(^OS X)/', $distro)) { |
|
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. ![]() |
|||
414 | $this->sys->setDistributionIcon('Apple.png'); |
||
415 | if (preg_match('/((^Mac OS X Server)|(^Mac OS X)|(^OS X Server)|(^OS X)) (\d+\.\d+)/', $distro, $ver) |
||
416 | && ($list = @parse_ini_file(APP_ROOT."/data/osnames.ini", true)) |
||
417 | && isset($list['OS X'][$ver[6]])) { |
||
418 | $distro.=' '.$list['OS X'][$ver[6]]; |
||
419 | } |
||
420 | } |
||
421 | |||
422 | $this->sys->setDistribution($distro); |
||
423 | |||
424 | return; |
||
425 | } |
||
426 | } |
||
427 | } |
||
428 | } |
||
429 | |||
430 | /** |
||
431 | * Processes |
||
432 | * |
||
433 | * @return void |
||
434 | */ |
||
435 | 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. ![]() |
|||
436 | { |
||
437 | if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) { |
||
438 | $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY); |
||
439 | $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. ![]() |
|||
440 | foreach ($lines as $line) { |
||
441 | if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) { |
||
442 | $processes['*']++; |
||
443 | $state = $ar_buf[1]; |
||
444 | if ($state == 'U') $state = 'D'; //linux format |
||
445 | elseif ($state == 'I') $state = 'S'; |
||
446 | elseif ($state == 'D') $state = 'd'; //invalid |
||
447 | if (isset($processes[$state])) { |
||
448 | $processes[$state]++; |
||
449 | } else { |
||
450 | $processes[$state] = 1; |
||
451 | } |
||
452 | } |
||
453 | } |
||
454 | if ($processes['*'] > 0) { |
||
455 | $this->sys->setProcesses($processes); |
||
456 | } |
||
457 | } |
||
458 | } |
||
459 | |||
460 | /** |
||
461 | * get the information |
||
462 | * |
||
463 | * @see PSI_Interface_OS::build() |
||
464 | * |
||
465 | * @return Void |
||
466 | */ |
||
467 | public function build() |
||
468 | { |
||
469 | parent::build(); |
||
470 | $this->_uptime(); |
||
471 | $this->_network(); |
||
472 | $this->_processes(); |
||
473 | $this->_tb(); |
||
474 | } |
||
475 | } |
||
476 |
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.