Unverified Commit 3e4529a0 authored by BaiJiangJie's avatar BaiJiangJie Committed by GitHub

Merge pull request #257 from jumpserver/dev_bai

[Update] 优化telnet连接逻辑
parents 1919898d 5db8340f
...@@ -300,25 +300,31 @@ class TelnetConnection: ...@@ -300,25 +300,31 @@ class TelnetConnection:
logger.info(msg) logger.info(msg)
return None, msg return None, msg
if data.startswith(telnetlib.IAC): # 将数据以 \r\n 进行分割
self.option_negotiate(data) _data_list = data.split(b'\r\n')
else: for _data in _data_list:
result = self.login_auth(data) if not _data:
if result:
msg = 'Successful asset connection.<{}>/<{}>/<{}>.'.format(
self.client.user, self.system_user.username,
self.asset.hostname
)
logger.info(msg)
return self.sock, None
elif result is False:
self.sock.close()
msg = 'Authentication failed.\r\n'
logger.info(msg)
return None, msg
elif result is None:
continue continue
if _data.startswith(telnetlib.IAC):
self.option_negotiate(_data)
else:
result = self.login_auth(_data)
if result:
msg = 'Successful asset connection.<{}>/<{}>/<{}>.'.format(
self.client.user, self.system_user.username,
self.asset.hostname
)
logger.info(msg)
return self.sock, None
elif result is False:
self.sock.close()
msg = 'Authentication failed.\r\n'
logger.info(msg)
return None, msg
elif result is None:
continue
def option_negotiate(self, data): def option_negotiate(self, data):
""" """
Telnet server option negotiate before connection Telnet server option negotiate before connection
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment