|
@@ -38,6 +38,7 @@ import select
|
|
|
import signal
|
|
|
import time
|
|
|
import getpass
|
|
|
+import re
|
|
|
|
|
|
|
|
|
class SSHTunnel(object):
|
|
@@ -205,14 +206,15 @@ class SSHTunnel(object):
|
|
|
|
|
|
PROMPT_PW = "'s Password:"
|
|
|
PROMPT_AUTH = "The authenticity of host "
|
|
|
- PROMPT_YESNO = " (yes/no)?"
|
|
|
+ PROMPT_YESNO = re.compile(r".*\s\(\[?yes\]?/\[?no\]?(/[\[\]\w\s\d_\-]+)?\)\s*\?\s*")
|
|
|
AUTH_FINISH = "Authenticated to "
|
|
|
|
|
|
def __handshake(self, ptyMasterFd, timeout):
|
|
|
timeoutEnd = monotonic_time() + (timeout or 0)
|
|
|
sentPw, authReq, finished = False, [], False
|
|
|
while not finished:
|
|
|
- self.sleep(0.1)
|
|
|
+ if not self.sleep(0.1):
|
|
|
+ raise AwlSimError("Establishing SSH tunnel cancelled.")
|
|
|
if timeout and monotonic_time() >= timeoutEnd:
|
|
|
raise AwlSimError("Timeout establishing SSH tunnel.")
|
|
|
fromSsh = self.__read(ptyMasterFd)
|
|
@@ -249,7 +251,8 @@ class SSHTunnel(object):
|
|
|
if self.PROMPT_AUTH.lower() in lineLow:
|
|
|
authReq.append(line)
|
|
|
continue
|
|
|
- if self.PROMPT_YESNO.lower() in lineLow and authReq:
|
|
|
+ if (self.PROMPT_YESNO.match(lineLow, re.IGNORECASE) and
|
|
|
+ authReq):
|
|
|
ok = self.hostAuth("\n".join(authReq))
|
|
|
if not ok:
|
|
|
raise AwlSimError("SSH tunnel host "
|
|
@@ -265,8 +268,11 @@ class SSHTunnel(object):
|
|
|
|
|
|
def sleep(self, seconds):
|
|
|
"""Sleep for a number of seconds.
|
|
|
+ Returns True, if everything is Ok.
|
|
|
+ Returns False, if the connection operation shall be cancelled.
|
|
|
"""
|
|
|
time.sleep(seconds)
|
|
|
+ return True
|
|
|
|
|
|
def sshMessage(self, message, isDebug):
|
|
|
"""Print a SSH log message.
|