From 8e8d8c9d6a32b7550750793d361b4af17f151c29 Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Fri, 25 Mar 2016 22:19:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=9B=9E=E6=94=BEOK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlog/views.py | 41 ++++++++++++++++++++++++++++------------- jumpserver/settings.py | 26 +++++++++++++------------- run_server.py | 14 +++++++------- 3 files changed, 48 insertions(+), 33 deletions(-) diff --git a/jlog/views.py b/jlog/views.py index 69716bda2..085a9307e 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -1,8 +1,7 @@ # coding:utf-8 from django.db.models import Q from django.template import RequestContext -from django.shortcuts import render_to_response - +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 @@ -114,20 +113,36 @@ def log_history(request): return HttpResponse('无日志记录!') +# @require_role('admin') +# 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('无日志记录!') @require_role('admin') 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) + """ + Author: liuzheng712@gmail.com + """ + if request.method == "GET": + return render(request, 'jlog/record.html') + elif request.method == "POST": + log_id = request.REQUEST.get('id', None) + if log_id: + logs = TermLogRecorder(request.user) + log = TermLog.objects.get(id=int(log_id)) + return HttpResponse(logs.load_full_log(log.filename)) else: - return HttpResponse('无日志记录!') - + return HttpResponse("ERROR") + else: + return HttpResponse("ERROR METHOD!") @require_role('admin') def log_detail(request, offset): diff --git a/jumpserver/settings.py b/jumpserver/settings.py index 1ab24fac5..d01dcc96a 100644 --- a/jumpserver/settings.py +++ b/jumpserver/settings.py @@ -99,23 +99,23 @@ WSGI_APPLICATION = 'jumpserver.wsgi.application' # Database # https://docs.djangoproject.com/en/1.7/ref/settings/#databases -# DATABASES = { -# 'default': { -# 'ENGINE': 'django.db.backends.mysql', -# 'NAME': DB_DATABASE, -# 'USER': DB_USER, -# 'PASSWORD': DB_PASSWORD, -# 'HOST': DB_HOST, -# 'PORT': DB_PORT, -# } -# } - DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'ENGINE': 'django.db.backends.mysql', + 'NAME': DB_DATABASE, + 'USER': DB_USER, + 'PASSWORD': DB_PASSWORD, + 'HOST': DB_HOST, + 'PORT': DB_PORT, } } + +# DATABASES = { +# 'default': { +# 'ENGINE': 'django.db.backends.sqlite3', +# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), +# } +# } TEMPLATE_CONTEXT_PROCESSORS = ( 'django.contrib.auth.context_processors.auth', 'django.core.context_processors.debug', diff --git a/run_server.py b/run_server.py index 95c7c1448..71ddf0ad2 100755 --- a/run_server.py +++ b/run_server.py @@ -22,7 +22,7 @@ import tornado.httpclient from tornado.websocket import WebSocketClosedError from tornado.options import define, options -# from pyinotify import WatchManager, ProcessEvent, IN_DELETE, IN_CREATE, IN_MODIFY, AsyncNotifier +from pyinotify import WatchManager, ProcessEvent, IN_DELETE, IN_CREATE, IN_MODIFY, AsyncNotifier import select from connect import Tty, User, Asset, PermRole, logger, get_object, gen_resource @@ -101,12 +101,12 @@ class MyThread(threading.Thread): pass -# class EventHandler(ProcessEvent): -# def __init__(self, client=None): -# self.client = client -# -# def process_IN_MODIFY(self, event): -# self.client.write_message(f.read()) +class EventHandler(ProcessEvent): + def __init__(self, client=None): + self.client = client + + def process_IN_MODIFY(self, event): + self.client.write_message(f.read()) def file_monitor(path='.', client=None):