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
 * SunOS System Class
-
 
4
 *
-
 
5
 * PHP version 5
-
 
6
 *
-
 
7
 * @category  PHP
-
 
8
 * @package   PSI SunOS 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.SunOS.inc.php 687 2012-09-06 20:54:49Z namiltd $
-
 
13
 * @link      http://phpsysinfo.sourceforge.net
-
 
14
 */
-
 
15
 /**
-
 
16
 * SunOS sysinfo class
-
 
17
 * get all the required information from SunOS systems
-
 
18
 *
-
 
19
 * @category  PHP
-
 
20
 * @package   PSI SunOS OS class
-
 
21
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
-
 
22
 * @copyright 2009 phpSysInfo
-
 
23
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
-
 
24
 * @version   Release: 3.0
-
 
25
 * @link      http://phpsysinfo.sourceforge.net
-
 
26
 */
-
 
27
class SunOS extends OS
-
 
28
{
-
 
29
 
-
 
30
    /**
-
 
31
     * content of prtconf -v
-
 
32
     *
-
 
33
     * @var array
-
 
34
     */
-
 
35
    private $_prtconf = null;
-
 
36
 
-
 
37
    /**
-
 
38
     * Execute prtconf -v and save ass array
-
 
39
     *
-
 
40
     * @return array
-
 
41
     */
-
 
42
    protected function prtconf()
-
 
43
    {
-
 
44
        if ($this->_prtconf === null) {
-
 
45
            $this->_prtconf = array();
-
 
46
            if (CommonFunctions::executeProgram('prtconf', '-v', $buf, PSI_DEBUG) && ($buf!="")) {
-
 
47
                $blocks = preg_split( '/\n(?=    \S)/', $buf, -1, PREG_SPLIT_NO_EMPTY);
-
 
48
                if (!empty($blocks) && (count($blocks)>2)) {
-
 
49
                    array_shift($blocks);
-
 
50
                    foreach ($blocks as $block) {
-
 
51
                        if (preg_match('/^    (\S+) /',$block, $ar_buf)) {
-
 
52
                            $group = trim($ar_buf[1], ',');
-
 
53
                            $grouparr = array();
-
 
54
                            $blocks1 = preg_split( '/\n(?=        \S)/', $block, -1, PREG_SPLIT_NO_EMPTY);
-
 
55
                            if (!empty($blocks1) && count($blocks1)) {
-
 
56
                                array_shift($blocks1);
-
 
57
                                foreach ($blocks1 as $block1) {
-
 
58
                                    if (!preg_match('/^        name=\'([^\']+)\'/',$block1)
-
 
59
                                       && preg_match('/^        (\S+) /',$block1, $ar_buf)) {
-
 
60
                                        $device = trim($ar_buf[1], ',');
-
 
61
                                        $devicearr = array();
-
 
62
                                        $blocks2 = preg_split( '/\n(?=            \S)/', $block1, -1, PREG_SPLIT_NO_EMPTY);
-
 
63
                                        if (!empty($blocks2) && count($blocks2)) {
-
 
64
                                            array_shift($blocks2);
-
 
65
                                            foreach ($blocks2 as $block2) {
-
 
66
                                                if (!preg_match('/^            name=\'([^\']+)\'/',$block2)
-
 
67
                                                   && preg_match('/^            (\S+) /',$block2, $ar_buf)) {
-
 
68
                                                    $subdev = trim($ar_buf[1], ',');
-
 
69
                                                    $subdevarr = array();
-
 
70
                                                    $blocks3 = preg_split( '/\n(?=                \S)/', $block2, -1, PREG_SPLIT_NO_EMPTY);
-
 
71
                                                    if (!empty($blocks3) && count($blocks3)) {
-
 
72
                                                        array_shift($blocks3);
-
 
73
                                                        foreach ($blocks3 as $block3) {
-
 
74
                                                            if (preg_match('/^                name=\'([^\']+)\' [\s\S]+ value=\'?([^\']+)\'?/m',$block3, $ar_buf)) {
-
 
75
                                                                if ($subdev==='Hardware') {
-
 
76
                                                                    $subdevarr[$ar_buf[1]] = $ar_buf[2];
-
 
77
                                                                    $subdevarr['device'] = $device;
-
 
78
                                                                }
-
 
79
                                                            }
-
 
80
                                                        }
-
 
81
                                                        if (count($subdevarr)) {
-
 
82
                                                            $devicearr = $subdevarr;
-
 
83
                                                        }
-
 
84
                                                    }
-
 
85
                                                }
-
 
86
                                            }
-
 
87
                                        }
-
 
88
                                        if (count($devicearr)) {
-
 
89
                                            $grouparr[$device][] = $devicearr;
-
 
90
                                        }
-
 
91
                                    }
-
 
92
                                }
-
 
93
                            }
-
 
94
                            if (count($grouparr)) {
-
 
95
                                $this->_prtconf[$group][] = $grouparr;
-
 
96
                            }
-
 
97
                        }
-
 
98
                    }
-
 
99
                }
-
 
100
            }
-
 
101
        }
-
 
102
 
-
 
103
        return $this->_prtconf;
-
 
104
    }
-
 
105
 
-
 
106
    /**
-
 
107
     * Extract kernel values via kstat() interface
-
 
108
     *
-
 
109
     * @param string $key key for kstat programm
-
 
110
     *
-
 
111
     * @return string
-
 
112
     */
-
 
113
    private function _kstat($key)
-
 
114
    {
-
 
115
        if (CommonFunctions::executeProgram('kstat', '-p d '.$key, $m, PSI_DEBUG) && ($m!=="")) {
-
 
116
            list($key, $value) = preg_split("/\t/", $m, 2);
-
 
117
 
-
 
118
            return trim($value);
-
 
119
        } else {
-
 
120
            return '';
-
 
121
        }
-
 
122
    }
2
 
123
 
-
 
124
    /**
-
 
125
     * Virtual Host Name
-
 
126
     *
-
 
127
     * @return void
-
 
128
     */
-
 
129
    private function _hostname()
-
 
130
    {
-
 
131
        if (PSI_USE_VHOST === true) {
-
 
132
            if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
-
 
133
        } else {
-
 
134
            if (CommonFunctions::executeProgram('uname', '-n', $result, PSI_DEBUG)) {
3
// phpSysInfo - A PHP System Information Script
135
                $ip = gethostbyname($result);
4
// http://phpsysinfo.sourceforge.net/
136
                if ($ip != $result) {
-
 
137
                    $this->sys->setHostname(gethostbyaddr($ip));
-
 
138
                }
-
 
139
            }
-
 
140
        }
-
 
141
    }
5
 
142
 
6
// This program is free software; you can redistribute it and/or
-
 
7
// modify it under the terms of the GNU General Public License
-
 
8
// as published by the Free Software Foundation; either version 2
-
 
9
// of the License, or (at your option) any later version.
-
 
10
 
-
 
11
// This program is distributed in the hope that it will be useful,
-
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
-
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-
 
14
// GNU General Public License for more details.
-
 
15
 
-
 
16
// You should have received a copy of the GNU General Public License
-
 
17
// along with this program; if not, write to the Free Software
-
 
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
 
19
 
-
 
20
// $Id: class.SunOS.inc.php,v 1.24 2007/02/18 18:59:54 bigmichi1 Exp $
-
 
21
 
-
 
22
$error->addError("WARN", "The SunOS version of phpSysInfo is work in progress, some things currently don't work");
-
 
23
 
-
 
24
class sysinfo {
-
 
25
  // Extract kernel values via kstat() interface
-
 
26
  function kstat ($key) {
-
 
27
    $m = execute_program('kstat', "-p d $key");
-
 
28
    list($key, $value) = explode("\t", trim($m), 2);
-
 
29
    return $value;
-
 
30
  } 
-
 
31
 
-
 
32
  function vhostname () {
-
 
33
    if (! ($result = getenv('SERVER_NAME'))) {
-
 
34
      $result = 'N.A.';
-
 
35
    } 
143
    /**
36
    return $result;
144
     * Kernel Version
37
  } 
-
 
38
  // get the IP address of our vhost name
-
 
39
  function vip_addr () {
-
 
40
    return gethostbyname($this->vhostname());
-
 
41
  }
-
 
42
  // get our canonical hostname
-
 
43
  function chostname () {
-
 
44
    if ($result = execute_program('uname', '-n')) {
-
 
45
      $result = gethostbyaddr(gethostbyname($result));
-
 
46
    } else {
-
 
47
      $result = 'N.A.';
-
 
48
    } 
145
     *
49
    return $result;
146
     * @return void
50
  } 
-
 
51
  // get the IP address of our canonical hostname
-
 
52
  function ip_addr () {
-
 
53
    if (!($result = getenv('SERVER_ADDR'))) {
-
 
54
      $result = gethostbyname($this->chostname());
-
 
55
    } 
147
     */
56
    return $result;
-
 
57
  } 
-
 
58
 
-
 
59
  function kernel () {
148
    private function _kernel()
60
    $os = execute_program('uname', '-s');
-
 
61
    $version = execute_program('uname', '-r');
-
 
62
    return $os . ' ' . $version;
-
 
63
  } 
-
 
64
 
-
 
65
  function uptime () {
-
 
66
    $result = time() - $this->kstat('unix:0:system_misc:boot_time');
-
 
67
 
-
 
68
    return $result;
-
 
69
  } 
-
 
70
 
-
 
71
  function users () {
-
 
72
    $who = explode('=', execute_program('who', '-q'));
-
 
73
    $result = $who[1];
-
 
74
    return $result;
-
 
75
  } 
-
 
76
 
-
 
77
  function loadavg ($bar = false) {
-
 
78
    $load1 = $this->kstat('unix:0:system_misc:avenrun_1min');
-
 
79
    $load5 = $this->kstat('unix:0:system_misc:avenrun_5min');
-
 
80
    $load15 = $this->kstat('unix:0:system_misc:avenrun_15min');
-
 
81
    $results['avg'] = array( round($load1/256, 2), round($load5/256, 2), round($load15/256, 2) );
-
 
82
    return $results;
-
 
83
  } 
149
    {
84
 
-
 
85
  function cpu_info () {
-
 
86
    $results = array();
-
 
87
    $ar_buf = array();
-
 
88
 
-
 
89
    $results['model'] = execute_program('uname', '-i');
150
        if (CommonFunctions::executeProgram('uname', '-s', $os, PSI_DEBUG) && ($os!="")) {
90
    $results['cpuspeed'] = $this->kstat('cpu_info:0:cpu_info0:clock_MHz');
-
 
91
    $results['cache'] = $this->kstat('cpu_info:0:cpu_info0:cpu_type');
-
 
92
    $results['cpus'] = $this->kstat('unix:0:system_misc:ncpus');
-
 
93
 
-
 
94
    return $results;
-
 
95
  } 
-
 
96
 
-
 
97
  function pci () {
-
 
98
    // FIXME
-
 
99
    $results = array();
-
 
100
    return $results;
-
 
101
  } 
-
 
102
 
-
 
103
  function ide () {
-
 
104
    // FIXME
-
 
105
    $results = array();
-
 
106
    return $results;
-
 
107
  } 
-
 
108
 
-
 
109
  function scsi () {
-
 
110
    // FIXME
-
 
111
    $results = array();
-
 
112
    return $results;
-
 
113
  } 
-
 
114
 
-
 
115
  function usb () {
-
 
116
    // FIXME
-
 
117
    $results = array();
-
 
118
    return $results;
-
 
119
  } 
-
 
120
 
-
 
121
  function sbus () {
-
 
122
    $results = array();
-
 
123
    $_results[0] = "";
-
 
124
    // TODO. Nothing here yet. Move along.
-
 
125
    $results = $_results;
-
 
126
    return $results;
-
 
127
  }
-
 
128
 
-
 
129
  function network () {
-
 
130
    $results = array();
-
 
131
 
-
 
132
    $netstat = execute_program('netstat', '-ni | awk \'(NF ==10){print;}\'');
151
            if (CommonFunctions::executeProgram('uname', '-r', $version, PSI_DEBUG) && ($version!="")) {
133
    $lines = explode("\n", $netstat);
152
                $os.=' '.$version;
134
    $results = array();
-
 
135
    for ($i = 0, $max = sizeof($lines); $i < $max; $i++) {
-
 
136
      $ar_buf = preg_split("/\s+/", $lines[$i]);
-
 
137
      if ((!empty($ar_buf[0])) && ($ar_buf[0] != 'Name')) {
-
 
138
        $results[$ar_buf[0]] = array();
-
 
139
 
-
 
140
        $results[$ar_buf[0]]['rx_bytes'] = 0;
-
 
141
        $results[$ar_buf[0]]['rx_packets'] = $ar_buf[4];
-
 
142
        $results[$ar_buf[0]]['rx_errs'] = $ar_buf[5];
-
 
143
        $results[$ar_buf[0]]['rx_drop'] = 0;
-
 
144
 
-
 
145
        $results[$ar_buf[0]]['tx_bytes'] = 0;
-
 
146
        $results[$ar_buf[0]]['tx_packets'] = $ar_buf[6];
-
 
147
        $results[$ar_buf[0]]['tx_errs'] = $ar_buf[7];
-
 
148
        $results[$ar_buf[0]]['tx_drop'] = 0;
-
 
149
 
-
 
150
        $results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[
-
 
151
        7];
153
            }
152
        $results[$ar_buf[0]]['drop'] = 0;
-
 
153
 
-
 
154
        preg_match('/^(\D+)(\d+)$/', $ar_buf[0], $intf);
-
 
155
        $prefix = $intf[1] . ':' . $intf[2] . ':' . $intf[1] . $intf[2] . ':';
154
            if (CommonFunctions::executeProgram('uname', '-v', $subversion, PSI_DEBUG) && ($subversion!="")) {
156
        $cnt = $this->kstat($prefix . 'drop');
155
                $os.=' ('.$subversion.')';
157
 
-
 
158
        if ($cnt > 0) {
-
 
159
          $results[$ar_buf[0]]['rx_drop'] = $cnt;
-
 
160
        } 
156
            }
161
        $cnt = $this->kstat($prefix . 'obytes64');
157
            if (CommonFunctions::executeProgram('uname', '-i', $platform, PSI_DEBUG) && ($platform!="")) {
162
 
-
 
163
        if ($cnt > 0) {
158
                $os.=' '.$platform;
164
          $results[$ar_buf[0]]['tx_bytes'] = $cnt;
-
 
165
        } 
159
            }
166
        $cnt = $this->kstat($prefix . 'rbytes64');
160
            $this->sys->setKernel($os);
167
 
-
 
168
        if ($cnt > 0) {
-
 
169
          $results[$ar_buf[0]]['rx_bytes'] = $cnt;
-
 
170
        }
161
        }
171
      } 
-
 
172
    } 
162
    }
173
    return $results;
-
 
174
  } 
-
 
175
 
-
 
176
  function memory () {
-
 
177
    $results['devswap'] = array();
-
 
178
 
-
 
179
    $results['ram'] = array();
-
 
180
 
-
 
181
    $pagesize = $this->kstat('unix:0:seg_cache:slab_size');
-
 
182
    $results['ram']['total'] = $this->kstat('unix:0:system_pages:pagestotal') * $pagesize / 1024;
-
 
183
    $results['ram']['used'] = $this->kstat('unix:0:system_pages:pageslocked') * $pagesize / 1024;
-
 
184
    $results['ram']['free'] = $this->kstat('unix:0:system_pages:pagesfree') * $pagesize / 1024;
-
 
185
    $results['ram']['shared'] = 0;
-
 
186
    $results['ram']['buffers'] = 0;
-
 
187
    $results['ram']['cached'] = 0;
-
 
188
 
-
 
189
    $results['ram']['percent'] = round(($results['ram']['used'] * 100) / $results['ram']['total']);
-
 
190
 
-
 
191
    $results['swap'] = array();
-
 
192
    $results['swap']['total'] = $this->kstat('unix:0:vminfo:swap_avail') / 1024 / 1024;
-
 
193
    $results['swap']['used'] = $this->kstat('unix:0:vminfo:swap_alloc') / 1024 / 1024;
-
 
194
    $results['swap']['free'] = $this->kstat('unix:0:vminfo:swap_free') / 1024 / 1024;
-
 
195
    $results['swap']['percent'] = round(($ar_buf[1] * 100) / $ar_buf[0]);
-
 
196
    $results['swap']['percent'] = round(($results['swap']['used'] * 100) / $results['swap']['total']);
-
 
197
    return $results;
-
 
198
  } 
-
 
199
 
-
 
200
  function filesystems () {
-
 
201
    $df = execute_program('df', '-k');
-
 
202
    $mounts = explode("\n", $df);
-
 
203
 
-
 
204
    $dftypes = execute_program('df', '-n');
-
 
205
    $mounttypes = explode("\n", $dftypes);
-
 
206
 
-
 
207
    for ($i = 1, $j = 0, $max = sizeof($mounts); $i < $max; $i++) {
-
 
208
      $ar_buf = preg_split('/\s+/', $mounts[$i], 6);
-
 
209
      $ty_buf = explode(':', $mounttypes[$i-1], 2);
-
 
210
 
-
 
211
      if (hide_mount($ar_buf[5])) {
-
 
212
        continue;
-
 
213
      }
-
 
214
 
-
 
215
      $results[$j] = array();
-
 
216
 
-
 
217
      $results[$j]['disk'] = $ar_buf[0];
-
 
218
      $results[$j]['size'] = $ar_buf[1];
-
 
219
      $results[$j]['used'] = $ar_buf[2];
-
 
220
      $results[$j]['free'] = $ar_buf[3];
-
 
221
      $results[$j]['percent'] = round(($results[$j]['used'] * 100) / $results[$j]['size']);
-
 
222
      $results[$j]['mount'] = $ar_buf[5];
-
 
223
      $results[$j]['fstype'] = $ty_buf[1];
-
 
224
      $j++;
-
 
225
    } 
-
 
226
    return $results;
-
 
227
  } 
-
 
228
  
-
 
229
  function distro () {
-
 
230
    $result = 'SunOS';  	
-
 
231
    return($result);
-
 
232
  }
-
 
233
 
-
 
234
  function distroicon () {
-
 
235
    $result = 'SunOS.png';
-
 
236
    return($result);
-
 
237
  }
-
 
238
} 
-
 
239
 
163
 
-
 
164
    /**
-
 
165
     * UpTime
-
 
166
     * time the system is running
-
 
167
     *
-
 
168
     * @return void
-
 
169
     */
-
 
170
    private function _uptime()
-
 
171
    {
-
 
172
        $this->sys->setUptime(time() - $this->_kstat('unix:0:system_misc:boot_time'));
-
 
173
    }
-
 
174
 
-
 
175
    /**
-
 
176
     * Processor Load
-
 
177
     * optionally create a loadbar
-
 
178
     *
-
 
179
     * @return void
-
 
180
     */
-
 
181
    private function _loadavg()
-
 
182
    {
-
 
183
        $load1 = $this->_kstat('unix:0:system_misc:avenrun_1min');
-
 
184
        $load5 = $this->_kstat('unix:0:system_misc:avenrun_5min');
-
 
185
        $load15 = $this->_kstat('unix:0:system_misc:avenrun_15min');
-
 
186
        $this->sys->setLoad(round($load1 / 256, 2).' '.round($load5 / 256, 2).' '.round($load15 / 256, 2));
-
 
187
    }
-
 
188
 
-
 
189
    /**
-
 
190
     * CPU information
-
 
191
     *
-
 
192
     * @return void
-
 
193
     */
-
 
194
    private function _cpuinfo()
-
 
195
    {
-
 
196
        if (CommonFunctions::executeProgram('kstat', '-p d cpu_info:*:cpu_info*:core_id', $m, PSI_DEBUG) && ($m!=="")) {
-
 
197
            $cpuc = count(preg_split('/\n/', $m, -1, PREG_SPLIT_NO_EMPTY));
-
 
198
            for ($cpu=0; $cpu < $cpuc; $cpu++) {
-
 
199
                $dev = new CpuDevice();
-
 
200
                if (($buf = $this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':current_clock_Hz')) !== "") {
-
 
201
                    $dev->setCpuSpeed($buf/1000000);
-
 
202
                } elseif (($buf = $this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':clock_MHz')) !== "") {
-
 
203
                    $dev->setCpuSpeed($buf);
-
 
204
                }
-
 
205
                if (($buf = $this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':supported_frequencies_Hz')) !== "") {
-
 
206
                    $cpuarr = preg_split('/:/', $buf, -1, PREG_SPLIT_NO_EMPTY);
-
 
207
                    if (($cpuarrc=count($cpuarr))>1) {
-
 
208
                        $dev->setCpuSpeedMin($cpuarr[0]/1000000);
-
 
209
                        $dev->setCpuSpeedMax($cpuarr[$cpuarrc-1]/1000000);
-
 
210
                    }
-
 
211
                }
-
 
212
                if (($buf  =$this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':brand')) !== "") {
-
 
213
                    $dev->setModel($buf);
-
 
214
                } elseif (($buf  =$this->_kstat('cpu_info:'.$cpu.':cpu_info'.$cpu.':cpu_type')) !== "") {
-
 
215
                    $dev->setModel($buf);
-
 
216
                } elseif (CommonFunctions::executeProgram('uname', '-p', $buf, PSI_DEBUG) && ($buf!="")) {
-
 
217
                    $dev->setModel($buf);
-
 
218
                } elseif (CommonFunctions::executeProgram('uname', '-i', $buf, PSI_DEBUG) && ($buf!="")) {
-
 
219
                    $dev->setModel($buf);
-
 
220
                }
