Subversion Repositories ALCASAR

Rev

Rev 2976 | Rev 3100 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2976 Rev 3037
Line 24... Line 24...
24
 * @link      http://phpsysinfo.sourceforge.net
24
 * @link      http://phpsysinfo.sourceforge.net
25
 */
25
 */
26
class CommonFunctions
26
class CommonFunctions
27
{
27
{
28
    /**
28
    /**
29
     * holds codepage for chcp
29
     * holds dmi memory data
30
     *
30
     *
31
     * @var integer
31
     * @var array
32
     */
32
     */
33
    private static $_cp = null;
-
 
34
 
-
 
35
    /**
-
 
36
     * value of checking run as administrator
-
 
37
     *
-
 
38
     * @var boolean
-
 
39
     */
-
 
40
    private static $_asadmin = null;
33
    private static $_dmimd = null;
41
 
-
 
42
    public static function setcp($cp)
-
 
43
    {
-
 
44
        self::$_cp = $cp;
-
 
45
    }
-
 
46
 
-
 
47
    public static function getcp()
-
 
48
    {
-
 
49
        return self::$_cp;
-
 
50
    }
-
 
51
 
-
 
52
    public static function isAdmin()
-
 
53
    {
-
 
54
        if (self::$_asadmin == null) {
-
 
55
            if (PSI_OS == 'WINNT') {
-
 
56
                $strBuf = '';
-
 
57
                self::executeProgram('sfc', '2>&1', $strBuf, false); // 'net session' for detection does not work if "Server" (LanmanServer) service is stopped
-
 
58
                if (preg_match('/^\/SCANNOW\s/m', preg_replace('/(\x00)/', '', $strBuf))) { // SCANNOW checking - also if Unicode
-
 
59
                    self::$_asadmin = true;
-
 
60
                } else {
-
 
61
                    self::$_asadmin = false;
-
 
62
                }
-
 
63
            } else {
-
 
64
                self::$_asadmin = false;
-
 
65
            }
-
 
66
        }
-
 
67
 
-
 
68
        return self::$_asadmin;
-
 
69
    }
-
 
70
 
34
 
71
    private static function _parse_log_file($string)
35
    private static function _parse_log_file($string)
72
    {
36
    {
73
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
37
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
74
            $log_file = substr(PSI_LOG, 1);
38
            $log_file = substr(PSI_LOG, 1);
Line 175... Line 139...
175
            }
139
            }
176
            if (($strPath !== $exceptPath) && !is_dir($strPath)) {
140
            if (($strPath !== $exceptPath) && !is_dir($strPath)) {
177
                continue;
141
                continue;
178
            }
142
            }
179
            $strProgrammpath = $strPathS.$strProgram;
143
            $strProgrammpath = $strPathS.$strProgram;
180
            if (is_executable($strProgrammpath) || ((PSI_OS == 'WINNT') && (strtolower($path_parts['extension']) == 'py'))) {
144
            if (is_executable($strProgrammpath) || ((PSI_OS == 'WINNT') && (strtolower($path_parts['extension']) == 'py') && is_file($strProgrammpath))) {
181
                return $strProgrammpath;
145
                return $strProgrammpath;
182
            }
146
            }
183
        }
147
        }
184
 
148
 
185
        return null;
149
        return null;
Line 193... Line 157...
193
     *
157
     *
194
     * @param string  $strProgramname name of the program
158
     * @param string  $strProgramname name of the program
195
     * @param string  $strArgs        arguments to the program
159
     * @param string  $strArgs        arguments to the program
196
     * @param string  &$strBuffer     output of the command
160
     * @param string  &$strBuffer     output of the command
197
     * @param boolean $booErrorRep    en- or disables the reporting of errors which should be logged
161
     * @param boolean $booErrorRep    en- or disables the reporting of errors which should be logged
198
     * @param integer $timeout        timeout value in seconds (default value is PSI_EXEC_TIMEOUT_INT)
162
     * @param int     $timeout        timeout value in seconds (default value is PSI_EXEC_TIMEOUT_INT)
199
     *
163
     *
200
     * @return boolean command successfull or not
164
     * @return boolean command successfull or not
201
     */
165
     */
202
    public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = PSI_EXEC_TIMEOUT_INT)
166
    public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = PSI_EXEC_TIMEOUT_INT)
203
    {
167
    {
Line 214... Line 178...
214
 
178
 
215
                return true;
179
                return true;
216
            }
180
            }
217
        }
181
        }
218
 
182
 
-
 
183
        if (PSI_ROOT_FILESYSTEM !== '') { // disabled if ROOTFS defined
-
 
184
 
-
 
185
            return false;
-
 
186
        }
-
 
187
 
219
        if ((PSI_OS != 'WINNT') && preg_match('/^([^=]+=[^ \t]+)[ \t]+(.*)$/', $strProgramname, $strmatch)) {
188
        if ((PSI_OS != 'WINNT') && preg_match('/^([^=]+=[^ \t]+)[ \t]+(.*)$/', $strProgramname, $strmatch)) {
220
            $strSet = $strmatch[1].' ';
189
            $strSet = $strmatch[1].' ';
221
            $strProgramname = $strmatch[2];
190
            $strProgramname = $strmatch[2];
222
        } else {
191
        } else {
223
            $strSet = '';
192
            $strSet = '';
Line 279... Line 248...
279
 
248
 
280
        $strBuffer = '';
249
        $strBuffer = '';
281
        $strError = '';
250
        $strError = '';
282
        $pipes = array();
251
        $pipes = array();
283
        $descriptorspec = array(0=>array("pipe", "r"), 1=>array("pipe", "w"), 2=>array("pipe", "w"));
252
        $descriptorspec = array(0=>array("pipe", "r"), 1=>array("pipe", "w"), 2=>array("pipe", "w"));
284
        if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN === true) {
253
        if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
285
            if (PSI_OS == 'WINNT') {
254
            if (PSI_OS == 'WINNT') {
286
                $process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>nul", "r");
255
                $process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>nul", "r");
287
            } else {
256
            } else {
288
                $process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>/dev/null", "r");
257
                $process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>/dev/null", "r");
289
            }
258
            }
290
        } else {
259
        } else {
291
            $process = proc_open($strSet.$strProgram.$strArgs, $descriptorspec, $pipes);
260
            $process = proc_open($strSet.$strProgram.$strArgs, $descriptorspec, $pipes);
292
        }
261
        }
293
        if (is_resource($process)) {
262
        if (is_resource($process)) {
294
            $te = self::_timeoutfgets($pipes, $strBuffer, $strError, $timeout);
263
            $te = self::_timeoutfgets($pipes, $strBuffer, $strError, $timeout);
295
            if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN === true) {
264
            if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
296
                $return_value = pclose($pipes[1]);
265
                $return_value = pclose($pipes[1]);
297
            } else {
266
            } else {
298
                fclose($pipes[0]);
267
                fclose($pipes[0]);
299
                fclose($pipes[1]);
268
                fclose($pipes[1]);
300
                fclose($pipes[2]);
269
                fclose($pipes[2]);
Line 380... Line 349...
380
    /**
349
    /**
381
     * read a file and return the content as a string
350
     * read a file and return the content as a string
382
     *
351
     *
383
     * @param string  $strFileName name of the file which should be read
352
     * @param string  $strFileName name of the file which should be read
384
     * @param string  &$strRet     content of the file (reference)
353
     * @param string  &$strRet     content of the file (reference)
385
     * @param integer $intLines    control how many lines should be read
354
     * @param int     $intLines    control how many lines should be read
386
     * @param integer $intBytes    control how many bytes of each line should be read
355
     * @param int     $intBytes    control how many bytes of each line should be read
387
     * @param boolean $booErrorRep en- or disables the reporting of errors which should be logged
356
     * @param boolean $booErrorRep en- or disables the reporting of errors which should be logged
388
     *
357
     *
389
     * @return boolean command successfull or not
358
     * @return boolean command successfull or not
390
     */
359
     */
391
    public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
360
    public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
Line 403... Line 372...
403
 
372
 
404
                return true;
373
                return true;
405
            }
374
            }
406
        }
375
        }
407
 
376
 
-
 
377
        if (PSI_ROOT_FILESYSTEM !== '') {
-
 
378
            $rfsinfo = "[".PSI_ROOT_FILESYSTEM."]";
-
 
379
        } else {
-
 
380
            $rfsinfo = '';
-
 
381
        }
-
 
382
 
408
        $strFile = "";
383
        $strFile = "";
409
        $intCurLine = 1;
384
        $intCurLine = 1;
410
        $error = PSI_Error::singleton();
385
        $error = PSI_Error::singleton();
411
        if (file_exists($strFileName)) {
386
        if (file_exists(PSI_ROOT_FILESYSTEM.$strFileName)) {
412
            if (is_readable($strFileName)) {
387
            if (is_readable(PSI_ROOT_FILESYSTEM.$strFileName)) {
413
                if ($fd = fopen($strFileName, 'r')) {
388
                if ($fd = fopen(PSI_ROOT_FILESYSTEM.$strFileName, 'r')) {
414
                    while (!feof($fd)) {
389
                    while (!feof($fd)) {
415
                        $strFile .= fgets($fd, $intBytes);
390
                        $strFile .= fgets($fd, $intBytes);
416
                        if ($intLines <= $intCurLine && $intLines != 0) {
391
                        if ($intLines <= $intCurLine && $intLines != 0) {
417
                            break;
392
                            break;
418
                        } else {
393
                        } else {
Line 428... Line 403...
428
                            error_log("---".gmdate('r T')."--- Reading: ".$strFileName."\n".$strRet, 3, PSI_LOG);
403
                            error_log("---".gmdate('r T')."--- Reading: ".$strFileName."\n".$strRet, 3, PSI_LOG);
429
                        }
404
                        }
430
                    }
405
                    }
431
                } else {
406
                } else {
432
                    if ($booErrorRep) {
407
                    if ($booErrorRep) {
433
                        $error->addError('fopen('.$strFileName.')', 'file can not read by phpsysinfo');
408
                        $error->addError('fopen('.$rfsinfo.$strFileName.')', 'file can not read by phpsysinfo');
434
                    }
409
                    }
435
 
410
 
436
                    return false;
411
                    return false;
437
                }
412
                }
438
            } else {
413
            } else {
439
                if ($booErrorRep) {
414
                if ($booErrorRep) {
440
                    $error->addError('fopen('.$strFileName.')', 'file permission error');
415
                    $error->addError('fopen('.$rfsinfo.$strFileName.')', 'file permission error');
441
                }
416
                }
442
 
417
 
443
                return false;
418
                return false;
444
            }
419
            }
445
        } else {
420
        } else {
446
            if ($booErrorRep) {
421
            if ($booErrorRep) {
447
                $error->addError('file_exists('.$strFileName.')', 'the file does not exist on your machine');
422
                $error->addError('file_exists('.$rfsinfo.$strFileName.')', 'the file does not exist on your machine');
448
            }
423
            }
449
 
424
 
450
            return false;
425
            return false;
451
        }
426
        }
452
 
427
 
453
        return true;
428
        return true;
454
    }
429
    }
455
 
430
 
456
    /**
431
    /**
-
 
432
     * read a data file and return the content as a string
-
 
433
     *
-
 
434
     * @param string $strDataFileName name of the data file which should be read
-
 
435
     * @param string &$strRet         content of the data file (reference)
-
 
436
     *
-
 
437
     * @return boolean command successfull or not
-
 
438
     */
-
 
439
    public static function rftsdata($strDataFileName, &$strRet)
-
 
440
    {
-
 
441
        $strFile = "";
-
 
442
        $strFileName = PSI_APP_ROOT."/data/".$strDataFileName;
-
 
443
        $error = PSI_Error::singleton();
-
 
444
        if (file_exists($strFileName)) {
-
 
445
            if (is_readable($strFileName)) {
-
 
446
                if ($fd = fopen($strFileName, 'r')) {
-
 
447
                    while (!feof($fd)) {
-
 
448
                        $strFile .= fgets($fd, 4096);
-
 
449
                    }
-
 
450
                    fclose($fd);
-
 
451
                    $strRet = $strFile;
-
 
452
                } else {
-
 
453
                    $error->addError('fopen('.$strFileName.')', 'file can not read by phpsysinfo');
-
 
454
 
-
 
455
                    return false;
-
 
456
                }
-
 
457
            } else {
-
 
458
                $error->addError('fopen('.$strFileName.')', 'file permission error');
-
 
459
 
-
 
460
                return false;
-
 
461
            }
-
 
462
        } else {
-
 
463
            $error->addError('file_exists('.$strFileName.')', 'the file does not exist on your machine');
-
 
464
 
-
 
465
            return false;
-
 
466
        }
-
 
467
 
-
 
468
        return true;
-
 
469
    }
-
 
470
 
-
 
471
    /**
-
 
472
     * Find pathnames matching a pattern
-
 
473
     *
-
 
474
     * @param string $pattern the pattern. No tilde expansion or parameter substitution is done.
-
 
475
     * @param int    $flags
-
 
476
     *
-
 
477
     * @return an array containing the matched files/directories, an empty array if no file matched or false on error
-
 
478
     */
-
 
479
    public static function findglob($pattern, $flags = 0)
-
 
480
    {
-
 
481
        $outarr = glob(PSI_ROOT_FILESYSTEM.$pattern, $flags);
-
 
482
        if (PSI_ROOT_FILESYSTEM == '') {
-
 
483
            return $outarr;
-
 
484
        } elseif ($outarr === false) {
-
 
485
            return false;
-
 
486
        } else {
-
 
487
            $len = strlen(PSI_ROOT_FILESYSTEM);
-
 
488
            $newoutarr = array();
-
 
489
            foreach ($outarr as $out) {
-
 
490
                $newoutarr[] = substr($out, $len); // path without ROOTFS
-
 
491
            }
-
 
492
 
-
 
493
            return $newoutarr;
-
 
494
        }
-
 
495
    }
-
 
496
 
-
 
497
    /**
457
     * file exists
498
     * file exists
458
     *
499
     *
459
     * @param string $strFileName name of the file which should be check
500
     * @param string $strFileName name of the file which should be check
460
     *
501
     *
461
     * @return boolean command successfull or not
502
     * @return boolean command successfull or not
Line 473... Line 514...
473
                    return false;
514
                    return false;
474
                }
515
                }
475
            }
516
            }
476
        }
517
        }
477
 
518
 
478
        $exists =  file_exists($strFileName);
519
        $exists =  file_exists(PSI_ROOT_FILESYSTEM.$strFileName);
479
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && (substr(PSI_LOG, 0, 1)!="-") && (substr(PSI_LOG, 0, 1)!="+")) {
520
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && (substr(PSI_LOG, 0, 1)!="-") && (substr(PSI_LOG, 0, 1)!="+")) {
480
            if ((substr($strFileName, 0, 5) === "/dev/") && $exists) {
521
            if ((substr($strFileName, 0, 5) === "/dev/") && $exists) {
481
                error_log("---".gmdate('r T')."--- Reading: ".$strFileName."\ndevice exists\n", 3, PSI_LOG);
522
                error_log("---".gmdate('r T')."--- Reading: ".$strFileName."\ndevice exists\n", 3, PSI_LOG);
482
            }
523
            }
483
        }
524
        }
Line 532... Line 573...
532
     *
573
     *
533
     * @return void
574
     * @return void
534
     */
575
     */
535
    public static function checkForExtensions($arrExt = array())
576
    public static function checkForExtensions($arrExt = array())
536
    {
577
    {
537
        if (defined('PSI_SYSTEM_CODEPAGE') && ((strcasecmp(PSI_SYSTEM_CODEPAGE, "UTF-8") == 0) || (strcasecmp(PSI_SYSTEM_CODEPAGE, "CP437") == 0)))
578
        if (defined('PSI_SYSTEM_CODEPAGE') && (PSI_SYSTEM_CODEPAGE !== null) && ((strcasecmp(PSI_SYSTEM_CODEPAGE, "UTF-8") == 0) || (strcasecmp(PSI_SYSTEM_CODEPAGE, "CP437") == 0)))
538
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom');
579
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom');
539
        elseif (PSI_OS == 'WINNT')
580
        elseif (PSI_OS == 'WINNT')
540
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom', 'mbstring', 'com_dotnet');
581
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom', 'mbstring', 'com_dotnet');
541
        else
582
        else
542
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom', 'mbstring');
583
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom', 'mbstring');
Line 554... Line 595...
554
            }
595
            }
555
        }
596
        }
556
        $text .= "  </Error>\n";
597
        $text .= "  </Error>\n";
557
        $text .= "</phpsysinfo>";
598
        $text .= "</phpsysinfo>";
558
        if ($error) {
599
        if ($error) {
559
            header("Content-Type: text/xml\n\n");
600
            header('Content-Type: text/xml');
560
            echo $text;
601
            echo $text;
561
            die();
602
            die();
562
        }
603
        }
563
    }
604
    }
564
 
605
 
565
    /**
606
    /**
566
     * get the content of stdout/stderr with the option to set a timeout for reading
607
     * get the content of stdout/stderr with the option to set a timeout for reading
567
     *
608
     *
568
     * @param array   $pipes   array of file pointers for stdin, stdout, stderr (proc_open())
609
     * @param array  $pipes   array of file pointers for stdin, stdout, stderr (proc_open())
569
     * @param string  &$out    target string for the output message (reference)
610
     * @param string &$out    target string for the output message (reference)
570
     * @param string  &$err    target string for the error message (reference)
611
     * @param string &$err    target string for the error message (reference)
571
     * @param integer $timeout timeout value in seconds
612
     * @param int    $timeout timeout value in seconds
572
     *
613
     *
573
     * @return boolean timeout expired or not
614
     * @return boolean timeout expired or not
574
     */
615
     */
575
    private static function _timeoutfgets($pipes, &$out, &$err, $timeout)
616
    private static function _timeoutfgets($pipes, &$out, &$err, $timeout)
576
    {
617
    {
577
        $w = null;
618
        $w = null;
578
        $e = null;
619
        $e = null;
579
        $te = false;
620
        $te = false;
580
 
621
 
581
        if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN === true) {
622
        if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
582
            $pipe2 = false;
623
            $pipe2 = false;
583
        } else {
624
        } else {
584
            $pipe2 = true;
625
            $pipe2 = true;
585
        }
626
        }
586
        while (!(feof($pipes[1]) && (!$pipe2 || feof($pipes[2])))) {
627
        while (!(feof($pipes[1]) && (!$pipe2 || feof($pipes[2])))) {
Line 612... Line 653...
612
 
653
 
613
        return $te;
654
        return $te;
614
    }
655
    }
615
 
656
 
616
    /**
657
    /**
617
     * function for getting a list of values in the specified context
-
 
618
     * optionally filter this list, based on the list from third parameter
-
 
619
     *
-
 
620
     * @param $wmi object holds the COM object that we pull the WMI data from
-
 
621
     * @param string $strClass name of the class where the values are stored
-
 
622
     * @param array  $strValue filter out only needed values, if not set all values of the class are returned
-
 
623
     *
-
 
624
     * @return array content of the class stored in an array
-
 
625
     */
-
 
