[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
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 21228 2006-04-06 13:52:08Z ralfbecker $ 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 $arrInstance = array(); 59 foreach($arrProp as $propItem) 60 { 61 eval("\$value = \$objItem->" .$propItem->Name .";"); 62 if( empty( $strValue ) ) { 63 $arrInstance[$propItem->Name] = trim($value); 64 } else { 65 if( in_array( $propItem->Name, $strValue ) ) { 66 $arrInstance[$propItem->Name] = trim($value); 67 } 68 } 69 } 70 $arrData[] = $arrInstance; 71 } 72 return $arrData; 73 } 74 75 // private function for getting different device types from the system 76 function _devicelist ( $strType ) { 77 if( empty( $this->wmidevices ) ) { 78 $this->wmidevices = $this->_GetWMI( "Win32_PnPEntity", array( "Name", "PNPDeviceID" ) ); 79 } 80 81 $list = array(); 82 foreach ( $this->wmidevices as $device ) { 83 if ( substr( $device["PNPDeviceID"], 0, strpos( $device["PNPDeviceID"], "\\" ) + 1 ) == ( $strType . "\\" ) ) { 84 $list[] = $device["Name"]; 85 } 86 } 87 88 return $list; 89 } 90 91 // get our canonical hostname 92 function chostname () 93 { 94 $buffer = $this->_GetWMI( "Win32_ComputerSystem", array( "Name" ) ); 95 $result = $buffer[0]["Name"]; 96 return gethostbyaddr(gethostbyname($result)); 97 } 98 99 // get the IP address of our canonical hostname 100 function ip_addr () 101 { 102 $buffer = $this->_GetWMI( "Win32_ComputerSystem", array( "Name" ) ); 103 $result = $buffer[0]["Name"]; 104 return gethostbyname($result); 105 } 106 107 function kernel () 108 { 109 $buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "Version", "ServicePackMajorVersion" ) ); 110 $result = $buffer[0]["Version"]; 111 if( $buffer[0]["ServicePackMajorVersion"] > 0 ) { 112 $result .= " SP" . $buffer[0]["ServicePackMajorVersion"]; 113 } 114 return $result; 115 } 116 117 // get the time the system is running 118 function uptime () 119 { 120 $result = 0; 121 $buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "LastBootUpTime" ) ); 122 123 $year = intval(substr($buffer[0]["LastBootUpTime"], 0, 4)); 124 $month = intval(substr($buffer[0]["LastBootUpTime"], 4, 2)); 125 $day = intval(substr($buffer[0]["LastBootUpTime"], 6, 2)); 126 $hour = intval(substr($buffer[0]["LastBootUpTime"], 8, 2)); 127 $minute = intval(substr($buffer[0]["LastBootUpTime"], 10, 2)); 128 $seconds = intval(substr($buffer[0]["LastBootUpTime"], 12, 2)); 129 130 $hour -= date("Z") / 60 / 60; // GMT-Offset 131 132 $boottime = mktime($hour, $minute, $seconds, $month, $day, $year); 133 134 $result = mktime() - $boottime; 135 136 return $result; 137 } 138 139 // count the users, which are logged in 140 function users () 141 { 142 if( !stristr( $this->_GetWMI( "Win32_OperatingSystem", array( "Version" ) ), "2000 P" ) ) return "N.A."; 143 $buffer = $this->_GetWMI( "Win32_PerfRawData_TermService_TerminalServices", array( "TotalSessions" ) ); 144 return $buffer[0]["TotalSessions"]; 145 } 146 147 // get the load of the processors 148 function loadavg ($bar = false) 149 { 150 $buffer = $this->_GetWMI( "Win32_Processor", array( "LoadPercentage" ) ); 151 $cpuload = array(); 152 for( $i = 0; $i < count( $buffer ); $i++ ) { 153 $cpuload['avg'][] = $buffer[$i]["LoadPercentage"]; 154 } 155 if ($bar) { 156 $cpuload['cpupercent'] = array_sum( $cpuload['avg'] ) / count( $buffer ); 157 } 158 return $cpuload; 159 } 160 161 // get some informations about the cpu's 162 function cpu_info () 163 { 164 $buffer = $this->_GetWMI( "Win32_Processor", array( "Name", "L2CacheSize", "CurrentClockSpeed", "ExtClock" ) ); 165 $results["cpus"] = 0; 166 foreach ($buffer as $cpu) { 167 $results["cpus"]++; 168 $results["model"] = $cpu["Name"]; 169 $results["cache"] = $cpu["L2CacheSize"]; 170 $results["cpuspeed"] = $cpu["CurrentClockSpeed"]; 171 $results["busspeed"] = $cpu["ExtClock"]; 172 } 173 return $results; 174 } 175 176 // get the pci devices from the system 177 function pci () 178 { 179 $pci = $this->_devicelist( "PCI" ); 180 return $pci; 181 } 182 183 // get the ide devices from the system 184 function ide () 185 { 186 $buffer = $this->_devicelist( "IDE" ); 187 $ide = array(); 188 foreach ( $buffer as $device ) { 189 $ide[]['model'] = $device; 190 } 191 return $ide; 192 } 193 194 // get the scsi devices from the system 195 function scsi () 196 { 197 $scsi = $this->_devicelist( "SCSI" ); 198 return $scsi; 199 } 200 201 // get the usb devices from the system 202 function usb () 203 { 204 $usb = $this->_devicelist( "USB" ); 205 return $usb; 206 } 207 208 // get the sbus devices from the system - currently not called 209 function sbus () 210 { 211 $sbus = $this->_devicelist( "SBUS" ); 212 return $sbus; 213 } 214 215 // get the netowrk devices and rx/tx bytes 216 function network () 217 { 218 $buffer = $this->_GetWMI( "Win32_PerfRawData_Tcpip_NetworkInterface" ); 219 $results = array(); 220 foreach ( $buffer as $device ) { 221 $dev_name = $device["Name"]; 222 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_tcpip_networkinterface.asp 223 $results[$dev_name]['rx_bytes'] = $device["BytesReceivedPersec"]; 224 $results[$dev_name]['rx_packets'] = $device["PacketsReceivedPersec"]; 225 $results[$dev_name]['rx_errs'] = $device["PacketsReceivedErrors"]; 226 $results[$dev_name]['rx_drop'] = $device["PacketsReceivedDiscarded"]; 227 228 $results[$dev_name]['tx_bytes'] = $device["BytesSentPersec"]; 229 $results[$dev_name]['tx_packets'] = $device["PacketsSentPersec"]; 230 231 $results[$dev_name]['errs'] = $device["PacketsReceivedErrors"]; 232 $results[$dev_name]['drop'] = $device["PacketsReceivedDiscarded"]; 233 } 234 return $results; 235 } 236 237 function memory () 238 { 239 $buffer = $this->_GetWMI( "Win32_LogicalMemoryConfiguration", array( "TotalPhysicalMemory" ) ); 240 $results['ram']['total'] = $buffer[0]["TotalPhysicalMemory"]; 241 242 $buffer = $this->_GetWMI( "Win32_PerfRawData_PerfOS_Memory", array( "AvailableKBytes" ) ); 243 $results['ram']['free'] = $buffer[0]["AvailableKBytes"]; 244 245 $results['ram']['used'] = $results['ram']['total'] - $results['ram']['free']; 246 $results['ram']['t_used'] = $results['ram']['used']; 247 $results['ram']['t_free'] = $results['ram']['total'] - $results['ram']['t_used']; 248 $results['ram']['percent'] = ceil( ( $results['ram']['t_used'] * 100 ) / $results['ram']['total'] ); 249 $results['swap']['total'] = 0; 250 $results['swap']['used'] = 0; 251 $results['swap']['free'] = 0; 252 253 $buffer = $this->_GetWMI( "Win32_PageFileUsage" ); // no need to filter, using nearly everything from output 254 $k = 0; 255 foreach ($buffer as $swapdevice) { 256 $results['devswap'][$k]['dev'] = $swapdevice["Name"]; 257 $results['devswap'][$k]['total'] = $swapdevice["AllocatedBaseSize"] * 1024; 258 $results['devswap'][$k]['used'] = $swapdevice["CurrentUsage"] * 1024; 259 $results['devswap'][$k]['free'] = ( $swapdevice["AllocatedBaseSize"] - $swapdevice["CurrentUsage"] ) * 1024; 260 $results['devswap'][$k]['percent'] = ceil( $swapdevice["CurrentUsage"] / $swapdevice["AllocatedBaseSize"] ); 261 262 $results['swap']['total'] += $results['devswap'][$k]['total']; 263 $results['swap']['used'] += $results['devswap'][$k]['used']; 264 $results['swap']['free'] += $results['devswap'][$k]['free']; 265 $k += 1; 266 } 267 $results['swap']['percent'] = ceil( $results['swap']['used'] / $results['swap']['total'] * 100 ); 268 return $results; 269 } 270 271 // get the filesystem informations 272 function filesystems () 273 { 274 $typearray = array("Unknown", "No Root Directory", "Removeable Disk", 275 "Local Disk", "Network Drive", "Compact Disc", "RAM Disk"); 276 $floppyarray = array("Unknown", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.", 277 "3 1/2 in.", "3 1/2 in.", "5 1/4 in.", "5 1/4 in.", "5 1/4 in.", 278 "5 1/4 in.", "5 1/4 in.", "Other", "HD", "3 1/2 in.", "3 1/2 in.", 279 "5 1/4 in.", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.", "5 1/4 in.", 280 "3 1/2 in.", "3 1/2 in.", "8 in."); 281 282 $buffer = $this->_GetWMI( "Win32_LogicalDisk" , array( "Name", "Size", "FreeSpace", "FileSystem", "DriveType", "MediaType" ) ); 283 284 $k = 0; 285 foreach ( $buffer as $filesystem ) { 286 if ( hide_mount( $filesystem["Name"] ) ) { 287 continue; 288 } 289 $results[$k]['mount'] = $filesystem["Name"]; 290 $results[$k]['size'] = $filesystem["Size"] / 1024; 291 $results[$k]['used'] = ( $filesystem["Size"] - $filesystem["FreeSpace"] ) / 1024; 292 $results[$k]['free'] = $filesystem["FreeSpace"] / 1024; 293 @$results[$k]['percent'] = ceil( $results[$k]['used'] / $results[$k]['size'] * 100 ); // silence this line, nobody is having a floppy in the drive everytime 294 $results[$k]['fstype'] = $filesystem["FileSystem"]; 295 $results[$k]['disk'] = $typearray[$filesystem["DriveType"]]; 296 if ( $filesystem["DriveType"] == 2 ) $results[$k]['disk'] .= " (" . $floppyarray[$filesystem["MediaType"]] . ")"; 297 $k += 1; 298 } 299 return $results; 300 } 301 302 function distro () 303 { 304 $buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "Caption" ) ); 305 return $buffer[0]["Caption"]; 306 } 307 308 function distroicon () 309 { 310 return 'xp.gif'; 311 } 312 } 313 314 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |