deal_command添加到静态方法中

pull/26/head
ibuler 2015-11-16 23:33:44 +08:00
parent 4abf2b06d8
commit ce02d430ba
3 changed files with 125 additions and 124 deletions

View File

@ -25,7 +25,7 @@ from jumpserver.settings import LOG_DIR
login_user = get_object(User, username=getpass.getuser())
VIM_FLAG = False
try:
import termios
@ -68,12 +68,40 @@ def check_vim_status(command, ssh):
return False
def deal_command(str_r, ssh):
class Tty(object):
"""
A virtual tty class
一个虚拟终端类实现连接ssh和记录日志基类
"""
def __init__(self, username, asset_name):
self.username = username
self.asset_name = asset_name
self.ip = None
self.port = 22
self.channel = None
#self.asset = get_object(Asset, name=asset_name)
#self.user = get_object(User, username=username)
self.role = None
self.ssh = None
self.connect_info = None
self.login_type = 'ssh'
@staticmethod
def is_output(strings):
newline_char = ['\n', '\r', '\r\n']
for char in newline_char:
if char in strings:
return True
return False
@staticmethod
def deal_command(str_r, ssh):
"""
处理命令中特殊字符
"""
t = time.time()
str_r = re.sub('\x07','',str_r) #删除响铃
patch_char = re.compile('\x08\x1b\[C') #删除方向左右一起的按键
while patch_char.search(str_r):
@ -190,33 +218,6 @@ def deal_command(str_r, ssh):
else:
return ''
class Tty(object):
"""
A virtual tty class
一个虚拟终端类实现连接ssh和记录日志基类
"""
def __init__(self, username, asset_name):
self.username = username
self.asset_name = asset_name
self.ip = None
self.port = 22
self.channel = None
#self.asset = get_object(Asset, name=asset_name)
#self.user = get_object(User, username=username)
self.role = None
self.ssh = None
self.connect_info = None
self.login_type = 'ssh'
@staticmethod
def is_output(strings):
newline_char = ['\n', '\r', '\r\n']
for char in newline_char:
if char in strings:
return True
return False
@staticmethod
def remove_control_char(str_r):
"""
@ -402,7 +403,7 @@ class SshTty(Tty):
input_mode = True
if str(x) in ['\r', '\n', '\r\n']:
data = self.remove_control_char(data)
data = self.deal_command(data, self.ssh)
TtyLog(log=log, datetime=datetime.datetime.now(), cmd=data).save()
data = ''

View File

@ -13,7 +13,7 @@ password = mysql234
database = jumpserver
[websocket]
web_socket_host = 127.0.0.1:3000
web_socket_host = j:3000
[mail]
mail_enable = 1

View File

@ -236,7 +236,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
if data.get('data'):
self.term.input_mode = True
if str(data['data']) in ['\r', '\n', '\r\n']:
TtyLog(log=self.log, datetime=datetime.datetime.now(), cmd=self.term.remove_control_char(self.term.data)).save()
TtyLog(log=self.log, datetime=datetime.datetime.now(), cmd=self.term.deal_command(self.term.data, self.term.ssh)).save()
self.term.data = ''
self.term.input_mode = False
self.term.channel.send(data['data'])