mirror of https://github.com/jumpserver/jumpserver
修改日志数据库部分
parent
2d1e001ddf
commit
44b2bcb759
|
@ -13,6 +13,19 @@ class Log(models.Model):
|
||||||
pid = models.IntegerField()
|
pid = models.IntegerField()
|
||||||
is_finished = models.BooleanField(default=False)
|
is_finished = models.BooleanField(default=False)
|
||||||
end_time = models.DateTimeField(null=True)
|
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):
|
def __unicode__(self):
|
||||||
return self.log_path
|
return self.log_path
|
||||||
|
|
|
@ -7,7 +7,7 @@ from jperm.perm_api import user_have_perm
|
||||||
from django.http import HttpResponseNotFound
|
from django.http import HttpResponseNotFound
|
||||||
from jlog.log_api import renderTemplate
|
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
|
from jumpserver.settings import LOG_DIR
|
||||||
import zipfile
|
import zipfile
|
||||||
import json
|
import json
|
||||||
|
@ -137,7 +137,7 @@ def log_record(request):
|
||||||
log_id = request.REQUEST.get('id', None)
|
log_id = request.REQUEST.get('id', None)
|
||||||
if log_id:
|
if log_id:
|
||||||
logs = TermLogRecorder(request.user)
|
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))
|
return HttpResponse(logs.load_full_log(log.filename))
|
||||||
else:
|
else:
|
||||||
return HttpResponse("ERROR")
|
return HttpResponse("ERROR")
|
||||||
|
@ -261,16 +261,16 @@ class TermLogRecorder(object):
|
||||||
zf.setpassword(password)
|
zf.setpassword(password)
|
||||||
zf.writestr(filename, json.dumps(self.log))
|
zf.writestr(filename, json.dumps(self.log))
|
||||||
zf.close()
|
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))
|
history=json.dumps(self.CMD), timestamp=int(self.recoderStartTime))
|
||||||
if self.user:
|
if self.user:
|
||||||
record.user.add(self.user)
|
record.userMM.add(self.user)
|
||||||
except:
|
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),
|
filename=filename, history=json.dumps(self.CMD),
|
||||||
timestamp=int(self.recoderStartTime))
|
timestamp=int(self.recoderStartTime))
|
||||||
if self.user:
|
if self.user:
|
||||||
record.user.add(self.user)
|
record.userMM.add(self.user)
|
||||||
|
|
||||||
def list(self, user=None, uid=None):
|
def list(self, user=None, uid=None):
|
||||||
tmp = []
|
tmp = []
|
||||||
|
@ -281,7 +281,7 @@ class TermLogRecorder(object):
|
||||||
else:
|
else:
|
||||||
user = self.user
|
user = self.user
|
||||||
if 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():
|
for i in self._lists.all():
|
||||||
tmp.append(
|
tmp.append(
|
||||||
{'filename': i.filename, 'locale': i.logPath == 'locale', 'nick': i.nick, 'timestamp': i.timestamp,
|
{'filename': i.filename, 'locale': i.logPath == 'locale', 'nick': i.nick, 'timestamp': i.timestamp,
|
||||||
|
@ -299,7 +299,7 @@ class TermLogRecorder(object):
|
||||||
if self._lists:
|
if self._lists:
|
||||||
self.file = self._lists.get(filename=filename)
|
self.file = self._lists.get(filename=filename)
|
||||||
else:
|
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':
|
if self.file.logPath == 'locale':
|
||||||
return self.file.log
|
return self.file.log
|
||||||
else:
|
else:
|
||||||
|
@ -323,7 +323,7 @@ class TermLogRecorder(object):
|
||||||
if self._lists:
|
if self._lists:
|
||||||
self.file = self._lists.get(filename=filename)
|
self.file = self._lists.get(filename=filename)
|
||||||
else:
|
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 self.file.history
|
||||||
return 'ERROR User(None)'
|
return 'ERROR User(None)'
|
||||||
|
|
||||||
|
@ -335,7 +335,7 @@ class TermLogRecorder(object):
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
if user:
|
if user:
|
||||||
TermLog.objects.get(filename=filename).user.add(user)
|
Log.objects.get(filename=filename).userMM.add(user)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -347,6 +347,6 @@ class TermLogRecorder(object):
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
if user:
|
if user:
|
||||||
TermLog.objects.get(filename=filename).user.remove(user)
|
Log.objects.get(filename=filename).userMM.remove(user)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue