From 44b2bcb7594cab588d96a183aa1b740bbc998bdd Mon Sep 17 00:00:00 2001 From: liuzheng712 Date: Fri, 25 Mar 2016 22:24:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jlog/models.py | 13 +++++++++++++ jlog/views.py | 22 +++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/jlog/models.py b/jlog/models.py index dfb418651..3a50259e5 100644 --- a/jlog/models.py +++ b/jlog/models.py @@ -13,6 +13,19 @@ class Log(models.Model): pid = models.IntegerField() is_finished = models.BooleanField(default=False) end_time = models.DateTimeField(null=True) + ''' + add by liuzheng + ''' + userMM = models.ManyToManyField(User) + logPath = models.TextField() + filename = models.CharField(max_length=40) + logPWD = models.TextField() # log zip file's + nick = models.TextField(null=True) # log's nick name + log = models.TextField(null=True) + history = models.TextField(null=True) + timestamp = models.IntegerField(default=int(time.time())) + datetimestamp = models.DateTimeField(auto_now_add=True) + def __unicode__(self): return self.log_path diff --git a/jlog/views.py b/jlog/views.py index 085a9307e..d917f0748 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -7,7 +7,7 @@ from jperm.perm_api import user_have_perm from django.http import HttpResponseNotFound from jlog.log_api import renderTemplate -from jlog.models import Log, ExecLog, FileLog, TermLog +from jlog.models import Log, ExecLog, FileLog from jumpserver.settings import LOG_DIR import zipfile import json @@ -137,7 +137,7 @@ def log_record(request): log_id = request.REQUEST.get('id', None) if log_id: logs = TermLogRecorder(request.user) - log = TermLog.objects.get(id=int(log_id)) + log = Log.objects.get(id=int(log_id)) return HttpResponse(logs.load_full_log(log.filename)) else: return HttpResponse("ERROR") @@ -261,16 +261,16 @@ class TermLogRecorder(object): zf.setpassword(password) zf.writestr(filename, json.dumps(self.log)) zf.close() - record = TermLog.objects.create(logPath=filepath, logPWD=password, filename=filename, + record = Log.objects.create(logPath=filepath, logPWD=password, filename=filename, history=json.dumps(self.CMD), timestamp=int(self.recoderStartTime)) if self.user: - record.user.add(self.user) + record.userMM.add(self.user) except: - record = TermLog.objects.create(logPath='locale', logPWD=password, log=json.dumps(self.log), + record = Log.objects.create(logPath='locale', logPWD=password, log=json.dumps(self.log), filename=filename, history=json.dumps(self.CMD), timestamp=int(self.recoderStartTime)) if self.user: - record.user.add(self.user) + record.userMM.add(self.user) def list(self, user=None, uid=None): tmp = [] @@ -281,7 +281,7 @@ class TermLogRecorder(object): else: user = self.user if user: - self._lists = TermLog.objects.filter(user=user.id) + self._lists = Log.objects.filter(user=user.id) for i in self._lists.all(): tmp.append( {'filename': i.filename, 'locale': i.logPath == 'locale', 'nick': i.nick, 'timestamp': i.timestamp, @@ -299,7 +299,7 @@ class TermLogRecorder(object): if self._lists: self.file = self._lists.get(filename=filename) else: - self.file = TermLog.objects.get(user=user.id, filename=filename) + self.file = Log.objects.get(user=user.id, filename=filename) if self.file.logPath == 'locale': return self.file.log else: @@ -323,7 +323,7 @@ class TermLogRecorder(object): if self._lists: self.file = self._lists.get(filename=filename) else: - self.file = TermLog.objects.get(user=user.id, filename=filename) + self.file = Log.objects.get(user=user.id, filename=filename) return self.file.history return 'ERROR User(None)' @@ -335,7 +335,7 @@ class TermLogRecorder(object): else: pass if user: - TermLog.objects.get(filename=filename).user.add(user) + Log.objects.get(filename=filename).userMM.add(user) return True return False @@ -347,6 +347,6 @@ class TermLogRecorder(object): else: pass if user: - TermLog.objects.get(filename=filename).user.remove(user) + Log.objects.get(filename=filename).userMM.remove(user) return True return False