Merge branch 'dev' of github.com:jumpserver/jumpserver into TermLogRecorder

pull/167/head
liuzheng712 2016-03-25 23:58:04 +08:00
commit 5e329f51a4
2 changed files with 13 additions and 14 deletions

View File

@ -92,7 +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.vim_end_flag = False
self.vim_end_pattern = re.compile(r'\x1b\[\?1049', re.X)
self.vim_pattern = re.compile(r'\W?vi[m]?\s.* | \W?fg\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
@ -122,7 +123,7 @@ class Tty(object):
:return:返回去除PS1或者mysql字符串的结果 :return:返回去除PS1或者mysql字符串的结果
""" """
result = None result = None
match = self.ps1_pattern.split(command) match = re.compile('\[?.*@.*\]?[\$#]\s').split(command)
if match: if match:
# 只需要最后的一个PS1后面的字符串 # 只需要最后的一个PS1后面的字符串
result = match[-1].strip() result = match[-1].strip()
@ -303,7 +304,6 @@ class SshTty(Tty):
data = '' data = ''
input_str = '' input_str = ''
input_mode = False input_mode = False
vim_end_flag = False
try: try:
tty.setraw(sys.stdin.fileno()) tty.setraw(sys.stdin.fileno())
tty.setcbreak(sys.stdin.fileno()) tty.setcbreak(sys.stdin.fileno())
@ -334,8 +334,6 @@ class SshTty(Tty):
except OSError as msg: except OSError as msg:
if msg.errno == errno.EAGAIN: if msg.errno == errno.EAGAIN:
continue continue
#sys.stdout.write(x)
#sys.stdout.flush()
now_timestamp = time.time() now_timestamp = time.time()
log_time_f.write('%s %s\n' % (round(now_timestamp-pre_timestamp, 4), len(x))) log_time_f.write('%s %s\n' % (round(now_timestamp-pre_timestamp, 4), len(x)))
log_time_f.flush() log_time_f.flush()
@ -364,13 +362,13 @@ class SshTty(Tty):
if input_str != x: if input_str != x:
data += input_str data += input_str
if self.vim_flag: if self.vim_flag:
match = re.compile(r'\x1b\[\?1049', re.X).findall(self.vim_data) match = self.vim_end_pattern.findall(self.vim_data)
if match: if match:
if vim_end_flag or len(match) == 2: if self.vim_end_flag or len(match) == 2:
self.vim_flag = False self.vim_flag = False
vim_end_flag = False self.vim_end_flag = False
else: else:
vim_end_flag = True self.vim_end_flag = True
else: else:
data = self.deal_command(data)[0:200] data = self.deal_command(data)[0:200]
if len(data) > 0: if len(data) > 0:

View File

@ -371,12 +371,13 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
self.term.input_mode = True self.term.input_mode = True
if str(jsondata['data']) in ['\r', '\n', '\r\n']: if str(jsondata['data']) in ['\r', '\n', '\r\n']:
if self.term.vim_flag: if self.term.vim_flag:
match = self.term.ps1_pattern.search(self.term.vim_data) match = re.compile(r'\x1b\[\?1049', re.X).findall(self.vim_data)
if match: if match:
if self.term.vim_end_flag or len(match) == 2:
self.term.vim_flag = False self.term.vim_flag = False
result = self.term.deal_command(self.term.data)[0:200] self.term.vim_end_flag = False
if len(result) > 0: else:
TtyLog(log=self.log, datetime=datetime.datetime.now(), cmd=result).save() self.term.vim_end_flag = True
else: else:
result = self.term.deal_command(self.term.data)[0:200] result = self.term.deal_command(self.term.data)[0:200]
if len(result) > 0: if len(result) > 0: