mirror of
https://github.com/danog/tgseclib.git
synced 2024-11-27 04:34:45 +01:00
Merge branch 'stream-get-contents-1.0' into 2.0
This commit is contained in:
commit
8bb4592225
@ -1028,14 +1028,10 @@ class SSH2
|
|||||||
Feed. Such lines MUST NOT begin with "SSH-", and SHOULD be encoded
|
Feed. Such lines MUST NOT begin with "SSH-", and SHOULD be encoded
|
||||||
in ISO-10646 UTF-8 [RFC3629] (language is not specified). Clients
|
in ISO-10646 UTF-8 [RFC3629] (language is not specified). Clients
|
||||||
MUST be able to process such lines." */
|
MUST be able to process such lines." */
|
||||||
$temp = '';
|
$data = '';
|
||||||
$extra = '';
|
while (!feof($this->fsock) && !preg_match('#(.*)^(SSH-(\d\.\d+).*)#ms', $data, $matches)) {
|
||||||
while (!feof($this->fsock) && !preg_match('#^SSH-(\d\.\d+)#', $temp, $matches)) {
|
$line = '';
|
||||||
if (substr($temp, -2) == "\r\n") {
|
while (true) {
|
||||||
$extra.= $temp;
|
|
||||||
$temp = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->curTimeout) {
|
if ($this->curTimeout) {
|
||||||
if ($this->curTimeout < 0) {
|
if ($this->curTimeout < 0) {
|
||||||
$this->is_timeout = true;
|
$this->is_timeout = true;
|
||||||
@ -1056,7 +1052,17 @@ class SSH2
|
|||||||
$this->curTimeout-= $elapsed;
|
$this->curTimeout-= $elapsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
$temp.= fgets($this->fsock, 255);
|
$temp = stream_get_line($this->fsock, 255, "\n");
|
||||||
|
if (strlen($temp) == 255) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$line.= "$temp\n";
|
||||||
|
if (substr($line, -2) == "\r\n") {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data.= $line;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (feof($this->fsock)) {
|
if (feof($this->fsock)) {
|
||||||
@ -1064,20 +1070,22 @@ class SSH2
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$extra = $matches[1];
|
||||||
|
|
||||||
$this->identifier = $this->_generate_identifier();
|
$this->identifier = $this->_generate_identifier();
|
||||||
|
|
||||||
if (defined('NET_SSH2_LOGGING')) {
|
if (defined('NET_SSH2_LOGGING')) {
|
||||||
$this->_append_log('<-', $extra . $temp);
|
$this->_append_log('<-', $matches[0]);
|
||||||
$this->_append_log('->', $this->identifier . "\r\n");
|
$this->_append_log('->', $this->identifier . "\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->server_identifier = trim($temp, "\r\n");
|
$this->server_identifier = trim($temp, "\r\n");
|
||||||
if (strlen($extra)) {
|
if (strlen($extra)) {
|
||||||
$this->errors[] = utf8_decode($extra);
|
$this->errors[] = utf8_decode($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($matches[1] != '1.99' && $matches[1] != '2.0') {
|
if ($matches[3] != '1.99' && $matches[3] != '2.0') {
|
||||||
user_error("Cannot connect to SSH $matches[1] servers");
|
user_error("Cannot connect to SSH $matches[3] servers");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2891,7 +2899,7 @@ class SSH2
|
|||||||
}
|
}
|
||||||
|
|
||||||
$start = microtime(true);
|
$start = microtime(true);
|
||||||
$raw = fread($this->fsock, $this->decrypt_block_size);
|
$raw = stream_get_contents($this->fsock, $this->decrypt_block_size);
|
||||||
|
|
||||||
if (!strlen($raw)) {
|
if (!strlen($raw)) {
|
||||||
return '';
|
return '';
|
||||||
@ -2919,7 +2927,7 @@ class SSH2
|
|||||||
|
|
||||||
$buffer = '';
|
$buffer = '';
|
||||||
while ($remaining_length > 0) {
|
while ($remaining_length > 0) {
|
||||||
$temp = fread($this->fsock, $remaining_length);
|
$temp = stream_get_contents($this->fsock, $remaining_length);
|
||||||
if ($temp === false || feof($this->fsock)) {
|
if ($temp === false || feof($this->fsock)) {
|
||||||
user_error('Error reading from socket');
|
user_error('Error reading from socket');
|
||||||
$this->bitmap = 0;
|
$this->bitmap = 0;
|
||||||
@ -2937,7 +2945,7 @@ class SSH2
|
|||||||
$padding = $this->_string_shift($raw, $padding_length); // should leave $raw empty
|
$padding = $this->_string_shift($raw, $padding_length); // should leave $raw empty
|
||||||
|
|
||||||
if ($this->hmac_check !== false) {
|
if ($this->hmac_check !== false) {
|
||||||
$hmac = fread($this->fsock, $this->hmac_size);
|
$hmac = stream_get_contents($this->fsock, $this->hmac_size);
|
||||||
if ($hmac === false || strlen($hmac) != $this->hmac_size) {
|
if ($hmac === false || strlen($hmac) != $this->hmac_size) {
|
||||||
user_error('Error reading socket');
|
user_error('Error reading socket');
|
||||||
$this->bitmap = 0;
|
$this->bitmap = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user