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
// phpSysInfo - A PHP System Information Script
2
/**
3
// http://phpsysinfo.sourceforge.net/
3
 * WINNT System Class
4
// This program is free software; you can redistribute it and/or
4
 *
5
// modify it under the terms of the GNU General Public License
5
 * PHP version 5
6
// as published by the Free Software Foundation; either version 2
6
 *
7
// of the License, or (at your option) any later version.
7
 * @category  PHP
8
// This program is distributed in the hope that it will be useful,
8
 * @package   PSI WINNT OS class
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * @copyright 2009 phpSysInfo
11
// GNU General Public License for more details.
11
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
12
// You should have received a copy of the GNU General Public License
12
 * @version   SVN: $Id: class.WINNT.inc.php 699 2012-09-15 11:57:13Z namiltd $
13
// along with this program; if not, write to the Free Software
13
 * @link      http://phpsysinfo.sourceforge.net
14
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
14
 */
15
// WINNT implementation written by Carl C. Longnecker, longneck@iname.com
15
 /**
16
// $Id: class.WINNT.inc.php,v 1.25 2007/03/07 20:21:27 bigmichi1 Exp $
16
 * WINNT sysinfo class
17
 
17
 * get all the required information from WINNT systems
18
class sysinfo {
18
 * information are retrieved through the WMI interface
19
  // $wmi holds the COM object that we pull all the WMI data from
19
 *
20
  var $wmi; 
20
 * @category  PHP
21
 
21
 * @package   PSI WINNT OS class
22
  // $wmidevices holds all devices, which are in the system
22
 * @author    Michael Cramer <BigMichi1@users.sourceforge.net>
23
  var $wmidevices;
23
 * @copyright 2009 phpSysInfo
24
 
24
 * @license   http://opensource.org/licenses/gpl-2.0.php GNU General Public License version 2, or (at your option) any later version
25
  // this constructor initialis the $wmi object
25
 * @version   Release: 3.0
26
  function sysinfo ()
26
 * @link      http://phpsysinfo.sourceforge.net
27
  {
27
 */
28
    // don't set this params for local connection, it will not work
28
class WINNT extends OS
29
    $strHostname = '';
29
{
30
    $strUser = '';
30
    /**
31
    $strPassword = '';
31
     * holds the data from WMI Win32_OperatingSystem
32
 
32
     *
33
    // initialize the wmi object
33
     * @var array
34
    $objLocator = new COM("WbemScripting.SWbemLocator");
34
     */
35
    if($strHostname == "") {
35
    private $_Win32_OperatingSystem = null;
36
        $this->wmi = $objLocator->ConnectServer();
36
 
37
      } else{
37
    /**
38
        $this->wmi = $objLocator->ConnectServer($strHostname, "rootcimv2", "$strHostname\$strUser", $strPassword);
38
     * holds the data from WMI Win32_ComputerSystem
39
      }
39
     *
40
  } 
40
     * @var array
41
 
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
42
    private $_Win32_ComputerSystem = null;
43
  function _GetWMI($strClass, $strValue = array() ) {
43
 
44
    $objWEBM = $this->wmi->Get($strClass);
44
    /**
45
 
45
     * holds the data from WMI Win32_Processor
46
    if( PHP_VERSION < 5 ) {
46
     *
47
      $objProp = $objWEBM->Properties_;
47
     * @var array
48
      $arrProp = $objProp->Next($objProp->Count);
48
     */
49
      $objWEBMCol = $objWEBM->Instances_();
49
    private $_Win32_Processor = null;
50
      $arrWEBMCol = $objWEBMCol->Next($objWEBMCol->Count);
50
 
51
    } else {
51
     /**
52
      $arrProp = $objWEBM->Properties_;
52
     * holds the data from WMI Win32_PerfFormattedData_PerfOS_Processor
53
      $arrWEBMCol = $objWEBM->Instances_();
53
     *
54
    }
54
     * @var array
55
 
55
     */
56
    foreach($arrWEBMCol as $objItem)
56
    private $_Win32_PerfFormattedData_PerfOS_Processor = null;
57
    {
57
 
58
        @reset($arrProp);
58
    /**
59
        $arrInstance = array();
59
     * holds the data from systeminfo command
60
        foreach($arrProp as $propItem)
60
     *
61
        {
61
     * @var string
62
            eval("\$value = \$objItem->" .$propItem->Name .";");
62
     */
63
            if( empty( $strValue ) ) {
63
    private $_systeminfo = null;
64
              $arrInstance[$propItem->Name] = trim($value);
64
 
-
 
65
    /**
-
 
66
     * holds the COM object that we pull all the WMI data from
-
 
67
     *
-
 
68
     * @var Object
-
 
69
     */
-
 
70
    private $_wmi = null;
-
 
71
 
-
 
72
    /**
-
 
73
     * holds the COM object that we pull all the RegRead data from
-
 
74
     *
-
 
75
     * @var Object
-
 
76
     */
-
 
77
    private $_reg = null;
-
 
78
 
-
 
79
    /**
-
 
80
     * holds the COM object that we pull all the EnumKey data from
-
 
81
     *
-
 
82
     * @var Object
-
 
83
     */
-
 
84
    private $_key = null;
-
 
85
 
-
 
86
    /**
-
 
87
     * holds all devices, which are in the system
-
 
88
     *
-
 
89
     * @var array
-
 
90
     */
-
 
91
    private $_wmidevices;
-
 
92
 
-
 
93
    /**
-
 
94
     * holds all disks, which are in the system
-
 
95
     *
-
 
96
     * @var array
-
 
97
     */
-
 
98
    private $_wmidisks;
-
 
99
 
-
 
100
    /**
-
 
101
     * store language encoding of the system to convert some output to utf-8
-
 
102
     *
-
 
103
     * @var string
-
 
104
     */
-
 
105
    private $_codepage = null;
-
 
106
 
-
 
107
    /**
-
 
108
     * store language of the system
-
 
109
     *
-
 
110
     * @var string
-
 
111
     */
-
 
112
    private $_syslang = null;
-
 
113
 
-
 
114
    /**
-
 
115
     * reads the data from WMI Win32_OperatingSystem
-
 
116
     *
-
 
117
     * @return array
-
 
118
     */
-
 
119
    private function _get_Win32_OperatingSystem()
-
 
120
    {
-
 
121
        if ($this->_Win32_OperatingSystem === null) $this->_Win32_OperatingSystem = CommonFunctions::getWMI($this->_wmi, 'Win32_OperatingSystem', array('CodeSet', 'Locale', 'LastBootUpTime', 'LocalDateTime', 'Version', 'ServicePackMajorVersion', 'Caption', 'OSArchitecture', 'TotalVisibleMemorySize', 'FreePhysicalMemory'));
-
 
122
        return $this->_Win32_OperatingSystem;
-
 
123
    }
-
 
124
 
-
 
125
    /**
-
 
126
     * reads the data from WMI Win32_ComputerSystem
-
 
127
     *
-
 
128
     * @return array
-
 
129
     */
-
 
130
    private function _get_Win32_ComputerSystem()
-
 
131
    {
-
 
132
        if ($this->_Win32_ComputerSystem === null) $this->_Win32_ComputerSystem = CommonFunctions::getWMI($this->_wmi, 'Win32_ComputerSystem', array('Name', 'Manufacturer', 'Model'));
-
 
133
        return $this->_Win32_ComputerSystem;
-
 
134
    }
-
 
135
 
-
 
136
    /**
-
 
137
     * reads the data from WMI Win32_Processor
-
 
138
     *
-
 
139
     * @return array
-
 
140
     */
-
 
141
    private function _get_Win32_Processor()
-
 
142
    {
-
 
143
        if ($this->_Win32_Processor === null) $this->_Win32_Processor = CommonFunctions::getWMI($this->_wmi, 'Win32_Processor', array('LoadPercentage', 'AddressWidth', 'Name', 'L2CacheSize', 'L3CacheSize', 'CurrentClockSpeed', 'ExtClock', 'NumberOfCores', 'NumberOfLogicalProcessors', 'MaxClockSpeed', 'Manufacturer'));
-
 
144
        return $this->_Win32_Processor;
-
 
145
    }
-
 
146
 
-
 
147
    /**
-
 
148
     * reads the data from WMI Win32_PerfFormattedData_PerfOS_Processor
-
 
149
     *
-
 
150
     * @return array
-
 
151
     */
-
 
152
    private function _get_Win32_PerfFormattedData_PerfOS_Processor()
-
 
153
    {
-
 
154
        if ($this->_Win32_PerfFormattedData_PerfOS_Processor === null) {
-
 
155
            $this->_Win32_PerfFormattedData_PerfOS_Processor = array();
-
 
156
            $buffer = $this->_get_Win32_OperatingSystem();
-
 
157
            if ($buffer && isset($buffer[0]) && isset($buffer[0]['Version']) && version_compare($buffer[0]['Version'], "5.1", ">=")) { // minimal windows 2003 or windows XP
-
 
158
                $cpubuffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfFormattedData_PerfOS_Processor', array('Name', 'PercentProcessorTime'));
-
 
159
                if ($cpubuffer) foreach ($cpubuffer as $cpu) {
-
 
160
                    if (isset($cpu['Name']) && isset($cpu['PercentProcessorTime'])) {
-
 
161
                        $this->_Win32_PerfFormattedData_PerfOS_Processor['cpu'.$cpu['Name']] = $cpu['PercentProcessorTime'];
-
 
162
                    }
-
 
163
                }
-
 
164
            }
-
 
165
        }
-
 
166
 
-
 
167
        return $this->_Win32_PerfFormattedData_PerfOS_Processor;
-
 
168
    }
-
 
169
 
-
 
170
    /**
-
 
171
     * reads the data from systeminfo
-
 
172
     *
-
 
173
     * @return string
-
 
174
     */
-
 
175
    private function _get_systeminfo()
-
 
176
    {
-
 
177
        if ($this->_systeminfo === null) CommonFunctions::executeProgram('systeminfo', '', $this->_systeminfo, false);
-
 
178
        return $this->_systeminfo;
-
 
179
    }
-
 
180
 
-
 
181
    /**
-
 
182
     * build the global Error object and create the WMI connection
-
 
183
     */
-
 
184
    public function __construct($blockname = false)
-
 
185
    {
-
 
186
        parent::__construct($blockname);
-
 
187
        try {
-
 
188
            // initialize the wmi object
-
 
189
            $objLocator = new COM('WbemScripting.SWbemLocator');
-
 
190
            $this->_wmi = $objLocator->ConnectServer('', 'root\CIMv2');
-
 
191
        } catch (Exception $e) {
-
 
192
            $this->error->addError("WMI connect error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
-
 
193
        }
-
 
194
        try {
-
 
195
            // initialize the RegRead object
-
 
196
            $this->_reg = new COM("WScript.Shell");
-
 
197
        } catch (Exception $e) {
-
 
198
            //$this->error->addError("Windows Scripting Host error", "PhpSysInfo can not initialize Windows Scripting Host for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
-
 
199
            $this->_reg = false;
-
 
200
        }
-
 
201
        try {
-
 
202
            // initialize the EnumKey object
-
 
203
            $this->_key = new COM("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\default:StdRegProv");
-
 
204
        } catch (Exception $e) {
-
 
205
            //$this->error->addError("WWinmgmts Impersonationlevel Script Error", "PhpSysInfo can not initialize Winmgmts Impersonationlevel Script for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed.");
-
 
206
            $this->_key = false;
-
 
207
        }
-
 
208
 
-
 
209
        $this->_getCodeSet();
-
 
210
    }
-
 
211
 
-
 
212
    /**
-
 
213
     * store the codepage of the os for converting some strings to utf-8
-
 
214
     *
-
 
215
     * @return void
-
 
216
     */
-
 
217
    private function _getCodeSet()
-
 
218
    {
-
 
219
        $buffer = $this->_get_Win32_OperatingSystem();
-
 
220
        if (!$buffer) {
-
 
221
            if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage\\ACP", $strBuf, false)) {
-
 
222
                $buffer[0]['CodeSet'] = $strBuf;
-
 
223
            }
-
 
224
            if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Nls\\Language\\Default", $strBuf, false)) {
-
 
225
                $buffer[0]['Locale'] = $strBuf;
-
 
226
            }
-
 
227
        }
-
 
228
        if ($buffer && isset($buffer[0])) {
-
 
229
            if (isset($buffer[0]['CodeSet'])) {
-
 
230
                $codeset = $buffer[0]['CodeSet'];
-
 
231
                if ($codeset == 932) {
-
 
232
                    $codename = ' (SJIS)';
-
 
233
                } elseif ($codeset == 949) {
-
 
234
                    $codename = ' (EUC-KR)';
-
 
235
                } elseif ($codeset == 950) {
-
 
236
                    $codename = ' (BIG-5)';
-
 
237
                } else {
-
 
238
                    $codename = '';
-
 
239
                }
-
 
240
                CommonFunctions::setcp($codeset);
-
 
241
                $this->_codepage = 'windows-'.$codeset.$codename;
-
 
242
            }
-
 
243
            if (isset($buffer[0]['Locale']) && (($locale = hexdec($buffer[0]['Locale']))>0)) {
-
 
244
                $lang = "";
-
 
245
                if (is_readable(PSI_APP_ROOT.'/data/languages.ini') && ($langdata = @parse_ini_file(PSI_APP_ROOT.'/data/languages.ini', true))) {
-
 
246
                    if (isset($langdata['WINNT'][$locale])) {
-
 
247
                        $lang = $langdata['WINNT'][$locale];
-
 
248
                    }
-
 
249
                }
-
 
250
                if ($lang == "") {
-
 
251
                    $lang = 'Unknown';
-
 
252
                }
-
 
253
                $this->_syslang = $lang.' ('.$locale.')';
-
 
254
            }
-
 
255
        }
-
 
256
    }
-
 
257
 
-
 
258
    /**
-
 
259
     * retrieve different device types from the system based on selector
-
 
260
     *
-
 
261
     * @param string $strType type of the devices that should be returned
-
 
262
     *
-
 
263
     * @return array list of devices of the specified type
-
 
264
     */
-
 
265
    private function _devicelist($strType)
-
 
266
    {
-
 
267
        if (empty($this->_wmidevices)) {
-
 
268
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
-
 
269
                $this->_wmidevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PnPEntity', array('Name', 'PNPDeviceID', 'Manufacturer', 'PNPClass'));
-
 
270
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
-
 
271
                    $this->_wmidisks = CommonFunctions::getWMI($this->_wmi, 'Win32_DiskDrive', array('PNPDeviceID', 'Size', 'SerialNumber'));
-
 
272
                } else {
-
 
273
                    $this->_wmidisks = CommonFunctions::getWMI($this->_wmi, 'Win32_DiskDrive', array('PNPDeviceID', 'Size'));
-
 
274
                }
-
 
275
            } else {
-
 
276
                $this->_wmidevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PnPEntity', array('Name', 'PNPDeviceID'));
-
 
277
                $this->_wmidisks = array();
-
 
278
            }
-
 
279
        }
-
 
280
        $list = array();
-
 
281
        foreach ($this->_wmidevices as $device) {
-
 
282
            if (substr($device['PNPDeviceID'], 0, strpos($device['PNPDeviceID'], "\\") + 1) == ($strType."\\")) {
-
 
283
                if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
-
 
284
                    if (!isset($device['PNPClass']) || ($device['PNPClass']===$strType) || ($device['PNPClass']==='System')) {
-
 
285
                        $device['PNPClass'] = null;
-
 
286
                    }
-
 
287
                    if (preg_match('/^\(.*\)$/', $device['Manufacturer'])) {
-
 
288
                        $device['Manufacturer'] = null;
-
 
289
                    }
-
 
290
                    $device['Capacity'] = null;
-
 
291
                    if (($strType==='IDE')||($strType==='SCSI')) {
-
 
292
                        foreach ($this->_wmidisks as $disk) {
-
 
293
                            if (($disk['PNPDeviceID'] === $device['PNPDeviceID']) && isset($disk['Size'])) {
-
 
294
                                $device['Capacity'] = $disk['Size'];
-
 
295
                                break;
-
 
296
                            }
-
 
297
                        }
-
 
298
                    }
-
 
299
                    $device['Serial'] = null;
-
 
300
                    if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
-
 
301
                        if ($strType==='USB') {
-
 
302
                            if (preg_match('/\\\\(\w+)$/', $device['PNPDeviceID'], $buf)) {
-
 
303
                                $device['Serial'] = $buf[1];
-
 
304
                            }
-
 
305
                        } elseif (($strType==='IDE')||($strType==='SCSI')) {
-
 
306
                            foreach ($this->_wmidisks as $disk) {
-
 
307
                                if (($disk['PNPDeviceID'] === $device['PNPDeviceID']) && isset($disk['SerialNumber'])) {
-
 
308
                                    $device['Serial'] = $disk['SerialNumber'];
-
 
309
                                    break;
-
 
310
                                }
-
 
311
                            }
-
 
312
                        }
-
 
313
                    }
-
 
314
                    $list[] = array('Name'=>$device['Name'], 'Manufacturer'=>$device['Manufacturer'], 'Product'=>$device['PNPClass'], 'Capacity'=>$device['Capacity'], 'Serial'=>$device['Serial']);
-
 
315
                } else {
-
 
316
                    $list[] = array('Name'=>$device['Name']);
-
 
317
                }
-
 
318
            }
-
 
319
        }
