mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-11 16:15:52 +00:00
SSH2: make it so you can connect using open sockets
This commit is contained in:
parent
e251f6c372
commit
33a97391bc
@ -874,7 +874,9 @@ class Net_SSH2
|
||||
/**
|
||||
* Default Constructor.
|
||||
*
|
||||
* @param String $host
|
||||
* $host can either be a string, representing the host, or a stream resource.
|
||||
*
|
||||
* @param Mixed $host
|
||||
* @param optional Integer $port
|
||||
* @param optional Integer $timeout
|
||||
* @see Net_SSH2::login()
|
||||
@ -978,10 +980,17 @@ class Net_SSH2
|
||||
34 => 'NET_SSH2_MSG_KEXDH_GEX_REQUEST')
|
||||
);
|
||||
|
||||
if (is_resource($host)) {
|
||||
$this->fsock = $host;
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_string($host)) {
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
$this->timeout = $timeout;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Crypto Engine Mode
|
||||
@ -1017,6 +1026,7 @@ class Net_SSH2
|
||||
|
||||
$this->last_packet = strtok(microtime(), ' ') + strtok(''); // == microtime(true) in PHP5
|
||||
|
||||
if (!is_resource($this->fsock)) {
|
||||
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
|
||||
$this->fsock = @fsockopen($this->host, $this->port, $errno, $errstr, $this->curTimeout);
|
||||
if (!$this->fsock) {
|
||||
@ -1031,6 +1041,7 @@ class Net_SSH2
|
||||
$this->is_timeout = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* According to the SSH2 specs,
|
||||
|
||||
|
@ -85,4 +85,17 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase
|
||||
|
||||
$this->assertInternalType('string', $ssh->getServerPublicHostKey());
|
||||
}
|
||||
|
||||
public function testOpenSocketConnect()
|
||||
{
|
||||
$fsock = fsockopen($this->getEnv('SSH_HOSTNAME'), 22);
|
||||
$ssh = new Net_SSH2($fsock);
|
||||
|
||||
$username = $this->getEnv('SSH_USERNAME');
|
||||
$password = $this->getEnv('SSH_PASSWORD');
|
||||
$this->assertTrue(
|
||||
$ssh->login($username, $password),
|
||||
'SSH2 login using an open socket failed.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user