[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/bin/ -> ssh-connect (source)

   1  #!/usr/bin/env php
   2  <?php
   3  
   4  // This is a wrapper script for Git, Mercurial, and Subversion. It primarily
   5  // serves to inject "-o StrictHostKeyChecking=no" into the SSH arguments.
   6  
   7  $root = dirname(dirname(dirname(__FILE__)));
   8  require_once $root.'/scripts/__init_script__.php';
   9  
  10  // Contrary to the documentation, Git may pass a "-p" flag. If it does, respect
  11  // it and move it before the "--" argument.
  12  $args = new PhutilArgumentParser($argv);
  13  $args->parsePartial(
  14    array(
  15      array(
  16        'name' => 'port',
  17        'short' => 'p',
  18        'param' => pht('port'),
  19        'help' => pht('Port number to connect to.'),
  20      ),
  21    ));
  22  $unconsumed_argv = $args->getUnconsumedArgumentVector();
  23  
  24  $pattern = array();
  25  $arguments = array();
  26  
  27  $pattern[] = 'ssh';
  28  
  29  $pattern[] = '-o';
  30  $pattern[] = 'StrictHostKeyChecking=no';
  31  
  32  // This prevents "known host" failures, and covers for issues where HOME is set
  33  // to something unusual.
  34  $pattern[] = '-o';
  35  $pattern[] = 'UserKnownHostsFile=/dev/null';
  36  
  37  $credential_phid = getenv('PHABRICATOR_CREDENTIAL');
  38  if ($credential_phid) {
  39    $viewer = PhabricatorUser::getOmnipotentUser();
  40    $key = PassphraseSSHKey::loadFromPHID($credential_phid, $viewer);
  41  
  42    $pattern[] = '-l %P';
  43    $arguments[] = $key->getUsernameEnvelope();
  44    $pattern[] = '-i %P';
  45    $arguments[] = $key->getKeyfileEnvelope();
  46  }
  47  
  48  $port = $args->getArg('port');
  49  if ($port) {
  50    $pattern[] = '-p %d';
  51    $arguments[] = $port;
  52  }
  53  
  54  $pattern[] = '--';
  55  
  56  $passthru_args = $unconsumed_argv;
  57  foreach ($passthru_args as $passthru_arg) {
  58    $pattern[] = '%s';
  59    $arguments[] = $passthru_arg;
  60  }
  61  
  62  $pattern = implode(' ', $pattern);
  63  array_unshift($arguments, $pattern);
  64  
  65  $err = newv('PhutilExecPassthru', $arguments)
  66    ->execute();
  67  
  68  exit($err);


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1