Skip to content

Commit

Permalink
Merge pull request #104 from nokia/ssh_fix_resize
Browse files Browse the repository at this point in the history
fix resize window issue
  • Loading branch information
Ernold11 authored Jan 22, 2019
2 parents bd4a208 + 9056d92 commit 9d36ee6
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions moler/cmd/unix/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class Ssh(GenericUnixCommand):
_re_password = re.compile(r"(password.*:)", re.IGNORECASE)
_re_failed_strings = re.compile(r"Permission denied|No route to host|ssh: Could not", re.IGNORECASE)
_re_host_key_verification_failed = re.compile(r"Host key verification failed", re.IGNORECASE)
_re_resize = re.compile(r"999H")

def __init__(self, connection, login, password, host, prompt=None, expected_prompt='>', port=0,
known_hosts_on_failure='keygen', set_timeout=r'export TMOUT=\"2678400\"', set_prompt=None,
term_mono="TERM=xterm-mono", newline_chars=None, encrypt_password=True, runner=None,
target_newline="\n", allowed_newline_after_prompt=False):

"""
:param connection: moler connection to device, terminal when command is executed
:param login: ssh login
Expand Down Expand Up @@ -75,6 +75,7 @@ def __init__(self, connection, login, password, host, prompt=None, expected_prom
self._sent_prompt = False
self._sent_password = False
self._sent_continue_connecting = False
self._resize_sent = False

def build_command_string(self):
"""
Expand All @@ -100,6 +101,7 @@ def on_new_line(self, line, is_full_line):
:return: Nothing
"""
try:
self._check_if_resize(line)
self._check_if_failure(line)
self._get_hosts_file_if_displayed(line)
self._push_yes_if_needed(line)
Expand Down Expand Up @@ -309,6 +311,17 @@ def _is_target_prompt(self, line):
"""
return self._regex_helper.search_compiled(self._re_expected_prompt, line)

def _check_if_resize(self, line):
"""
Checks if line from device has information about size of windows.
:param line: Line from device.
:return: Match object if regex matches, None otherwise.
"""
if self._regex_helper.search_compiled(Ssh._re_resize, line) and not self._resize_sent:
self._resize_sent = True
self.connection.sendline("")
raise ParsingDone()


COMMAND_OUTPUT = """
client:~/>TERM=xterm-mono ssh -l user host.domain.net
Expand Down Expand Up @@ -379,7 +392,6 @@ def _is_target_prompt(self, line):

COMMAND_RESULT_rm = {}


COMMAND_OUTPUT_keygen = """
client:~/>TERM=xterm-mono ssh -l user host.domain.net
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Expand Down Expand Up @@ -413,7 +425,6 @@ def _is_target_prompt(self, line):

COMMAND_RESULT_keygen = {}


COMMAND_OUTPUT_2_passwords = """
client:~/>TERM=xterm-mono ssh -l user host.domain.net
You are about to access a private system. This system is for the use of
Expand All @@ -440,3 +451,38 @@ def _is_target_prompt(self, line):
}

COMMAND_RESULT_2_passwords = {}

COMMAND_OUTPUT_resize_window = """
client:~/>TERM=xterm-mono ssh -l user host.domain.net
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
[...].
Please contact your system administrator.
Add correct host key in /home/you/.ssh/known_hosts to get rid of this message.
Offending RSA key in /home/you/.ssh/known_hosts:86
RSA host key for host.domain.net has changed and you have requested strict checking.
Host key verification failed.
client:~/>sh-keygen -R host.domain.net
client:~/>TERM=xterm-mono ssh -l user host.domain.net
To edit this message please edit /etc/ssh_banner
You may put information to /etc/ssh_banner who is owner of this PC
Password:
Last login: Sun Jan 6 13:42:05 UTC+2 2019 on ttyAMA2
7[r[999;999H[6n
resize: unknown character, exiting.
Have a lot of fun...
host:~ #
host:~ # export TMOUT="2678400"
host:~ #"""

COMMAND_KWARGS_resize_window = {
"login": "user", "password": "english", "known_hosts_on_failure": "keygen",
"host": "host.domain.net", "prompt": "client.*>", "expected_prompt": "host.*#"
}

COMMAND_RESULT_resize_window = {}

0 comments on commit 9d36ee6

Please sign in to comment.