Subversion Repositories ALCASAR

Rev

Rev 325 | Rev 2976 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 325 Rev 2770
Line 1... Line 1...
1
<?php 
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
    } */
-
 
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
    }
2
 
60
 
-
 
61
    /**
-
 
62
     * get a value from ioreg command
-
 
63
     *
3
// phpSysInfo - A PHP System Information Script
64
     * @param string $key key of the value to get
-
 
65
     *
-
 
66
     * @return string
-
 
67
     */
4
// http://phpsysinfo.sourceforge.net/
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
    }
5
 
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);
-
 
105
            } else { /* kern.boottime= 1096732600 */
-
 
106
              $this->sys->setUptime(time() - $a);
-
 
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');
6
// This program is free software; you can redistribute it and/or
122
            if (!is_null($buf) && (trim($buf) != "")) {
-
 
123
                $this->sys->setMachine(trim($buf));
-
 
124
                if (CommonFunctions::rfts(PSI_APP_ROOT.'/data/ModelTranslation.txt', $buffer)) {
-
 
125
                    $buffer = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
7
// modify it under the terms of the GNU General Public License
126
                    foreach ($buffer as $line) {
8
// as published by the Free Software Foundation; either version 2
127
                        $ar_buf = preg_split("/:/", $line, 3);
9
// of the License, or (at your option) any later version.
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]));
-
 
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
                if (preg_match("/ VMX/", $buf)) {
-
 
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
        if (is_null($ncpu) || (trim($ncpu) == "") || (!($ncpu >= 1)))
-
 
164
            $ncpu = 1;
-
 
165
        for ($ncpu ; $ncpu > 0 ; $ncpu--) {
-
 
166
            $this->sys->setCpus($dev);
-
 
167
        }
-
 
168
    }
10
 
169
 
-
 
170
    /**
11
// This program is distributed in the hope that it will be useful,
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();
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
182
                if (!preg_match('/"IOName" = "([^"]*)"/', $line, $ar_buf)) {
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
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) {
14
// GNU General Public License for more details.
194
                $this->sys->setPciDevices($dev);
-
 
195
            }
-
 
196
        }
-
 
197
    }
15
 
198
 
-
 
199
    /**
16
// You should have received a copy of the GNU General Public License
200
     * get the ide device information out of ioreg
-
 
201
     *
-
 
202
     * @return void
-
 
203
     */
-
 
204
    protected function ide()
-
 
205
    {
17
// along with this program; if not, write to the Free Software
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();
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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
        }
19
 
215
 
-
 
216
        $s = $this->_grabioreg('IOAHCIBlockStorageDevice');
20
// $Id: class.Darwin.inc.php,v 1.33 2006/06/14 16:36:34 bigmichi1 Exp $
217
        $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
21
if (!defined('IN_PHPSYSINFO')) {
218
        foreach ($lines as $line) {
22
    die("No Hacking");
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
    }
23
}
226
 
-
 
227
    /**
-
 
228
     * get the usb device information out of ioreg
-
 
229
     *
-
 
230
     * @return void
-
 
231
     */
-
 
232
    protected function usb()
-
 
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
                    if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
-
 
242
                        if (preg_match('/"USB Vendor Name" = "([^"]*)"/', $line, $ar_buf)) {
-
 
243
                            $dev->setManufacturer(trim($ar_buf[1]));
-
 
244
                        }
-
 
245
                        if (preg_match('/"USB Product Name" = "([^"]*)"/', $line, $ar_buf)) {
-
 
246
                            $dev->setProduct(trim($ar_buf[1]));
-
 
247
                        }
-
 
248
                        if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL
-
 
249
                           && preg_match('/"USB Serial Number" = "([^"]*)"/', $line, $ar_buf)) {
-
 
250
                            $dev->setSerial(trim($ar_buf[1]));
-
 
251
                        }
-
 
252
                    }
-
 
253
                    $this->sys->setUsbDevices($dev);
-
 
254
        }
-
 
255
    }
24
 
256
 
-
 
257
    /**
-
 
258
     * get the scsi device information out of ioreg
-
 
259
     *
-
 
260
     * @return void
-
 
261
     */
-
 
262
    protected function scsi()
-
 
263
    {
25
require_once(APP_ROOT . '/includes/os/class.BSD.common.inc.php');
264
        $s = $this->_grabioreg('IOBlockStorageServices');
-
 
265
        $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
-
 
266
        foreach ($lines as $line) {
-
 
267
                    $dev = new HWDevice();
-
 
268
                    if (!preg_match('/"Product Name"="([^"]*)"/', $line, $ar_buf))
-
 
269
                       $ar_buf = preg_split("/[\s@]+/", $line, 19);
-
 
270
                    $dev->setName(trim($ar_buf[1]));
-
 
271
                    $this->sys->setScsiDevices($dev);
-
 
272
        }
-
 
273
    }
26
 
274
 
-
 
275
    /**
-
 
276
     * get memory and swap information
-
 
277
     *
-
 
278
     * @return void
-
 
279
     */
-
 
280
    protected function memory()
-
 
281
    {
-
 
282
        $s = $this->grabkey('hw.memsize');
-
 
283
        if (CommonFunctions::executeProgram('vm_stat', '', $pstat, PSI_DEBUG)) {
-
 
284
            // calculate free memory from page sizes (each page = 4096)
-
 
285
            if (preg_match('/^Pages free:\s+(\S+)/m', $pstat, $free_buf)) {
-
 
286
                if (preg_match('/^Anonymous pages:\s+(\S+)/m', $pstat, $anon_buf)
-
 
287
                   && preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)
-
 
288
                   && preg_match('/^File-backed pages:\s+(\S+)/m', $pstat, $fileb_buf)) {
-
 
289
                        // OS X 10.9 or never
-
 
290
                        $this->sys->setMemFree($free_buf[1] * 4 * 1024);
-
 
291
                        $this->sys->setMemApplication(($anon_buf[1]+$wire_buf[1]) * 4 * 1024);
-
 
292
                        $this->sys->setMemCache($fileb_buf[1] * 4 * 1024);
27
$error->addWarning("The Darwin version of phpSysInfo is work in progress, some things currently don't work");
293
                        if (preg_match('/^Pages occupied by compressor:\s+(\S+)/m', $pstat, $compr_buf)) {
-
 
294
                            $this->sys->setMemBuffer($compr_buf[1] * 4 * 1024);
-
 
295
                        }
-
 
296
                } else {
-
 
297
                    if (preg_match('/^Pages speculative:\s+(\S+)/m', $pstat, $spec_buf)) {
-
 
298
                        $this->sys->setMemFree(($free_buf[1]+$spec_buf[1]) * 4 * 1024);
-
 
299
                    } else {
-
 
300
                        $this->sys->setMemFree($free_buf[1] * 4 * 1024);
-
 
301
                    }
-
 
302
                    $appMemory = 0;
-
 
303
                    if (preg_match('/^Pages wired down:\s+(\S+)/m', $pstat, $wire_buf)) {
-
 
304
                        $appMemory += $wire_buf[1] * 4 * 1024;
-
 
305
                    }
-
 
306
                    if (preg_match('/^Pages active:\s+(\S+)/m', $pstat, $active_buf)) {
-
 
307
                        $appMemory += $active_buf[1] * 4 * 1024;
-
 
308
                    }
-
 
309
                    $this->sys->setMemApplication($appMemory);
-
 
310
 
-
 
311
                    if (preg_match('/^Pages inactive:\s+(\S+)/m', $pstat, $inactive_buf)) {
-
 
312
                        $this->sys->setMemCache($inactive_buf[1] * 4 * 1024);
-
 
313
                    }
-
 
314
                }
-
 
315
            } else {
-
 
316
                $lines = preg_split("/\n/", $pstat, -1, PREG_SPLIT_NO_EMPTY);
-
 
317
                $ar_buf = preg_split("/\s+/", $lines[1], 19);
-
 
318
                $this->sys->setMemFree($ar_buf[2] * 4 * 1024);
-
 
319
            }
-
 
320
 
-
 
321
            $this->sys->setMemTotal($s);
-
 
322
            $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
-
 
323
 
-
 
324
            if (CommonFunctions::executeProgram('sysctl', 'vm.swapusage | colrm 1 22', $swapBuff, PSI_DEBUG)) {
-
 
325
                $swap1 = preg_split('/M/', $swapBuff);
-
 
326
                $swap2 = preg_split('/=/', $swap1[1]);
-
 
327
                $swap3 = preg_split('/=/', $swap1[2]);
-
 
328
                $dev = new DiskDevice();
-
 
329
                $dev->setName('SWAP');
-
 
330
                $dev->setMountPoint('SWAP');
-
 
331
                $dev->setFsType('swap');
-
 
332
                $dev->setTotal($swap1[0] * 1024 * 1024);
-
 
333
                $dev->setUsed($swap2[1] * 1024 * 1024);
-
 
334
                $dev->setFree($swap3[1] * 1024 * 1024);
-
 
335
                $this->sys->setSwapDevices($dev);
-
 
336
            }
-
 
337
        }
-
 
338
    }
28
 
339
 
29
class sysinfo extends bsd_common {
-
 
30
  var $cpu_regexp;
-
 
31
  var $scsi_regexp; 
-
 
32
  
-
 
33
  var $parser;
-
 
34
  // Our contstructor
-
 
35
  // this function is run on the initialization of this class
-
 
36
  function sysinfo () {
-
 
37
    // $this->cpu_regexp = "CPU: (.*) \((.*)-MHz (.*)\)";
-
 
38
    // $this->scsi_regexp1 = "^(.*): <(.*)> .*SCSI.*device";
-
 
39
    $this->cpu_regexp2 = "/(.*) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)/";
-
 
40
    $this->parser = new Parser();
-
 
41
  } 
-
 
42
 
-
 
43
  function grab_key ($key) {
-
 
44
    $s = execute_program('sysctl', $key);
-
 
45
    $s = ereg_replace($key . ': ', '', $s);
-
 
46
    $s = ereg_replace($key . ' = ', '', $s); // fix Apple set keys
-
 
47
    
340
    /**
48
    return $s;
-
 
49
  } 
-
 
50
 
-
 
51
  function grab_ioreg ($key) {
-
 
52
    $s = execute_program('ioreg', '-cls "' . $key . '" | grep "' . $key . '"'); //ioreg -cls "$key" | grep "$key"
-
 
53
    $s = ereg_replace('\|', '', $s);
-
 
54
    $s = ereg_replace('\+\-\o', '', $s);
-
 
55
    $s = ereg_replace('[ ]+', '', $s);
-
 
56
    $s = ereg_replace('<[^>]+>', '', $s); // remove possible XML conflicts
-
 
57
 
-
 
58
    return $s;
-
 
59
  } 
-
 
60
 
-
 
61
  function get_sys_ticks () {
-
 
62
    $a = execute_program('sysctl', '-n kern.boottime'); // get boottime (value in seconds) 
-
 
63
    $sys_ticks = time() - $a;
-
 
64
 
-
 
65
    return $sys_ticks;
-
 
66
  } 
-
 
67
 
-
 
68
  function cpu_info () {
-
 
69
    $results = array(); 
-
 
70
    // $results['model'] = $this->grab_key('hw.model'); // need to expand this somehow...
-
 
71
    // $results['model'] = $this->grab_key('hw.machine');
-
 
72
    $results['model'] = ereg_replace('Processor type: ', '', execute_program('hostinfo', '| grep "Processor type"')); // get processor type
-
 
73
    $results['cpus'] = $this->grab_key('hw.ncpu');
-
 
74
    $results['cpuspeed'] = round($this->grab_key('hw.cpufrequency') / 1000000); // return cpu speed - Mhz
-
 
75
    $results['busspeed'] = round($this->grab_key('hw.busfrequency') / 1000000); // return bus speed - Mhz
-
 
76
    $results['cache'] = round($this->grab_key('hw.l2cachesize') / 1024); // return l2 cache
-
 
77
 
-
 
78
    if (($this->grab_key('hw.model') == "PowerMac3,6") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G4 - (PowerPC 7450)';} // is Dual G4
-
 
79
    if (($this->grab_key('hw.model') == "PowerMac7,2") && ($results['cpus'] == "2")) { $results['model'] = 'Dual G5 - (PowerPC 970)';} // is Dual G5
-
 
80
    if (($this->grab_key('hw.model') == "PowerMac1,1") && ($results['cpus'] == "1")) { $results['model'] = 'B&W G3 - (PowerPC 750)';} // is B&W G3
-
 
81
 
-
 
82
    return $results;
-
 
83
  } 
-
 
84
  // get the pci device information out of ioreg
341
     * get the thunderbolt device information out of ioreg
85
  function pci () {
-
 
86
    $results = array();
-
 
87
    $s = $this->grab_ioreg('IOPCIDevice');
-
 
88
 
-
 
89
    $lines = explode("\n", $s);
-
 
90
    for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
-
 
91
      $ar_buf = preg_split("/\s+/", $lines[$i], 19);
-
 
92
      $results[$i] = $ar_buf[0];
-
 
93
    } 
342
     *
94
    asort($results);
343
     * @return void
95
    return array_values(array_unique($results));
-
 
96
  } 
-
 
97
  // get the ide device information out of ioreg
-
 
98
  function ide () {
-
 
99
    $results = array(); 
-
 
100
    // ioreg | grep "Media  <class IOMedia>"
-
 
101
    $s = $this->grab_ioreg('IOATABlockStorageDevice'); 
-
 
102
 
-
 
103
    $lines = explode("\n", $s);
-
 
104
    $j = 0;
-
 
105
    for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
-
 
106
      $ar_buf = preg_split("/\/\//", $lines[$i], 19);
-
 
107
 
-
 
108
      if ( isset( $ar_buf[1] ) && $ar_buf[1] == 'class IOMedia' && preg_match('/Media/', $ar_buf[0])) {
-
 
109
        $results[$j++]['model'] = $ar_buf[0];
-
 
110
      } 
344
     */
111
    } 
-
 
112
    asort($results);
345
    protected function _tb()
113
    return array_values(array_unique($results));
-
 
114
  } 
346
    {
115
 
-
 
116
  function memory () {
-
 
117
    $s = $this->grab_key('hw.memsize');
347
        $s = $this->_grabioreg('IOThunderboltPort');
118
 
-
 
119
    $results['ram'] = array();
-
 
120
    $results['swap'] = array();
-
 
121
    $results['devswap'] = array();
-
 
122
    
-
 
123
    $pstat = execute_program('vm_stat'); // use darwin's vm_stat
-
 
124
    $lines = explode("\n", $pstat);
-
 
125
    for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
-
 
126
      $ar_buf = preg_split("/\s+/", $lines[$i], 19);
348
        $lines = preg_split("/\n/", $s, -1, PREG_SPLIT_NO_EMPTY);
127
 
-
 
128
      if ($i == 1) {
349
        foreach ($lines as $line) {
129
        $results['ram']['free'] = $ar_buf[2] * 4; // calculate free memory from page sizes (each page = 4MB)
-
 
130
      } 
-
 
131
    } 
-
 
132
 
-
 
133
    $results['ram']['total'] = $s / 1024;
-
 
134
    $results['ram']['shared'] = 0;
-
 
135
    $results['ram']['buffers'] = 0;
-
 
136
    $results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
-
 
137
    $results['ram']['cached'] = 0;
-
 
138
 
-
 
139
    $results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']); 
-
 
140
    // need to fix the swap info...
-
 
141
    // meanwhile silence and / or disable the swap information
-
 
142
    $pstat = execute_program('swapinfo', '-k', false);
-
 
143
    if( $pstat != "ERROR" ) {
-
 
144
        $lines = explode("\n", $pstat);
350
                    $dev = new HWDevice();
145
 
-
 
146
        for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
351
                    if (!preg_match('/"Description" = "([^"]*)"/', $line, $ar_buf))
147
          $ar_buf = preg_split("/\s+/", $lines[$i], 6);
352
                       $ar_buf = preg_split("/[\s@]+/", $line, 19);
148
    
-
 
149
          if ($i == 0) {
-
 
150
            $results['swap']['total'] = 0;
353
                    $dev->setName(trim($ar_buf[1]));
151
            $results['swap']['used'] = 0;
-
 
152
            $results['swap']['free'] = 0;
354
                    $this->sys->setTbDevices($dev);
153
          } else {
-
 
154
            $results['swap']['total'] = $results['swap']['total'] + $ar_buf[1];
-
 
155
            $results['swap']['used'] = $results['swap']['used'] + $ar_buf[2];
-
 
156
            $results['swap']['free'] = $results['swap']['free'] + $ar_buf[3];
-
 
157
          } 
-
 
158
        } 
355
        }
159
        $results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
-
 
160
    }