-
 
221
                $this->sys->setCpus($dev);
-
 
222
            }
-
 
223
         }
-
 
224
    }
-
 
225
 
-
 
226
    /**
-
 
227
     * PCI devices
-
 
228
     *
-
 
229
     * @return void
-
 
230
     */
-
 
231
    protected function _pci()
-
 
232
    {
-
 
233
        $prtconf = $this->prtconf();
-
 
234
        if ((count($prtconf)>1) && isset($prtconf['pci'])) {
-
 
235
            foreach ($prtconf['pci'] as $prt) {
-
 
236
                foreach ($prt as $pci) {
-
 
237
                    foreach ($pci as $pcidev) {
-
 
238
                        if (isset($pcidev['device'])) {
-
 
239
                            $dev = new HWDevice();
-
 
240
                            if (isset($pcidev['model'])) {
-
 
241
                                $name = $pcidev['model'];
-
 
242
                            } else {
-
 
243
                                $name = $pcidev['device'];
-
 
244
                            }
-
 
245
                            if (isset($pcidev['device-name'])) {
-
 
246
                                $name .= ': '.$pcidev['device-name'];
-
 
247
                            }
-
 
248
                            $dev->setName($name);
-
 
249
 
-
 
250
                            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
-
 
251
                                if (isset($pcidev['subsystem-name']) && ($pcidev['subsystem-name']!=='unknown subsystem')) {
-
 
252
                                    $dev->setProduct($pcidev['subsystem-name']);
-
 
253
                                }
-
 
254
                                if (isset($pcidev['vendor-name'])) {
-
 
255
                                    $dev->setManufacturer($pcidev['vendor-name']);
-
 
256
                                }
-
 
257
                            }
-
 
258
 
-
 
259
                            $this->sys->setPciDevices($dev);
-
 
260
                        }
-
 
261
                    }
-
 
262
                }
-
 
263
            }
-
 
264
        }