-
 
320
 
-
 
321
        return $list;
-
 
322
    }
-
 
323
 
-
 
324
    /**
-
 
325
     * Host Name
-
 
326
     *
-
 
327
     * @return void
-
 
328
     */
-
 
329
    private function _hostname()
-
 
330
    {
-
 
331
        if (PSI_USE_VHOST === true) {
-
 
332
            if (CommonFunctions::readenv('SERVER_NAME', $hnm)) $this->sys->setHostname($hnm);
-
 
333
        } else {
-
 
334
            $buffer = $this->_get_Win32_ComputerSystem();
-
 
335
            if (!$buffer && CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName\\ComputerName", $strBuf, false) && (strlen($strBuf) > 0)) {
-
 
336
                    $buffer[0]['Name'] = $strBuf;
-
 
337
            }
-
 
338
            if ($buffer) {
-
 
339
                $result = $buffer[0]['Name'];
-
 
340
                $ip = gethostbyname($result);
-
 
341
                if ($ip != $result) {
-
 
342
                    if ((version_compare("10.0.0.0", $ip, "<=") && version_compare($ip, "10.255.255.255", "<=")) ||
-
 
343
                        (version_compare("172.16.0.0", $ip, "<=") && version_compare($ip, "172.31.255.255", "<=")) ||
-
 
344
                        (version_compare("192.168.0.0", $ip, "<=") && version_compare($ip, "192.168.255.255", "<=")) ||
-
 
345
                        (version_compare("127.0.0.0", $ip, "<=") && version_compare($ip, "127.255.255.255", "<=")) ||
-
 
346
                        (version_compare("169.254.1.0", $ip, "<=") && version_compare($ip, "169.254.254.255", "<=")) ||
-
 
347
                        (version_compare("255.255.255.255", $ip, "=="))) {
-
 
348
                        $this->sys->setHostname($result); // internal ip
-
 
349
                    } else {
-
 
350
                        $this->sys->setHostname(gethostbyaddr($ip));
-
 
351
                    }
-
 
352
                }
-
 
353
            } else {
-
 
354
                if (CommonFunctions::readenv('COMPUTERNAME', $hnm)) $this->sys->setHostname($hnm);
-
 
355
            }
-
 
356
        }
-
 
357
    }
-
 
358
 
-
 
359
    /**
-
 
360
     * UpTime
-
 
361
     * time the system is running
-
 
362
     *
-
 
363
     * @return void
-
 
364
     */
-
 
365
    private function _uptime()
-
 
366
    {
-
 
367
        $result = 0;
-
 
368
        date_default_timezone_set('UTC');
-
 
369
        $buffer = $this->_get_Win32_OperatingSystem();
-
 
370
        if ($buffer && ($buffer[0]['LastBootUpTime'] !== null)) {
-
 
371
            $local = $buffer[0]['LocalDateTime'];
-
 
372
            $boot = $buffer[0]['LastBootUpTime'];
-
 
373
 
-
 
374
            $lyear = intval(substr($local, 0, 4));
-
 
375
            $lmonth = intval(substr($local, 4, 2));
-
 
376
            $lday = intval(substr($local, 6, 2));
-
 
377
            $lhour = intval(substr($local, 8, 2));
-
 
378
            $lminute = intval(substr($local, 10, 2));
-
 
379
            $lseconds = intval(substr($local, 12, 2));
-
 
380
            $loffset = intval(substr($boot, 21, 4));
-
 
381
 
-
 
382
            $byear = intval(substr($boot, 0, 4));
-
 
383
            $bmonth = intval(substr($boot, 4, 2));
-
 
384
            $bday = intval(substr($boot, 6, 2));
-
 
385
            $bhour = intval(substr($boot, 8, 2));
-
 
386
            $bminute = intval(substr($boot, 10, 2));
-
 
387
            $bseconds = intval(substr($boot, 12, 2));
-
 
388
            $boffset = intval(substr($boot, 21, 4));
-
 
389
 
-
 
390
            if (version_compare($buffer[0]['Version'], "5.1", "<")) { // fix LastBootUpTime on Windows 2000 and older
-
 
391
                $boffset += $boffset;
-
 
392
            }
-
 
393
 
-
 
394
            $localtime = mktime($lhour, $lminute, $lseconds, $lmonth, $lday, $lyear) - $loffset*60;
-
 
395
            $boottime = mktime($bhour, $bminute, $bseconds, $bmonth, $bday, $byear) - $boffset*60;
-
 
396
 
-
 
397
            $result = $localtime - $boottime;
-
 
398
 
-
 
399
            $this->sys->setUptime($result);
-
 
400
        } elseif (($this->sys->getDistribution()=="ReactOS") && CommonFunctions::executeProgram('uptime', '', $strBuf, false) && (strlen($strBuf) > 0) && preg_match("/^System Up Time:\s+(\d+) days, (\d+) Hours, (\d+) Minutes, (\d+) Seconds/", $strBuf, $ar_buf)) {
-
 
401
            $sec = $ar_buf[4];
-
 
402
            $min = $ar_buf[3];
-
 
403
            $hours = $ar_buf[2];
-
 
404
            $days = $ar_buf[1];
-
 
405
            $this->sys->setUptime($days * 86400 + $hours * 3600 + $min * 60 + $sec);
-
 
406
        }
-
 
407
    }
-
 
408
 
-
 
409
    /**
-
 
410
     * Number of Users
-
 
411
     *
-
 
412
     * @return void
-
 
413
     */
-
 
414
    protected function _users()
-
 
415
    {
-
 
416
        if (CommonFunctions::executeProgram('quser', '', $strBuf, false) && (strlen($strBuf) > 0)) {
-
 
417
                $lines = preg_split('/\n/', $strBuf);
-
 
418
                $users = count($lines)-1;
-
 
419
        } else {
-
 
420
            $users = 0;
-
 
421
            $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Process', array('Caption'));
-
 
422
            foreach ($buffer as $process) {
-
 
423
                if (strtoupper($process['Caption']) == strtoupper('explorer.exe')) {
-
 
424
                    $users++;
-
 
425
                }
-
 
426
            }
-
 
427
        }
-
 
428
        $this->sys->setUsers($users);
-
 
429
    }
-
 
430
 
-
 
431
    /**
-
 
432
     * Distribution
-
 
433
     *
-
 
434
     * @return void
-
 
435
     */
-
 
436
    private function _distro()
-
 