356
    }
161
    
-
 
162
    return $results;
-
 
163
  } 
-
 
164
 
-
 
165
  function network () {
-
 
166
    $netstat = execute_program('netstat', '-nbdi | cut -c1-24,42- | grep Link');
-
 
167
    $lines = explode("\n", $netstat);
-
 
168
    $results = array();
-
 
169
    for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
-
 
170
      $ar_buf = preg_split("/\s+/", $lines[$i], 10);
-
 
171
      if (!empty($ar_buf[0])) {
-
 
172
        $results[$ar_buf[0]] = array();
-
 
173
 
-
 
174
        $results[$ar_buf[0]]['rx_bytes'] = $ar_buf[5];
-
 
175
        $results[$ar_buf[0]]['rx_packets'] = $ar_buf[3];
-
 
176
        $results[$ar_buf[0]]['rx_errs'] = $ar_buf[4];
-
 
177
        $results[$ar_buf[0]]['rx_drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
-
 
178
 
-
 
179
        $results[$ar_buf[0]]['tx_bytes'] = $ar_buf[8];
-
 
180
        $results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
-
 
181
        $results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
-
 
182
        $results[$ar_buf[0]]['tx_drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
-
 
183
 
-
 
184
        $results[$ar_buf[0]]['errs'] = $ar_buf[4] + $ar_buf[7];
-
 
185
        $results[$ar_buf[0]]['drop'] = isset( $ar_buf[10] ) ? $ar_buf[10] : 0;
-
 
186
      } 
-
 
187
    } 
-
 
188
    return $results;
-
 
189
  } 
-
 
190
 
-
 
191
  function distroicon () {
-
 
192
    $result = 'Darwin.png';
-
 
193
    return($result);
-
 
194
  }
-
 
195
 
357
 
-
 
358
    /**
-
 
359
     * get network information
-
 
360
     *
-
 
361
     * @return void
-
 
362
     */
-
 
363
    private function _network()
-
 
364
    {
-
 
365
        if (CommonFunctions::executeProgram('netstat', '-nbdi | cut -c1-24,42- | grep Link', $netstat, PSI_DEBUG)) {
-
 
366
            $lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
-
 
367
            foreach ($lines as $line) {
-
 
368
                $ar_buf = preg_split("/\s+/", $line, 10);
-
 
369
                if (!empty($ar_buf[0])) {
-
 
370
                    $dev = new NetDevice();
-
 
371
                    $dev->setName($ar_buf[0]);
-
 
372
                    $dev->setTxBytes($ar_buf[8]);
-
 
373
                    $dev->setRxBytes($ar_buf[5]);
-
 
374
                    $dev->setErrors($ar_buf[4] + $ar_buf[7]);
-
 
375
                    if (isset($ar_buf[10])) {
-
 
376
                        $dev->setDrops($ar_buf[10]);
-
 
377
                    }
-
 
378
                    if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS) && (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' 2>/dev/null', $bufr2, PSI_DEBUG))) {
-
 
379
                        $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
-
 
380
                        foreach ($bufe2 as $buf2) {
-
 
381
                            if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) {
-
 
382
                                if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
-
 
383
                            } elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
-
 
384
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
-
 
385
                            } elseif ((preg_match('/^\s+inet6\s+([^\s%]+)\s+prefixlen/i', $buf2, $ar_buf2)
-
 
386
                                  || preg_match('/^\s+inet6\s+([^\s%]+)%\S+\s+prefixlen/i', $buf2, $ar_buf2))
-
 
387
                                  && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1])) {
-
 
388
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
-
 
389
                            } elseif (preg_match('/^\s+media:\s+/i', $buf2) && preg_match('/[\(\s](\d+)(G*)base/i', $buf2, $ar_buf2)) {
-
 
390
                                if (isset($ar_buf2[2]) && strtoupper($ar_buf2[2])=="G") {
-
 
391
                                    $unit = "G";
-
 
392
                                } else {
-
 
393
                                    $unit = "M";
-
 
394
                                }
-
 
395
                                if (preg_match('/[<\s]([^\s<]+)-duplex/i', $buf2, $ar_buf3))
-
 
396
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s '.strtolower($ar_buf3[1]));
-
 
397
                                else
-
 
398
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1].$unit.'b/s');
-
 
