mirror of https://github.com/jumpserver/jumpserver
pull issue #120
parent
7dcf050dc4
commit
b2ccbc3f9e
47
connect.py
47
connect.py
|
@ -92,8 +92,8 @@ class Tty(object):
|
||||||
self.remote_ip = ''
|
self.remote_ip = ''
|
||||||
self.login_type = login_type
|
self.login_type = login_type
|
||||||
self.vim_flag = False
|
self.vim_flag = False
|
||||||
self.ps1_pattern = re.compile('\[.*@.*\][\$#]\s')
|
self.ps1_pattern = re.compile('\[?.*@.*\]?[\$#]\s')
|
||||||
self.vim_pattern = re.compile(r'\Wvi[m]+\s.* | \Wfg\s.*', re.X)
|
self.vim_pattern = re.compile(r'\W?vi[m]?\s.* | \W?fg\s.*', re.X)
|
||||||
self.vim_data = ''
|
self.vim_data = ''
|
||||||
self.stream = None
|
self.stream = None
|
||||||
self.screen = None
|
self.screen = None
|
||||||
|
@ -141,25 +141,28 @@ class Tty(object):
|
||||||
:return:返回最后的处理结果
|
:return:返回最后的处理结果
|
||||||
"""
|
"""
|
||||||
command = ''
|
command = ''
|
||||||
self.stream.feed(data)
|
try:
|
||||||
# 从虚拟屏幕中获取处理后的数据
|
self.stream.feed(data)
|
||||||
for line in reversed(self.screen.buffer):
|
# 从虚拟屏幕中获取处理后的数据
|
||||||
line_data = "".join(map(operator.attrgetter("data"), line)).strip()
|
for line in reversed(self.screen.buffer):
|
||||||
if len(line_data) > 0:
|
line_data = "".join(map(operator.attrgetter("data"), line)).strip()
|
||||||
parser_result = self.command_parser(line_data)
|
if len(line_data) > 0:
|
||||||
if parser_result is not None:
|
parser_result = self.command_parser(line_data)
|
||||||
# 2个条件写一起会有错误的数据
|
if parser_result is not None:
|
||||||
if len(parser_result) > 0:
|
# 2个条件写一起会有错误的数据
|
||||||
command = parser_result
|
if len(parser_result) > 0:
|
||||||
else:
|
command = parser_result
|
||||||
command = line_data
|
else:
|
||||||
break
|
command = line_data
|
||||||
if command != '':
|
break
|
||||||
# 判断用户输入的是否是vim 或者fg命令
|
if command != '':
|
||||||
if self.vim_pattern.search(command):
|
# 判断用户输入的是否是vim 或者fg命令
|
||||||
self.vim_flag = True
|
if self.vim_pattern.search(command):
|
||||||
# 虚拟屏幕清空
|
self.vim_flag = True
|
||||||
self.screen.reset()
|
# 虚拟屏幕清空
|
||||||
|
self.screen.reset()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
return command
|
return command
|
||||||
|
|
||||||
def get_log(self):
|
def get_log(self):
|
||||||
|
@ -403,7 +406,7 @@ class SshTty(Tty):
|
||||||
# 获取连接的隧道并设置窗口大小 Make a channel and set windows size
|
# 获取连接的隧道并设置窗口大小 Make a channel and set windows size
|
||||||
global channel
|
global channel
|
||||||
win_size = self.get_win_size()
|
win_size = self.get_win_size()
|
||||||
#self.channel = channel = ssh.invoke_shell(height=win_size[0], width=win_size[1], term='xterm')
|
# self.channel = channel = ssh.invoke_shell(height=win_size[0], width=win_size[1], term='xterm')
|
||||||
self.channel = channel = transport.open_session()
|
self.channel = channel = transport.open_session()
|
||||||
channel.get_pty(term='xterm', height=win_size[0], width=win_size[1])
|
channel.get_pty(term='xterm', height=win_size[0], width=win_size[1])
|
||||||
channel.invoke_shell()
|
channel.invoke_shell()
|
||||||
|
|
Loading…
Reference in New Issue