437
    {
-
 
438
        $buffer = $this->_get_Win32_OperatingSystem();
-
 
439
        if ($buffer) {
-
 
440
            $ver = $buffer[0]['Version'];
-
 
441
            $kernel = $ver;
-
 
442
            if ($buffer[0]['ServicePackMajorVersion'] > 0) {
-
 
443
                $kernel .= ' SP'.$buffer[0]['ServicePackMajorVersion'];
-
 
444
            }
-
 
445
            if (isset($buffer[0]['OSArchitecture']) && preg_match("/^(\d+)/", $buffer[0]['OSArchitecture'], $bits)) {
-
 
446
                $this->sys->setKernel($kernel.' ('.$bits[1].'-bit)');
-
 
447
            } elseif (($allCpus = $this->_get_Win32_Processor()) && isset($allCpus[0]['AddressWidth'])) {
-
 
448
                $this->sys->setKernel($kernel.' ('.$allCpus[0]['AddressWidth'].'-bit)');
-
 
449
            } else {
-
 
450
                $this->sys->setKernel($kernel);
-
 
451
            }
-
 
452
            $this->sys->setDistribution($buffer[0]['Caption']);
-
 
453
 
-
 
454
            if (version_compare($ver, "5.1", "<"))
-
 
455
                $icon = 'Win2000.png';
-
 
456
            elseif (version_compare($ver, "5.1", ">=") && version_compare($ver, "6.0", "<"))
-
 
457
                $icon = 'WinXP.png';
-
 
458
            elseif (version_compare($ver, "6.0", ">=") && version_compare($ver, "6.2", "<"))
-
 
459
                $icon = 'WinVista.png';
-
 
460
            else
-
 
461
                $icon = 'Win8.png';
-
 
462
            $this->sys->setDistributionIcon($icon);
-
 
463
        } elseif (CommonFunctions::executeProgram('cmd', '/c ver 2>nul', $ver_value, false)) {
-
 
464
                if (preg_match("/ReactOS\r?\nVersion\s+(.+)/", $ver_value, $ar_temp)) {
-
 
465
                    $this->sys->setDistribution("ReactOS");
-
 
466
                    $this->sys->setKernel($ar_temp[1]);
-
 
467
                    $this->sys->setDistributionIcon('ReactOS.png');
-
 
468
                    $this->_wmi = false; // No WMI info on ReactOS yet
-
 
469
                } elseif (preg_match("/^(Microsoft [^\[]*)\s*\[\D*\s*(.+)\]/", $ver_value, $ar_temp)) {
-
 
470
                    if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProductName", $strBuf, false) && (strlen($strBuf) > 0)) {
-
 
471
                        if (preg_match("/^Microsoft /", $strBuf)) {
-
 
472
                            $this->sys->setDistribution($strBuf);
-
 
473
                        } else {
-
 
474
                            $this->sys->setDistribution("Microsoft ".$strBuf);
-
 
475
                        }
-
 
476
                    } else {
-
 
477
                        $this->sys->setDistribution($ar_temp[1]);
-
 
478
                    }
-
 
479
                    $kernel = $ar_temp[2];
-
 
480
                    $this->sys->setKernel($kernel);
-
 
481
                    if ((($kernel[1] == '.') && ($kernel[0] <5)) || (substr($kernel, 0, 4) == '5.0.'))
-
 
482
                        $icon = 'Win2000.png';
-
 
483
                    elseif ((substr($kernel, 0, 4) == '6.0.') || (substr($kernel, 0, 4) == '6.1.'))
-
 
484
                        $icon = 'WinVista.png';
-
 
485
                    elseif ((substr($kernel, 0, 4) == '6.2.') || (substr($kernel, 0, 4) == '6.3.') || (substr($kernel, 0, 4) == '6.4.') || (substr($kernel, 0, 5) == '10.0.'))
-
 
486
                        $icon = 'Win8.png';
-
 
487
                    else
-
 
488
                        $icon = 'WinXP.png';
-
 
489
                    $this->sys->setDistributionIcon($icon);
-
 
490
                } else {
-
 
491
                    $this->sys->setDistribution("WinNT");
-
 
492
                    $this->sys->setDistributionIcon('Win2000.png');
-
 
493
                }
-
 
494
        } else {
-
 
495
            $this->sys->setDistribution("WinNT");
-
 
496
            $this->sys->setDistributionIcon('Win2000.png');
-
 
497
        }
-
 
498
    }
-
 
499
 
-
 
500
    /**
-
 
501
     * Processor Load
-
 
502
     * optionally create a loadbar
-
 
503
     *
-
 
504
     * @return void
-
 
505
     */
-
 
506
    private function _loadavg()
-
 
507
    {
-
 
508
        if (($cpubuffer = $this->_get_Win32_PerfFormattedData_PerfOS_Processor()) && isset($cpubuffer['cpu_Total'])) {
-
 
509
            $this->sys->setLoad($cpubuffer['cpu_Total']);
-
 
510
            if (PSI_LOAD_BAR) {
-
 
511
                $this->sys->setLoadPercent($cpubuffer['cpu_Total']);
-
 
512
            }
-
 
513
        } elseif ($buffer = $this->_get_Win32_Processor()) {
-
 
514
            $loadok = true;
-
 
515
            $sum = 0;
-
 
516
            foreach ($buffer as $load) {
-
 
517
                $value = $load['LoadPercentage'];
-
 
518
                if ($value !== null) {
-
 
519
                    $sum += $value;
-
 
520
                } else {
-
 
521
                    $loadok = false;
-
 
522
                    break;
-
 
523
                }
-
 
524
            }
-
 
525
            if ($loadok) {
-
 
526
                $percent = $sum / count($buffer);
-
 
527
                $this->sys->setLoad($percent);
-
 
528
                if (PSI_LOAD_BAR) {
-
 
529
                    $this->sys->setLoadPercent($percent);
-
 
530
                }
-
 
531
            }
-
 
532
        }
-
 
533
    }
-
 
534
 
-
 
535
    /**
-
 
536
     * CPU information
-
 
537
     *
-
 
538
     * @return void
-
 
539
     */
-
 
540
    private function _cpuinfo()
-
 
541
    {
-
 
542
        $allCpus = $this->_get_Win32_Processor();
-
 
543
        if (!$allCpus) {
-
 
544
            $hkey = "HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor";
-
 
545
            if (CommonFunctions::enumKey($this->_key, $hkey, $arrBuf, false)) {
-
 
546
                foreach ($arrBuf as $coreCount) {
-
 
547
                    if (CommonFunctions::readReg($this->_reg, $hkey."\\".$coreCount."\\ProcessorNameString", $strBuf, false)) {
-
 
548
                        $allCpus[$coreCount]['Name'] = $strBuf;
-
 
549
                    }
-
 
550
                    if (CommonFunctions::readReg($this->_reg, $hkey."\\".$coreCount."\\~MHz", $strBuf, false)) {
-
 
551
                        if (preg_match("/^0x([0-9a-f]+)$/i", $strBuf, $hexvalue)) {
-
 
552
                            $allCpus[$coreCount]['CurrentClockSpeed'] = hexdec($hexvalue[1]);
-
 
553
                        }
-
 
554
                    }
-
 
555
                    if (CommonFunctions::readReg($this->_reg, $hkey."\\".$coreCount."\\VendorIdentifier", $strBuf, false)) {
-
 
556
                        $allCpus[$coreCount]['Manufacturer'] = $strBuf;
-
 
557
                    }
-
 
558
                }
-
 
559
            }
-
 
560
        }
-
 
561
 
-
 
562
        $globalcpus = 0;
-
 
563
        foreach ($allCpus as $oneCpu) {
-
 
564
            $cpuCount = 1;
-
 
565
            if (isset($oneCpu['NumberOfLogicalProcessors'])) {
-
 
566
                $cpuCount = $oneCpu['NumberOfLogicalProcessors'];
-
 
567
            } elseif (isset($oneCpu['NumberOfCores'])) {
-
 
568
                $cpuCount = $oneCpu['NumberOfCores'];
-
 
569
            }
-
 
570
            $globalcpus+=$cpuCount;
-
 
571
        }
-
 
572
 
-
 
573
        foreach ($allCpus as $oneCpu) {
-
 
574
            $cpuCount = 1;
-
 
575
            if (isset($oneCpu['NumberOfLogicalProcessors'])) {
-
 
576
                $cpuCount = $oneCpu['NumberOfLogicalProcessors'];
-
 
577
            } elseif (isset($oneCpu['NumberOfCores'])) {
-
 
578
                $cpuCount = $oneCpu['NumberOfCores'];
-
 
579
            }
-
 
580
            for ($i = 0; $i < $cpuCount; $i++) {
-
 
581
                $cpu = new CpuDevice();
-
 
582
                if (isset($oneCpu['Name'])) $cpu->setModel($oneCpu['Name']);
-
 
583
                if (isset($oneCpu['L3CacheSize']) && ($oneCpu['L3CacheSize'] > 0)) {
-
 
584
                    $cpu->setCache($oneCpu['L3CacheSize'] * 1024);
-
 
585
                } elseif (isset($oneCpu['L2CacheSize'])) {
-
 
586
                    $cpu->setCache($oneCpu['L2CacheSize'] * 1024);
-
 
587
                }
-
 
588
                if (isset($oneCpu['CurrentClockSpeed'])) {
-
 
589
                    $cpu->setCpuSpeed($oneCpu['CurrentClockSpeed']);
-
 
590
                    if (isset($oneCpu['MaxClockSpeed']) && ($oneCpu['CurrentClockSpeed'] < $oneCpu['MaxClockSpeed'])) $cpu->setCpuSpeedMax($oneCpu['MaxClockSpeed']);
-
 
591
                }
-
 
592
                if (isset($oneCpu['ExtClock'])) $cpu->setBusSpeed($oneCpu['ExtClock']);
-
 
593
                if (isset($oneCpu['Manufacturer'])) $cpu->setVendorId($oneCpu['Manufacturer']);
-
 
594
                if (PSI_LOAD_BAR) {
-
 
595
                    if (($cpubuffer = $this->_get_Win32_PerfFormattedData_PerfOS_Processor()) && (count($cpubuffer) == ($globalcpus+1)) && isset($cpubuffer['cpu'.$i])) {
-
 
596
                           $cpu->setLoad($cpubuffer['cpu'.$i]);
-
 
597
                    } elseif ((count($allCpus) == $globalcpus) && isset($oneCpu['LoadPercentage'])) {
-
 
598
                        $cpu->setLoad($oneCpu['LoadPercentage']);
-
 
599
                    }
-
 
600
                }
-
 
601
                $this->sys->setCpus($cpu);
-
 
602
            }
-
 
603
        }
-
 
604
    }