-
 
265
    }
-
 
266
 
-
 
267
    /**
-
 
268
     * Network devices
-
 
269
     *
-
 
270
     * @return void
-
 
271
     */
-
 
272
    private function _network()
-
 
273
    {
-
 
274
        if (CommonFunctions::executeProgram('netstat', '-ni | awk \'(NF ==10){print;}\'', $netstat, PSI_DEBUG)) {
-
 
275
            $lines = preg_split("/\n/", $netstat, -1, PREG_SPLIT_NO_EMPTY);
-
 
276
            foreach ($lines as $line) {
-
 
277
                $ar_buf = preg_split("/\s+/", $line);
-
 
278
                if (!empty($ar_buf[0]) && $ar_buf[0] !== 'Name') {
-
 
279
                    $dev = new NetDevice();
-
 
280
                    $dev->setName($ar_buf[0]);
-
 
281
                    $results[$ar_buf[0]]['errs'] = $ar_buf[5] + $ar_buf[7];
-
 
282
                    if (preg_match('/^(\D+)(\d+)$/', $ar_buf[0], $intf)) {
-
 
283
                        $prefix = $intf[1].':'.$intf[2].':'.$intf[1].$intf[2].':';
-
 
284
                    } elseif (preg_match('/^(\D.*)(\d+)$/', $ar_buf[0], $intf)) {
-
 
285
                        $prefix = $intf[1].':'.$intf[2].':mac:';
-
 
286
                    } else {
-
 
287
                        $prefix = "";
-
 
288
                    }
-
 
289
                    if ($prefix !== "") {
-
 
290
                        $cnt = $this->_kstat($prefix.'drop');
-
 
291
                        if ($cnt > 0) {
-
 
292
                            $dev->setDrops($cnt);
-
 
293
                        }
-
 
294
                        $cnt = $this->_kstat($prefix.'obytes64');
-
 
295
                        if ($cnt > 0) {
-
 
296
                            $dev->setTxBytes($cnt);
-
 
297
                        }
-
 
298
                        $cnt = $this->_kstat($prefix.'rbytes64');
-
 
299
                        if ($cnt > 0) {
-
 
300
                            $dev->setRxBytes($cnt);
-
 
301
                        }
-
 
302
                    }
-
 
303
                    if (defined('PSI_SHOW_NETWORK_INFOS') && (PSI_SHOW_NETWORK_INFOS)) {
-
 
304
                        if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0], $bufr2, PSI_DEBUG) && ($bufr2!=="")) {
-
 
305
                            $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
-
 
306
                            foreach ($bufe2 as $buf2) {
-
 
307
                                if (preg_match('/^\s+ether\s+(\S+)/i', $buf2, $ar_buf2)) {
-
 
308
                                    if (!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').preg_replace('/:/', '-', strtoupper($ar_buf2[1])));
-
 
309
                                } elseif (preg_match('/^\s+inet\s+(\S+)\s+netmask/i', $buf2, $ar_buf2)) {
-
 
310
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').$ar_buf2[1]);
-
 
311
                                }
-
 
312
                            }
-
 
313
                        }
-
 
314
                        if (CommonFunctions::executeProgram('ifconfig', $ar_buf[0].' inet6', $bufr2, PSI_DEBUG) && ($bufr2!=="")) {
-
 
315
                            $bufe2 = preg_split("/\n/", $bufr2, -1, PREG_SPLIT_NO_EMPTY);
-
 
316
                            foreach ($bufe2 as $buf2) {
-
 
317
                                if (preg_match('/^\s+inet6\s+([^\s\/]+)/i', $buf2, $ar_buf2)
-
 
318
                                   && ($ar_buf2[1]!="::") && !preg_match('/^fe80::/i', $ar_buf2[1]))
-
 
319
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ar_buf2[1]));
-
 
320
                            }
-
 
321
                        }
-
 
322
                    }
