From cf1da2a4201fbe7b261fc5af1d6de945e00bbd96 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Tue, 29 Mar 2016 20:56:19 +0800 Subject: [PATCH] bugfix --- jlog/log_api.py | 8 ++++++++ jlog/views.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/jlog/log_api.py b/jlog/log_api.py index cce830c03..669960312 100644 --- a/jlog/log_api.py +++ b/jlog/log_api.py @@ -79,6 +79,14 @@ 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) + json = scriptToJSON(scriptf, timing) + return json + def kill_invalid_connection(): unfinished_logs = Log.objects.filter(is_finished=False) now = datetime.datetime.now() diff --git a/jlog/views.py b/jlog/views.py index 7c2627de8..09c79a9d8 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -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: