Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/NetworkConfigRouterOS/SSH.php

    r738 r873  
    1818  {
    1919    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");
    2222    else
    2323    {
    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");
    2525      else
    2626      {
    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");
    2929        else
    3030        {
    3131          $Response = '';
    3232          stream_set_blocking($Stream, true);
    33           while($Buffer = fread($Stream, 4000))
     33          while ($Buffer = fread($Stream, 4000))
    3434          {
    3535            $Response .= $Buffer;
     
    3737            /*
    3838            //echo(') '.strlen($Buffer).' '.ord($Buffer{0}).'(');
    39             for($I = 0; $I < strlen($Buffer); $I++)
     39            for ($I = 0; $I < strlen($Buffer); $I++)
    4040            {
    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} == '>')
    4343              {
    4444                fwrite($Stream, $Commands."\n\r");
     
    5454    }
    5555    echo($Response);
    56     return(explode("\n", substr($Response, 0, -1)));
     56    return (explode("\n", substr($Response, 0, -1)));
    5757  }
    5858}
Note: See TracChangeset for help on using the changeset viewer.