mirror of https://github.com/jumpserver/jumpserver
修改日志数据库部分
parent
2d1e001ddf
commit
44b2bcb759
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue