|
|
@ -2,6 +2,7 @@
|
|
|
|
#
|
|
|
|
#
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import tarfile
|
|
|
|
import tarfile
|
|
|
|
|
|
|
|
|
|
|
|
from django.core.files.storage import default_storage
|
|
|
|
from django.core.files.storage import default_storage
|
|
|
|
from django.db.models import F
|
|
|
|
from django.db.models import F
|
|
|
|
from django.http import FileResponse
|
|
|
|
from django.http import FileResponse
|
|
|
@ -15,21 +16,22 @@ from rest_framework.decorators import action
|
|
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
|
from rest_framework.permissions import IsAuthenticated
|
|
|
|
from rest_framework.response import Response
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
|
|
|
|
|
|
|
from common.drf.filters import BaseFilterSet
|
|
|
|
from common.api import AsyncApiMixin
|
|
|
|
from common.const.http import GET
|
|
|
|
from common.const.http import GET
|
|
|
|
|
|
|
|
from common.drf.filters import BaseFilterSet
|
|
|
|
from common.drf.filters import DatetimeRangeFilter
|
|
|
|
from common.drf.filters import DatetimeRangeFilter
|
|
|
|
from common.drf.renders import PassthroughRenderer
|
|
|
|
from common.drf.renders import PassthroughRenderer
|
|
|
|
from common.api import AsyncApiMixin
|
|
|
|
from common.storage.replay import ReplayStorageHandler
|
|
|
|
from common.utils import data_to_json, is_uuid
|
|
|
|
from common.utils import data_to_json, is_uuid
|
|
|
|
from common.utils import get_logger, get_object_or_none
|
|
|
|
from common.utils import get_logger, get_object_or_none
|
|
|
|
from common.storage.replay import ReplayStorageHandler
|
|
|
|
|
|
|
|
from rbac.permissions import RBACPermission
|
|
|
|
|
|
|
|
from orgs.mixins.api import OrgBulkModelViewSet
|
|
|
|
from orgs.mixins.api import OrgBulkModelViewSet
|
|
|
|
from orgs.utils import tmp_to_root_org, tmp_to_org
|
|
|
|
from orgs.utils import tmp_to_root_org, tmp_to_org
|
|
|
|
|
|
|
|
from rbac.permissions import RBACPermission
|
|
|
|
from terminal import serializers
|
|
|
|
from terminal import serializers
|
|
|
|
|
|
|
|
from terminal.const import TerminalType
|
|
|
|
from terminal.models import Session
|
|
|
|
from terminal.models import Session
|
|
|
|
from terminal.utils import is_session_approver
|
|
|
|
|
|
|
|
from terminal.permissions import IsSessionAssignee
|
|
|
|
from terminal.permissions import IsSessionAssignee
|
|
|
|
|
|
|
|
from terminal.utils import is_session_approver
|
|
|
|
from users.models import User
|
|
|
|
from users.models import User
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
__all__ = [
|
|
|
@ -182,14 +184,20 @@ class SessionReplayViewSet(AsyncApiMixin, viewsets.ViewSet):
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
@staticmethod
|
|
|
|
def get_replay_data(session, url):
|
|
|
|
def get_replay_data(session, url):
|
|
|
|
tp = 'json'
|
|
|
|
all_guacamole_types = (
|
|
|
|
if session.protocol in ('rdp', 'vnc'):
|
|
|
|
TerminalType.lion, TerminalType.guacamole,
|
|
|
|
# 需要考虑录像播放和离线播放器的约定,暂时不处理
|
|
|
|
TerminalType.razor, TerminalType.xrdp
|
|
|
|
tp = 'guacamole'
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if url.endswith('.cast.gz'):
|
|
|
|
if url.endswith('.cast.gz'):
|
|
|
|
tp = 'asciicast'
|
|
|
|
tp = 'asciicast'
|
|
|
|
if url.endswith('.replay.mp4'):
|
|
|
|
elif url.endswith('.replay.mp4'):
|
|
|
|
tp = 'mp4'
|
|
|
|
tp = 'mp4'
|
|
|
|
|
|
|
|
elif (getattr(session.terminal, 'type', None) in all_guacamole_types) or \
|
|
|
|
|
|
|
|
(session.protocol in ('rdp', 'vnc')):
|
|
|
|
|
|
|
|
tp = 'guacamole'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
tp = 'json'
|
|
|
|
|
|
|
|
|
|
|
|
download_url = reverse('api-terminal:session-replay-download', kwargs={'pk': session.id})
|
|
|
|
download_url = reverse('api-terminal:session-replay-download', kwargs={'pk': session.id})
|
|
|
|
data = {
|
|
|
|
data = {
|
|
|
|