Subversion Repositories ALCASAR

Rev

Rev 3037 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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