-
 
605
 
-
 
606
    /**
-
 
607
     * Machine information
-
 
608
     *
-
 
609
     * @return void
-
 
610
     */
-
 
611
    private function _machine()
-
 
612
    {
-
 
613
        $buffer = $this->_get_Win32_ComputerSystem();
-
 
614
        if ($buffer) {
-
 
615
            $buf = "";
-
 
616
            if (isset($buffer[0]['Manufacturer']) && !preg_match("/^To be filled by O\.E\.M\.$|^System manufacturer$|^Not Specified$/i", $buf2=$buffer[0]['Manufacturer'])) {
-
 
617
                $buf .= ' '.$buf2;
-
 
618
            }
-
 
619
 
-
 
620
            if (isset($buffer[0]['Model']) && !preg_match("/^To be filled by O\.E\.M\.$|^System Product Name$|^Not Specified$/i", $buf2=$buffer[0]['Model'])) {
-
 
621
                $buf .= ' '.$buf2;
-
 
622
            }
-
 
623
            if (trim($buf) != "") {
-
 
624
                $this->sys->setMachine(trim($buf));
-
 
625
            }
-
 
626
        }
-
 
627
    }
-
 
628
 
-
 
629
    /**
-
 
630
     * Hardwaredevices
-
 
631
     *
-
 
632
     * @return void
-
 
633
     */
-
 
634
    private function _hardware()
-
 
635
    {
-
 
636
        foreach ($this->_devicelist('PCI') as $pciDev) {
-
 
637
            $dev = new HWDevice();
-
 
638
            $dev->setName($pciDev['Name']);
-
 
639
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
-
 
640
                $dev->setManufacturer($pciDev['Manufacturer']);
-
 
641
                $dev->setProduct($pciDev['Product']);
-
 
642
            }
-
 
643
            $this->sys->setPciDevices($dev);
-
 
644
        }
-
 
645
 
-
 
646
        foreach ($this->_devicelist('IDE') as $ideDev) {
-
 
647
            $dev = new HWDevice();
-
 
648
            $dev->setName($ideDev['Name']);
-
 
649
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
-
 
650
                $dev->setCapacity($ideDev['Capacity']);
-
 
651
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
-
 
652
                    $dev->setSerial($ideDev['Serial']);
-
 
653
                }
-
 
654
            }
-
 
655
            $this->sys->setIdeDevices($dev);
-
 
656
        }
-
 
657
 
-
 
658
        foreach ($this->_devicelist('SCSI') as $scsiDev) {
-
 
659
            $dev = new HWDevice();
-
 
660
            $dev->setName($scsiDev['Name']);
-
 
661
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
-
 
662
                $dev->setCapacity($scsiDev['Capacity']);
-
 
663
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
-
 
664
                    $dev->setSerial($scsiDev['Serial']);
-
 
665
                }
-
 
666
            }
-
 
667
            $this->sys->setScsiDevices($dev);
-
 
668
        }
-
 
669
 
-
 
670
        foreach ($this->_devicelist('USB') as $usbDev) {
-
 
671
            $dev = new HWDevice();
-
 
672
            $dev->setName($usbDev['Name']);
-
 
673
            if (defined('PSI_SHOW_DEVICES_INFOS') && PSI_SHOW_DEVICES_INFOS) {
-
 
674
                $dev->setManufacturer($usbDev['Manufacturer']);
-
 
675
                $dev->setProduct($usbDev['Product']);
-
 
676
                if (defined('PSI_SHOW_DEVICES_SERIAL') && PSI_SHOW_DEVICES_SERIAL) {
-
 
677
                    $dev->setSerial($usbDev['Serial']);
-
 
678
                }
-
 
679
            }
-
 
680
            $this->sys->setUsbDevices($dev);
-
 
681
        }
-
 
682
    }
-
 
683
 
-
 
684
    /**
-
 
685
     * Network devices
-
 
686
     *
-
 
687
     * @return void
-
 
688
     */
-
 
689
    private function _network()
-
 
690
    {
-
 
691
        if ($this->_wmi) {
-
 
692
            $buffer = $this->_get_Win32_OperatingSystem();
-
 
693
            if ($buffer && isset($buffer[0]) && isset($buffer[0]['Version']) && version_compare($buffer[0]['Version'], "6.2", ">=")) { // minimal windows 2012 or windows 8
-
 
694
                $allDevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfRawData_Tcpip_NetworkAdapter', array('Name', 'BytesSentPersec', 'BytesTotalPersec', 'BytesReceivedPersec', 'PacketsReceivedErrors', 'PacketsReceivedDiscarded', 'CurrentBandwidth'));
65
            } else {
695
            } else {
66
              if( in_array( $propItem->Name, $strValue ) ) {
696
                $allDevices = CommonFunctions::getWMI($this->_wmi, 'Win32_PerfRawData_Tcpip_NetworkInterface', array('Name', 'BytesSentPersec', 'BytesTotalPersec', 'BytesReceivedPersec', 'PacketsReceivedErrors', 'PacketsReceivedDiscarded', 'CurrentBandwidth'));
67
                $arrInstance[$propItem->Name] = trim($value);
697
            }
68
              }
698
            if ($allDevices) {
69
            }
699
                $aliases = array();
70
        }
700
                $hkey = "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
71
        $arrData[] = $arrInstance;
701
                if (CommonFunctions::enumKey($this->_key, $hkey, $arrBuf, false)) {
72
    }
702
                    foreach ($arrBuf as $netID) {
73
    return $arrData;
703
                        if (CommonFunctions::readReg($this->_reg, $hkey."\\".$netID."\\Connection\\PnPInstanceId", $strInstanceID, false)) { //a w Name jest net alias
74
  }
704
                            if (CommonFunctions::readReg($this->_reg, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\".$strInstanceID."\\FriendlyName", $strName, false)) {
75
 
705
                                $cname = str_replace(array('(', ')', '#'), array('[', ']', '_'), $strName); //convert to canonical
76
  // private function for getting different device types from the system
706
                                if (!isset($aliases[$cname])) { // duplicate checking
77
  function _devicelist ( $strType ) {
707
                                    $aliases[$cname]['id'] = $netID;
78
    if( empty( $this->wmidevices ) ) {
708
                                    $aliases[$cname]['name'] = $strName;
79
      $this->wmidevices = $this->_GetWMI( "Win32_PnPEntity", array( "Name", "PNPDeviceID" ) );
709
                                    if (CommonFunctions::readReg($this->_reg, $hkey."\\".$netID."\\Connection\\Name", $strCName, false)
80
    }
710
                                       && (str_replace(array('(', ')', '#'), array('[', ']', '_'), $strCName) !== $cname)) {
81
 
711
                                        $aliases[$cname]['netname'] = $strCName;
82
    $list = array();
712
                                    }
83
    foreach ( $this->wmidevices as $device ) {
713
                                } else {
84
      if ( substr( $device["PNPDeviceID"], 0, strpos( $device["PNPDeviceID"], "\\" ) + 1 ) == ( $strType . "\\" ) ) {
714
                                    $aliases[$cname]['id'] = '';
85
        $list[] = $device["Name"];
715
                                }
86
      } 
716
                            }
87
    }
717
                        }
88
 
718
                    }
89
    return $list;
719
                }
90
  }
720
 
91
  
721
                $aliases2 = array();
92
  // get our apache SERVER_NAME or vhost
722
                $hkey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards";
93
  function vhostname () {
723
                if (CommonFunctions::enumKey($this->_key, $hkey, $arrBuf, false)) {
94
    if (! ($result = getenv('SERVER_NAME'))) {
724
                    foreach ($arrBuf as $netCount) {
95
      $result = 'N.A.';
725
                        if (CommonFunctions::readReg($this->_reg, $hkey."\\".$netCount."\\Description", $strName, false)
96
    } 
726
                            && CommonFunctions::readReg($this->_reg, $hkey."\\".$netCount."\\ServiceName", $strGUID, false)) {
97
    return $result;
727
                            $cname = str_replace(array('(', ')', '#'), array('[', ']', '_'), $strName); //convert to canonical
98
  } 
728
                            if (!isset($aliases2[$cname])) { // duplicate checking
99
 
729
                                $aliases2[$cname]['id'] = $strGUID;
100
  // get the IP address of our vhost name
730
                                $aliases2[$cname]['name'] = $strName;
101
  function vip_addr () {
731
                            } else {
102
    return gethostbyname($this->vhostname());
732
                                $aliases2[$cname]['id'] = '';
103
  }
733
                            }
104
 
734
                        }
105
  // get our canonical hostname
735
                    }
106
  function chostname ()
736
                }
107
  {
737
 
108
    $buffer = $this->_GetWMI( "Win32_ComputerSystem", array( "Name" ) );
738
                $allNetworkAdapterConfigurations = CommonFunctions::getWMI($this->_wmi, 'Win32_NetworkAdapterConfiguration', array('SettingID', /*'Description',*/ 'MACAddress', 'IPAddress'));
109
    $result = $buffer[0]["Name"];
739
                foreach ($allDevices as $device) if (!preg_match('/^WAN Miniport \[/', $device['Name'])) {
110
    return gethostbyaddr(gethostbyname($result));
740
                    $dev = new NetDevice();
111
  }
741
                    $name = $device['Name'];
112
 
742
 
113
  // get the IP address of our canonical hostname
743
                    if (preg_match('/^isatap\.({[A-Fa-f0-9\-]*})/', $name)) {
114
  function ip_addr ()
744
                        $dev->setName("Microsoft ISATAP Adapter");
115
  {
745
                    } else {
116
    $buffer = $this->_GetWMI( "Win32_ComputerSystem", array( "Name" ) );
746
                        if (preg_match('/\s-\s([^-]*)$/', $name, $ar_name)) {
117
    $result = $buffer[0]["Name"];
747
                            $name=substr($name, 0, strlen($name)-strlen($ar_name[0]));
118
    return gethostbyname($result);
748
                        }
119
  }
749
                        $dev->setName($name);
120
 
750
                    }
121
  function kernel ()
751
 
122
  {
752
                    $macexist = false;
123
    $buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "Version", "ServicePackMajorVersion" ) );
753
                    if (((($ali=$aliases) && isset($ali[$name])) || (($ali=$aliases2) && isset($ali[$name]))) && isset($ali[$name]['id']) && ($ali[$name]['id'] !== "")) {
124
    $result = $buffer[0]["Version"];
754
                        foreach ($allNetworkAdapterConfigurations as $NetworkAdapterConfiguration) {
125
    if( $buffer[0]["ServicePackMajorVersion"] > 0 ) {
755
                            if ($ali[$name]['id']==$NetworkAdapterConfiguration['SettingID']) {
126
      $result .= " SP" . $buffer[0]["ServicePackMajorVersion"];
756
                                $mininame = $ali[$name]['name'];
127
    }
757
                                if (preg_match('/^isatap\.({[A-Fa-f0-9\-]*})/', $mininame))
128
    return $result;
758
                                    $mininame="Microsoft ISATAP Adapter";
129
  } 
759
                                elseif (preg_match('/\s-\s([^-]*)$/', $mininame, $ar_name))
130
 
760
                                    $name=substr($mininame, 0, strlen($mininame)-strlen($ar_name[0]));
131
  // get the time the system is running
761
                                $dev->setName($mininame);
132
  function uptime ()
762
                                if (trim($NetworkAdapterConfiguration['MACAddress']) !== "") $macexist = true;
133
  {
763
                                if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
134
    $result = 0;
764
                                    if (isset($ali[$name]['netname'])) $dev->setInfo(str_replace(';', ':', $ali[$name]['netname']));
135
    $buffer = $this->_GetWMI( "Win32_OperatingSystem", array( "LastBootUpTime", "LocalDateTime" ) );
765
                                    if ((!defined('PSI_HIDE_NETWORK_MACADDR') || !PSI_HIDE_NETWORK_MACADDR)
136
 
766
                                       && (trim($NetworkAdapterConfiguration['MACAddress']) !== "")) $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').str_replace(':', '-', strtoupper($NetworkAdapterConfiguration['MACAddress'])));
137
    $byear = intval(substr($buffer[0]["LastBootUpTime"], 0, 4));
767
                                    if (isset($NetworkAdapterConfiguration['IPAddress']))
138
    $bmonth = intval(substr($buffer[0]["LastBootUpTime"], 4, 2));
768
                                        foreach ($NetworkAdapterConfiguration['IPAddress'] as $ipaddres)
139
    $bday = intval(substr($buffer[0]["LastBootUpTime"], 6, 2));
769
                                            if (($ipaddres != "0.0.0.0") && ($ipaddres != "::") && !preg_match('/^fe80::/i', $ipaddres))
140
    $bhour = intval(substr($buffer[0]["LastBootUpTime"], 8, 2));
770
                                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ipaddres));
141
    $bminute = intval(substr($buffer[0]["LastBootUpTime"], 10, 2));
771
                                }
142
    $bseconds = intval(substr($buffer[0]["LastBootUpTime"], 12, 2));
772
 
143
 
773
                                break;
144
    $lyear = intval(substr($buffer[0]["LocalDateTime"], 0, 4));
774
                            }
145
    $lmonth = intval(substr($buffer[0]["LocalDateTime"], 4, 2));
775
                        }
146
    $lday = intval(substr($buffer[0]["LocalDateTime"], 6, 2));
776
                    }
147
    $lhour = intval(substr($buffer[0]["LocalDateTime"], 8, 2));
777
 
148
    $lminute = intval(substr($buffer[0]["LocalDateTime"], 10, 2));
778
                    if ($macexist
149
    $lseconds = intval(substr($buffer[0]["LocalDateTime"], 12, 2));
779
//                        || ($device['CurrentBandwidth'] >= 1000000)
150
 
780
                        || ($device['BytesTotalPersec'] != 0)
151
    $boottime = mktime($bhour, $bminute, $bseconds, $bmonth, $bday, $byear);
781
                        || ($device['BytesSentPersec'] != 0)
152
    $localtime = mktime($lhour, $lminute, $lseconds, $lmonth, $lday, $lyear);
782
                        || ($device['BytesReceivedPersec'] != 0)
153
 
783
                        || ($device['PacketsReceivedErrors'] != 0)
154
    $result = $localtime - $boottime;
784
                        || ($device['PacketsReceivedDiscarded'] != 0)) { // hide unused
155
 
785
                        if (defined('PSI_SHOW_NETWORK_INFOS') && PSI_SHOW_NETWORK_INFOS) {
156
    return $result;
786
                            if (($speedinfo = $device['CurrentBandwidth']) >= 1000000) {
157
  } 
787
                                if ($speedinfo > 1000000000) {
158
 
788
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').round($speedinfo/1000000000, 2)."Gb/s");
159
  // count the users, which are logged in
789
                                } else {
160
  function users ()
790
                                    $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').round($speedinfo/1000000, 2)."Mb/s");
161
  {
791
                                }
162
    if( stristr( $this->kernel(), "2000 P" ) ) return "N.A."; 
792
                            }
163
    $buffer = $this->_GetWMI( "Win32_PerfRawData_TermService_TerminalServices", array( "TotalSessions" ) );
793
                        }
164
    return $buffer[0]["TotalSessions"];
794
 
165
  } 
795
                        // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_tcpip_networkinterface.asp
166
 
796
                        // there is a possible bug in the wmi interfaceabout uint32 and uint64: http://www.ureader.com/message/1244948.aspx, so that
167
  // get the load of the processors
797
                        // magative numbers would occour, try to calculate the nagative value from total - positive number
168
  function loadavg ($bar = false)
798
                        $txbytes = $device['BytesSentPersec'];
