mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-08 18:59:47 +00:00
[Change] Rename applications -> terminal
This commit is contained in:
2
apps/terminal/backends/replay/__init__.py
Normal file
2
apps/terminal/backends/replay/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# ~*~ coding: utf-8 ~*~
|
||||
|
14
apps/terminal/backends/replay/base.py
Normal file
14
apps/terminal/backends/replay/base.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# coding: utf-8
|
||||
import abc
|
||||
|
||||
|
||||
class RecordBase(object):
|
||||
__metaclass__ = abc.ABCMeta
|
||||
|
||||
@abc.abstractmethod
|
||||
def save(self, proxy_log_id, output, timestamp):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def filter(self, date_from_ts=None, proxy_log_id=None):
|
||||
pass
|
31
apps/terminal/backends/replay/db.py
Normal file
31
apps/terminal/backends/replay/db.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# ~*~ coding: utf-8 ~*~
|
||||
|
||||
from .base import RecordBase
|
||||
from audits.models import RecordLog
|
||||
|
||||
|
||||
class RecordStore(RecordBase):
|
||||
model = RecordLog
|
||||
queryset = []
|
||||
|
||||
def save(self, proxy_log_id, output, timestamp):
|
||||
return self.model.objects.create(
|
||||
proxy_log_id=proxy_log_id, output=output, timestamp=timestamp
|
||||
)
|
||||
|
||||
def filter(self, date_from_ts=None, proxy_log_id=''):
|
||||
filter_kwargs = {}
|
||||
|
||||
if date_from_ts:
|
||||
filter_kwargs['timestamp__gte'] = date_from_ts
|
||||
if proxy_log_id:
|
||||
filter_kwargs['proxy_log_id'] = proxy_log_id
|
||||
|
||||
if filter_kwargs:
|
||||
self.queryset = self.model.objects.filter(**filter_kwargs)
|
||||
return self.queryset
|
||||
|
||||
def all(self):
|
||||
"""返回所有数据"""
|
||||
return self.model.objects.all()
|
||||
|
20
apps/terminal/backends/replay/serializers.py
Normal file
20
apps/terminal/backends/replay/serializers.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# ~*~ coding: utf-8 ~*~
|
||||
import base64
|
||||
from rest_framework import serializers
|
||||
from audits.models import RecordLog
|
||||
from audits.backends import record_store
|
||||
|
||||
|
||||
class RecordSerializer(serializers.ModelSerializer):
|
||||
"""使用这个类作为基础Command Log Serializer类, 用来序列化"""
|
||||
class Meta:
|
||||
model = RecordLog
|
||||
fields = '__all__'
|
||||
|
||||
def create(self, validated_data):
|
||||
try:
|
||||
output = validated_data['output']
|
||||
validated_data['output'] = base64.b64decode(output)
|
||||
except IndexError:
|
||||
pass
|
||||
return record_store.save(**dict(validated_data))
|
Reference in New Issue
Block a user