'] = '>'; $entities['"'] = '"'; $entities['\''] = '''; return str_replace(array_keys($entities), array_values($entities), $str); } // }}} // {{{ quoteCommand function quoteCommand($cmd) { global $config; // On Windows machines, the whole line needs quotes round it so that it's // passed to cmd.exe correctly if ($config->serverIsWindows) { $cmd = '"'.$cmd.'"'; } return $cmd; } // }}} // {{{ execCommand function execCommand($cmd, &$retcode) { global $config; // On Windows machines, the whole line needs quotes round it so that it's // passed to cmd.exe correctly // Since php 5.3.0 the quoting seems to be done internally if ($config->serverIsWindows && version_compare(PHP_VERSION, '5.3.0alpha') === -1) { $cmd = '"'.$cmd.'"'; } return @exec($cmd, $tmp, $retcode); } // }}} // {{{ popenCommand function popenCommand($cmd, $mode) { global $config; // On Windows machines, the whole line needs quotes round it so that it's // passed to cmd.exe correctly // Since php 5.3.0 the quoting seems to be done internally if ($config->serverIsWindows && version_compare(PHP_VERSION, '5.3.0alpha') === -1) { $cmd = '"'.$cmd.'"'; } return popen($cmd, $mode); } // }}} // {{{ passthruCommand function passthruCommand($cmd) { global $config; // On Windows machines, the whole line needs quotes round it so that it's // passed to cmd.exe correctly // Since php 5.3.0 the quoting seems to be done internally if ($config->serverIsWindows && version_compare(PHP_VERSION, '5.3.0alpha') === -1) { $cmd = '"'.$cmd.'"'; } return passthru($cmd); } // }}} // {{{ runCommand function runCommand($cmd, $mayReturnNothing = false) { global $lang; $output = array(); $err = false; $c = quoteCommand($cmd); $descriptorspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')); $resource = proc_open($c, $descriptorspec, $pipes); $error = ''; if (!is_resource($resource)) { echo '

'.$lang['BADCMD'].': '.stripCredentialsFromCommand($cmd).'

'; exit; } $handle = $pipes[1]; $firstline = true; while (!feof($handle)) { $line = fgets($handle); if ($firstline && empty($line) && !$mayReturnNothing) { $err = true; } $firstline = false; $output[] = toOutputEncoding(rtrim($line)); } while (!feof($pipes[2])) { $error .= fgets($pipes[2]); } $error = toOutputEncoding(trim($error)); fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); proc_close($resource); if (!$err) { return $output; } else { echo '

'.$lang['BADCMD'].': '.stripCredentialsFromCommand($cmd).'

'.nl2br($error).'

'; } } // }}} function stripCredentialsFromCommand($cmd) { global $config; $quotingChar = ($config->serverIsWindows ? '"' : "'"); $quotedString = $quotingChar.'([^'.$quotingChar.'\\\\]*(\\\\.[^'.$quotingChar.'\\\\]*)*)'.$quotingChar; $patterns = array('|--username '.$quotedString.' |U', '|--password '.$quotedString.' |U'); $replacements = array('--username '.quote('***').' ', '--password '.quote('***').' '); $cmd = preg_replace($patterns, $replacements, $cmd, 1); return $cmd; } // {{{ quote // // Quote a string to send to the command line function quote($str) { global $config; if ($config->serverIsWindows) { return '"'.$str.'"'; } else { return escapeshellarg($str); } } // }}}