626
    public static function getWMI($wmi, $strClass, $strValue = array())
-
 
627
    {
-
 
628
        $arrData = array();
-
 
629
        if (gettype($wmi) === "object") {
-
 
630
            $value = "";
-
 
631
            try {
-
 
632
                $objWEBM = $wmi->Get($strClass);
-
 
633
                $arrProp = $objWEBM->Properties_;
-
 
634
                $arrWEBMCol = $objWEBM->Instances_();
-
 
635
                foreach ($arrWEBMCol as $objItem) {
-
 
636
                    if (is_array($arrProp)) {
-
 
637
                        reset($arrProp);
-
 
638
                    }
-
 
639
                    $arrInstance = array();
-
 
640
                    foreach ($arrProp as $propItem) {
-
 
641
                        $value = $objItem->{$propItem->Name}; //instead exploitable eval("\$value = \$objItem->".$propItem->Name.";");
-
 
642
                        if (empty($strValue)) {
-
 
643
                            if (is_string($value)) $arrInstance[$propItem->Name] = trim($value);
-
 
644
                            else $arrInstance[$propItem->Name] = $value;
-
 
645
                        } else {
-
 
646
                            if (in_array($propItem->Name, $strValue)) {
-
 
647
                                if (is_string($value)) $arrInstance[$propItem->Name] = trim($value);
-
 
648
                                else $arrInstance[$propItem->Name] = $value;
-
 
649
                            }
-
 
650
                        }
-
 
651
                    }
-
 
652
                    $arrData[] = $arrInstance;
-
 
653
                }
-
 
654
            } catch (Exception $e) {
-
 
655
                if (PSI_DEBUG) {
-
 
656
                    $error = PSI_Error::singleton();
-
 
657
                    $error->addError("getWMI()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));
-
 
658
                }
-
 
659
            }
-
 
660
        } elseif ((gettype($wmi) === "string") && (PSI_OS == 'Linux')) {
-
 
661
            $delimeter = '@@@DELIM@@@';
-
 
662
            if (self::executeProgram('wmic', '--delimiter="'.$delimeter.'" '.$wmi.' '.$strClass.'" 2>/dev/null', $strBuf, true) && preg_match("/^CLASS:\s/", $strBuf)) {
-
 
663
                if (self::$_cp) {
-
 
664
                    if (self::$_cp == 932) {
-
 
665
                        $codename = ' (SJIS)';
-
 
666
                    } elseif (self::$_cp == 949) {
-
 
667
                        $codename = ' (EUC-KR)';
-
 
668
                    } elseif (self::$_cp == 950) {
-
 
669
                        $codename = ' (BIG-5)';
-
 
670
                    } else {
-
 
671
                        $codename = '';
-
 
672
                    }
-
 
673
                    self::convertCP($strBuf, 'windows-'.self::$_cp.$codename);
-
 
674
                }
-
 
675
                $lines = preg_split('/\n/', $strBuf, -1, PREG_SPLIT_NO_EMPTY);
-
 
676
                if (count($lines) >=3) {
-
 
677
                    unset($lines[0]);
-
 
678
                    $names = preg_split('/'.$delimeter.'/', $lines[1], -1, PREG_SPLIT_NO_EMPTY);
-
 
679
                    $namesc = count($names);
-
 
680
                    unset($lines[1]);
-
 
681
                    foreach ($lines as $line) {
-
 
682
                        $arrInstance = array();
-
 
683
                        $values = preg_split('/'.$delimeter.'/', $line, -1);
-
 
684
                        if (count($values) == $namesc) {
-
 
685
                            foreach ($values as $id=>$value) {
-
 
686
                                if (empty($strValue)) {
-
 
687
                                    if ($value !== "(null)") $arrInstance[$names[$id]] = trim($value);
-
 
688
                                    else $arrInstance[$names[$id]] = null;
-
 
689
                                } else {
-
 
690
                                    if (in_array($names[$id], $strValue)) {
-
 
691
                                        if ($value !== "(null)") $arrInstance[$names[$id]] = trim($value);
-
 
692
                                        else $arrInstance[$names[$id]] = null;
-
 
693
                                    }
-
 
694
                                }
-
 
695
                            }
-
 
696
                            $arrData[] = $arrInstance;
-
 
697
                        }
-
 
698
                    }
-
 
699
                }
-
 
700
            }
-
 
701
        }
-
 
702
 
-
 
703
        return $arrData;
-
 
704
    }
-
 
705
 
-
 
706
    /**
-
 
707
     * get all configured plugins from phpsysinfo.ini (file must be included and processed before calling this function)
658
     * get all configured plugins from phpsysinfo.ini (file must be included and processed before calling this function)
708
     *
659
     *
709
     * @return array
660
     * @return array
710
     */
661
     */
711
    public static function getPlugins()
662
    public static function getPlugins()
Line 730... Line 681...
730
    {
681
    {
731
        return strnatcmp($a->getName(), $b->getName());
682
        return strnatcmp($a->getName(), $b->getName());
732
    }
683
    }
733
 
684
 
734
    /**
685
    /**
735
     * readReg function
686
     * get virtualizer from dmi data
736
     *
687
     *
737
     * @return boolean command successfull or not
688
     * @return string|null
738
     */
689
     */
739
    public static function readReg($reg, $strName, &$strBuffer, $booErrorRep = true)
690
    public static function decodevirtualizer($vendor_data)
740
    {
691
    {
741
        $arrBuffer = array();
692
        if (gettype($vendor_data) === "array") {
742
        $_hkey = array('HKEY_CLASSES_ROOT'=>0x80000000, 'HKEY_CURRENT_USER'=>0x80000001, 'HKEY_LOCAL_MACHINE'=>0x80000002, 'HKEY_USERS'=>0x80000003, 'HKEY_PERFORMANCE_DATA'=>0x80000004, 'HKEY_PERFORMANCE_TEXT'=>0x80000050, 'HKEY_PERFORMANCE_NLSTEXT'=>0x80000060, 'HKEY_CURRENT_CONFIG'=>0x80000005, 'HKEY_DYN_DATA'=>0x80000006);
693
            $vendarray = array(
743
 
-
 
744
        if ($reg === false) {
694
                'KVM' => 'kvm', // KVM
745
            if (defined('PSI_EMU_HOSTNAME')) {
695
                'Amazon EC2' => 'amazon', // Amazon EC2 Nitro using Linux KVM
746
                return false;
696
                'QEMU' => 'qemu', // QEMU
747
            }
-
 
748
            $last = strrpos($strName, "\\");
-
 
749
            $keyname = substr($strName, $last + 1);
697
                'VMware' => 'vmware', // VMware https://kb.vmware.com/s/article/1009458
750
            if (self::$_cp) {
698
                'VMW' => 'vmware',
751
                if (self::executeProgram('cmd', '/c chcp '.self::$_cp.' >nul & reg query "'.substr($strName, 0, $last).'" /v '.$keyname.' 2>&1', $strBuf, $booErrorRep) && (strlen($strBuf) > 0) && preg_match("/^\s*".$keyname."\s+REG_\S+\s+(.+)\s*$/mi", $strBuf, $buffer2)) {
699
                'innotek GmbH' => 'oracle', // Oracle VM VirtualBox
752
                    $strBuffer = $buffer2[1];
700
                'VirtualBox' => 'oracle',
753
                } else {
701
                'Xen' => 'xen', // Xen hypervisor
754
                    return false;
702
                'Bochs' => 'bochs', // Bochs
755
                }
-
 
756
            } else {
703
                'Parallels' => 'parallels', // Parallels
757
                if (self::executeProgram('reg', 'query "'.substr($strName, 0, $last).'" /v '.$keyname.' 2>&1', $strBuf, $booErrorRep) && (strlen($strBuf) > 0) && preg_match("/^\s*".$keyname."\s+REG_\S+\s+(.+)\s*$/mi", $strBuf, $buffer2)) {
-
 
758
                    $strBuffer = $buffer2[1];
704
                // https://wiki.freebsd.org/bhyve
759
                } else {
705
                'BHYVE' => 'bhyve', // bhyve
760
                    return false;
706
                'Hyper-V' => 'microsoft', // Hyper-V
761
                }
707
                'Microsoft Corporation Virtual Machine' => 'microsoft' // Hyper-V
762
            }
708
            );
763
        } elseif (gettype($reg) === "object") {
-
 
764
            $first = strpos($strName, "\\");
709
            for ($i = 0; $i < count($vendor_data); $i++) {
765
            $last = strrpos($strName, "\\");
-
 
766
            $hkey = substr($strName, 0, $first);
710
                foreach ($vendarray as $vend=>$virt) {
767
            if (isset($_hkey[$hkey])) {
-
 
768
                $sub_keys = new VARIANT();
-
 
769
                try {
-
 
770
                    $reg->Get("StdRegProv")->GetStringValue(strval($_hkey[$hkey]), substr($strName, $first+1, $last-$first-1), substr($strName, $last+1), $sub_keys);
-
 
771
                } catch (Exception $e) {
711
                    if (preg_match('/^'.$vend.'/', $vendor_data[$i])) {
772
                    if ($booErrorRep) {
712
                        return $virt;
773
                        $error = PSI_Error::singleton();
-
 
774
                        $error->addError("GetStringValue()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));
-
 
775
                    }
713
                    }
776
 
-
 
777
                    return false;
-
 
778
                }
714
                }
-
 
715
            }
779
                if (variant_get_type($sub_keys) !== VT_NULL) {
716
        } elseif (gettype($vendor_data) === "string") {
-
 
717
            $vidarray = array(
780
                    $strBuffer = strval($sub_keys);
718
                'bhyvebhyve' => 'bhyve', // bhyve
781
                } else {
719
                'KVMKVMKVM' => 'kvm', // KVM
-
 
720
                'MicrosoftHv' => 'microsoft', // Hyper-V
782
                    return false;
721
                'lrpepyhvr' => 'parallels', // Parallels
-
 
722
                'UnisysSpar64' => 'spar', // Unisys sPar
-
 
723
                'VMwareVMware' => 'vmware', // VMware
-
 
724
                'XenVMMXenVMM' => 'xen', // Xen hypervisor
-
 
725
                'ACRNACRNACRN' => 'acrn', // ACRN hypervisor
783
                }
726
                'TCGTCGTCGTCG' => 'qemu', // QEMU
-
 
727
                'QNXQVMBSQG' => 'qnx', // QNX hypervisor
-
 
728
                'VBoxVBoxVBox' => 'oracle' // Oracle VM VirtualBox
784
            } else {
729
            );
-
 
730
            $shortvendorid = trim(preg_replace('/[\s!\.]/', '', $vendor_data));
-
 
731
            if (($shortvendorid !== "") && isset($vidarray[$shortvendorid])) {
785
               return false;
732
                return $vidarray[$shortvendorid];
786
            }
733
            }
787
        }
734
        }
788
 
735
 
789
        return true;
736
        return null;
790
    }
737
    }
791
 
738
 
-
 
739
 
792
    /**
740
    /**
793
     * enumKey function
741
     * readdmimemdata function
794
     *
742
     *
795
     * @return boolean command successfull or not
743
     * @return array
796
     */
744
     */
797
    public static function enumKey($reg, $strName, &$arrBuffer, $booErrorRep = true)
745
    public static function readdmimemdata()
798
    {
746
    {
-
 
747
        if ((PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME') && (self::$_dmimd === null)) {
-
 
748
            self::$_dmimd = array();
799
        $arrBuffer = array();
749
            $buffer = '';
800
        $_hkey = array('HKEY_CLASSES_ROOT'=>0x80000000, 'HKEY_CURRENT_USER'=>0x80000001, 'HKEY_LOCAL_MACHINE'=>0x80000002, 'HKEY_USERS'=>0x80000003, 'HKEY_PERFORMANCE_DATA'=>0x80000004, 'HKEY_PERFORMANCE_TEXT'=>0x80000050, 'HKEY_PERFORMANCE_NLSTEXT'=>0x80000060, 'HKEY_CURRENT_CONFIG'=>0x80000005, 'HKEY_DYN_DATA'=>0x80000006);
750
            if (defined('PSI_DMIDECODE_ACCESS') && (strtolower(PSI_DMIDECODE_ACCESS)==='data')) {
801
 
-
 
802
        if ($reg === false) {
751
                self::rftsdata('dmidecode.tmp', $buffer);
803
            if (defined('PSI_EMU_HOSTNAME')) {
752
            } elseif (self::_findProgram('dmidecode')) {
804
                return false;
753
                self::executeProgram('dmidecode', '-t 17', $buffer, PSI_DEBUG);
805
            }
754
            }
806
            if (self::$_cp) {
755
            if (!empty($buffer)) {
807
                if (self::executeProgram('cmd', '/c chcp '.self::$_cp.' >nul & reg query "'.$strName.'" 2>&1', $strBuf, $booErrorRep) && (strlen($strBuf) > 0) && preg_match_all("/^".preg_replace("/\\\\/", "\\\\\\\\", $strName)."\\\\(.*)/mi", $strBuf, $buffer2)) {
756
                $banks = preg_split('/^(?=Handle\s)/m', $buffer, -1, PREG_SPLIT_NO_EMPTY);
808
                    foreach ($buffer2[1] as $sub_key) {
757
                foreach ($banks as $bank) if (preg_match('/^Handle\s/', $bank)) {
809
                        $arrBuffer[] = trim($sub_key);
758
                    $lines = preg_split("/\n/", $bank, -1, PREG_SPLIT_NO_EMPTY);
810
                    }
759
                    $mem = array();
811
                } else {
760
                    foreach ($lines as $line) if (preg_match('/^\s+([^:]+):(.+)/', $line, $params)) {
812
                    return false;
761
                        if (preg_match('/^0x([A-F\d]+)/', $params2 = trim($params[2]), $buff)) {
813
                }
762
                            $mem[trim($params[1])] = trim($buff[1]);
814
            } else {
763
                        } elseif ($params2 != '') {
815
                if (self::executeProgram('reg', 'query "'.$strName.'" 2>&1', $strBuf, $booErrorRep) && (strlen($strBuf) > 0) && preg_match_all("/^".preg_replace("/\\\\/", "\\\\\\\\", $strName)."\\\\(.*)/mi", $strBuf, $buffer2)) {
-
 
816
                    foreach ($buffer2[1] as $sub_key) {
764
                            $mem[trim($params[1])] = $params2;
817
                        $arrBuffer[] = trim($sub_key);
765
                        }
818
                    }
766
                    }
819
                } else {
-
 
820
                    return false;
-
 
821
                }
-
 
822
            }
-
 
823
        } elseif (gettype($reg) === "object") {
-
 
824
            $first = strpos($strName, "\\");
-
 
825
            $hkey = substr($strName, 0, $first);
-
 
826
            if (isset($_hkey[$hkey])) {
-
 
827
                $sub_keys = new VARIANT();
-
 
828
                try {
-
 
829
                   $reg->Get("StdRegProv")->EnumKey(strval($_hkey[$hkey]), substr($strName, $first+1), $sub_keys);
-
 
830
                } catch (Exception $e) {
-
 
831
                    if ($booErrorRep) {
767
                    if (!empty($mem)) {
832
                        $error = PSI_Error::singleton();
768
                        self::$_dmimd[] = $mem;
833
                        $error->addError("enumKey()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));;
-
 
834
                    }
769
                    }
835
 
-
 
836
                    return false;
-
 
837
                }
-
 
838
                if (variant_get_type($sub_keys) !== VT_NULL) foreach ($sub_keys as $sub_key) {
-
 
839
                    $arrBuffer[] = $sub_key;
-
 
840
                } else {
-
 
841
                    return false;
-
 
842
                }
770
                }
843
            } else {
-
 
844
               return false;
-
 
845
            }
771
            }
846
        }
772
        }
847
 
773
 
848
        return true;
-
 
849
    }
-
 
850
 
-
 
851
 
-
 
852
    /**
-
 
853
     * initWMI function
-
 
854
     *
-
 
855
     * @return string, object or false
-
 
856
     */
-
 
857
    public static function initWMI($namespace, $booErrorRep = false)
-
 
858
    {
-
 
859
        $wmi = false;
-
 
860
        try {
-
 
861
            if (PSI_OS == 'Linux') {
-
 
862
                if (defined('PSI_EMU_HOSTNAME'))
-
 
863
                    $wmi = '--namespace="'.$namespace.'" -U '.PSI_EMU_USER.'%'.PSI_EMU_PASSWORD.' //'.PSI_EMU_HOSTNAME.' "select * from';
-
 
864
            } elseif (PSI_OS == 'WINNT') {
-
 
865
                $objLocator = new COM('WbemScripting.SWbemLocator');
-
 
866
                if (defined('PSI_EMU_HOSTNAME'))
-
 
867
                    $wmi = $objLocator->ConnectServer(PSI_EMU_HOSTNAME, $namespace, PSI_EMU_USER, PSI_EMU_PASSWORD);
-
 
868
                else
-
 
869
                    $wmi = $objLocator->ConnectServer('', $namespace);
-
 
870
            }
-
 
871
        } catch (Exception $e) {
-
 
872
            if ($booErrorRep) {
-
 
873
                $error = PSI_Error::singleton();
-
 
874
                $error->addError("WMI connect ".$namespace." error", "PhpSysInfo can not connect to the WMI interface for security reasons.\nCheck an authentication mechanism for the directory where phpSysInfo is installed or credentials.");
-
 
875
            }
-
 
876
        }
-
 
877
 
-
 
878
        return $wmi;
774
        return self::$_dmimd;
879
    }
-
 
880
 
-
 
881
    /**
-
 
882
     * convertCP function
-
 
883
     *
-
 
884
     * @return void
-
 
885
     */
-
 
886
    public static function convertCP(&$strBuf, $encoding)
-
 
887
    {
-
 
888
        if (defined('PSI_SYSTEM_CODEPAGE') && ($encoding != null) && ($encoding != PSI_SYSTEM_CODEPAGE)) {
-
 
889
            $systemcp = PSI_SYSTEM_CODEPAGE;
-
 
890
            if (preg_match("/^windows-\d+ \((.+)\)$/", $systemcp, $buf)) {
-
 
891
                $systemcp = $buf[1];
-
 
892
            }
-
 
893
            if (preg_match("/^windows-\d+ \((.+)\)$/", $encoding, $buf)) {
-
 
894
                $encoding = $buf[1];
-
 
895
            }
-
 
896
            $enclist = mb_list_encodings();
-
 
897
            if (in_array($encoding, $enclist) && in_array($systemcp, $enclist)) {
-
 
898
                $strBuf = mb_convert_encoding($strBuf, $encoding, $systemcp);
-
 
899
            } elseif (function_exists("iconv")) {
-
 
900
                if (($iconvout=iconv($systemcp, $encoding.'//IGNORE', $strBuf))!==false) {
-
 
901
                    $strBuf = $iconvout;
-
 
902
                }
-
 
903
            } elseif (function_exists("libiconv") && (($iconvout=libiconv($systemcp, $encoding, $strBuf))!==false)) {
-
 
904
                $strBuf = $iconvout;
-
 
905
            }
-
 
906
        }
-
 
907
    }
775
    }
908
}
776
}