Exemple #1
0
 /**
  * Helper function for agent->_on_channel_open()
  *
  * Used when channels are created to inform agent
  * of said channel opening. Must be called after
  * channel open confirmation received
  *
  * @access private
  */
 function _on_channel_open()
 {
     if (isset($this->agent)) {
         $this->agent->_on_channel_open($this);
     }
 }
 /**
  * Login with an ssh-agent provided key
  *
  * @param String $username
  * @param System_SSH_Agent $agent
  * @return Boolean
  * @access private
  */
 function _ssh_agent_login($username, $agent)
 {
     $keys = $agent->requestIdentities();
     foreach ($keys as $key) {
         if ($this->_privatekey_login($username, $key)) {
             return true;
         }
     }
     return false;
 }
Exemple #3
0
 protected function getSSH()
 {
     $output = $this->runtimeTask->getOutput();
     $input = $this->runtimeTask->getInput();
     $ssh = new \Net_SSH2($this->node->getHostOrDefault(), $this->node->getPortOrDefault());
     // set up key
     $key = new \Crypt_RSA();
     if ($this->node->useAgent()) {
         // use ssh-agent
         if (class_exists('System_SSH_Agent', true) == false) {
             require_once 'System/SSH_Agent.php';
         }
         $key = new \System_SSH_Agent();
     } else {
         // use ssh key file
         if ($this->node->isUsedWithPassphrase()) {
             // use passphrase
             $key->setPassword($this->node->getPassphrase());
         }
         if (!$key->loadKey($this->node->getKeyContents())) {
             throw new \RuntimeException('Unable to load SSH key file: ' . $this->node->getKeyOrDefault());
         }
     }
     // login
     if (!$ssh->login($this->node->getUsernameOrDefault(), $key)) {
         $err = error_get_last();
         $emessage = isset($err['message']) ? $err['message'] : "";
         throw new \RuntimeException('Unable to login ' . $this->node->getName() . ". " . $emessage);
     }
     return $ssh;
 }