diff --git a/apps/terminal/api/command.py b/apps/terminal/api/command.py index 22a2bb5c3..5b60a114a 100644 --- a/apps/terminal/api/command.py +++ b/apps/terminal/api/command.py @@ -1,13 +1,10 @@ # -*- coding: utf-8 -*- # -import time from django.conf import settings from django.utils import timezone -from django.shortcuts import HttpResponse from rest_framework import generics from rest_framework.fields import DateTimeField from rest_framework.response import Response -from django.template import loader from terminal.models import CommandStorage, Session, Command from terminal.filters import CommandFilter @@ -23,7 +20,7 @@ from ..backends import ( from ..notifications import CommandAlertMessage logger = get_logger(__name__) -__all__ = ['CommandViewSet', 'CommandExportApi', 'InsecureCommandAlertAPI'] +__all__ = ['CommandViewSet', 'InsecureCommandAlertAPI'] class CommandQueryMixin: @@ -191,29 +188,6 @@ class CommandViewSet(JMSBulkModelViewSet): return Response({"msg": msg}, status=401) -class CommandExportApi(CommandQueryMixin, generics.ListAPIView): - serializer_class = SessionCommandSerializer - rbac_perms = { - 'list': 'terminal.view_command' - } - - def list(self, request, *args, **kwargs): - queryset = self.filter_queryset(self.get_queryset()) - - template = 'terminal/command_report.html' - context = { - 'queryset': queryset, - 'total_count': len(queryset), - 'now': time.time(), - } - content = loader.render_to_string(template, context, request) - content_type = 'application/octet-stream' - response = HttpResponse(content, content_type) - filename = 'command-report-{}.html'.format(int(time.time())) - response['Content-Disposition'] = 'attachment; filename="%s"' % filename - return response - - class InsecureCommandAlertAPI(generics.CreateAPIView): serializer_class = InsecureCommandAlertSerializer rbac_perms = { diff --git a/apps/terminal/backends/command/models.py b/apps/terminal/backends/command/models.py index 02a16d353..0a795b905 100644 --- a/apps/terminal/backends/command/models.py +++ b/apps/terminal/backends/command/models.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # +from datetime import datetime import uuid from django.db import models from django.utils.translation import ugettext_lazy as _ @@ -28,6 +29,10 @@ class AbstractSessionCommand(OrgModelMixin): class Meta: abstract = True + @lazyproperty + def timestamp_display(self): + return datetime.fromtimestamp(self.timestamp) + @lazyproperty def remote_addr(self): from terminal.models import Session diff --git a/apps/terminal/backends/command/serializers.py b/apps/terminal/backends/command/serializers.py index 625c4282e..2eb9e434c 100644 --- a/apps/terminal/backends/command/serializers.py +++ b/apps/terminal/backends/command/serializers.py @@ -36,6 +36,7 @@ class SessionCommandSerializer(SimpleSessionCommandSerializer): output = serializers.CharField(max_length=2048, allow_blank=True, label=_("Output")) risk_level_display = serializers.SerializerMethodField(label=_('Risk level display')) timestamp = serializers.IntegerField(label=_('Timestamp')) + timestamp_display = serializers.DateTimeField(label=_('Datetime')) remote_addr = serializers.CharField(read_only=True, label=_('Remote Address')) @staticmethod diff --git a/apps/terminal/urls/api_urls.py b/apps/terminal/urls/api_urls.py index c392f9c07..3f0445350 100644 --- a/apps/terminal/urls/api_urls.py +++ b/apps/terminal/urls/api_urls.py @@ -36,7 +36,6 @@ urlpatterns = [ path('tasks/kill-session/', api.KillSessionAPI.as_view(), name='kill-session'), path('tasks/kill-session-for-ticket/', api.KillSessionForTicketAPI.as_view(), name='kill-session-for-ticket'), path('terminals/config/', api.TerminalConfig.as_view(), name='terminal-config'), - path('commands/export/', api.CommandExportApi.as_view(), name="command-export"), path('commands/insecure-command/', api.InsecureCommandAlertAPI.as_view(), name="command-alert"), path('replay-storages/<uuid:pk>/test-connective/', api.ReplayStorageTestConnectiveApi.as_view(), name='replay-storage-test-connective'), path('command-storages/<uuid:pk>/test-connective/', api.CommandStorageTestConnectiveApi.as_view(), name='command-storage-test-connective'),