Subversion Repositories ALCASAR

Rev

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

Rev 2770 Rev 2976
Line 30... Line 30...
30
     *
30
     *
31
     * @var integer
31
     * @var integer
32
     */
32
     */
33
    private static $_cp = null;
33
    private static $_cp = null;
34
 
34
 
-
 
35
    /**
-
 
36
     * value of checking run as administrator
-
 
37
     *
-
 
38
     * @var boolean
-
 
39
     */
-
 
40
    private static $_asadmin = null;
-
 
41
 
35
    public static function setcp($cp)
42
    public static function setcp($cp)
36
    {
43
    {
37
        CommonFunctions::$_cp = $cp;
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;
38
    }
69
    }
39
 
70
 
40
    private static function _parse_log_file($string)
71
    private static function _parse_log_file($string)
41
    {
72
    {
42
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
73
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
Line 68... Line 99...
68
     *
99
     *
69
     * @param string $strProgram name of the program
100
     * @param string $strProgram name of the program
70
     *
101
     *
71
     * @return string|null complete path and name of the program
102
     * @return string|null complete path and name of the program
72
     */
103
     */
73
    private static function _findProgram($strProgram)
104
    public static function _findProgram($strProgram)
74
    {
105
    {
75
        $path_parts = pathinfo($strProgram);
106
        $path_parts = pathinfo($strProgram);
76
        if (empty($path_parts['basename'])) {
107
        if (empty($path_parts['basename'])) {
77
            return null;
108
            return null;
78
        }
109
        }
Line 82... Line 113...
82
            if ((PSI_OS == 'WINNT') && empty($path_parts['extension'])) {
113
            if ((PSI_OS == 'WINNT') && empty($path_parts['extension'])) {
83
                $strProgram .= '.exe';
114
                $strProgram .= '.exe';
84
                $path_parts = pathinfo($strProgram);
115
                $path_parts = pathinfo($strProgram);
85
            }
116
            }
86
            if (PSI_OS == 'WINNT') {
117
            if (PSI_OS == 'WINNT') {
87
                if (CommonFunctions::readenv('Path', $serverpath)) {
118
                if (self::readenv('Path', $serverpath)) {
88
                    $arrPath = preg_split('/;/', $serverpath, -1, PREG_SPLIT_NO_EMPTY);
119
                    $arrPath = preg_split('/;/', $serverpath, -1, PREG_SPLIT_NO_EMPTY);
89
                }
120
                }
90
            } else {
121
            } else {
91
                if (CommonFunctions::readenv('PATH', $serverpath)) {
122
                if (self::readenv('PATH', $serverpath)) {
92
                    $arrPath = preg_split('/:/', $serverpath, -1, PREG_SPLIT_NO_EMPTY);
123
                    $arrPath = preg_split('/:/', $serverpath, -1, PREG_SPLIT_NO_EMPTY);
93
                }
124
                }
94
            }
125
            }
95
            if (defined('PSI_UNAMEO') && (PSI_UNAMEO === 'Android') && !empty($arrPath)) {
126
            if (defined('PSI_UNAMEO') && (PSI_UNAMEO === 'Android') && !empty($arrPath)) {
96
                array_push($arrPath, '/system/bin'); // Termux patch
127
                array_push($arrPath, '/system/bin'); // Termux patch
Line 106... Line 137...
106
            array_push($arrPath, $path_parts['dirname']);
137
            array_push($arrPath, $path_parts['dirname']);
107
            $strProgram = $path_parts['basename'];
138
            $strProgram = $path_parts['basename'];
108
        }
139
        }
109
 
140
 
110
        //add some default paths if we still have no paths here
141
        //add some default paths if we still have no paths here
111
        if (empty($arrPath) && PSI_OS != 'WINNT') {
142
        if (empty($arrPath) && (PSI_OS != 'WINNT')) {
112
            if (PSI_OS == 'Android') {
143
            if (PSI_OS == 'Android') {
113
                array_push($arrPath, '/system/bin');
144
                array_push($arrPath, '/system/bin');
114
            } else {
145
            } else {
115
                array_push($arrPath, '/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
146
                array_push($arrPath, '/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
116
            }
147
            }
117
        }
148
        }
118
 
149
 
119
        $exceptPath = "";
150
        $exceptPath = "";
120
        if ((PSI_OS == 'WINNT') && CommonFunctions::readenv('WinDir', $windir)) {
151
        if ((PSI_OS == 'WINNT') && self::readenv('WinDir', $windir)) {
121
            foreach ($arrPath as $strPath) {
152
            foreach ($arrPath as $strPath) {
122
                if ((strtolower($strPath) == $windir."\\system32") && is_dir($windir."\\SysWOW64")) {
153
                if ((strtolower($strPath) == strtolower($windir)."\\system32") && is_dir($windir."\\SysWOW64")) {
123
                    if (is_dir($windir."\\sysnative")) {
154
                    if (is_dir($windir."\\sysnative\\drivers")) { // or strlen(decbin(~0)) == 32; is_dir($windir."\\sysnative") sometimes does not work
124
                        $exceptPath = $windir."\\sysnative"; //32-bit PHP on 64-bit Windows
155
                        $exceptPath = $windir."\\sysnative"; //32-bit PHP on 64-bit Windows
125
                    } else {
156
                    } else {
126
                        $exceptPath = $windir."\\SysWOW64"; //64-bit PHP on 64-bit Windows
157
                        $exceptPath = $windir."\\SysWOW64"; //64-bit PHP on 64-bit Windows
127
                    }
158
                    }
128
                    array_push($arrPath, $exceptPath);
159
                    array_push($arrPath, $exceptPath);
Line 143... Line 174...
143
                $strPathS = $strPath."/";
174
                $strPathS = $strPath."/";
144
            }
175
            }
145
            if (($strPath !== $exceptPath) && !is_dir($strPath)) {
176
            if (($strPath !== $exceptPath) && !is_dir($strPath)) {
146
                continue;
177
                continue;
147
            }
178
            }
148
            if (PSI_OS == 'WINNT') {
-
 
149
                $strProgrammpath = $strPathS.$strProgram;
-
 
150
            } else {
-
 
151
                $strProgrammpath = $strPathS.$strProgram;
179
            $strProgrammpath = $strPathS.$strProgram;
152
            }
-
 
153
            if (is_executable($strProgrammpath)) {
180
            if (is_executable($strProgrammpath) || ((PSI_OS == 'WINNT') && (strtolower($path_parts['extension']) == 'py'))) {
154
                return $strProgrammpath;
181
                return $strProgrammpath;
155
            }
182
            }
156
        }
183
        }
157
 
184
 
158
        return null;
185
        return null;
159
    }
186
    }
160
 
187
 
161
    /**
188
    /**
162
     * Execute a system program. return a trim()'d result.
189
     * Execute a system program. return a trim()'d result.
163
     * does very crude pipe checking.  you need ' | ' for it to work
190
     * does very crude pipe and multiple commands (on WinNT) checking.  you need ' | ' or ' & ' for it to work
164
     * ie $program = CommonFunctions::executeProgram('netstat', '-anp | grep LIST');
191
     * ie $program = CommonFunctions::executeProgram('netstat', '-anp | grep LIST');
165
     * NOT $program = CommonFunctions::executeProgram('netstat', '-anp|grep LIST');
192
     * NOT $program = CommonFunctions::executeProgram('netstat', '-anp|grep LIST');
166
     *
193
     *
167
     * @param string  $strProgramname name of the program
194
     * @param string  $strProgramname name of the program
168
     * @param string  $strArgs        arguments to the program
195
     * @param string  $strArgs        arguments to the program
Line 187... Line 214...
187
 
214
 
188
                return true;
215
                return true;
189
            }
216
            }
190
        }
217
        }
191
 
218
 
192
        if ((PSI_OS !== 'WINNT') && preg_match('/^([^=]+=[^ \t]+)[ \t]+(.*)$/', $strProgramname, $strmatch)) {
219
        if ((PSI_OS != 'WINNT') && preg_match('/^([^=]+=[^ \t]+)[ \t]+(.*)$/', $strProgramname, $strmatch)) {
193
            $strSet = $strmatch[1].' ';
220
            $strSet = $strmatch[1].' ';
194
            $strProgramname = $strmatch[2];
221
            $strProgramname = $strmatch[2];
195
        } else {
222
        } else {
196
            $strSet = '';
223
            $strSet = '';
197
        }
224
        }
Line 207... Line 234...
207
            if (preg_match('/\s/', $strProgram)) {
234
            if (preg_match('/\s/', $strProgram)) {
208
                $strProgram = '"'.$strProgram.'"';
235
                $strProgram = '"'.$strProgram.'"';
209
            }
236
            }
210
        }
237
        }
211
 
238
 
212
        if ((PSI_OS !== 'WINNT') && defined('PSI_SUDO_COMMANDS') && is_string(PSI_SUDO_COMMANDS)) {
239
        if ((PSI_OS != 'WINNT') && defined('PSI_SUDO_COMMANDS') && is_string(PSI_SUDO_COMMANDS)) {
213
            if (preg_match(ARRAY_EXP, PSI_SUDO_COMMANDS)) {
240
            if (preg_match(ARRAY_EXP, PSI_SUDO_COMMANDS)) {
214
                $sudocommands = eval(PSI_SUDO_COMMANDS);
241
                $sudocommands = eval(PSI_SUDO_COMMANDS);
215
            } else {
242
            } else {
216
                $sudocommands = array(PSI_SUDO_COMMANDS);
243
                $sudocommands = array(PSI_SUDO_COMMANDS);
217
            }
244
            }
Line 231... Line 258...
231
                    }
258
                    }
232
                }
259
                }
233
            }
260
            }
234
        }
261
        }
235
 
262
 
236
        // see if we've gotten a |, if we have we need to do path checking on the cmd
263
        // see if we've gotten a | or &, if we have we need to do path checking on the cmd
237
        if ($strArgs) {
264
        if ($strArgs) {
238
            $arrArgs = preg_split('/ /', $strArgs, -1, PREG_SPLIT_NO_EMPTY);
265
            $arrArgs = preg_split('/ /', $strArgs, -1, PREG_SPLIT_NO_EMPTY);
239
            for ($i = 0, $cnt_args = count($arrArgs); $i < $cnt_args; $i++) {
266
            for ($i = 0, $cnt_args = count($arrArgs); $i < $cnt_args; $i++) {
240
                if ($arrArgs[$i] == '|') {
267
                if (($arrArgs[$i] == '|') || ($arrArgs[$i] == '&')) {
241
                    $strCmd = $arrArgs[$i + 1];
268
                    $strCmd = $arrArgs[$i + 1];
242
                    $strNewcmd = self::_findProgram($strCmd);
269
                    $strNewcmd = self::_findProgram($strCmd);
-
 
270
                    if ($arrArgs[$i] == '|') {
243
                    $strArgs = preg_replace("/\| ".$strCmd.'/', '| "'.$strNewcmd.'"', $strArgs);
271
                        $strArgs = preg_replace('/\| '.$strCmd.'/', '| "'.$strNewcmd.'"', $strArgs);
-
 
272
                    } else {
-
 
273
                        $strArgs = preg_replace('/& '.$strCmd.'/', '& "'.$strNewcmd.'"', $strArgs);
-
 
274
                    }
244
                }
275
                }
245
            }
276
            }
246
            $strArgs = ' '.$strArgs;
277
            $strArgs = ' '.$strArgs;
247
        }
278
        }
248
 
279
 
Line 305... Line 336...
305
     * @return value if successfull or null if not
336
     * @return value if successfull or null if not
306
     */
337
     */
307
    public static function rolv($similarFileName, $match = "//", $replace = "")
338
    public static function rolv($similarFileName, $match = "//", $replace = "")
308
    {
339
    {
309
        $filename = preg_replace($match, $replace, $similarFileName);
340
        $filename = preg_replace($match, $replace, $similarFileName);
310
        if (CommonFunctions::fileexists($filename) && CommonFunctions::rfts($filename, $buf, 1, 4096, false) && (($buf=trim($buf)) != "")) {
341
        if (self::fileexists($filename) && self::rfts($filename, $buf, 1, 4096, false) && (($buf=trim($buf)) != "")) {
311
            return $buf;
342
            return $buf;
312
        } else {
343
        } else {
313
            return null;
344
            return null;
314
        }
345
        }
315
    }
346
    }
Line 501... Line 532...
501
     *
532
     *
502
     * @return void
533
     * @return void
503
     */
534
     */
504
    public static function checkForExtensions($arrExt = array())
535
    public static function checkForExtensions($arrExt = array())
505
    {
536
    {
506
        if ((strcasecmp(PSI_SYSTEM_CODEPAGE, "UTF-8") == 0) || (strcasecmp(PSI_SYSTEM_CODEPAGE, "CP437") == 0))
537
        if (defined('PSI_SYSTEM_CODEPAGE') && ((strcasecmp(PSI_SYSTEM_CODEPAGE, "UTF-8") == 0) || (strcasecmp(PSI_SYSTEM_CODEPAGE, "CP437") == 0)))
507
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom');
538
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom');
508
        elseif (PSI_OS == "WINNT")
539
        elseif (PSI_OS == 'WINNT')
509
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom', 'mbstring', 'com_dotnet');
540
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom', 'mbstring', 'com_dotnet');
510
        else
541
        else
511
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom', 'mbstring');
542
            $arrReq = array('simplexml', 'pcre', 'xml', 'dom', 'mbstring');
512
        $extensions = array_merge($arrExt, $arrReq);
543
        $extensions = array_merge($arrExt, $arrReq);
513
        $text = "";
544
        $text = "";
Line 624... Line 655...
624
                if (PSI_DEBUG) {
655
                if (PSI_DEBUG) {
625
                    $error = PSI_Error::singleton();
656
                    $error = PSI_Error::singleton();
626
                    $error->addError("getWMI()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));
657
                    $error->addError("getWMI()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));
627
                }
658
                }
628
            }
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
            }
629
        }
701
        }
630
 
702
 
631
        return $arrData;
703
        return $arrData;
632
    }
704
    }
633
 
705
 
Line 664... Line 736...
664
     *
736
     *
665
     * @return boolean command successfull or not
737
     * @return boolean command successfull or not
666
     */
738
     */
667
    public static function readReg($reg, $strName, &$strBuffer, $booErrorRep = true)
739
    public static function readReg($reg, $strName, &$strBuffer, $booErrorRep = true)
668
    {
740
    {
-
 
741
        $arrBuffer = array();
669
        $strBuffer = '';
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);
-
 
743
 
670
        if ($reg === false) {
744
        if ($reg === false) {
-
 
745
            if (defined('PSI_EMU_HOSTNAME')) {
-
 
746
                return false;
-
 
747
            }
671
            $last = strrpos($strName, "\\");
748
            $last = strrpos($strName, "\\");
672
            $keyname = substr($strName, $last + 1);
749
            $keyname = substr($strName, $last + 1);
673
            if (CommonFunctions::$_cp) {
750
            if (self::$_cp) {
674
                if (CommonFunctions::executeProgram('cmd', '/c chcp '.CommonFunctions::$_cp.' && 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)) {
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)) {
675
                    $strBuffer = $buffer2[1];
752
                    $strBuffer = $buffer2[1];
676
                } else {
753
                } else {
677
                    return false;
754
                    return false;
678
                }
755
                }
679
            } else {
756
            } else {
680
                if (CommonFunctions::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)) {
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)) {
681
                    $strBuffer = $buffer2[1];
758
                    $strBuffer = $buffer2[1];
682
                } else {
759
                } else {
683
                    return false;
760
                    return false;
684
                }
761
                }
685
            }
762
            }
686
        } elseif (gettype($reg) === "object") {
763
        } elseif (gettype($reg) === "object") {
-
 
764
            $first = strpos($strName, "\\");
-
 
765
            $last = strrpos($strName, "\\");
-
 
766
            $hkey = substr($strName, 0, $first);
687
            try {
767
            if (isset($_hkey[$hkey])) {
688
                $strBuffer = $reg->RegRead($strName);
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);
689
            } catch (Exception $e) {
771
                } catch (Exception $e) {
690
                if ($booErrorRep) {
772
                    if ($booErrorRep) {
691
                    $error = PSI_Error::singleton();
773
                        $error = PSI_Error::singleton();
692
                    $error->addError("readReg()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));
774
                        $error->addError("GetStringValue()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));
693
                }
775
                    }
694
 
776
 
-
 
777
                    return false;
-
 
778
                }
-
 
779
                if (variant_get_type($sub_keys) !== VT_NULL) {
-
 
780
                    $strBuffer = strval($sub_keys);
-
 
781
                } else {
-
 
782
                    return false;
-
 
783
                }
-
 
784
            } else {
695
                return false;
785
               return false;
696
            }
786
            }
697
        }
787
        }
698
 
788
 
699
        return true;
789
        return true;
700
    }
790
    }
701
 
791
 
702
 
-
 
703
    /**
792
    /**
704
     * enumKey function
793
     * enumKey function
705
     *
794
     *
706
     * @return boolean command successfull or not
795
     * @return boolean command successfull or not
707
     */
796
     */
708
    public static function enumKey($key, $strName, &$arrBuffer, $booErrorRep = true)
797
    public static function enumKey($reg, $strName, &$arrBuffer, $booErrorRep = true)
709
    {
798
    {
-
 
799
        $arrBuffer = array();
710
        $_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);
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);
711
 
801
 
712
        $arrBuffer = array();
802
        if ($reg === false) {
-
 
803
            if (defined('PSI_EMU_HOSTNAME')) {
713
        if ($key === false) {
804
                return false;
-
 
805
            }
714
            if (CommonFunctions::$_cp) {
806
            if (self::$_cp) {
715
                if (CommonFunctions::executeProgram('cmd', '/c chcp '.CommonFunctions::$_cp.' && reg query "'.$strName.'" 2>&1', $strBuf, $booErrorRep) && (strlen($strBuf) > 0) && preg_match_all("/^".preg_replace("/\\\\/", "\\\\\\\\", $strName)."\\\\(.*)/mi", $strBuf, $buffer2)) {
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)) {
716
                    foreach ($buffer2[1] as $sub_key) {
808
                    foreach ($buffer2[1] as $sub_key) {
717
                        $arrBuffer[] = trim($sub_key);
809
                        $arrBuffer[] = trim($sub_key);
718
                    }
810
                    }
719
                } else {
811
                } else {
720
                    return false;
812
                    return false;
721
                }
813
                }
722
            } else {
814
            } else {
723
                if (CommonFunctions::executeProgram('reg', 'query "'.$strName.'" 2>&1', $strBuf, $booErrorRep) && (strlen($strBuf) > 0) && preg_match_all("/^".preg_replace("/\\\\/", "\\\\\\\\", $strName)."\\\\(.*)/mi", $strBuf, $buffer2)) {
815
                if (self::executeProgram('reg', 'query "'.$strName.'" 2>&1', $strBuf, $booErrorRep) && (strlen($strBuf) > 0) && preg_match_all("/^".preg_replace("/\\\\/", "\\\\\\\\", $strName)."\\\\(.*)/mi", $strBuf, $buffer2)) {
724
                    foreach ($buffer2[1] as $sub_key) {
816
                    foreach ($buffer2[1] as $sub_key) {
725
                        $arrBuffer[] = trim($sub_key);
817
                        $arrBuffer[] = trim($sub_key);
726
                    }
818
                    }
727
                } else {
819
                } else {
728
                    return false;
820
                    return false;
729
                }
821
                }
730
            }
822
            }
731
        } elseif (gettype($key) === "object") {
823
        } elseif (gettype($reg) === "object") {
732
            $first = strpos($strName, "\\");
824
            $first = strpos($strName, "\\");
733
            $hkey = substr($strName, 0, $first);
825
            $hkey = substr($strName, 0, $first);
734
            if (isset($_hkey[$hkey])) {
826
            if (isset($_hkey[$hkey])) {
735
                $sub_keys = new VARIANT();
827
                $sub_keys = new VARIANT();
736
                try {
828
                try {
737
                   $key->EnumKey(strval($_hkey[$hkey]), substr($strName, $first+1), $sub_keys);
829
                   $reg->Get("StdRegProv")->EnumKey(strval($_hkey[$hkey]), substr($strName, $first+1), $sub_keys);
738
                } catch (Exception $e) {
830
                } catch (Exception $e) {
739
                    if ($booErrorRep) {
831
                    if ($booErrorRep) {
740
                        $error = PSI_Error::singleton();
832
                        $error = PSI_Error::singleton();
741
                        $error->addError("enumKey()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));;
833
                        $error->addError("enumKey()", preg_replace('/<br\/>/', "\n", preg_replace('/<b>|<\/b>/', '', $e->getMessage())));;
742
                    }
834
                    }
743
 
835
 
744
                    return false;
836
                    return false;
745
                }
837
                }
746
                foreach ($sub_keys as $sub_key) {
838
                if (variant_get_type($sub_keys) !== VT_NULL) foreach ($sub_keys as $sub_key) {
747
                    $arrBuffer[] = $sub_key;
839
                    $arrBuffer[] = $sub_key;
-
 
840
                } else {
-
 
841
                    return false;
748
                }
842
                }
749
            } else {
843
            } else {
750
               return false;
844
               return false;
751
            }
845
            }
752
        }
846
        }
753
 
847
 
754
        return true;
848
        return true;
755
    }
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;
-
 
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
    }
756
}
908
}