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