Subversion Repositories ALCASAR

Rev

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

Rev 3037 Rev 3100
Line 154... Line 154...
154
     * does very crude pipe and multiple commands (on WinNT) checking.  you need ' | ' or ' & ' for it to work
154
     * does very crude pipe and multiple commands (on WinNT) checking.  you need ' | ' or ' & ' for it to work
155
     * ie $program = CommonFunctions::executeProgram('netstat', '-anp | grep LIST');
155
     * ie $program = CommonFunctions::executeProgram('netstat', '-anp | grep LIST');
156
     * NOT $program = CommonFunctions::executeProgram('netstat', '-anp|grep LIST');
156
     * NOT $program = CommonFunctions::executeProgram('netstat', '-anp|grep LIST');
157
     *
157
     *
158
     * @param string  $strProgramname name of the program
158
     * @param string  $strProgramname name of the program
159
     * @param string  $strArgs        arguments to the program
159
     * @param string  $strArguments   arguments to the program
160
     * @param string  &$strBuffer     output of the command
160
     * @param string  &$strBuffer     output of the command
161
     * @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
162
     * @param int     $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)
163
     *
163
     *
164
     * @return boolean command successfull or not
164
     * @return boolean command successfull or not
165
     */
165
     */
166
    public static function executeProgram($strProgramname, $strArgs, &$strBuffer, $booErrorRep = true, $timeout = PSI_EXEC_TIMEOUT_INT)
166
    public static function executeProgram($strProgramname, $strArguments, &$strBuffer, $booErrorRep = true, $timeout = PSI_EXEC_TIMEOUT_INT, $separator = '')
167
    {
167
    {
-
 
168
        if (PSI_ROOT_FILESYSTEM !== '') { // disabled if ROOTFS defined
-
 
169
 
-
 
170
            return false;
-
 
171
        }
-
 
172
 
-
 
173
        if ((PSI_OS != 'WINNT') && preg_match('/^([^=]+=[^ \t]+)[ \t]+(.*)$/', $strProgramname, $strmatch)) {
-
 
174
            $strSet = $strmatch[1].' ';
-
 
175
            $strProgramname = $strmatch[2];
-
 
176
        } else {
-
 
177
            $strSet = '';
-
 
178
        }
-
 
179
        $strAll = trim($strSet.$strProgramname.' '.$strArguments);
-
 
180
 
168
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
181
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
169
            $out = self::_parse_log_file("Executing: ".trim($strProgramname.' '.$strArgs));
182
            $out = self::_parse_log_file("Executing: ".$strAll);
170
            if ($out == false) {
183
            if ($out == false) {
171
                if (substr(PSI_LOG, 0, 1)=="-") {
184
                if (substr(PSI_LOG, 0, 1)=="-") {
172
                    $strBuffer = '';
185
                    $strBuffer = '';
173
 
186
 
174
                    return false;
187
                    return false;
Line 178... Line 191...
178
 
191
 
179
                return true;
192
                return true;
180
            }
193
            }
181
        }
194
        }
182
 
195
 
-
 
196
        $PathStr = '';
-
 
197
        if (defined('PSI_EMU_PORT') && !in_array($strProgramname, array('ping', 'snmpwalk'))) {
183
        if (PSI_ROOT_FILESYSTEM !== '') { // disabled if ROOTFS defined
198
            if (defined('PSI_SUDO_COMMANDS') && is_string(PSI_SUDO_COMMANDS)) {
184
 
-
 
-
 
199
                if (preg_match(ARRAY_EXP, PSI_SUDO_COMMANDS)) {
-
 
200
                    $sudocommands = eval(PSI_SUDO_COMMANDS);
185
            return false;
201
                } else {
-
 
202
                    $sudocommands = array(PSI_SUDO_COMMANDS);
186
        }
203
                }
187
 
-
 
188
        if ((PSI_OS != 'WINNT') && preg_match('/^([^=]+=[^ \t]+)[ \t]+(.*)$/', $strProgramname, $strmatch)) {
204
                if (in_array($strProgramname, $sudocommands)) {
189
            $strSet = $strmatch[1].' ';
205
                    $strAll = 'sudo '.$strAll;
190
            $strProgramname = $strmatch[2];
206
                }
191
        } else {
207
            }
192
            $strSet = '';
208
            $strSet = '';
-
 
209
            $strProgramname = 'sshpass';
-
 
210
            $strOptions = '';
-
 
211
            if (defined('PSI_EMU_ADD_OPTIONS') && is_string(PSI_EMU_ADD_OPTIONS)) {
-
 
212
                if (preg_match(ARRAY_EXP, PSI_EMU_ADD_OPTIONS)) {
-
 
213
                    $arrParams = eval(PSI_EMU_ADD_OPTIONS);
-
 
214
                } else {
-
 
215
                    $arrParams = array(PSI_EMU_ADD_OPTIONS);
-
 
216
                }
-
 
217
                foreach ($arrParams as $Params) if (preg_match('/(\S+)\s*\=\s*(\S+)/', $Params, $obuf)) {
-
 
218
                    $strOptions = $strOptions.'-o '.$obuf[1].'='.$obuf[2].' ';
-
 
219
                }
-
 
220
            }
-
 
221
            if (defined('PSI_EMU_ADD_PATHS') && is_string(PSI_EMU_ADD_PATHS)) {
-
 
222
                if (preg_match(ARRAY_EXP, PSI_EMU_ADD_PATHS)) {
-
 
223
                    $arrPath = eval(PSI_EMU_ADD_PATHS);
-
 
224
                } else {
-
 
225
                    $arrPath = array(PSI_EMU_ADD_PATHS);
-
 
226
                }
-
 
227
                foreach ($arrPath as $Path) {
-
 
228
                    if ($PathStr === '') {
-
 
229
                        $PathStr = $Path;
-
 
230
                    } else {
-
 
231
                        $PathStr = $PathStr.':'.$Path;
-
 
232
                    }
-
 
233
                }
-
 
234
                if ($separator === '') {
-
 
235
                    $strArguments = '-e ssh -Tq '.$strOptions.'-o ConnectTimeout='.$timeout.' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '.PSI_EMU_USER.'@'.PSI_EMU_HOSTNAME.' -p '.PSI_EMU_PORT.' "PATH=\''.$PathStr.':$PATH\' '.$strAll.'"' ;
-
 
236
                } else {
-
 
237
                    $strArguments = '-e ssh -Tq '.$strOptions.'-o ConnectTimeout='.$timeout.' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '.PSI_EMU_USER.'@'.PSI_EMU_HOSTNAME.' -p '.PSI_EMU_PORT;
-
 
238
                }
-
 
239
            } else {
-
 
240
                if ($separator === '') {
-
 
241
                    $strArguments = '-e ssh -Tq '.$strOptions.'-o ConnectTimeout='.$timeout.' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '.PSI_EMU_USER.'@'.PSI_EMU_HOSTNAME.' -p '.PSI_EMU_PORT.' "'.$strAll.'"' ;
-
 
242
                } else {
-
 
243
                    $strArguments = '-e ssh -Tq '.$strOptions.'-o ConnectTimeout='.$timeout.' -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '.PSI_EMU_USER.'@'.PSI_EMU_HOSTNAME.' -p '.PSI_EMU_PORT;
-
 
244
                }
-
 
245
            }
-
 
246
            $externally = true;
-
 
247
        } else {
-
 
248
            $externally = false;
193
        }
249
        }
-
 
250
 
194
        $strProgram = self::_findProgram($strProgramname);
251
        $strProgram = self::_findProgram($strProgramname);
195
        $error = PSI_Error::singleton();
252
        $error = PSI_Error::singleton();
196
        if (!$strProgram) {
253
        if (!$strProgram) {
197
            if ($booErrorRep) {
254
            if ($booErrorRep || $externally) {
198
                $error->addError('find_program("'.$strProgramname.'")', 'program not found on the machine');
255
                $error->addError('find_program("'.$strProgramname.'")', 'program not found on the machine');
199
            }
256
            }
200
 
257
 
201
            return false;
258
            return false;
202
        } else {
259
        } else {
203
            if (preg_match('/\s/', $strProgram)) {
260
            if (preg_match('/\s/', $strProgram)) {
204
                $strProgram = '"'.$strProgram.'"';
261
                $strProgram = '"'.$strProgram.'"';
205
            }
262
            }
206
        }
263
        }
207
 
264
 
208
        if ((PSI_OS != 'WINNT') && defined('PSI_SUDO_COMMANDS') && is_string(PSI_SUDO_COMMANDS)) {
265
        if ((PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME') && defined('PSI_SUDO_COMMANDS') && is_string(PSI_SUDO_COMMANDS)) {
209
            if (preg_match(ARRAY_EXP, PSI_SUDO_COMMANDS)) {
266
            if (preg_match(ARRAY_EXP, PSI_SUDO_COMMANDS)) {
210
                $sudocommands = eval(PSI_SUDO_COMMANDS);
267
                $sudocommands = eval(PSI_SUDO_COMMANDS);
211
            } else {
268
            } else {
212
                $sudocommands = array(PSI_SUDO_COMMANDS);
269
                $sudocommands = array(PSI_SUDO_COMMANDS);
213
            }
270
            }
214
            if (in_array($strProgramname, $sudocommands)) {
271
            if (in_array($strProgramname, $sudocommands)) {
215
                $sudoProgram = self::_findProgram("sudo");
272
                $sudoProgram = self::_findProgram("sudo");
216
                if (!$sudoProgram) {
273
                if (!$sudoProgram) {
217
                    if ($booErrorRep) {
-
 
218
                        $error->addError('find_program("sudo")', 'program not found on the machine');
274
                    $error->addError('find_program("sudo")', 'program not found on the machine');
219
                    }
-
 
220
 
275
 
221
                    return false;
276
                    return false;
222
                } else {
277
                } else {
223
                    if (preg_match('/\s/', $sudoProgram)) {
278
                    if (preg_match('/\s/', $sudoProgram)) {
224
                        $strProgram = '"'.$sudoProgram.'" '.$strProgram;
279
                        $strProgram = '"'.$sudoProgram.'" '.$strProgram;
Line 227... Line 282...
227
                    }
282
                    }
228
                }
283
                }
229
            }
284
            }
230
        }
285
        }
231
 
286
 
-
 
287
        $strArgs = $strArguments;
232
        // see if we've gotten a | or &, if we have we need to do path checking on the cmd
288
        // see if we've gotten a | or &, if we have we need to do path checking on the cmd
233
        if ($strArgs) {
289
        if ($strArgs) {
234
            $arrArgs = preg_split('/ /', $strArgs, -1, PREG_SPLIT_NO_EMPTY);
290
            $arrArgs = preg_split('/ /', $strArgs, -1, PREG_SPLIT_NO_EMPTY);
235
            for ($i = 0, $cnt_args = count($arrArgs); $i < $cnt_args; $i++) {
291
            for ($i = 0, $cnt_args = count($arrArgs); $i < $cnt_args; $i++) {
236
                if (($arrArgs[$i] == '|') || ($arrArgs[$i] == '&')) {
292
                if (($arrArgs[$i] == '|') || ($arrArgs[$i] == '&')) {
237
                    $strCmd = $arrArgs[$i + 1];
293
                    $strCmd = $arrArgs[$i + 1];
238
                    $strNewcmd = self::_findProgram($strCmd);
294
                    $strNewcmd = self::_findProgram($strCmd);
-
 
295
                    if (!$strNewcmd) {
-
 
296
                        if ($booErrorRep || $externally) {
-
 
297
                            $error->addError('find_program("'.$strCmd.'")', 'program not found on the machine');
-
 
298
                        }
-
 
299
 
-
 
300
                        return false;
-
 
301
                    }
-
 
302
                    if (preg_match('/\s/', $strNewcmd)) {
239
                    if ($arrArgs[$i] == '|') {
303
                        if ($arrArgs[$i] == '|') {
240
                        $strArgs = preg_replace('/\| '.$strCmd.'/', '| "'.$strNewcmd.'"', $strArgs);
304
                            $strArgs = preg_replace('/\| '.$strCmd.'/', '| "'.$strNewcmd.'"', $strArgs);
-
 
305
                        } else {
-
 
306
                            $strArgs = preg_replace('/& '.$strCmd.'/', '& "'.$strNewcmd.'"', $strArgs);
-
 
307
                        }
241
                    } else {
308
                    } else {
-
 
309
                        if ($arrArgs[$i] == '|') {
-
 
310
                            $strArgs = preg_replace('/\| '.$strCmd.'/', '| '.$strNewcmd, $strArgs);
-
 
311
                        } else {
242
                        $strArgs = preg_replace('/& '.$strCmd.'/', '& "'.$strNewcmd.'"', $strArgs);
312
                            $strArgs = preg_replace('/& '.$strCmd.'/', '& '.$strNewcmd, $strArgs);
-
 
313
                        }
243
                    }
314
                    }
244
                }
315
                }
245
            }
316
            }
246
            $strArgs = ' '.$strArgs;
317
            $strArgs = ' '.$strArgs;
247
        }
318
        }
248
 
319
 
249
        $strBuffer = '';
320
        $strBuffer = '';
250
        $strError = '';
321
        $strError = '';
251
        $pipes = array();
322
        $pipes = array();
252
        $descriptorspec = array(0=>array("pipe", "r"), 1=>array("pipe", "w"), 2=>array("pipe", "w"));
323
        $descriptorspec = array(0=>array("pipe", "r"), 1=>array("pipe", "w"), 2=>array("pipe", "w"));
-
 
324
        if ($externally) {
-
 
325
            putenv('SSHPASS='.PSI_EMU_PASSWORD);
-
 
326
        }
253
        if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
327
        if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
-
 
328
            if ($separator !== '') {
-
 
329
                $error->addError('executeProgram', 'wrong execution mode');
-
 
330
 
-
 
331
                return false;
-
 
332
            }
254
            if (PSI_OS == 'WINNT') {
333
            if (PSI_OS == 'WINNT') {
255
                $process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>nul", "r");
334
                $process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>nul", "r");
256
            } else {
335
            } else {
257
                $process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>/dev/null", "r");
336
                $process = $pipes[1] = popen($strSet.$strProgram.$strArgs." 2>/dev/null", "r");
258
            }
337
            }
259
        } else {
338
        } else {
260
            $process = proc_open($strSet.$strProgram.$strArgs, $descriptorspec, $pipes);
339
            $process = proc_open($strSet.$strProgram.$strArgs, $descriptorspec, $pipes);
-
 
340
            if ($separator !== '') {
-
 
341
                if ($PathStr === '') {
-
 
342
                    fwrite($pipes[0], $strAll."\n  "); // spaces at end for handling 'more'
-
 
343
                } else {
-
 
344
                    fwrite($pipes[0], 'PATH=\''.$PathStr.':$PATH\' '.$strAll."\n");
-
 
345
                }
-
 
346
            }
-
 
347
        }
-
 
348
        if ($externally) {
-
 
349
            putenv('SSHPASS');
261
        }
350
        }
262
        if (is_resource($process)) {
351
        if (is_resource($process)) {
263
            $te = self::_timeoutfgets($pipes, $strBuffer, $strError, $timeout);
352
            $te = self::_timeoutfgets($pipes, $strBuffer, $strError, $timeout, $separator);
264
            if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
353
            if (defined("PSI_MODE_POPEN") && PSI_MODE_POPEN) {
265
                $return_value = pclose($pipes[1]);
354
                $return_value = pclose($pipes[1]);
266
            } else {
355
            } else {
267
                fclose($pipes[0]);
356
                fclose($pipes[0]);
268
                fclose($pipes[1]);
357
                fclose($pipes[1]);
Line 284... Line 373...
284
            return false;
373
            return false;
285
        }
374
        }
286
        $strError = trim($strError);
375
        $strError = trim($strError);
287
        $strBuffer = trim($strBuffer);
376
        $strBuffer = trim($strBuffer);
288
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && (substr(PSI_LOG, 0, 1)!="-") && (substr(PSI_LOG, 0, 1)!="+")) {
377
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && (substr(PSI_LOG, 0, 1)!="-") && (substr(PSI_LOG, 0, 1)!="+")) {
289
            error_log("---".gmdate('r T')."--- Executing: ".trim($strProgramname.$strArgs)."\n".$strBuffer."\n", 3, PSI_LOG);
378
            error_log("---".gmdate('r T')."--- Executing: ".$strAll."\n".$strBuffer."\n", 3, PSI_LOG);
290
        }
379
        }
291
        if (! empty($strError)) {
380
        if (! empty($strError)) {
292
            if ($booErrorRep) {
381
            if ($booErrorRep) {
293
                $error->addError($strProgram, $strError."\nReturn value: ".$return_value);
382
                $error->addError($strProgram, $strError."\nReturn value: ".$return_value);
294
            }
383
            }
Line 304... Line 393...
304
     *
393
     *
305
     * @return value if successfull or null if not
394
     * @return value if successfull or null if not
306
     */
395
     */
307
    public static function rolv($similarFileName, $match = "//", $replace = "")
396
    public static function rolv($similarFileName, $match = "//", $replace = "")
308
    {
397
    {
-
 
398
        if (defined('PSI_EMU_PORT')) {
-
 
399
            return null;
-
 
400
        }
-
 
401
 
309
        $filename = preg_replace($match, $replace, $similarFileName);
402
        $filename = preg_replace($match, $replace, $similarFileName);
310
        if (self::fileexists($filename) && self::rfts($filename, $buf, 1, 4096, false) && (($buf=trim($buf)) != "")) {
403
        if (self::fileexists($filename) && self::rfts($filename, $buf, 1, 4096, false) && (($buf=trim($buf)) != "")) {
311
            return $buf;
404
            return $buf;
312
        } else {
405
        } else {
313
            return null;
406
            return null;
Line 357... Line 450...
357
     *
450
     *
358
     * @return boolean command successfull or not
451
     * @return boolean command successfull or not
359
     */
452
     */
360
    public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
453
    public static function rfts($strFileName, &$strRet, $intLines = 0, $intBytes = 4096, $booErrorRep = true)
361
    {
454
    {
-
 
455
        if (defined('PSI_EMU_PORT')) {
-
 
456
            return false;
-
 
457
        }
-
 
458
 
362
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
459
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
363
            $out = self::_parse_log_file("Reading: ".$strFileName);
460
            $out = self::_parse_log_file("Reading: ".$strFileName);
364
            if ($out == false) {
461
            if ($out == false) {
365
                if (substr(PSI_LOG, 0, 1)=="-") {
462
                if (substr(PSI_LOG, 0, 1)=="-") {
366
                    $strRet = '';
463
                    $strRet = '';
Line 476... Line 573...
476
     *
573
     *
477
     * @return an array containing the matched files/directories, an empty array if no file matched or false on error
574
     * @return an array containing the matched files/directories, an empty array if no file matched or false on error
478
     */
575
     */
479
    public static function findglob($pattern, $flags = 0)
576
    public static function findglob($pattern, $flags = 0)
480
    {
577
    {
-
 
578
        if (defined('PSI_EMU_PORT')) {
-
 
579
            return false;
-
 
580
        }
-
 
581
 
481
        $outarr = glob(PSI_ROOT_FILESYSTEM.$pattern, $flags);
582
        $outarr = glob(PSI_ROOT_FILESYSTEM.$pattern, $flags);
482
        if (PSI_ROOT_FILESYSTEM == '') {
583
        if (PSI_ROOT_FILESYSTEM == '') {
483
            return $outarr;
584
            return $outarr;
484
        } elseif ($outarr === false) {
585
        } elseif ($outarr === false) {
485
            return false;
586
            return false;
Line 501... Line 602...
501
     *
602
     *
502
     * @return boolean command successfull or not
603
     * @return boolean command successfull or not
503
     */
604
     */
504
    public static function fileexists($strFileName)
605
    public static function fileexists($strFileName)
505
    {
606
    {
-
 
607
        if (defined('PSI_EMU_PORT')) {
-
 
608
            return false;
-
 
609
        }
-
 
610
 
506
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
611
        if (defined('PSI_LOG') && is_string(PSI_LOG) && (strlen(PSI_LOG)>0) && ((substr(PSI_LOG, 0, 1)=="-") || (substr(PSI_LOG, 0, 1)=="+"))) {
507
            $log_file = substr(PSI_LOG, 1);
612
            $log_file = substr(PSI_LOG, 1);
508
            if (file_exists($log_file)
613
            if (file_exists($log_file)
509
                && ($contents = @file_get_contents($log_file))
614
                && ($contents = @file_get_contents($log_file))
510
                && preg_match("/^\-\-\-[^-\n]+\-\-\- ".preg_quote("Reading: ".$strFileName, '/')."\n/m", $contents)) {
615
                && preg_match("/^\-\-\-[^-\n]+\-\-\- ".preg_quote("Reading: ".$strFileName, '/')."\n/m", $contents)) {
Line 611... Line 716...
611
     * @param string &$err    target string for the error message (reference)
716
     * @param string &$err    target string for the error message (reference)
612
     * @param int    $timeout timeout value in seconds
717
     * @param int    $timeout timeout value in seconds
613
     *
718
     *
614
     * @return boolean timeout expired or not
719
     * @return boolean timeout expired or not
615
     */
720
     */
616
    private static function _timeoutfgets($pipes, &$out, &$err, $timeout)
721
    private static function _timeoutfgets($pipes, &$out, &$err, $timeout, $separator = '')
617
    {
722
    {
618
        $w = null;
723
        $w = null;
619
        $e = null;
724
        $e = null;
620
        $te = false;
725
        $te = false;
621
 
726
 
Line 636... Line 741...
636
            if ($n === false) {
741
            if ($n === false) {
637
                error_log('stream_select: failed !');
742
                error_log('stream_select: failed !');
638
                break;
743
                break;
639
            } elseif ($n === 0) {
744
            } elseif ($n === 0) {
640
                error_log('stream_select: timeout expired !');
745
                error_log('stream_select: timeout expired !');
-
 
746
//                if ($separator !== '') {
-
 
747
//                    fwrite($pipes[0], "q");
-
 
748
//                }
641
                $te = true;
749
                $te = true;
642
                break;
750
                break;
643
            }
751
            }
644
 
752
 
645
            foreach ($read as $r) {
753
            foreach ($read as $r) {
Line 647... Line 755...
647
                    $out .= fread($r, 4096);
755
                    $out .= fread($r, 4096);
648
                } elseif (feof($pipes[1]) && $pipe2 && ($r == $pipes[2])) {//read STDERR after STDOUT
756
                } elseif (feof($pipes[1]) && $pipe2 && ($r == $pipes[2])) {//read STDERR after STDOUT
649
                    $err .= fread($r, 4096);
757
                    $err .= fread($r, 4096);
650
                }
758
                }
651
            }
759
            }
-
 
760
//            if (($separator !== '') && preg_match('/'.$separator.'[^'.$separator.']+'.$separator.'/', $out)) {
-
 
761
            if (($separator !== '') && preg_match('/'.$separator.'[\s\S]+'.$separator.'/', $out)) {
-
 
762
                fwrite($pipes[0], "quit\n");
-
 
763
                $separator = ''; //only one time
-
 
764
              //  $te = true;
-
 
765
              //  break;
-
 
766
            }
652
        }
767
        }
653
 
768
 
654
        return $te;
769
        return $te;
655
    }
770
    }
656
 
771
 
Line 690... Line 805...
690
    public static function decodevirtualizer($vendor_data)
805
    public static function decodevirtualizer($vendor_data)
691
    {
806
    {
692
        if (gettype($vendor_data) === "array") {
807
        if (gettype($vendor_data) === "array") {
693
            $vendarray = array(
808
            $vendarray = array(
694
                'KVM' => 'kvm', // KVM
809
                'KVM' => 'kvm', // KVM
-
 
810
                'OpenStack' => 'kvm', // Detect OpenStack instance as KVM in non x86 architecture
-
 
811
                'KubeVirt' => 'kvm', // Detect KubeVirt instance as KVM in non x86 architecture
695
                'Amazon EC2' => 'amazon', // Amazon EC2 Nitro using Linux KVM
812
                'Amazon EC2' => 'amazon', // Amazon EC2 Nitro using Linux KVM
696
                'QEMU' => 'qemu', // QEMU
813
                'QEMU' => 'qemu', // QEMU
697
                'VMware' => 'vmware', // VMware https://kb.vmware.com/s/article/1009458
814
                'VMware' => 'vmware', // VMware https://kb.vmware.com/s/article/1009458
698
                'VMW' => 'vmware',
815
                'VMW' => 'vmware',
699
                'innotek GmbH' => 'oracle', // Oracle VM VirtualBox
816
                'innotek GmbH' => 'oracle', // Oracle VM VirtualBox
Line 702... Line 819...
702
                'Bochs' => 'bochs', // Bochs
819
                'Bochs' => 'bochs', // Bochs
703
                'Parallels' => 'parallels', // Parallels
820
                'Parallels' => 'parallels', // Parallels
704
                // https://wiki.freebsd.org/bhyve
821
                // https://wiki.freebsd.org/bhyve
705
                'BHYVE' => 'bhyve', // bhyve
822
                'BHYVE' => 'bhyve', // bhyve
706
                'Hyper-V' => 'microsoft', // Hyper-V
823
                'Hyper-V' => 'microsoft', // Hyper-V
-
 
824
                'Apple Virtualization' => 'apple', // Apple Virtualization.framework guests
707
                'Microsoft Corporation Virtual Machine' => 'microsoft' // Hyper-V
825
                'Microsoft Corporation Virtual Machine' => 'microsoft' // Hyper-V
708
            );
826
            );
709
            for ($i = 0; $i < count($vendor_data); $i++) {
827
            for ($i = 0; $i < count($vendor_data); $i++) {
710
                foreach ($vendarray as $vend=>$virt) {
828
                foreach ($vendarray as $vend=>$virt) {
711
                    if (preg_match('/^'.$vend.'/', $vendor_data[$i])) {
829
                    if (preg_match('/^'.$vend.'/', $vendor_data[$i])) {
Line 715... Line 833...
715
            }
833
            }
716
        } elseif (gettype($vendor_data) === "string") {
834
        } elseif (gettype($vendor_data) === "string") {
717
            $vidarray = array(
835
            $vidarray = array(
718
                'bhyvebhyve' => 'bhyve', // bhyve
836
                'bhyvebhyve' => 'bhyve', // bhyve
719
                'KVMKVMKVM' => 'kvm', // KVM
837
                'KVMKVMKVM' => 'kvm', // KVM
-
 
838
                'LinuxKVMHv' => 'hv-kvm', // KVM (KVM + HyperV Enlightenments)
720
                'MicrosoftHv' => 'microsoft', // Hyper-V
839
                'MicrosoftHv' => 'microsoft', // Hyper-V
721
                'lrpepyhvr' => 'parallels', // Parallels
840
                'lrpepyhvr' => 'parallels', // Parallels
722
                'UnisysSpar64' => 'spar', // Unisys sPar
841
                'UnisysSpar64' => 'spar', // Unisys sPar
723
                'VMwareVMware' => 'vmware', // VMware
842
                'VMwareVMware' => 'vmware', // VMware
724
                'XenVMMXenVMM' => 'xen', // Xen hypervisor
843
                'XenVMMXenVMM' => 'xen', // Xen hypervisor
Line 742... Line 861...
742
     *
861
     *
743
     * @return array
862
     * @return array
744
     */
863
     */
745
    public static function readdmimemdata()
864
    public static function readdmimemdata()
746
    {
865
    {
747
        if ((PSI_OS != 'WINNT') && !defined('PSI_EMU_HOSTNAME') && (self::$_dmimd === null)) {
866
        if ((PSI_OS != 'WINNT') && (!defined('PSI_EMU_HOSTNAME') || defined('PSI_EMU_PORT')) && (self::$_dmimd === null)) {
748
            self::$_dmimd = array();
867
            self::$_dmimd = array();
749
            $buffer = '';
868
            $buffer = '';
750
            if (defined('PSI_DMIDECODE_ACCESS') && (strtolower(PSI_DMIDECODE_ACCESS)==='data')) {
869
            if (defined('PSI_DMIDECODE_ACCESS') && (strtolower(PSI_DMIDECODE_ACCESS)==='data')) {
751
                self::rftsdata('dmidecode.tmp', $buffer);
870
                self::rftsdata('dmidecode.tmp', $buffer);
752
            } elseif (self::_findProgram('dmidecode')) {
871
            } elseif (self::_findProgram('dmidecode')) {