169
  {
799
                        $rxbytes = $device['BytesReceivedPersec'];
170
    $buffer = $this->_GetWMI( "Win32_Processor", array( "LoadPercentage" ) );
800
                        if (($txbytes < 0) && ($rxbytes < 0)) {
171
    $cpuload = array();
801
                            $txbytes += 4294967296;
172
    for( $i = 0; $i < count( $buffer ); $i++ ) {
802
                            $rxbytes += 4294967296;
173
      $cpuload['avg'][] = $buffer[$i]["LoadPercentage"];
803
                        } elseif ($txbytes < 0) {
174
    }
804
                            if ($device['BytesTotalPersec'] > $rxbytes)
175
    if ($bar) {
805
                               $txbytes = $device['BytesTotalPersec'] - $rxbytes;
176
      $cpuload['cpupercent'] = array_sum( $cpuload['avg'] ) / count( $buffer );
806
                            else
177
    }
807
                               $txbytes += 4294967296;
178
    return $cpuload;
808
                        } elseif ($rxbytes < 0) {
179
  } 
809
                            if ($device['BytesTotalPersec'] > $txbytes)
180
 
810
                               $rxbytes = $device['BytesTotalPersec'] - $txbytes;
181
  // get some informations about the cpu's
811
                            else
182
  function cpu_info ()
812
                               $rxbytes += 4294967296;
183
  {
813
                        }
184
    $buffer = $this->_GetWMI( "Win32_Processor", array( "Name", "L2CacheSize", "CurrentClockSpeed", "ExtClock" ) );
814
                        $dev->setTxBytes($txbytes);
185
    $results["cpus"] = 0;
815
                        $dev->setRxBytes($rxbytes);
186
    foreach ($buffer as $cpu) {
816
                        $dev->setErrors($device['PacketsReceivedErrors']);
187
      $results["cpus"]++;
817
                        $dev->setDrops($device['PacketsReceivedDiscarded']);
188
      $results["model"] = $cpu["Name"];
818
 
189
      $results["cache"] = $cpu["L2CacheSize"];
819
                        $this->sys->setNetDevices($dev);
190
      $results["cpuspeed"] = $cpu["CurrentClockSpeed"];
820
                    }
191
      $results["busspeed"] = $cpu["ExtClock"];
821
                }
192
    } 
822
            }
193
    return $results;
823
        } elseif (($buffer = $this->_get_systeminfo()) && preg_match('/^(\s+)\[\d+\]:[^\r\n]+\r\n\s+[^\s\[]/m', $buffer, $matches, PREG_OFFSET_CAPTURE)) {
194
  } 
824
            $netbuf = substr($buffer, $matches[0][1]);
195
 
825
            if (preg_match('/^[^\s]/m', $netbuf, $matches2, PREG_OFFSET_CAPTURE)) {
196
  // get the pci devices from the system
826
                $netbuf = substr($netbuf, 0, $matches2[0][1]);
197
  function pci ()
827
            }
198
  {
828
            $netstrs = preg_split('/^'.$matches[1][0].'\[\d+\]:/m', $netbuf, -1, PREG_SPLIT_NO_EMPTY);
199
    $pci = $this->_devicelist( "PCI" );
829
            $devnr = 0;
200
    return $pci;
830
            foreach ($netstrs as $netstr) {
201
  } 
831
                $netstrls = preg_split('/\r\n/', $netstr, -1, PREG_SPLIT_NO_EMPTY);
202
 
832
                if (sizeof($netstrls)>1) {
203
  // get the ide devices from the system
833
                    $dev = new NetDevice();
204
  function ide ()
834
                    foreach ($netstrls as $nr=>$netstrl) {
205
  {
835
                        if ($nr === 0) {
206
    $buffer = $this->_devicelist( "IDE" );
836
                            $name = trim($netstrl);
207
    $ide = array();
837
                            if ($name !== "") {
208
    foreach ( $buffer as $device ) {
838
                                $dev->setName($name);
209
        $ide[]['model'] = $device;
839
                            } else {
210
    } 
840
                                $dev->setName('dev'.$devnr);
211
    return $ide;
841
                                $devnr++;
212
  } 
842
                            }
213
 
843
                        } elseif (preg_match('/\[\d+\]:\s+(.+)/', $netstrl, $netinfo)) {
214
  // get the scsi devices from the system
844
                            $ipaddres = trim($netinfo[1]);
215
  function scsi ()
845
                            if (($ipaddres!="0.0.0.0") && !preg_match('/^fe80::/i', $ipaddres))
216
  {
846
                                $dev->setInfo(($dev->getInfo()?$dev->getInfo().';':'').strtolower($ipaddres));
217
    $scsi = $this->_devicelist( "SCSI" );
847
                        }
218
    return $scsi;
848
                    }
219
  } 
849
                    $this->sys->setNetDevices($dev);
220
 
850
                }
221
  // get the usb devices from the system
851
            }
222
  function usb ()
852
        }
223
  {
853
    }
224
    $usb = $this->_devicelist( "USB" );
854
 
225
    return $usb;
855
    /**
226
  } 
856
     * Physical memory information and Swap Space information
227
 
857
     *
228
  // get the sbus devices from the system - currently not called
858
     * @link http://msdn2.microsoft.com/En-US/library/aa394239.aspx
229
  function sbus ()
859
     * @link http://msdn2.microsoft.com/en-us/library/aa394246.aspx
230
  {
860
     * @return void
231
    $sbus = $this->_devicelist( "SBUS" );
861
     */
232
    return $sbus;
862
    private function _memory()
233
  } 
