From 9ca5c805438fceb6874db06a92891119d7e0fed6 Mon Sep 17 00:00:00 2001 From: golonsylwek Date: Tue, 22 Jan 2019 08:58:18 +0100 Subject: [PATCH 1/3] fix resize window issue --- moler/cmd/unix/ssh.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/moler/cmd/unix/ssh.py b/moler/cmd/unix/ssh.py index ec1e7f9fd..e366dd8ba 100644 --- a/moler/cmd/unix/ssh.py +++ b/moler/cmd/unix/ssh.py @@ -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 @@ -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): """ @@ -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) @@ -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 @@ -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 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ -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 From 5f400de3eb22ab729f9bee72505ead0c70973316 Mon Sep 17 00:00:00 2001 From: golonsylwek Date: Tue, 22 Jan 2019 10:41:46 +0100 Subject: [PATCH 2/3] add test resize window --- moler/cmd/unix/ssh.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/moler/cmd/unix/ssh.py b/moler/cmd/unix/ssh.py index e366dd8ba..9815fb17b 100644 --- a/moler/cmd/unix/ssh.py +++ b/moler/cmd/unix/ssh.py @@ -451,3 +451,38 @@ def _check_if_resize(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 +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 = {} From 9056d9285f1e6fda3ceed8b055859363f791fac2 Mon Sep 17 00:00:00 2001 From: golonsylwek Date: Tue, 22 Jan 2019 13:19:49 +0100 Subject: [PATCH 3/3] change resize output --- moler/cmd/unix/ssh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moler/cmd/unix/ssh.py b/moler/cmd/unix/ssh.py index 9815fb17b..33443831e 100644 --- a/moler/cmd/unix/ssh.py +++ b/moler/cmd/unix/ssh.py @@ -473,7 +473,7 @@ def _check_if_resize(self, line): 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 +7[r[999;999H[6n resize: unknown character, exiting. Have a lot of fun... host:~ #