From e46d95258630af32ae876b1562a806a0bd96f16b Mon Sep 17 00:00:00 2001 From: remittor Date: Thu, 17 Apr 2025 08:15:59 +0300 Subject: [PATCH] gateway: Fix prompt in get_telnet and set TELNET window size: 1000x32 --- gateway.py | 4 +++- xmir_base/telnetlib/telnetlib.py | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gateway.py b/gateway.py index b9bdc73..c1cfd6d 100644 --- a/gateway.py +++ b/gateway.py @@ -790,6 +790,7 @@ class Gateway(): return False def get_telnet(self, verbose = 0, password = None): + from telnetlib import NOP, IAC, SB, NAWS, SE try: tn = telnetlib.Telnet(self.ip_addr, timeout=4) except Exception as e: @@ -799,10 +800,11 @@ class Gateway(): try: p_login = b'login: ' p_passw = b'Password: ' - prompt = f"{self.login}@XiaoQiang:(.*?)#".encode('ascii') + prompt = f"{self.login}@XiaoQiang:(.*?)# ".encode('ascii') idx, obj, output = tn.expect([p_login, prompt], timeout=2) if idx < 0: raise Exception('TELNET auth error (1)') + tn.sock.sendall(IAC + SB + NAWS + b'\x03\xE8\x00\x20' + IAC + SE) if idx > 0: tn.prompt = obj.group() return tn diff --git a/xmir_base/telnetlib/telnetlib.py b/xmir_base/telnetlib/telnetlib.py index 8ce053e..c6f79e9 100644 --- a/xmir_base/telnetlib/telnetlib.py +++ b/xmir_base/telnetlib/telnetlib.py @@ -38,8 +38,6 @@ import socket import selectors from time import monotonic as _time -__all__ = ["Telnet"] - # Tunable parameters DEBUGLEVEL = 0