0

I'm using the following code to interact with an SSH session. All is fine until the last line of code.

I'm getting nice screen prints on my webpage, until the last getScreen(), when it throws the following errors. I will say that after my last command, the ssh sessions window (in putty at least) goes into kinda a live mode, almost like a tail command, and the window will populate info as it comes into the ssh session. It looks to be a pre-determined size ?

Ideally, I want to pipe what comes into this window to a file, that is my ultimate goal, but for now just getting it to show on screen would be helpful.

PHP Notice:  Undefined offset: 79 in E:\jackwad\IIS\portal\File\ANSI.php on line 556
PHP Notice:  Trying to get property 'foreground' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 499
PHP Notice:  Trying to get property 'foreground' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 500
PHP Notice:  Trying to get property 'foreground' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 501
PHP Notice:  Trying to get property 'background' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 507
PHP Notice:  Trying to get property 'background' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 508
PHP Notice:  Trying to get property 'background' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 509
PHP Notice:  Trying to get property 'bold' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 515
PHP Notice:  Trying to get property 'underline' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 522
PHP Notice:  Trying to get property 'blink' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 529
PHP Notice:  Undefined offset: 79 in E:\jackwad\IIS\portal\File\ANSI.php on line 558
PHP Notice:  Trying to get property 'foreground' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 499
PHP Notice:  Trying to get property 'foreground' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 503
PHP Notice:  Trying to get property 'background' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 507
PHP Notice:  Trying to get property 'background' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 511
PHP Notice:  Trying to get property 'bold' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 515
PHP Notice:  Trying to get property 'underline' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 522
PHP Notice:  Trying to get property 'blink' of non-object in E:\jackwad\IIS\portal\File\ANSI.php on line 529

My Code:

include('Net/SSH2.php');
include('File/ANSI.php');

$ssh = new Net_SSH2('1xx.xx.xx.xx');
if (!$ssh->login('xxxxx', 'xxxxxxxx')) {
    exit('Login Failed');
}

$ansi = new File_ANSI();

$ansi->appendString($ssh->read('username@username:~$'));
$ssh->write("\n");
$ssh->setTimeout(2);
$ansi->appendString($ssh->read());
echo $ansi->getScreen();

$ssh->write("sat\n");
$ssh->setTimeout(2);
$ansi->appendString($ssh->read());
echo $ansi->getScreen();

$ssh->write("W2KTT\n");
$ssh->setTimeout(2);
$ansi->appendString($ssh->read());
echo $ansi->getScreen();

$ssh->write("some text 102\n");
$ssh->setTimeout(5);
$ansi->appendString($ssh->read());
$ansi->getScreen(); //this is the problem line

ANSI.php

500 - function _getScreen()
501 - {
502 -     $output = '';
503 -     $last_attr = $this->base_attr_cell;
504 -     for ($i = 0; $i <= $this->max_y; $i++) {
505 -         for ($j = 0; $j <= $this->max_x; $j++) {
506 -             $cur_attr = $this->attrs[$i][$j];
507 -             $output.= $this->_processCoordinate($last_attr, $cur_attr, isset($this->screen[$i][$j]) ? $this->screen[$i][$j] : '');
508 -             $last_attr = $this->attrs[$i][$j];
509 -         }
510 -         $output.= "\r\n";
511 -     }
512 -     $output = substr($output, 0, -2);
513 -     // close any remaining open tags
514 -     $output.= $this->_processCoordinate($last_attr, $this->base_attr_cell, '');
515 -     return rtrim($output);
516 - }
Kenster
  • 23,465
  • 21
  • 80
  • 106
Vacek
  • 179
  • 1
  • 12
  • 1
    I wonder if https://github.com/phpseclib/phpseclib/commit/bcaa494af229dfeccc50ebf2062b218e6c1fa567 would fix the issue for you. – neubert Jun 17 '20 at 15:17
  • 1
    You my friend, are a genius ;) It does fix my issues exactly. nice find and thanks. – Vacek Jun 17 '20 at 15:27

0 Answers0