325 |
richard |
1 |
<?php
|
|
|
2 |
// phpSysInfo - A PHP System Information Script
|
|
|
3 |
// http://phpsysinfo.sourceforge.net/
|
|
|
4 |
// This program is free software; you can redistribute it and/or
|
|
|
5 |
// modify it under the terms of the GNU General Public License
|
|
|
6 |
// as published by the Free Software Foundation; either version 2
|
|
|
7 |
// of the License, or (at your option) any later version.
|
|
|
8 |
// This program is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
// You should have received a copy of the GNU General Public License
|
|
|
13 |
// along with this program; if not, write to the Free Software
|
|
|
14 |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
15 |
// WINNT implementation written by Carl C. Longnecker, longneck@iname.com
|
|
|
16 |
// $Id: class.WINNT.inc.php,v 1.25 2007/03/07 20:21:27 bigmichi1 Exp $
|
|
|
17 |
|
|
|
18 |
class sysinfo {
|
|
|
19 |
// $wmi holds the COM object that we pull all the WMI data from
|
|
|
20 |
var $wmi;
|
|
|
21 |
|
|
|
22 |
// $wmidevices holds all devices, which are in the system
|
|
|
23 |
var $wmidevices;
|
|
|
24 |
|
|
|
25 |
// this constructor initialis the $wmi object
|
|
|
26 |
function sysinfo ()
|
|
|
27 |
{
|
|
|
28 |
// don't set this params for local connection, it will not work
|
|
|
29 |
$strHostname = '';
|
|
|
30 |
$strUser = '';
|
|
|
31 |
$strPassword = '';
|
|
|
32 |
|
|
|
33 |
// initialize the wmi object
|
|
|
34 |
$objLocator = new COM("WbemScripting.SWbemLocator");
|
|
|
35 |
if($strHostname == "") {
|
|
|
36 |
$this->wmi = $objLocator->ConnectServer();
|
|
|
37 |
} else{
|
|
|
38 |
$this->wmi = $objLocator->ConnectServer($strHostname, "rootcimv2", "$strHostname\$strUser", $strPassword);
|
|
|
39 |
}
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
// private function for getting a list of values in the specified context, optionally filter this list, based on the list from second parameter
|
|
|
43 |
function _GetWMI($strClass, $strValue = array() ) {
|
|
|
44 |
$objWEBM = $this->wmi->Get($strClass);
|
|
|
45 |
|
|
|
46 |
if( PHP_VERSION < 5 ) {
|
|
|
47 |
$objProp = $objWEBM->Properties_;
|
|
|
48 |
$arrProp = $objProp->Next($objProp->Count);
|
|
|
49 |
$objWEBMCol = $objWEBM->Instances_();
|
|
|
50 |
$arrWEBMCol = $objWEBMCol->Next($objWEBMCol->Count);
|
|
|
51 |
} else {
|
|
|
52 |
$arrProp = $objWEBM->Properties_;
|
|
|
53 |
$arrWEBMCol = $objWEBM->Instances_();
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
foreach($arrWEBMCol as $objItem)
|
|
|
57 |
{
|
|
|
58 |
@reset($arrProp);
|
|
|
59 |
$arrInstance = array();
|
|
|
60 |
foreach($arrProp as $propItem)
|
|
|
61 |
{
|
|
|
62 |
eval("\$value = \$objItem->" .$propItem->Name .";");
|
|
|
63 |
if( empty( $strValue ) ) {
|
|
|
64 |
$arrInstance[$propItem->Name] = trim($value);
|
|
|
65 |
} else {
|
|
|
66 |
if( in_array( $propItem->Name, $strValue ) ) {
|
|
|
67 |
$arrInstance[$propItem->Name] = trim($value);
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
$arrData[] = $arrInstance;
|
|
|
72 |
}
|
|
|
73 |
return $arrData;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
// private function for getting different device types from the system
|
|
|
77 |
function _devicelist ( $strType ) {
|
|
|
78 |
if( empty( $this->wmidevices ) ) {
|
|
|
79 |
$this->wmidevices = $this->_GetWMI( "Win32_PnPEntity", array( "Name", "PNPDeviceID" ) );
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
$list = array();
|
|
|
83 |
foreach ( $this->wmidevices as $device ) {
|
|
|
84 |
if ( substr( $device["PNPDeviceID"], 0, strpos( $device["PNPDeviceID"], "\\" ) + 1 ) == ( $strType . "\\" ) ) {
|
|
|
85 |
$list[] = $device["Name"];
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
return $list;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
// get our apache SERVER_NAME or vhost
|
|
|
93 |
function vhostname () {
|
|
|
94 |
if (! ($result = getenv('SERVER_NAME'))) {
|
|
|
95 |
$result = 'N.A.';
|
|
|
96 |
}
|
|
|
97 |
return $result;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
// get the IP address of our vhost name
|
|
|
101 |
function vip_addr () {
|
|
|
102 |
return gethostbyname($this->vhostname());
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
// get our canonical hostname
|
|
|
106 |
function chostname ()
|
|
|
107 |
{
|
|
|
108 |
$buffer = $this->_GetWMI( "Win32_ComputerSystem", array( "Name" ) );
|
|
|
109 |
$result = $buffer[0]["Name"];
|
|
|
110 |
return gethostbyaddr(gethostbyname($result));
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
// get the IP address of our canonical hostname
|
|
|
114 |
function ip_addr ()
|
|
|
115 |
{
|
|
|
116 |
$buffer = $this->_GetWMI( "Win32_ComputerSystem", array( "Name" ) );
|
|
|
117 |
$result = $buffer[0]["Name"];
|
|
|
118 |
return gethostbyname($result);
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
function kernel ()
|
|
|
122 |
{
|
|
|
123 |
$buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "Version", "ServicePackMajorVersion" ) );
|
|
|
124 |
$result = $buffer[0]["Version"];
|
|
|
125 |
if( $buffer[0]["ServicePackMajorVersion"] > 0 ) {
|
|
|
126 |
$result .= " SP" . $buffer[0]["ServicePackMajorVersion"];
|
|
|
127 |
}
|
|
|
128 |
return $result;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
// get the time the system is running
|
|
|
132 |
function uptime ()
|
|
|
133 |
{
|
|
|
134 |
$result = 0;
|
|
|
135 |
$buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "LastBootUpTime", "LocalDateTime" ) );
|
|
|
136 |
|
|
|
137 |
$byear = intval(substr($buffer[0]["LastBootUpTime"], 0, 4));
|
|
|
138 |
$bmonth = intval(substr($buffer[0]["LastBootUpTime"], 4, 2));
|
|
|
139 |
$bday = intval(substr($buffer[0]["LastBootUpTime"], 6, 2));
|
|
|
140 |
$bhour = intval(substr($buffer[0]["LastBootUpTime"], 8, 2));
|
|
|
141 |
$bminute = intval(substr($buffer[0]["LastBootUpTime"], 10, 2));
|
|
|
142 |
$bseconds = intval(substr($buffer[0]["LastBootUpTime"], 12, 2));
|
|
|
143 |
|
|
|
144 |
$lyear = intval(substr($buffer[0]["LocalDateTime"], 0, 4));
|
|
|
145 |
$lmonth = intval(substr($buffer[0]["LocalDateTime"], 4, 2));
|
|
|
146 |
$lday = intval(substr($buffer[0]["LocalDateTime"], 6, 2));
|
|
|
147 |
$lhour = intval(substr($buffer[0]["LocalDateTime"], 8, 2));
|
|
|
148 |
$lminute = intval(substr($buffer[0]["LocalDateTime"], 10, 2));
|
|
|
149 |
$lseconds = intval(substr($buffer[0]["LocalDateTime"], 12, 2));
|
|
|
150 |
|
|
|
151 |
$boottime = mktime($bhour, $bminute, $bseconds, $bmonth, $bday, $byear);
|
|
|
152 |
$localtime = mktime($lhour, $lminute, $lseconds, $lmonth, $lday, $lyear);
|
|
|
153 |
|
|
|
154 |
$result = $localtime - $boottime;
|
|
|
155 |
|
|
|
156 |
return $result;
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
// count the users, which are logged in
|
|
|
160 |
function users ()
|
|
|
161 |
{
|
|
|
162 |
if( stristr( $this->kernel(), "2000 P" ) ) return "N.A.";
|
|
|
163 |
$buffer = $this->_GetWMI( "Win32_PerfRawData_TermService_TerminalServices", array( "TotalSessions" ) );
|
|
|
164 |
return $buffer[0]["TotalSessions"];
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
// get the load of the processors
|
|
|
168 |
function loadavg ($bar = false)
|
|
|
169 |
{
|
|
|
170 |
$buffer = $this->_GetWMI( "Win32_Processor", array( "LoadPercentage" ) );
|
|
|
171 |
$cpuload = array();
|
|
|
172 |
for( $i = 0; $i < count( $buffer ); $i++ ) {
|
|
|
173 |
$cpuload['avg'][] = $buffer[$i]["LoadPercentage"];
|
|
|
174 |
}
|
|
|
175 |
if ($bar) {
|
|
|
176 |
$cpuload['cpupercent'] = array_sum( $cpuload['avg'] ) / count( $buffer );
|
|
|
177 |
}
|
|
|
178 |
return $cpuload;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
// get some informations about the cpu's
|
|
|
182 |
function cpu_info ()
|
|
|
183 |
{
|
|
|
184 |
$buffer = $this->_GetWMI( "Win32_Processor", array( "Name", "L2CacheSize", "CurrentClockSpeed", "ExtClock" ) );
|
|
|
185 |
$results["cpus"] = 0;
|
|
|
186 |
foreach ($buffer as $cpu) {
|
|
|
187 |
$results["cpus"]++;
|
|
|
188 |
$results["model"] = $cpu["Name"];
|
|
|
189 |
$results["cache"] = $cpu["L2CacheSize"];
|
|
|
190 |
$results["cpuspeed"] = $cpu["CurrentClockSpeed"];
|
|
|
191 |
$results["busspeed"] = $cpu["ExtClock"];
|
|
|
192 |
}
|
|
|
193 |
return $results;
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
// get the pci devices from the system
|
|
|
197 |
function pci ()
|
|
|
198 |
{
|
|
|
199 |
$pci = $this->_devicelist( "PCI" );
|
|
|
200 |
return $pci;
|
|
|
201 |
}
|
|
|
202 |
|
|
|
203 |
// get the ide devices from the system
|
|
|
204 |
function ide ()
|
|
|
205 |
{
|
|
|
206 |
$buffer = $this->_devicelist( "IDE" );
|
|
|
207 |
$ide = array();
|
|
|
208 |
foreach ( $buffer as $device ) {
|
|
|
209 |
$ide[]['model'] = $device;
|
|
|
210 |
}
|
|
|
211 |
return $ide;
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
// get the scsi devices from the system
|
|
|
215 |
function scsi ()
|
|
|
216 |
{
|
|
|
217 |
$scsi = $this->_devicelist( "SCSI" );
|
|
|
218 |
return $scsi;
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
// get the usb devices from the system
|
|
|
222 |
function usb ()
|
|
|
223 |
{
|
|
|
224 |
$usb = $this->_devicelist( "USB" );
|
|
|
225 |
return $usb;
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
// get the sbus devices from the system - currently not called
|
|
|
229 |
function sbus ()
|
|
|
230 |
{
|
|
|
231 |
$sbus = $this->_devicelist( "SBUS" );
|
|
|
232 |
return $sbus;
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
// get the netowrk devices and rx/tx bytes
|
|
|
236 |
function network () {
|
|
|
237 |
$results = array();
|
|
|
238 |
$buffer = $this->_GetWMI( "Win32_PerfRawData_Tcpip_NetworkInterface" );
|
|
|
239 |
foreach( $buffer as $device ) {
|
|
|
240 |
$dev_name = $device["Name"];
|
|
|
241 |
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_tcpip_networkinterface.asp
|
|
|
242 |
// there is a possible bug in the wmi interfaceabout uint32 and uint64: http://www.ureader.com/message/1244948.aspx, so that
|
|
|
243 |
// magative numbers would occour, try to calculate the nagative value from total - positive number
|
|
|
244 |
|
|
|
245 |
if( $device["BytesSentPersec"] < 0) {
|
|
|
246 |
$results[$dev_name]['tx_bytes'] = $device["BytesTotalPersec"] - $device["BytesReceivedPersec"];
|
|
|
247 |
} else {
|
|
|
248 |
$results[$dev_name]['tx_bytes'] = $device["BytesSentPersec"];
|
|
|
249 |
}
|
|
|
250 |
if( $device["BytesReceivedPersec"] < 0 ) {
|
|
|
251 |
$results[$dev_name]['rx_bytes'] = $device["BytesTotalPersec"] - $device["BytesSentPersec"];
|
|
|
252 |
} else {
|
|
|
253 |
$results[$dev_name]['rx_bytes'] = $device["BytesReceivedPersec"];
|
|
|
254 |
}
|
|
|
255 |
|
|
|
256 |
$results[$dev_name]['rx_packets'] = $device["PacketsReceivedPersec"];
|
|
|
257 |
$results[$dev_name]['tx_packets'] = $device["PacketsSentPersec"];
|
|
|
258 |
|
|
|
259 |
$results[$dev_name]['rx_errs'] = $device["PacketsReceivedErrors"];
|
|
|
260 |
$results[$dev_name]['rx_drop'] = $device["PacketsReceivedDiscarded"];
|
|
|
261 |
|
|
|
262 |
$results[$dev_name]['errs'] = $device["PacketsReceivedErrors"];
|
|
|
263 |
$results[$dev_name]['drop'] = $device["PacketsReceivedDiscarded"];
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
return $results;
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
function memory ()
|
|
|
270 |
{
|
|
|
271 |
$buffer = $this->_GetWMI( "Win32_LogicalMemoryConfiguration", array( "TotalPhysicalMemory" ) );
|
|
|
272 |
$results['ram']['total'] = $buffer[0]["TotalPhysicalMemory"];
|
|
|
273 |
|
|
|
274 |
$buffer = $this->_GetWMI( "Win32_PerfRawData_PerfOS_Memory", array( "AvailableKBytes" ) );
|
|
|
275 |
$results['ram']['free'] = $buffer[0]["AvailableKBytes"];
|
|
|
276 |
|
|
|
277 |
$results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
|
|
|
278 |
$results['ram']['percent'] = ceil( ( $results['ram']['used'] * 100 ) / $results['ram']['total'] );
|
|
|
279 |
$results['swap']['total'] = 0;
|
|
|
280 |
$results['swap']['used'] = 0;
|
|
|
281 |
$results['swap']['free'] = 0;
|
|
|
282 |
|
|
|
283 |
$buffer = $this->_GetWMI( "Win32_PageFileUsage" ); // no need to filter, using nearly everything from output
|
|
|
284 |
$k = 0;
|
|
|
285 |
foreach ($buffer as $swapdevice) {
|
|
|
286 |
$results['devswap'][$k]['dev'] = $swapdevice["Name"];
|
|
|
287 |
$results['devswap'][$k]['total'] = $swapdevice["AllocatedBaseSize"] * 1024;
|
|
|
288 |
$results['devswap'][$k]['used'] = $swapdevice["CurrentUsage"] * 1024;
|
|
|
289 |
$results['devswap'][$k]['free'] = ( $swapdevice["AllocatedBaseSize"] - $swapdevice["CurrentUsage"] ) * 1024;
|
|
|
290 |
$results['devswap'][$k]['percent'] = ceil( $swapdevice["CurrentUsage"] / $swapdevice["AllocatedBaseSize"] );
|
|
|
291 |
|
|
|
292 |
$results['swap']['total'] += $results['devswap'][$k]['total'];
|
|
|
293 |
$results['swap']['used'] += $results['devswap'][$k]['used'];
|
|
|
294 |
$results['swap']['free'] += $results['devswap'][$k]['free'];
|
|
|
295 |
$k += 1;
|
|
|
296 |
}
|
|
|
297 |
$results['swap']['percent'] = ceil( $results['swap']['used'] / $results['swap']['total'] * 100 );
|
|
|
298 |
return $results;
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
// get the filesystem informations
|
|
|
302 |
function filesystems ()
|
|
|
303 |
{
|
|
|
304 |
$typearray = array("Unknown", "No Root Directory", "Removeable Disk",
|
|
|
305 |
"Local Disk", "Network Drive", "Compact Disc", "RAM Disk");
|
|
|
306 |
$floppyarray = array("Unknown", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.",
|
|
|
307 |
"3 1/2 in.", "3 1/2 in.", "5 1/4 in.", "5 1/4 in.", "5 1/4 in.",
|
|
|
308 |
"5 1/4 in.", "5 1/4 in.", "Other", "HD", "3 1/2 in.", "3 1/2 in.",
|
|
|
309 |
"5 1/4 in.", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.", "5 1/4 in.",
|
|
|
310 |
"3 1/2 in.", "3 1/2 in.", "8 in.");
|
|
|
311 |
|
|
|
312 |
$buffer = $this->_GetWMI( "Win32_LogicalDisk" , array( "Name", "Size", "FreeSpace", "FileSystem", "DriveType", "MediaType" ) );
|
|
|
313 |
|
|
|
314 |
$k = 0;
|
|
|
315 |
foreach ( $buffer as $filesystem ) {
|
|
|
316 |
if ( hide_mount( $filesystem["Name"] ) ) {
|
|
|
317 |
continue;
|
|
|
318 |
}
|
|
|
319 |
$results[$k]['mount'] = $filesystem["Name"];
|
|
|
320 |
$results[$k]['size'] = $filesystem["Size"] / 1024;
|
|
|
321 |
$results[$k]['used'] = ( $filesystem["Size"] - $filesystem["FreeSpace"] ) / 1024;
|
|
|
322 |
$results[$k]['free'] = $filesystem["FreeSpace"] / 1024;
|
|
|
323 |
@$results[$k]['percent'] = ceil( $results[$k]['used'] / $results[$k]['size'] * 100 ); // silence this line, nobody is having a floppy in the drive everytime
|
|
|
324 |
$results[$k]['fstype'] = $filesystem["FileSystem"];
|
|
|
325 |
$results[$k]['disk'] = $typearray[$filesystem["DriveType"]];
|
|
|
326 |
if ( $filesystem["MediaType"] != "" && $filesystem["DriveType"] == 2 ) $results[$k]['disk'] .= " (" . $floppyarray[$filesystem["MediaType"]] . ")";
|
|
|
327 |
$k += 1;
|
|
|
328 |
}
|
|
|
329 |
return $results;
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
function distro ()
|
|
|
333 |
{
|
|
|
334 |
$buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "Caption" ) );
|
|
|
335 |
return $buffer[0]["Caption"];
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
function distroicon ()
|
|
|
339 |
{
|
|
|
340 |
return 'xp.gif';
|
|
|
341 |
}
|
|
|
342 |
}
|
|
|
343 |
|
|
|
344 |
?>
|