399
                            }
-
 
400
                        }
-
 
401
                    }
-
 
402
                    $this->sys->setNetDevices($dev);
-
 
403
                }
-
 
404
            }
-
 
405
        }
196
} 
406
    }
197
 
407
 
-
 
408
    /**
-
 
409
     * get icon name
-
 
410
     *
-
 
411
     * @return void
-
 
412
     */
-
 
413
    protected function distro()
-
 
414
    {
-
 
415
        $this->sys->setDistributionIcon('Darwin.png');
-
 
416
        if (!CommonFunctions::executeProgram('system_profiler', 'SPSoftwareDataType', $buffer, PSI_DEBUG)) {
-
 
417
            parent::distro();
-
 
418
        } else {
-
 
419
            $arrBuff = preg_split("/\n/", $buffer, -1, PREG_SPLIT_NO_EMPTY);
-
 
420
            foreach ($arrBuff as $line) {
-
 
421
                $arrLine = preg_split("/:/", $line, -1, PREG_SPLIT_NO_EMPTY);
-
 
422
                if (trim($arrLine[0]) === "System Version") {
-
 
423
                    $distro = trim($arrLine[1]);
-
 
424
 
-
 
425
                    if (preg_match('/^Mac OS|^OS X|^macOS/', $distro)) {
-
 
426
                        $this->sys->setDistributionIcon('Apple.png');
-
 
427
                        if (preg_match('/(^Mac OS X Server|^Mac OS X|^OS X Server|^OS X|^macOS Server|^macOS) (\d+\.\d+)/', $distro, $ver)
-
 
428
                            && ($list = @parse_ini_file(PSI_APP_ROOT."/data/osnames.ini", true))
-
 
429
                            && isset($list['OS X'][$ver[2]])) {
-
 
430
                            $distro.=' '.$list['OS X'][$ver[2]];
-
 
431
                        }
-
 
432
                    }
-
 
433
 
-
 
434
                    $this->sys->setDistribution($distro);
-
 
435
 
-
 
436
                    return;
-
 
437
                }
-
 
438
            }
-
 
439
        }
-
 
440
    }
-
 
441
 
-
 
442
    /**
-
 
443
     * Processes
-
 
444
     *
-
 
445
     * @return void
-
 
446
     */
-
 
447
    protected function _processes()
-
 
448
    {
-
 
449
        if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
-
 
450
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
-
 
451
            $processes['*'] = 0;
-
 
452
            foreach ($lines as $line) {
-
 
453
                if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
-
 
454
                    $processes['*']++;
-
 
455
                    $state = $ar_buf[1];
-
 
456
                    if ($state == 'U') $state = 'D'; //linux format
-
 
457
                    elseif ($state == 'I') $state = 'S';
-
 
458
                    elseif ($state == 'D') $state = 'd'; //invalid
-
 
459
                    if (isset($processes[$state])) {
-
 
460
                        $processes[$state]++;
-
 
461
                    } else {
-
 
462
                        $processes[$state] = 1;
-
 
463
                    }
-
 
464
                }
-
 
465
            }
-
 
466
            if ($processes['*'] > 0) {
-
 
467
                $this->sys->setProcesses($processes);
-
 
468
            }
-
 
469
        }
-
 
470
    }
-
 
471
 
-
 
472
    /**
-
 
473
     * get the information
-
 
474
     *
-
 
475
     * @see PSI_Interface_OS::build()
-
 
476
     *
-
 
477
     * @return Void
-
 
478
     */
-
 
479
    public function build()
-
 
480
    {
-
 
481
        parent::build();
-
 
482
        if (!$this->blockname || $this->blockname==='vitals') {
-
 
483
            $this->_uptime();
-
 
484
            $this->_processes();
-
 
485
        }
-
 
486
        if (!$this->blockname || $this->blockname==='hardware') {
-
 
487
            $this->_tb();
-
 
488
        }
-
 
489
        if (!$this->blockname || $this->blockname==='network') {
-
 
490
            $this->_network();
-
 
491
        }
-
 
492
    }
198
?>
493
}