-
 
323
 
-
 
324
                    $this->sys->setNetDevices($dev);
-
 
325
                }
-
 
326
            }
-
 
327
        }
-
 
328
    }
-
 
329
 
-
 
330
    /**
-
 
331
     * Physical memory information and Swap Space information
-
 
332
     *
-
 
333
     * @return void
-
 
334
     */
-
 
335
    private function _memory()
-
 
336
    {
-
 
337
        $pagesize = $this->_kstat('unix:0:seg_cache:slab_size');
-
 
338
        $this->sys->setMemTotal($this->_kstat('unix:0:system_pages:pagestotal') * $pagesize);
-
 
339
        $this->sys->setMemUsed($this->_kstat('unix:0:system_pages:pageslocked') * $pagesize);
-
 
340
        $this->sys->setMemFree($this->_kstat('unix:0:system_pages:pagesfree') * $pagesize);
-
 
341
        $dev = new DiskDevice();
-
 
342
        $dev->setName('SWAP');
-
 
343
        $dev->setFsType('swap');
-
 
344
        $dev->setMountPoint('SWAP');
-
 
345
        $dev->setTotal($this->_kstat('unix:0:vminfo:swap_avail') / 1024);
-
 
346
        $dev->setUsed($this->_kstat('unix:0:vminfo:swap_alloc') / 1024);
-
 
347
        $dev->setFree($this->_kstat('unix:0:vminfo:swap_free') / 1024);
-
 
348
        $this->sys->setSwapDevices($dev);
-
 
349
    }
