本文整理汇总了PHP中escapeshellarg函数的典型用法代码示例。如果您正苦于以下问题:PHP escapeshellarg函数的具体用法?PHP escapeshellarg怎么用?PHP escapeshellarg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了escapeshellarg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor.
*
* @param Horde_Vcs_Base $rep A repository object.
* @param string $dn Path to the directory.
* @param array $opts Any additional options:
*
* @throws Horde_Vcs_Exception
*/
public function __construct(Horde_Vcs_Base $rep, $dn, $opts = array())
{
parent::__construct($rep, $dn, $opts);
$cmd = $rep->getCommand() . ' ls ' . escapeshellarg($rep->sourceroot . $this->_dirName);
$dir = proc_open($cmd, array(1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
if (!$dir) {
throw new Horde_Vcs_Exception('Failed to execute svn ls: ' . $cmd);
}
if ($error = stream_get_contents($pipes[2])) {
proc_close($dir);
throw new Horde_Vcs_Exception($error);
}
/* Create two arrays - one of all the files, and the other of all the
* dirs. */
$errors = array();
while (!feof($pipes[1])) {
$line = chop(fgets($pipes[1], 1024));
if (!strlen($line)) {
continue;
}
if (substr($line, 0, 4) == 'svn:') {
$errors[] = $line;
} elseif (substr($line, -1) == '/') {
$this->_dirs[] = substr($line, 0, -1);
} else {
$this->_files[] = $rep->getFile($this->_dirName . '/' . $line);
}
}
proc_close($dir);
}
示例2: escapeArgument
/**
* Escapes a string to be used as a shell argument.
*
* @param string $argument The argument that will be escaped
*
* @return string The escaped argument
*/
public static function escapeArgument($argument)
{
//Fix for PHP bug #43784 escapeshellarg removes % from given string
//Fix for PHP bug #49446 escapeshellarg doesn't work on Windows
//@see https://bugs.php.net/bug.php?id=43784
//@see https://bugs.php.net/bug.php?id=49446
if ('\\' === DIRECTORY_SEPARATOR) {
if ('' === $argument) {
return escapeshellarg($argument);
}
$escapedArgument = '';
$quote = false;
foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
if ('"' === $part) {
$escapedArgument .= '\\"';
} elseif (self::isSurroundedBy($part, '%')) {
// Avoid environment variable expansion
$escapedArgument .= '^%"' . substr($part, 1, -1) . '"^%';
} else {
// escape trailing backslash
if ('\\' === substr($part, -1)) {
$part .= '\\';
}
$quote = true;
$escapedArgument .= $part;
}
}
if ($quote) {
$escapedArgument = '"' . $escapedArgument . '"';
}
return $escapedArgument;
}
return escapeshellarg($argument);
}
示例3: db
public function db($command = '', $args = '')
{
if (count($command) == 1 && reset($command) == 'help') {
return $this->db_help();
}
$defaults = array('host' => defined('IMPORT_DB_HOST') ? IMPORT_DB_HOST : DB_HOST, 'user' => defined('IMPORT_DB_USER') ? IMPORT_DB_USER : DB_USER, 'password' => defined('IMPORT_DB_PASSWORD') ? IMPORT_DB_PASSWORD : '', 'name' => defined('IMPORT_DB_NAME') ? IMPORT_DB_NAME : '', 'port' => '3306', 'ssh_host' => defined('IMPORT_DB_SSH_HOST') ? IMPORT_DB_SSH_HOST : '', 'ssh_user' => defined('IMPORT_DB_SSH_USER') ? IMPORT_DB_SSH_USER : '', 'table' => '');
$args = wp_parse_args($args, $defaults);
$start_time = time();
if ($args['ssh_host']) {
shell_exec(sprintf("ssh -f -L 3308:%s:%s %s@%s sleep 600 >> logfile", $args['host'], $args['port'], $args['ssh_user'], $args['ssh_host']));
$args['host'] = '127.0.0.1';
$args['port'] = '3308';
}
WP_CLI::line('Importing database from ' . $args['host'] . '...' . ($args['ssh_host'] ? ' via ssh tunnel: ' . $args['ssh_host'] : ''));
$password = $args['password'] ? '--password=' . escapeshellarg($args['password']) : '';
// TODO pipe through sed or interconnectIT's search replace script
if (defined('IMPORT_DB_REMOTE_ABSPATH')) {
$sed = " | sed s," . trailingslashit(IMPORT_DB_REMOTE_ABSPATH) . "," . ABSPATH . ",g";
} else {
$sed = '';
}
if ($args['site']) {
$args['table'] = "wp_{$args['site']}_commentmeta wp_{$args['site']}_comments wp_{$args['site']}_links wp_{$args['site']}_options wp_{$args['site']}_postmeta wp_{$args['site']}_posts wp_{$args['site']}_term_relationships wp_{$args['site']}_term_taxonomy wp_{$args['site']}_terms";
}
$exec = sprintf('mysqldump --verbose --host=%s --user=%s %s -P %s %s %s %s | mysql --host=%s --user=%s --password=%s %s', $args['host'], $args['user'], $password, $args['port'], $args['name'], $args['table'], $sed, DB_HOST, DB_USER, escapeshellarg(DB_PASSWORD), DB_NAME);
WP_CLI::line('Running: ' . $exec);
WP_CLI::launch($exec);
WP_CLI::success(sprintf('Finished. Took %d seconds', time() - $start_time));
wp_cache_flush();
}
示例4: do_update_plugin
function do_update_plugin($dir, $domain)
{
$old = getcwd();
chdir($dir);
if (!file_exists('locale')) {
mkdir('locale');
}
$files = get_plugin_sources(".");
$cmd = <<<END
xgettext \\
--from-code=UTF-8 \\
--default-domain={$domain} \\
--output=locale/{$domain}.pot \\
--language=PHP \\
--add-comments=TRANS \\
--keyword='' \\
--keyword="_m:1,1t" \\
--keyword="_m:1c,2,2t" \\
--keyword="_m:1,2,3t" \\
--keyword="_m:1c,2,3,4t" \\
END;
foreach ($files as $file) {
$cmd .= ' ' . escapeshellarg($file);
}
passthru($cmd);
chdir($old);
}
示例5: escapeArgument
public static function escapeArgument($argument)
{
if ('\\' === DIRECTORY_SEPARATOR) {
if ('' === $argument) {
return escapeshellarg($argument);
}
$escapedArgument = '';
$quote = false;
foreach (preg_split('/(")/i', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
if ('"' === $part) {
$escapedArgument .= '\\"';
} elseif (self::isSurroundedBy($part, '%')) {
$escapedArgument .= '^%"' . substr($part, 1, -1) . '"^%';
} else {
if ('\\' === substr($part, -1)) {
$part .= '\\';
}
$quote = true;
$escapedArgument .= $part;
}
}
if ($quote) {
$escapedArgument = '"' . $escapedArgument . '"';
}
return $escapedArgument;
}
return escapeshellarg($argument);
}
示例6: prepareCommand
/**
*
* @param string $message SMS message
* @return string Parsed command
* @throws ConfigurationException
*/
private function prepareCommand($message)
{
$tokens = [];
$params = array_merge($this->params, ['message' => escapeshellarg($message)]);
foreach ($params as $name => $value) {
$token = '#' . strtoupper($name) . '#';
if (is_scalar($value)) {
$tokens[$token] = $value;
}
}
$command = str_replace(array_keys($tokens), array_values($tokens), $this->command);
try {
$useSsh = (bool) $this->getParam('use_ssh');
} catch (ConfigurationException $exp) {
$useSsh = false;
}
if ($useSsh) {
$sshHost = (string) $this->getParam('ssh_host');
$sshLogin = (string) $this->getParam('ssh_login');
if (empty($sshHost) || empty($sshLogin)) {
throw new ConfigurationException(__CLASS__ . ' is not configured properly. If SSH is enabled then parameters "ssh_host" and "ssh_login" must be set.');
}
$tokens['#COMMAND#'] = $command;
$command = str_replace(array_keys($tokens), array_values($tokens), $this->sshCommand);
}
return $command;
}
示例7: testAcceptsValidStringInput
public function testAcceptsValidStringInput()
{
$msg = escapeshellarg(file_get_contents("{$this->filesDir}valid.txt"));
$cmd = "{$this->validateScript} {$msg}";
$result = $this->runCmd($cmd, $output);
$this->assertTrue($result, $output);
}
示例8: compress
public function compress($source, $type)
{
$cmd = sprintf('java -jar %s --type %s --charset UTF-8 --line-break 1000', escapeshellarg($this->yuiPath), $type);
$process = proc_open($cmd, array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")), $pipes);
fwrite($pipes[0], $source);
fclose($pipes[0]);
$output = array("stdout" => "", "stderr" => "");
$readSockets = array("stdout" => $pipes[1], "stderr" => $pipes[2]);
$empty = array();
while (false !== stream_select($readSockets, $empty, $empty, 1)) {
foreach ($readSockets as $stream) {
$output[$stream == $pipes[1] ? "stdout" : "stderr"] .= stream_get_contents($stream);
}
$readSockets = array("stdout" => $pipes[1], "stderr" => $pipes[2]);
$eof = true;
foreach ($readSockets as $stream) {
$eof &= feof($stream);
}
if ($eof) {
break;
}
}
$compressed = $output['stdout'];
$errors = $output['stderr'];
$this->errors = "" !== $errors;
if ($this->errors) {
$compressed = "";
$this->errors = sprintf("alert('compression errors, check your source and console for details'); console.error(%s); ", json_encode($errors));
}
proc_close($process);
return $compressed;
}
示例9: call
/**
* Call a drush command.
*/
public function call($command, $options = array(), $args = array())
{
// Reset previous command.
$this->result = null;
$cmd = array();
$cmd[] = 'drush';
$cmd[] = $this->alias;
$cmd[] = $command;
$cmd[] = '--backend --quiet';
foreach ($options as $option) {
$cmd[] = escapeshellarg($option);
}
foreach ($args as $arg) {
$cmd[] = escapeshellarg($arg);
}
$cmd = implode(' ', $cmd);
$output = '';
$retval = $this->exec($cmd, $output);
if ($retval > 0) {
throw new DrushException('Error running ' . $cmd);
} else {
$this->result = $this->parseDrushOutput($output);
}
return $this;
}
示例10: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
if (!class_exists($arguments['class'])) {
throw new InvalidArgumentException(sprintf('The class "%s" does not exist.', $arguments['class']));
}
// base lib and test directories
$r = new ReflectionClass($arguments['class']);
list($libDir, $testDir) = $this->getDirectories($r->getFilename());
$path = str_replace($libDir, '', dirname($r->getFilename()));
$test = $testDir . '/unit' . $path . '/' . $r->getName() . 'Test.php';
// use either the test directory or project's bootstrap
if (!file_exists($bootstrap = $testDir . '/bootstrap/unit.php')) {
$bootstrap = sfConfig::get('sf_test_dir') . '/bootstrap/unit.php';
}
if (file_exists($test) && $options['force']) {
$this->getFilesystem()->remove($test);
}
if (file_exists($test)) {
$this->logSection('task', sprintf('A test script for the class "%s" already exists.', $r->getName()), null, 'ERROR');
} else {
$this->getFilesystem()->copy(dirname(__FILE__) . '/skeleton/test/UnitTest.php', $test);
$this->getFilesystem()->replaceTokens($test, '##', '##', array('CLASS' => $r->getName(), 'BOOTSTRAP' => $this->getBootstrapPathPhp($bootstrap, $test), 'DATABASE' => $this->isDatabaseClass($r) ? "\n\$databaseManager = new sfDatabaseManager(\$configuration);\n" : ''));
}
if (isset($options['editor-cmd'])) {
$this->getFilesystem()->execute($options['editor-cmd'] . ' ' . escapeshellarg($test));
}
}
示例11: checkPassword
/**
* Check if the password is correct without logging in the user
*
* @param string $uid The username
* @param string $password The password
*
* @return true/false
*/
public function checkPassword($uid, $password)
{
$uidEscaped = escapeshellarg($uid);
$password = escapeshellarg($password);
$result = array();
$command = self::SMBCLIENT . ' //' . $this->host . '/dummy -U' . $uidEscaped . '%' . $password;
$lastline = exec($command, $output, $retval);
if ($retval === 127) {
OCP\Util::writeLog('user_external', 'ERROR: smbclient executable missing', OCP\Util::ERROR);
return false;
} else {
if (strpos($lastline, self::LOGINERROR) !== false) {
//normal login error
return false;
} else {
if (strpos($lastline, 'NT_STATUS_BAD_NETWORK_NAME') !== false) {
//login on minor error
goto login;
} else {
if ($retval != 0) {
//some other error
OCP\Util::writeLog('user_external', 'ERROR: smbclient error: ' . trim($lastline), OCP\Util::ERROR);
return false;
} else {
login:
$this->storeUser($uid);
return $uid;
}
}
}
}
}
示例12: createOwnVhostStarter
public function createOwnVhostStarter()
{
if (Settings::Get('phpfpm.enabled') == '1' && Settings::Get('phpfpm.enabled_ownvhost') == '1') {
$mypath = makeCorrectDir(dirname(dirname(dirname(__FILE__))));
// /var/www/froxlor, needed for chown
$user = Settings::Get('phpfpm.vhost_httpuser');
$group = Settings::Get('phpfpm.vhost_httpgroup');
$domain = array('id' => 'none', 'domain' => Settings::Get('system.hostname'), 'adminid' => 1, 'mod_fcgid_starter' => -1, 'mod_fcgid_maxrequests' => -1, 'guid' => $user, 'openbasedir' => 0, 'email' => Settings::Get('panel.adminmail'), 'loginname' => 'froxlor.panel', 'documentroot' => $mypath);
// all the files and folders have to belong to the local user
// now because we also use fcgid for our own vhost
safe_exec('chown -R ' . $user . ':' . $group . ' ' . escapeshellarg($mypath));
// get php.ini for our own vhost
$php = new phpinterface($domain);
// get php-config
if (Settings::Get('phpfpm.enabled') == '1') {
// fpm
$phpconfig = $php->getPhpConfig(Settings::Get('phpfpm.vhost_defaultini'));
} else {
// fcgid
$phpconfig = $php->getPhpConfig(Settings::Get('system.mod_fcgid_defaultini_ownvhost'));
}
// create starter-file | config-file
$php->getInterface()->createConfig($phpconfig);
// create php.ini (fpm does nothing here, as it
// defines ini-settings in its pool config)
$php->getInterface()->createIniFile($phpconfig);
}
}
示例13: mimeFromShell
private function mimeFromShell()
{
if (!strstr(strtolower(PHP_OS), 'win')) {
if (($this->_mime = exec('file -bi ' . escapeshellarg($this->_path))) && strlen($this->_mime)) {
/*
* it's a stupid exception for MS docs files
* The linux command "file -bi" returns then this:
* application/msword application/msword
* which sucks totally :(
*/
if (strstr($this->_mime, ' ') && !strstr($this->_mime, ';')) {
$this->_mime = explode(' ', $this->_mime);
if (trim($this->_mime[0]) == $this->_mime[1]) {
$this->_mime = $this->_mime[0];
}
}
$this->parseMime();
return true;
} else {
return false;
}
} else {
return false;
}
}
示例14: dump_base
protected function dump_base(base $base, InputInterface $input, OutputInterface $output)
{
$date_obj = new DateTime();
$filename = sprintf('%s%s_%s.sql', p4string::addEndSlash($input->getArgument('directory')), $base->get_dbname(), $date_obj->format('Y_m_d_H_i_s'));
$command = sprintf('mysqldump %s %s %s %s %s %s --default-character-set=utf8', '--host=' . escapeshellarg($base->get_host()), '--port=' . escapeshellarg($base->get_port()), '--user=' . escapeshellarg($base->get_user()), '--password=' . escapeshellarg($base->get_passwd()), '--databases', escapeshellarg($base->get_dbname()));
if ($input->getOption('gzip')) {
$filename .= '.gz';
$command .= ' | gzip -9';
} elseif ($input->getOption('bzip')) {
$filename .= '.bz2';
$command .= ' | bzip2 -9';
}
$output->write(sprintf('Generating <info>%s</info> ... ', $filename));
$command .= ' > ' . escapeshellarg($filename);
$process = new Process($command);
$process->setTimeout((int) $input->getOption('timeout'));
$process->run();
if (!$process->isSuccessful()) {
$output->writeln('<error>Failed</error>');
return 1;
}
if (file_exists($filename) && filesize($filename) > 0) {
$output->writeln('OK');
return 0;
} else {
$output->writeln('<error>Failed</error>');
return 1;
}
}
示例15: main
/**
* The main entry point
*
* @throws BuildException
*/
function main()
{
$this->setup('info');
exec('git log -n 1 --no-decorate --pretty=format:"%h" ' . escapeshellarg(realpath($this->workingCopy)), $out);
$version = $out[0];
$this->project->setProperty($this->getPropertyName(), $version);
}