Altax\Module\Task\Process\Process::getSSH PHP Method

getSSH() protected method

protected getSSH ( )
    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;
    }