Merge pull request #180 from jumpserver/bugfix

修复日志回放问题
pull/184/head
ibuler 2016-03-29 23:52:19 +08:00
commit 489d796d7b
2 changed files with 24 additions and 2 deletions

View File

@ -79,6 +79,21 @@ def renderTemplate(script_path, time_file_path, dimensions=(24, 80), templatenam
return rendered
def renderJSON(script_path, time_file_path):
with copen(script_path, encoding='utf-8', errors='replace', newline='\r\n') as scriptf:
# with open(script_path) as scriptf:
with open(time_file_path) as timef:
timing = getTiming(timef)
ret = {}
with closing(scriptf):
scriptf.readline() # ignore first header line from script file
offset = 0
for t in timing:
dt = scriptf.read(t[1])
offset += t[0]
ret[str(offset/float(1000))] = dt.decode('utf-8', 'replace')
return dumps(ret)
def kill_invalid_connection():
unfinished_logs = Log.objects.filter(is_finished=False)
now = datetime.datetime.now()

View File

@ -5,7 +5,7 @@ from django.shortcuts import render_to_response, render
from jumpserver.api import *
from jperm.perm_api import user_have_perm
from django.http import HttpResponseNotFound
from jlog.log_api import renderTemplate
from jlog.log_api import renderJSON
from jlog.models import Log, ExecLog, FileLog, TermLog
from jumpserver.settings import LOG_DIR
@ -138,7 +138,14 @@ def log_record(request):
if log_id:
TermL = TermLogRecorder(request.user)
log = Log.objects.get(id=int(log_id))
return HttpResponse(TermL.load_full_log(filename=log.filename))
if len(log.filename) == 0:
log_file = log.log_path + '.log'
log_time = log.log_path + '.time'
if os.path.isfile(log_file) and os.path.isfile(log_time):
content = renderJSON(log_file, log_time)
return HttpResponse(content)
else:
return HttpResponse(TermL.load_full_log(filename=log.filename))
else:
return HttpResponse("ERROR")
else: