325 |
richard |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
// phpSysInfo - A PHP System Information Script
|
|
|
4 |
// http://phpsysinfo.sourceforge.net/
|
|
|
5 |
|
|
|
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 |
}
|
|
|
36 |
return $result;
|
|
|
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 |
}
|
|
|
49 |
return $result;
|
|
|
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 |
}
|
|
|
56 |
return $result;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
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 |
}
|
|
|
84 |
|
|
|
85 |
function cpu_info () {
|
|
|
86 |
$results = array();
|
|
|
87 |
$ar_buf = array();
|
|
|
88 |
|
|
|
89 |
$results['model'] = execute_program('uname', '-i');
|
|
|
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;}\'');
|
|
|
133 |
$lines = explode("\n", $netstat);
|
|
|
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];
|
|
|
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] . ':';
|
|
|
156 |
$cnt = $this->kstat($prefix . 'drop');
|
|
|
157 |
|
|
|
158 |
if ($cnt > 0) {
|
|
|
159 |
$results[$ar_buf[0]]['rx_drop'] = $cnt;
|
|
|
160 |
}
|
|
|
161 |
$cnt = $this->kstat($prefix . 'obytes64');
|
|
|
162 |
|
|
|
163 |
if ($cnt > 0) {
|
|
|
164 |
$results[$ar_buf[0]]['tx_bytes'] = $cnt;
|
|
|
165 |
}
|
|
|
166 |
$cnt = $this->kstat($prefix . 'rbytes64');
|
|
|
167 |
|
|
|
168 |
if ($cnt > 0) {
|
|
|
169 |
$results[$ar_buf[0]]['rx_bytes'] = $cnt;
|
|
|
170 |
}
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
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 |
|
|
|
240 |
?>
|