diff --git a/jlog/log_api.py b/jlog/log_api.py index c9d54149a..5ef484777 100644 --- a/jlog/log_api.py +++ b/jlog/log_api.py @@ -49,7 +49,7 @@ def scriptToJSON(scriptf, timing=None): return dumps(ret) -def renderTemplate(script_path, time_file_path, dimensions=(24, 60), templatename=DEFAULT_TEMPLATE): +def renderTemplate(script_path, time_file_path, dimensions=(24, 80), templatename=DEFAULT_TEMPLATE): with copen(script_path, encoding='utf-8', errors='replace') as scriptf: with open(time_file_path) as timef: timing = getTiming(timef) diff --git a/jlog/urls.py b/jlog/urls.py index 24d821f12..fe061e799 100644 --- a/jlog/urls.py +++ b/jlog/urls.py @@ -6,6 +6,7 @@ urlpatterns = patterns('', url(r'^$', log_list), url(r'^log_list/(\w+)/$', log_list), # url(r'^log_kill/', log_kill), - # url(r'^history/$', log_history), + url(r'^history/$', log_history), + url(r'^record/$', log_record), # url(r'^search/$', log_search), ) \ No newline at end of file diff --git a/jlog/views.py b/jlog/views.py index 187802a7b..53a954b17 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -9,6 +9,7 @@ from django.http import HttpResponseNotFound CONF = ConfigParser() CONF.read('%s/jumpserver.conf' % BASE_DIR) from jlog.models import Log +from jlog.log_api import renderTemplate # def get_user_info(request, offset): # """ 获取用户信息及环境 """ @@ -72,31 +73,38 @@ def log_list(request, offset): # return render_to_response('jlog/log_offline.html', locals(), context_instance=RequestContext(request)) # else: # return HttpResponseNotFound(u'没有此进程!') -# -# -# def log_history(request): -# """ 命令历史记录 """ -# log_id = request.GET.get('id', 0) -# log = Log.objects.filter(id=int(log_id)) -# if log: -# log = log[0] -# dept_name = log.dept_name -# deptname = get_session_user_info(request)[4] -# if is_group_admin(request) and dept_name != deptname: -# return httperror(request, '查看失败, 您无权查看!') -# -# elif is_common_user(request): -# return httperror(request, '查看失败, 您无权查看!') -# -# log_his = "%s.his" % log.log_path -# if os.path.isfile(log_his): -# f = open(log_his) -# content = f.read() -# return HttpResponse(content) -# else: -# return httperror(request, '无日志记录, 请查看日志处理脚本是否开启!') -# -# + + +def log_history(request): + """ 命令历史记录 """ + log_id = request.GET.get('id', 0) + log = Log.objects.filter(id=int(log_id)) + if log: + log = log[0] + log_his = "%s.his" % log.log_path + print log_his + if os.path.isfile(log_his): + f = open(log_his) + content = f.read() + return HttpResponse(content) + else: + return HttpResponse('无日志记录, 请查看日志处理脚本是否开启!') + + +def log_record(request): + log_id = request.GET.get('id', 0) + log = Log.objects.filter(id=int(log_id)) + if log: + log = log[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 = renderTemplate(log_file, log_time) + return HttpResponse(content) + else: + return HttpResponse('无日志记录, 请查看日志处理脚本是否开启!') + + # def log_search(request): # """ 日志搜索 """ # offset = request.GET.get('env', '') diff --git a/jumpserver/api.py b/jumpserver/api.py index b4ee56595..38a7821eb 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -202,7 +202,7 @@ class Jtty(object): try: log_file_f = open(log_file_path + '.log', 'a') log_time_f = open(log_file_path + '.time', 'a') - log_res_f = open(log_file_path + '.res', 'a') + log_res_f = open(log_file_path + '.his', 'a') except IOError: raise ServerError('Create logfile failed, Please modify %s permission.' % today_connect_log_dir) diff --git a/templates/jlog/log_offline.html b/templates/jlog/log_offline.html index b949a0e18..91726cd4f 100644 --- a/templates/jlog/log_offline.html +++ b/templates/jlog/log_offline.html @@ -1,6 +1,7 @@ {% extends 'base.html' %} {% block content %} {% include 'nav_cat_bar.html' %} +