2770 |
rexy |
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 <BigMichi1@users.sourceforge.net>
|
|
|
10 |
* @copyright 2009 phpSysInfo
|
|
|
11 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
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 <BigMichi1@users.sourceforge.net>
|
|
|
23 |
* @copyright 2009 phpSysInfo
|
|
|
24 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
|
|
|
25 |
* @version Release: 3.0
|
|
|
26 |
* @link http://phpsysinfo.sourceforge.net
|
|
|
27 |
*/
|
|
|
28 |
class Darwin extends BSDCommon
|
|
|
29 |
{
|
|
|
30 |
/**
|
|
|
31 |
* define the regexp for log parser
|
|
|
32 |
*/
|
|
|
33 |
/* public function __construct($blockname = false)
|
|
|
34 |
{
|
|
|
35 |
parent::__construct($blockname);
|
|
|
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 |
} */
|
325 |
richard |
41 |
|
2770 |
rexy |
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);
|
325 |
richard |
54 |
|
2770 |
rexy |
55 |
return $s;
|
|
|
56 |
} else {
|
|
|
57 |
return '';
|
|
|
58 |
}
|
|
|
59 |
}
|
325 |
richard |
60 |
|
2770 |
rexy |
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);
|
325 |
richard |
77 |
|
2770 |
rexy |
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 |
}
|
325 |
richard |
85 |
|
2770 |
rexy |
86 |
return $out;
|
|
|
87 |
} else {
|
|
|
88 |
return '';
|
|
|
89 |
}
|
|
|
90 |
}
|
325 |
richard |
91 |
|
2770 |
rexy |
92 |
/**
|
|
|
93 |
* get CPU information
|
|
|
94 |
*
|
|
|
95 |
* @return void
|
|
|
96 |
*/
|
|
|
97 |
protected function cpuinfo()
|
|
|
98 |
{
|
|
|
99 |
$dev = new CpuDevice();
|
|
|
100 |
if (CommonFunctions::executeProgram('hostinfo', '| grep "Processor type"', $buf, PSI_DEBUG)) {
|
|
|
101 |
$dev->setModel(preg_replace('/Processor type: /', '', $buf));
|
|
|
102 |
$buf=$this->grabkey('hw.model');
|
3037 |
rexy |
103 |
if (($buf !== null) && (trim($buf) != "")) {
|
2770 |
rexy |
104 |
$this->sys->setMachine(trim($buf));
|
3037 |
rexy |
105 |
if (CommonFunctions::rftsdata('ModelTranslation.txt', $buffer)) {
|
2770 |
rexy |
106 |
$buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
107 |
foreach ($buffer as $line) {
|
|
|
108 |
$ar_buf = preg_split("/:/", $line, 3);
|
|
|
109 |
if (trim($buf) === trim($ar_buf[0])) {
|
|
|
110 |
$dev->setModel(trim($ar_buf[2]));
|
|
|
111 |
$this->sys->setMachine($this->sys->getMachine().' - '.trim($ar_buf[1]));
|
|
|
112 |
break;
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
$buf=$this->grabkey('machdep.cpu.brand_string');
|
3037 |
rexy |
118 |
if (($buf !== null) && (trim($buf) != "") &&
|
2770 |
rexy |
119 |
((trim($buf) != "i486 (Intel 80486)") || ($dev->getModel() == ""))) {
|
|
|
120 |
$dev->setModel(trim($buf));
|
|
|
121 |
}
|
|
|
122 |
$buf=$this->grabkey('machdep.cpu.features');
|
3037 |
rexy |
123 |
if (($buf !== null) && (trim($buf) != "")) {
|
2770 |
rexy |
124 |
if (preg_match("/ VMX/", $buf)) {
|
|
|
125 |
$dev->setVirt("vmx");
|
|
|
126 |
} elseif (preg_match("/ SVM/", $buf)) {
|
|
|
127 |
$dev->setVirt("svm");
|
|
|
128 |
}
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
$dev->setCpuSpeed(round($this->grabkey('hw.cpufrequency') / 1000000));
|
|
|
132 |
$dev->setBusSpeed(round($this->grabkey('hw.busfrequency') / 1000000));
|
|
|
133 |
$bufn=$this->grabkey('hw.cpufrequency_min');
|
|
|
134 |
$bufx=$this->grabkey('hw.cpufrequency_max');
|
3037 |
rexy |
135 |
if (($bufn !== null) && (trim($bufn) != "") && ($bufx !== null) && (trim($bufx) != "") && ($bufn != $bufx)) {
|
2770 |
rexy |
136 |
$dev->setCpuSpeedMin(round($bufn / 1000000));
|
|
|
137 |
$dev->setCpuSpeedMax(round($bufx / 1000000));
|
|
|
138 |
}
|
|
|
139 |
$buf=$this->grabkey('hw.l2cachesize');
|
3037 |
rexy |
140 |
if ($buf !== "") {
|
2770 |
rexy |
141 |
$dev->setCache(round($buf));
|
|
|
142 |
}
|
|
|
143 |
$ncpu = $this->grabkey('hw.ncpu');
|
3037 |
rexy |
144 |
if (($ncpu === "") || !($ncpu >= 1)) {
|
2770 |
rexy |
145 |
$ncpu = 1;
|
3037 |
rexy |
146 |
}
|
|
|
147 |
if (($ncpu == 1) && PSI_LOAD_BAR) {
|
|
|
148 |
$dev->setLoad($this->cpuusage());
|
|
|
149 |
}
|
2770 |
rexy |
150 |
for ($ncpu ; $ncpu > 0 ; $ncpu--) {
|
|
|
151 |
$this->sys->setCpus($dev);
|
|
|
152 |
}
|
|
|
153 |
}
|
325 |
richard |
154 |
|
2770 |
rexy |
155 |
/**
|
|
|
156 |
* get the pci device information out of ioreg
|
|
|
157 |
*
|
|
|
158 |
* @return void
|
|
|
159 |
*/
|
|
|
160 |
protected function pci()
|
|
|
161 |
{
|
|
|
162 |
if (!$arrResults = Parser::lspci(false)) { //no lspci port
|
|
|
163 |
$s = $this->_grabioreg('IOPCIDevice');
|
|
|
164 |
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
165 |
foreach ($lines as $line) {
|
|
|
166 |
$dev = new HWDevice();
|
|
|
167 |
if (!preg_match('/"IOName" = "([^"]*)"/', $line, $ar_buf)) {
|
|
|
168 |
$ar_buf = preg_split("/[\s@]+/", $line, 19);
|
|
|
169 |
}
|
|
|
170 |
if (preg_match('/"model" = <?"([^"]*)"/', $line, $ar_buf2)) {
|
|
|
171 |
$dev->setName(trim($ar_buf[1]). ": ".trim($ar_buf2[1]));
|
|
|
172 |
} else {
|
|
|
173 |
$dev->setName(trim($ar_buf[1]));
|
|
|
174 |
}
|
|
|
175 |
$this->sys->setPciDevices($dev);
|
|
|
176 |
}
|
|
|
177 |
} else {
|
|
|
178 |
foreach ($arrResults as $dev) {
|
|
|
179 |
$this->sys->setPciDevices($dev);
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
}
|
325 |
richard |
183 |
|
2770 |
rexy |
184 |
/**
|
|
|
185 |
* get the ide device information out of ioreg
|
|
|
186 |
*
|
|
|
187 |
* @return void
|
|
|
188 |
*/
|
|
|
189 |
protected function ide()
|
|
|
190 |
{
|
|
|
191 |
$s = $this->_grabioreg('IOATABlockStorageDevice');
|
|
|
192 |
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
193 |
foreach ($lines as $line) {
|
|
|
194 |
$dev = new HWDevice();
|
|
|
195 |
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
|
|
|
196 |
$ar_buf = preg_split("/[\s@]+/", $line, 19);
|
|
|
197 |
$dev->setName(trim($ar_buf[1]));
|
|
|
198 |
$this->sys->setIdeDevices($dev);
|
|
|
199 |
}
|
325 |
richard |
200 |
|
2770 |
rexy |
201 |
$s = $this->_grabioreg('IOAHCIBlockStorageDevice');
|
|
|
202 |
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
203 |
foreach ($lines as $line) {
|
|
|
204 |
$dev = new HWDevice();
|
|
|
205 |
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
|
|
|
206 |
$ar_buf = preg_split("/[\s@]+/", $line, 19);
|
|
|
207 |
$dev->setName(trim($ar_buf[1]));
|
|
|
208 |
$this->sys->setIdeDevices($dev);
|
|
|
209 |
}
|
|
|
210 |
}
|
325 |
richard |
211 |
|
2770 |
rexy |
212 |
/**
|
|
|
213 |
* get the usb device information out of ioreg
|
|
|
214 |
*
|
|
|
215 |
* @return void
|
|
|
216 |
*/
|
|
|
217 |
protected function usb()
|
|
|
218 |
{
|
|
|
219 |
$s = $this->_grabioreg('IOUSBDevice');
|
|
|
220 |
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
221 |
foreach ($lines as $line) {
|
|
|
222 |
$dev = new HWDevice();
|
|
|
223 |
if (!preg_match('/"USB Product Name" = "([^"]*)"/', $line, $ar_buf))
|
|
|
224 |
$ar_buf = preg_split("/[\s@]+/", $line, 19);
|
|
|
225 |
$dev->setName(trim($ar_buf[1]));
|
|
|
226 |
if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
|
|
|
227 |
if (preg_match('/"USB Vendor Name" = "([^"]*)"/', $line, $ar_buf)) {
|
|
|
228 |
$dev->setManufacturer(trim($ar_buf[1]));
|
|
|
229 |
}
|
|
|
230 |
if (preg_match('/"USB Product Name" = "([^"]*)"/', $line, $ar_buf)) {
|
|
|
231 |
$dev->setProduct(trim($ar_buf[1]));
|
|
|
232 |
}
|
|
|
233 |
if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
|
|
|
234 |
&& preg_match('/"USB Serial Number" = "([^"]*)"/', $line, $ar_buf)) {
|
|
|
235 |
$dev->setSerial(trim($ar_buf[1]));
|
|
|
236 |
}
|
|
|
237 |
}
|
|
|
238 |
$this->sys->setUsbDevices($dev);
|
|
|
239 |
}
|
|
|
240 |
}
|
325 |
richard |
241 |
|
2770 |
rexy |
242 |
/**
|
|
|
243 |
* get the scsi device information out of ioreg
|
|
|
244 |
*
|
|
|
245 |
* @return void
|
|
|
246 |
*/
|
|
|
247 |
protected function scsi()
|
|
|
248 |
{
|
|
|
249 |
$s = $this->_grabioreg('IOBlockStorageServices');
|
|
|
250 |
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
251 |
foreach ($lines as $line) {
|
|
|
252 |
$dev = new HWDevice();
|
|
|
253 |
if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
|
|
|
254 |
$ar_buf = preg_split("/[\s@]+/", $line, 19);
|
|
|
255 |
$dev->setName(trim($ar_buf[1]));
|
|
|
256 |
$this->sys->setScsiDevices($dev);
|
|
|
257 |
}
|
|
|
258 |
}
|
325 |
richard |
259 |
|
2770 |
rexy |
260 |
/**
|
|
|
261 |
* get memory and swap information
|
|
|
262 |
*
|
|
|
263 |
* @return void
|
|
|
264 |
*/
|
|
|
265 |
protected function memory()
|
|
|
266 |
{
|
|
|
267 |
$s = $this->grabkey('hw.memsize');
|
|
|
268 |
if (CommonFunctions::executeProgram('vm_stat', '', $pstat, PSI_DEBUG)) {
|
|
|
269 |
// calculate free memory from page sizes (each page = 4096)
|
|
|
270 |
if (preg_match('/^Pages free:\s+(\S+)/m', $pstat, $free_buf)) {
|
|
|
271 |
if (preg_match('/^Anonymous pages:\s+(\S+)/m', $pstat, $anon_buf)
|
|
|
272 |
&& preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)
|
|
|
273 |
&& preg_match('/^File-backed pages:\s+(\S+)/m', $pstat, $fileb_buf)) {
|
|
|
274 |
// OS X 10.9 or never
|
|
|
275 |
$this->sys->setMemFree($free_buf[1] * 4 * 1024);
|
|
|
276 |
$this->sys->setMemApplication(($anon_buf[1]+$wire_buf[1]) * 4 * 1024);
|
|
|
277 |
$this->sys->setMemCache($fileb_buf[1] * 4 * 1024);
|
|
|
278 |
if (preg_match('/^Pages occupied by compressor:\s+(\S+)/m', $pstat, $compr_buf)) {
|
|
|
279 |
$this->sys->setMemBuffer($compr_buf[1] * 4 * 1024);
|
|
|
280 |
}
|
|
|
281 |
} else {
|
|
|
282 |
if (preg_match('/^Pages speculative:\s+(\S+)/m', $pstat, $spec_buf)) {
|
|
|
283 |
$this->sys->setMemFree(($free_buf[1]+$spec_buf[1]) * 4 * 1024);
|
|
|
284 |
} else {
|
|
|
285 |
$this->sys->setMemFree($free_buf[1] * 4 * 1024);
|
|
|
286 |
}
|
|
|
287 |
$appMemory = 0;
|
|
|
288 |
if (preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)) {
|
|
|
289 |
$appMemory += $wire_buf[1] * 4 * 1024;
|
|
|
290 |
}
|
|
|
291 |
if (preg_match('/^Pages active:\s+(\S+)/m', $pstat, $active_buf)) {
|
|
|
292 |
$appMemory += $active_buf[1] * 4 * 1024;
|
|
|
293 |
}
|
|
|
294 |
$this->sys->setMemApplication($appMemory);
|
325 |
richard |
295 |
|
2770 |
rexy |
296 |
if (preg_match('/^Pages inactive:\s+(\S+)/m', $pstat, $inactive_buf)) {
|
|
|
297 |
$this->sys->setMemCache($inactive_buf[1] * 4 * 1024);
|
|
|
298 |
}
|
|
|
299 |
}
|
|
|
300 |
} else {
|
|
|
301 |
$lines = preg_split("/\n/", $pstat, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
302 |
$ar_buf = preg_split("/\s+/", $lines[1], 19);
|
|
|
303 |
$this->sys->setMemFree($ar_buf[2] * 4 * 1024);
|
|
|
304 |
}
|
325 |
richard |
305 |
|
2770 |
rexy |
306 |
$this->sys->setMemTotal($s);
|
|
|
307 |
$this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
|
325 |
richard |
308 |
|
2770 |
rexy |
309 |
if (CommonFunctions::executeProgram('sysctl', 'vm.swapusage | colrm 1 22', $swapBuff, PSI_DEBUG)) {
|
|
|
310 |
$swap1 = preg_split('/M/', $swapBuff);
|
|
|
311 |
$swap2 = preg_split('/=/', $swap1[1]);
|
|
|
312 |
$swap3 = preg_split('/=/', $swap1[2]);
|
2976 |
rexy |
313 |
if (($swap=trim($swap1[0])) > 0) {
|
|
|
314 |
$dev = new DiskDevice();
|
|
|
315 |
$dev->setName('SWAP');
|
|
|
316 |
$dev->setMountPoint('SWAP');
|
|
|
317 |
$dev->setFsType('swap');
|
|
|
318 |
$dev->setTotal($swap * 1024 * 1024);
|
|
|
319 |
$dev->setUsed(trim($swap2[1]) * 1024 * 1024);
|
|
|
320 |
$dev->setFree(trim($swap3[1]) * 1024 * 1024);
|
|
|
321 |
$this->sys->setSwapDevices($dev);
|
|
|
322 |
}
|
2770 |
rexy |
323 |
}
|
|
|
324 |
}
|
|
|
325 |
}
|
325 |
richard |
326 |
|
2770 |
rexy |
327 |
/**
|
|
|
328 |
* get the thunderbolt device information out of ioreg
|
|
|
329 |
*
|
|
|
330 |
* @return void
|
|
|
331 |
*/
|
|
|
332 |
protected function _tb()
|
|
|
333 |
{
|
|
|
334 |
$s = $this->_grabioreg('IOThunderboltPort');
|
|
|
335 |
$lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
336 |
foreach ($lines as $line) {
|
|
|
337 |
$dev = new HWDevice();
|
|
|
338 |
if (!preg_match('/"Description" = "([^"]*)"/', $line, $ar_buf))
|
|
|
339 |
$ar_buf = preg_split("/[\s@]+/", $line, 19);
|
|
|
340 |
$dev->setName(trim($ar_buf[1]));
|
|
|
341 |
$this->sys->setTbDevices($dev);
|
|
|
342 |
}
|
|
|
343 |
}
|
325 |
richard |
344 |
|
2770 |
rexy |
345 |
/**
|
|
|
346 |
* get network information
|
|
|
347 |
*
|
|
|
348 |
* @return void
|
|
|
349 |
*/
|
|
|
350 |
private function _network()
|
|
|
351 |
{
|
|
|
352 |
if (CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-24,42- | grep Link', $netstat, PSI_DEBUG)) {
|
|
|
353 |
$lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
354 |
foreach ($lines as $line) {
|
|
|
355 |
$ar_buf = preg_split("/\s+/", $line, 10);
|
|
|
356 |
if (!empty($ar_buf[0])) {
|
|
|
357 |
$dev = new NetDevice();
|
|
|
358 |
$dev->setName($ar_buf[0]);
|
|
|
359 |
$dev->setTxBytes($ar_buf[8]);
|
|
|
360 |
$dev->setRxBytes($ar_buf[5]);
|
|
|
361 |
$dev->setErrors($ar_buf[4] + $ar_buf[7]);
|
|
|
362 |
if (isset($ar_buf[10])) {
|
|
|
363 |
$dev->setDrops($ar_buf[10]);
|
|
|
364 |
}
|
|
|
365 |
if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
|
|
|
366 |
$bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
367 |
foreach ($bufe2 as $buf2) {
|
|
|
368 |
if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) {
|
|
|
369 |
if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
|
|
|
370 |
} elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
|
|
|
371 |
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
|
|
|
372 |
} elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
|
|
|
373 |
|| preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
|
|
|
374 |
&& ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
|
|
|
375 |
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
|
|
|
376 |
} elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
|
|
|
377 |
if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
|
|
|
378 |
$unit = "G";
|
|
|
379 |
} else {
|
|
|
380 |
$unit = "M";
|
|
|
381 |
}
|
|
|
382 |
if (preg_match('/[<\s]([^\s<]+)-duplex/i', $buf2, $ar_buf3))
|
|
|
383 |
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]));
|
|
|
384 |
else
|
|
|
385 |
$dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s');
|
|
|
386 |
}
|
|
|
387 |
}
|
|
|
388 |
}
|
|
|
389 |
$this->sys->setNetDevices($dev);
|
|
|
390 |
}
|
|
|
391 |
}
|
|
|
392 |
}
|
|
|
393 |
}
|
325 |
richard |
394 |
|
2770 |
rexy |
395 |
/**
|
|
|
396 |
* get icon name
|
|
|
397 |
*
|
|
|
398 |
* @return void
|
|
|
399 |
*/
|
|
|
400 |
protected function distro()
|
|
|
401 |
{
|
|
|
402 |
$this->sys->setDistributionIcon('Darwin.png');
|
2976 |
rexy |
403 |
if ((!CommonFunctions::executeProgram('system_profiler', 'SPSoftwareDataType', $buffer, PSI_DEBUG) || !preg_match('/\n\s*System Version:/', $buffer))
|
|
|
404 |
&& (!CommonFunctions::executeProgram('sw_vers', '', $buffer, PSI_DEBUG) || !preg_match('/^ProductName:/', $buffer))) {
|
2770 |
rexy |
405 |
parent::distro();
|
|
|
406 |
} else {
|
2976 |
rexy |
407 |
$distro_tmp = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
408 |
foreach ($distro_tmp as $info) {
|
|
|
409 |
$info_tmp = preg_split('/:/', $info, 2);
|
3037 |
rexy |
410 |
if (isset($distro_tmp[0]) && ($distro_tmp[0] !== null) && (trim($distro_tmp[0]) != "") &&
|
|
|
411 |
isset($distro_tmp[1]) && ($distro_tmp[1] !== null) && (trim($distro_tmp[1]) != "")) {
|
2976 |
rexy |
412 |
$distro_arr[trim($info_tmp[0])] = trim($info_tmp[1]);
|
|
|
413 |
}
|
|
|
414 |
}
|
|
|
415 |
if (isset($distro_arr['ProductName']) && isset($distro_arr['ProductVersion']) && isset($distro_arr['BuildVersion'])) {
|
|
|
416 |
$distro_arr['System Version'] = $distro_arr['ProductName'].' '.$distro_arr['ProductVersion'].' ('.$distro_arr['BuildVersion'].')';
|
|
|
417 |
}
|
|
|
418 |
if (isset($distro_arr['System Version'])) {
|
|
|
419 |
$distro = $distro_arr['System Version'];
|
|
|
420 |
if (preg_match('/^Mac OS|^OS X|^macOS/', $distro)) {
|
|
|
421 |
$this->sys->setDistributionIcon('Apple.png');
|
|
|
422 |
if (preg_match('/(^Mac OS X Server|^Mac OS X|^OS X Server|^OS X|^macOS Server|^macOS) ((\d+)\.\d+)/', $distro, $ver)
|
|
|
423 |
&& ($list = @parse_ini_file(PSI_APP_ROOT."/data/osnames.ini", true))) {
|
|
|
424 |
if (isset($list['macOS'][$ver[2]])) {
|
|
|
425 |
$distro.=' '.$list['macOS'][$ver[2]];
|
|
|
426 |
} elseif (isset($list['macOS'][$ver[3]])) {
|
|
|
427 |
$distro.=' '.$list['macOS'][$ver[3]];
|
2770 |
rexy |
428 |
}
|
|
|
429 |
}
|
|
|
430 |
}
|
2976 |
rexy |
431 |
$this->sys->setDistribution($distro);
|
|
|
432 |
} else {
|
|
|
433 |
parent::distro();
|
2770 |
rexy |
434 |
}
|
|
|
435 |
}
|
|
|
436 |
}
|
325 |
richard |
437 |
|
2770 |
rexy |
438 |
/**
|
|
|
439 |
* Processes
|
|
|
440 |
*
|
|
|
441 |
* @return void
|
|
|
442 |
*/
|
|
|
443 |
protected function _processes()
|
|
|
444 |
{
|
|
|
445 |
if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
|
|
|
446 |
$lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
|
|
|
447 |
$processes['*'] = 0;
|
|
|
448 |
foreach ($lines as $line) {
|
|
|
449 |
if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
|
|
|
450 |
$processes['*']++;
|
|
|
451 |
$state = $ar_buf[1];
|
|
|
452 |
if ($state == 'U') $state = 'D'; //linux format
|
|
|
453 |
elseif ($state == 'I') $state = 'S';
|
|
|
454 |
elseif ($state == 'D') $state = 'd'; //invalid
|
|
|
455 |
if (isset($processes[$state])) {
|
|
|
456 |
$processes[$state]++;
|
|
|
457 |
} else {
|
|
|
458 |
$processes[$state] = 1;
|
|
|
459 |
}
|
|
|
460 |
}
|
|
|
461 |
}
|
|
|
462 |
if ($processes['*'] > 0) {
|
|
|
463 |
$this->sys->setProcesses($processes);
|
|
|
464 |
}
|
|
|
465 |
}
|
|
|
466 |
}
|
325 |
richard |
467 |
|
2770 |
rexy |
468 |
/**
|
|
|
469 |
* get the information
|
|
|
470 |
*
|
|
|
471 |
* @see PSI_Interface_OS::build()
|
|
|
472 |
*
|
3037 |
rexy |
473 |
* @return void
|
2770 |
rexy |
474 |
*/
|
|
|
475 |
public function build()
|
|
|
476 |
{
|
|
|
477 |
parent::build();
|
|
|
478 |
if (!$this->blockname || $this->blockname==='vitals') {
|
|
|
479 |
$this->_processes();
|
|
|
480 |
}
|
|
|
481 |
if (!$this->blockname || $this->blockname==='hardware') {
|
|
|
482 |
$this->_tb();
|
|
|
483 |
}
|
|
|
484 |
if (!$this->blockname || $this->blockname==='network') {
|
|
|
485 |
$this->_network();
|
|
|
486 |
}
|
325 |
richard |
487 |
}
|
2770 |
rexy |
488 |
}
|