Merge branch 'dev' of https://git.coding.net/jumpserver/jumpserver into NormalUserPageLZ

pull/26/head
liuzheng712 2015-11-17 09:53:48 +08:00
commit b9b965753b
3 changed files with 148 additions and 123 deletions

View File

@ -25,7 +25,7 @@ from jumpserver.settings import LOG_DIR
login_user = get_object(User, username=getpass.getuser()) login_user = get_object(User, username=getpass.getuser())
VIM_FLAG = False
try: try:
import termios import termios
@ -68,12 +68,40 @@ def check_vim_status(command, ssh):
return False 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) #删除响铃 str_r = re.sub('\x07','',str_r) #删除响铃
patch_char = re.compile('\x08\x1b\[C') #删除方向左右一起的按键 patch_char = re.compile('\x08\x1b\[C') #删除方向左右一起的按键
while patch_char.search(str_r): while patch_char.search(str_r):
@ -190,33 +218,6 @@ def deal_command(str_r, ssh):
else: else:
return '' 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 @staticmethod
def remove_control_char(str_r): def remove_control_char(str_r):
""" """
@ -402,7 +403,7 @@ class SshTty(Tty):
input_mode = True input_mode = True
if str(x) in ['\r', '\n', '\r\n']: 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() TtyLog(log=log, datetime=datetime.datetime.now(), cmd=data).save()
data = '' data = ''

24
jumpserver.conf Normal file
View File

@ -0,0 +1,24 @@
#coding: utf8
[base]
url = http://127.0.0.1
key = 88aaaf7ffe3c6c04
log = debug
[db]
host = 127.0.0.1
port = 3306
user = jumpserver
password = mysql234
database = jumpserver
[websocket]
web_socket_host = j:3000
[mail]
mail_enable = 1
email_host = smtp.exmail.qq.com
email_port = 25
email_host_user = noreply@jumpserver.org
email_host_password = jumpserver1234
email_use_tls = True

View File

@ -236,7 +236,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler):
if data.get('data'): if data.get('data'):
self.term.input_mode = True self.term.input_mode = True
if str(data['data']) in ['\r', '\n', '\r\n']: 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.data = ''
self.term.input_mode = False self.term.input_mode = False
self.term.channel.send(data['data']) self.term.channel.send(data['data'])