-
 
350
 
-
 
351
    /**
-
 
352
     * filesystem information
-
 
353
     *
-
 
354
     * @return void
-
 
355
     */
-
 
356
    private function _filesystems()
-
 
357
    {
-
 
358
        if (CommonFunctions::executeProgram('df', '-k', $df, PSI_DEBUG)) {
-
 
359
            $df = preg_replace('/\n\s/m', ' ', $df);
-
 
360
            $mounts = preg_split("/\n/", $df, -1, PREG_SPLIT_NO_EMPTY);
-
 
361
            foreach ($mounts as $mount) {
-
 
362
                $ar_buf = preg_split('/\s+/', $mount, 6);
-
 
363
                if (!empty($ar_buf[0]) && $ar_buf[0] !== 'Filesystem') {
-
 
364
                    $dev = new DiskDevice();
-
 
365
                    $dev->setName($ar_buf[0]);
-
 
366
                    $dev->setTotal($ar_buf[1] * 1024);
-
 
367
                    $dev->setUsed($ar_buf[2] * 1024);
-
 
368
                    $dev->setFree($ar_buf[3] * 1024);
-
 
369
                    $dev->setMountPoint($ar_buf[5]);
-
 
370
                    if (CommonFunctions::executeProgram('df', '-n', $dftypes, PSI_DEBUG)) {
-
 
371
                        $mounttypes = preg_split("/\n/", $dftypes, -1, PREG_SPLIT_NO_EMPTY);
-
 
372
                        foreach ($mounttypes as $type) {
-
 
373
                            $ty_buf = preg_split('/:/', $type, 2);
-
 
374
                            if (trim($ty_buf[0]) == $dev->getMountPoint()) {
-
 
375
                                $dev->setFsType($ty_buf[1]);
-
 
376
                                break;
-
 
377
                            }
-
 
378
                        }
-
 
379
                    } elseif (CommonFunctions::executeProgram('df', '-T', $dftypes, PSI_DEBUG)) {
-
 
380
                        $dftypes = preg_replace('/\n\s/m', ' ', $dftypes);
-
 
381
                        $mounttypes = preg_split("/\n/", $dftypes, -1, PREG_SPLIT_NO_EMPTY);
-
 
382
                        foreach ($mounttypes as $type) {
-
 
383
                            $ty_buf = preg_split("/\s+/", $type, 3);
-
 
384
                            if ($ty_buf[0] == $dev->getName()) {
-
 
385
                                $dev->setFsType($ty_buf[1]);
-
 
386
                                break;
-
 
387
                            }
-
 
388
                        }
-
 
389
                    }
-
 
390
                    $this->sys->setDiskDevices($dev);
-
 
391
                }
-
 
392
            }
-
 
393
        }
-
 
394
    }
-
 
395
 
-
 
396
    /**
-
 
397
     * Distribution Icon
-
 
398
     *
-
 
399
     * @return void
-
 
400
     */
-
 
401
    private function _distro()
-
 
402
    {
-
 
403
        if (CommonFunctions::rfts('/etc/release', $buf, 1, 4096, false) && (trim($buf)!="")) {
-
 
404
            $this->sys->setDistribution(trim($buf));
-
 
405
            $list = @parse_ini_file(PSI_APP_ROOT."/data/distros.ini", true);
-
 
406
            if ($list && preg_match('/^(\S+)\s*/', preg_replace('/^Open\s+/', 'Open', preg_replace('/^Oracle\s+/', 'Oracle', trim($buf))), $id_buf) && isset($list[$distid=(trim($id_buf[1].' SunOS'))]['Image'])) {
-
 
407
                $this->sys->setDistributionIcon($list[$distid]['Image']);
-
 
408
                if (isset($list[trim($distid)]['Name'])) {
-
 
409
                    $this->sys->setDistribution(trim($list[$distid]['Name']).' '.$this->sys->getDistribution());
-
 
410
                }
-
 
411
            } else {
-
 
412
                $this->sys->setDistributionIcon('SunOS.png');
-
 
413
            }
-
 
414
        } else {
-
 
415
            $this->sys->setDistribution('SunOS');
-
 
416
            $this->sys->setDistributionIcon('SunOS.png');
-
 
417
        }
-
 
418
    }
-
 
419
 
-
 
420
    /**
-
 
421
     * Processes
-
 
422
     *
-
 
423
     * @return void
-
 
424
     */
-
 
425
    protected function _processes()
-
 
426
    {
-
 
427
        if (CommonFunctions::executeProgram('ps', 'aux', $bufr, PSI_DEBUG)) {
-
 
428
            $lines = preg_split("/\n/", $bufr, -1, PREG_SPLIT_NO_EMPTY);
-
 
429
            $processes['*'] = 0;
-
 
430
            foreach ($lines as $line) {
-
 
431
                if (preg_match("/^\S+\s+\d+\s+\S+\s+\S+\s+\d+\s+\d+\s+\S+\s+(\w)/", $line, $ar_buf)) {
-
 
432
                    $processes['*']++;
-
 
433
                    $state = $ar_buf[1];
-
 
434
                    if ($state == 'O') $state = 'R'; //linux format
-
 
435
                    elseif ($state == 'W') $state = 'D';
-
 
436
                    elseif ($state == 'D') $state = 'd'; //invalid
-
 
437
                    if (isset($processes[$state])) {
-
 
438
                        $processes[$state]++;
-
 
439
                    } else {
-
 
440
                        $processes[$state] = 1;
-
 
441
                    }
-
 
442
                }
-
 
443
            }
-
 
444
            if ($processes['*'] > 0) {
-
 
445
                $this->sys->setProcesses($processes);
-
 
446
            }
-
 
447
        }
-
 
448
    }
-
 
449
 
-
 
450
    /**
-
 
451
     * get the information
-
 
452
     *
-
 
453
     * @see PSI_Interface_OS::build()
-
 
454
     *
-
 
455
     * @return Void
-
 
456
     */
-
 
457
    public function build()
-
 
458
    {
-
 
459
        $this->error->addError("WARN", "The SunOS version of phpSysInfo is a work in progress, some things currently don't work");
-
 
460
        if (!$this->blockname || $this->blockname==='vitals') {
-
 
461
            $this->_distro();
-
 
462
            $this->_hostname();
-
 
463
            $this->_kernel();
-
 
464
            $this->_uptime();
-
 
465
            $this->_users();
-
 
466
            $this->_loadavg();
-
 
467
            $this->_processes();
-
 
468
        }
-
 
469
        if (!$this->blockname || $this->blockname==='hardware') {
-
 
470
            $this->_cpuinfo();
-
 
471
            $this->_pci();
-
 
472
        }
-
 
473
        if (!$this->blockname || $this->blockname==='network') {
-
 
474
            $this->_network();
-
 
475
        }
-
 
476
        if (!$this->blockname || $this->blockname==='memory') {
-
 
477
            $this->_memory();
-
 
478
        }
-
 
479
        if (!$this->blockname || $this->blockname==='filesystem') {
-
 
480
            $this->_filesystems();
-
 
481
        }
-
 
482
    }
240
?>
483
}