Subversion Repositories ALCASAR

Rev

Rev 2976 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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