Changeset 873 for trunk/Modules/NetworkConfigRouterOS/SSH.php
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/NetworkConfigRouterOS/SSH.php
r738 r873 18 18 { 19 19 echo($Commands); 20 if (!function_exists("ssh2_connect")) die("Function ssh2_connect doesn't exist");21 if (!($this->Session = ssh2_connect($this->HostName, 22, $this->Methods))) echo("Fail: Unable to establish connection to host\n");20 if (!function_exists("ssh2_connect")) die("Function ssh2_connect doesn't exist"); 21 if (!($this->Session = ssh2_connect($this->HostName, 22, $this->Methods))) echo("Fail: Unable to establish connection to host\n"); 22 22 else 23 23 { 24 if (!ssh2_auth_password($this->Session, $this->UserName, $this->Password)) echo("Fail: unable to authenticate\n");24 if (!ssh2_auth_password($this->Session, $this->UserName, $this->Password)) echo("Fail: unable to authenticate\n"); 25 25 else 26 26 { 27 //if (!($Stream = ssh2_shell($this->Session, 'xterm', null, 80, 40, SSH2_TERM_UNIT_CHARS))) echo("Fail: unable to execute command\n");28 if (!($Stream = ssh2_exec($this->Session, $Commands))) echo("Fail: unable to execute command\n");27 //if (!($Stream = ssh2_shell($this->Session, 'xterm', null, 80, 40, SSH2_TERM_UNIT_CHARS))) echo("Fail: unable to execute command\n"); 28 if (!($Stream = ssh2_exec($this->Session, $Commands))) echo("Fail: unable to execute command\n"); 29 29 else 30 30 { 31 31 $Response = ''; 32 32 stream_set_blocking($Stream, true); 33 while ($Buffer = fread($Stream, 4000))33 while ($Buffer = fread($Stream, 4000)) 34 34 { 35 35 $Response .= $Buffer; … … 37 37 /* 38 38 //echo(') '.strlen($Buffer).' '.ord($Buffer{0}).'('); 39 for ($I = 0; $I < strlen($Buffer); $I++)39 for ($I = 0; $I < strlen($Buffer); $I++) 40 40 { 41 if (((ord($Buffer{$I}) >= 32) and (ord($Buffer{$I}) <= 128)) or ($Buffer{$I} = "\n") or ($Buffer{$I} = "\r")) echo($Buffer{$I});42 if ($Buffer{$I} == '>')41 if (((ord($Buffer{$I}) >= 32) and (ord($Buffer{$I}) <= 128)) or ($Buffer{$I} = "\n") or ($Buffer{$I} = "\r")) echo($Buffer{$I}); 42 if ($Buffer{$I} == '>') 43 43 { 44 44 fwrite($Stream, $Commands."\n\r"); … … 54 54 } 55 55 echo($Response); 56 return (explode("\n", substr($Response, 0, -1)));56 return (explode("\n", substr($Response, 0, -1))); 57 57 } 58 58 }
Note:
See TracChangeset
for help on using the changeset viewer.