mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-26 11:37:33 +00:00
Merge branch 'ssh-custom-socket-1.0' into ssh-custom-socket-2.0
Conflicts: phpseclib/Net/SSH2.php
This commit is contained in:
commit
4d086bee86
@ -869,7 +869,9 @@ class SSH2
|
|||||||
/**
|
/**
|
||||||
* Default Constructor.
|
* 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 $port
|
||||||
* @param optional Integer $timeout
|
* @param optional Integer $timeout
|
||||||
* @see \phpseclib\Net\SSH2::login()
|
* @see \phpseclib\Net\SSH2::login()
|
||||||
@ -954,9 +956,16 @@ class SSH2
|
|||||||
34 => 'NET_SSH2_MSG_KEXDH_GEX_REQUEST')
|
34 => 'NET_SSH2_MSG_KEXDH_GEX_REQUEST')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->host = $host;
|
if (is_resource($host)) {
|
||||||
$this->port = $port;
|
$this->fsock = $host;
|
||||||
$this->timeout = $timeout;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_string($host)) {
|
||||||
|
$this->host = $host;
|
||||||
|
$this->port = $port;
|
||||||
|
$this->timeout = $timeout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -993,19 +1002,21 @@ class SSH2
|
|||||||
|
|
||||||
$this->last_packet = microtime(true);
|
$this->last_packet = microtime(true);
|
||||||
|
|
||||||
$start = microtime(true);
|
if (!is_resource($this->fsock)) {
|
||||||
$this->fsock = @fsockopen($this->host, $this->port, $errno, $errstr, $this->curTimeout);
|
$start = microtime(true);
|
||||||
if (!$this->fsock) {
|
$this->fsock = @fsockopen($this->host, $this->port, $errno, $errstr, $this->curTimeout);
|
||||||
user_error(rtrim("Cannot connect to $host. Error $errno. $errstr"));
|
if (!$this->fsock) {
|
||||||
return false;
|
user_error(rtrim("Cannot connect to $host. Error $errno. $errstr"));
|
||||||
}
|
return false;
|
||||||
$elapsed = microtime(true) - $start;
|
}
|
||||||
|
$elapsed = microtime(true) - $start;
|
||||||
|
|
||||||
$this->curTimeout-= $elapsed;
|
$this->curTimeout-= $elapsed;
|
||||||
|
|
||||||
if ($this->curTimeout <= 0) {
|
if ($this->curTimeout <= 0) {
|
||||||
$this->is_timeout = true;
|
$this->is_timeout = true;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* According to the SSH2 specs,
|
/* According to the SSH2 specs,
|
||||||
|
@ -87,4 +87,17 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase
|
|||||||
|
|
||||||
$this->assertInternalType('string', $ssh->getServerPublicHostKey());
|
$this->assertInternalType('string', $ssh->getServerPublicHostKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testOpenSocketConnect()
|
||||||
|
{
|
||||||
|
$fsock = fsockopen($this->getEnv('SSH_HOSTNAME'), 22);
|
||||||
|
$ssh = new 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