863
    {
234
 
864
        if ($this->_wmi) {
235
	// get the netowrk devices and rx/tx bytes
865
            $buffer = $this->_get_Win32_OperatingSystem();
236
	function network () {
866
            if ($buffer) {
237
		$results = array();
867
                $this->sys->setMemTotal($buffer[0]['TotalVisibleMemorySize'] * 1024);
238
		$buffer = $this->_GetWMI( "Win32_PerfRawData_Tcpip_NetworkInterface" );
868
                $this->sys->setMemFree($buffer[0]['FreePhysicalMemory'] * 1024);
239
		foreach( $buffer as $device ) {
869
                $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
240
			$dev_name = $device["Name"];
870
            }
241
			// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_perfrawdata_tcpip_networkinterface.asp
871
            $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_PageFileUsage');
242
			// there is a possible bug in the wmi interfaceabout uint32 and uint64: http://www.ureader.com/message/1244948.aspx, so that
872
            foreach ($buffer as $swapdevice) {
243
			// magative numbers would occour, try to calculate the nagative value from total - positive number
873
                $dev = new DiskDevice();
244
			
874
                $dev->setName("SWAP");
245
			if( $device["BytesSentPersec"] < 0) {
875
                $dev->setMountPoint($swapdevice['Name']);
246
				$results[$dev_name]['tx_bytes'] = $device["BytesTotalPersec"] - $device["BytesReceivedPersec"];
876
                $dev->setTotal($swapdevice['AllocatedBaseSize'] * 1024 * 1024);
247
			} else {
877
                $dev->setUsed($swapdevice['CurrentUsage'] * 1024 * 1024);
248
				$results[$dev_name]['tx_bytes'] = $device["BytesSentPersec"];
878
                $dev->setFree($dev->getTotal() - $dev->getUsed());
249
			}
879
                $dev->setFsType('swap');
250
			if( $device["BytesReceivedPersec"] < 0 ) {
880
                $this->sys->setSwapDevices($dev);
251
				$results[$dev_name]['rx_bytes'] = $device["BytesTotalPersec"] - $device["BytesSentPersec"];
881
            }
252
			} else {
882
        } elseif (($buffer = $this->_get_systeminfo()) && preg_match("/:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+\s([\d \xFF]+)\sMB\r\n/m", $buffer, $buffer2)) {
253
				$results[$dev_name]['rx_bytes'] = $device["BytesReceivedPersec"];
883
//           && (preg_match("/:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+:\s([\d \xFF]+)\sMB\r\n.+\s([\d \xFF]+)\sMB\r\n.*:\s+(\S+)\r\n/m", $buffer, $buffer2)) {
254
			}
884
            $this->sys->setMemTotal(preg_replace('/(\s)|(\xFF)/', '', $buffer2[1]) * 1024 * 1024);
255
			
885
            $this->sys->setMemFree(preg_replace('/(\s)|(\xFF)/', '', $buffer2[2]) * 1024 * 1024);
256
			$results[$dev_name]['rx_packets'] = $device["PacketsReceivedPersec"];
886
            $this->sys->setMemUsed($this->sys->getMemTotal() - $this->sys->getMemFree());
257
			$results[$dev_name]['tx_packets'] = $device["PacketsSentPersec"];
887
        }
258
			
888
    }
259
			$results[$dev_name]['rx_errs'] = $device["PacketsReceivedErrors"];
889
 
260
			$results[$dev_name]['rx_drop'] = $device["PacketsReceivedDiscarded"];
890
    /**
261
			
891
     * filesystem information
262
			$results[$dev_name]['errs'] = $device["PacketsReceivedErrors"];
892
     *
263
			$results[$dev_name]['drop'] = $device["PacketsReceivedDiscarded"];
893
     * @return void
264
		}
894
     */
265
		
895
    private function _filesystems()
266
		return $results;
896
    {
267
	} 
897
        $typearray = array('Unknown', 'No Root Directory', 'Removable Disk', 'Local Disk', 'Network Drive', 'Compact Disc', 'RAM Disk');
268
 
898
        $floppyarray = array('Unknown', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', '5 1/4 in.', 'Other', 'HD', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '5 1/4 in.', '3 1/2 in.', '3 1/2 in.', '8 in.');
269
  function memory ()
899
        $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_LogicalDisk', array('Name', 'Size', 'FreeSpace', 'FileSystem', 'DriveType', 'MediaType'));
270
  {
900
        foreach ($buffer as $filesystem) {
271
    $buffer = $this->_GetWMI( "Win32_LogicalMemoryConfiguration", array( "TotalPhysicalMemory" ) );
901
            $dev = new DiskDevice();
272
    $results['ram']['total'] = $buffer[0]["TotalPhysicalMemory"];
902
            $dev->setMountPoint($filesystem['Name']);
273
 
903
            $dev->setFsType($filesystem['FileSystem']);
274
    $buffer = $this->_GetWMI( "Win32_PerfRawData_PerfOS_Memory", array( "AvailableKBytes" ) );
904
            if ($filesystem['Size'] > 0) {
275
    $results['ram']['free'] = $buffer[0]["AvailableKBytes"];
905
                $dev->setTotal($filesystem['Size']);
276
 
906
                $dev->setFree($filesystem['FreeSpace']);
277
    $results['ram']['used'] = $results['ram']['total'] - $results['ram']['free'];
907
                $dev->setUsed($filesystem['Size'] - $filesystem['FreeSpace']);
278
    $results['ram']['percent'] = ceil( ( $results['ram']['used'] * 100 ) / $results['ram']['total'] );
908
            }
279
    $results['swap']['total'] = 0;
909
            if ($filesystem['MediaType'] != "" && $filesystem['DriveType'] == 2) {
280
    $results['swap']['used'] = 0;
910
                $dev->setName($typearray[$filesystem['DriveType']]." (".$floppyarray[$filesystem['MediaType']].")");
281
    $results['swap']['free'] = 0;
911
            } else {
282
 
912
                $dev->setName($typearray[$filesystem['DriveType']]);
283
    $buffer = $this->_GetWMI( "Win32_PageFileUsage" ); // no need to filter, using nearly everything from output
913
            }
284
    $k = 0;
914
            $this->sys->setDiskDevices($dev);
285
    foreach ($buffer as $swapdevice) {
915
        }
286
      $results['devswap'][$k]['dev'] = $swapdevice["Name"];
916
        if (!$buffer && ($this->sys->getDistribution()=="ReactOS")) {
287
      $results['devswap'][$k]['total'] = $swapdevice["AllocatedBaseSize"] * 1024;
917
            // test for command 'free' on current disk
288
      $results['devswap'][$k]['used'] = $swapdevice["CurrentUsage"] * 1024;
918
            if (CommonFunctions::executeProgram('cmd', '/c free 2>nul', $out_value, true)) {
289
      $results['devswap'][$k]['free'] = ( $swapdevice["AllocatedBaseSize"] - $swapdevice["CurrentUsage"] ) * 1024;
919
                for ($letter='A'; $letter!='AA'; $letter++) if (CommonFunctions::executeProgram('cmd', '/c free '.$letter.': 2>nul', $out_value, false)) {
290
      $results['devswap'][$k]['percent'] = ceil( $swapdevice["CurrentUsage"] / $swapdevice["AllocatedBaseSize"] );
920
                    $values = preg_replace('/[^\d\n]/', '', $out_value);
291
 
921
                    if (preg_match('/\n(\d+)\n(\d+)\n(\d+)$/', $values, $out_dig)) {
292
      $results['swap']['total'] += $results['devswap'][$k]['total'];
922
                        $size = $out_dig[1];
293
      $results['swap']['used'] += $results['devswap'][$k]['used'];
923
                        $used = $out_dig[2];
294
      $results['swap']['free'] += $results['devswap'][$k]['free'];
924
                        $free = $out_dig[3];
295
      $k += 1;
925
                        if ($used + $free == $size) {
296
    } 
926
                            $dev = new DiskDevice();
297
    $results['swap']['percent'] = ceil( $results['swap']['used'] / $results['swap']['total'] * 100 );
927
                            $dev->setMountPoint($letter.":");
298
    return $results;
928
                            $dev->setFsType('Unknown');
299
  } 
929
                            $dev->setName('Unknown');
300
 
930
                            $dev->setTotal($size);
301
  // get the filesystem informations
931
                            $dev->setUsed($used);
302
  function filesystems ()
932
                            $dev->setFree($free);
303
  {
933
                            $this->sys->setDiskDevices($dev);
304
     $typearray = array("Unknown", "No Root Directory", "Removeable Disk",
934
                        }
305
        "Local Disk", "Network Drive", "Compact Disc", "RAM Disk");
935
                    }
306
     $floppyarray = array("Unknown", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.",
936
                }
307
        "3 1/2 in.", "3 1/2 in.", "5 1/4 in.", "5 1/4 in.", "5 1/4 in.",
937
            }
308
        "5 1/4 in.", "5 1/4 in.", "Other", "HD", "3 1/2 in.", "3 1/2 in.",
938
        }
309
        "5 1/4 in.", "5 1/4 in.", "3 1/2 in.", "3 1/2 in.", "5 1/4 in.",
939
    }
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
 
940
 
-
 
941
    /**
-
 
942
     * get os specific encoding
-
 
943
     *
-
 
944
     * @see OS::getEncoding()
-
 
945
     *
-
 
946
     * @return string
-
 
947
     */
-
 
948
    public function getEncoding()
-
 
949
    {
-
 
950
        return $this->_codepage;
-
 
951
    }
-
 
952
 
-
 
953
    /**
-
 
954
     * get os specific language
-
 
955
     *
-
 
956
     * @see OS::getLanguage()
-
 
957
     *
-
 
958
     * @return string
-
 
959
     */
-
 
960
    public function getLanguage()
-
 
961
    {
-
 
962
        return $this->_syslang;
-
 
963
    }
-
 
964
 
-
 
965
    public function _processes()
-
 
966
    {
-
 
967
        $processes['*'] = 0;
-
 
968
        if (CommonFunctions::executeProgram('qprocess', '*', $strBuf, false) && (strlen($strBuf) > 0)) {
-
 
969
            $lines = preg_split('/\n/', $strBuf);
-
 
970
            $processes['*'] = (count($lines)-1) - 3 ; //correction for process "qprocess *"
-
 
971
        }
-
 
972
        if ($processes['*'] <= 0) {
-
 
973
            $buffer = CommonFunctions::getWMI($this->_wmi, 'Win32_Process', array('Caption'));
-
 
974
            $processes['*'] = count($buffer);
-
 
975
        }
-
 
976
        $processes[' '] = $processes['*'];
-
 
977
        $this->sys->setProcesses($processes);
-
 
978
    }
-
 
979
 
-
 
980
    /**
-
 
981
     * get the information
-
 
982
     *
-
 
983
     * @see PSI_Interface_OS::build()
-
 
984
     *
-
 
985
     * @return Void
-
 
986
     */
-
 
987
    public function build()
-
 
988
    {
-
 
989
        $this->_distro(); //share getDistribution()
-
 
990
        if ($this->sys->getDistribution()=="ReactOS") {
-
 
991
            $this->error->addError("WARN", "The ReactOS version of phpSysInfo is a work in progress, some things currently don't work");
-
 
992
        }
-
 
993
        if (!$this->blockname || $this->blockname==='vitals') {
-
 
994
            $this->_hostname();
-
 
995
            $this->_users();
-
 
996
            $this->_uptime();
-
 
997
            $this->_loadavg();
-
 
998
            $this->_processes();
-
 
999
        }
-
 
1000
        if (!$this->blockname || $this->blockname==='network') {
-
 
1001
            $this->_network();
-
 
1002
        }
-
 
1003
        if (!$this->blockname || $this->blockname==='hardware') {
-
 
1004
            $this->_machine();
-
 
1005
            $this->_cpuinfo();
-
 
1006
            $this->_hardware();
-
 
1007
        }
-
 
1008
        if (!$this->blockname || $this->blockname==='filesystem') {
-
 
1009
            $this->_filesystems();
-
 
1010
        }
-
 
1011
        if (!$this->blockname || $this->blockname==='memory') {
-
 
1012
            $this->_memory();
-
 
1013
        }
-
 
1014
    }
344
?>
1015
}