mirror of https://github.com/jumpserver/jumpserver
[Update] 修改replay api (#1298)
parent
7f670ab709
commit
e9b86ca668
|
@ -304,40 +304,24 @@ class SessionReplayViewSet(viewsets.ViewSet):
|
||||||
return HttpResponseNotFound()
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
|
|
||||||
class SessionReplayV2ViewSet(viewsets.ViewSet):
|
class SessionReplayV2ViewSet(SessionReplayViewSet):
|
||||||
serializer_class = ReplaySerializer
|
serializer_class = ReplaySerializer
|
||||||
permission_classes = (IsSuperUserOrAppUser,)
|
permission_classes = (IsSuperUserOrAppUser,)
|
||||||
session = None
|
session = None
|
||||||
|
|
||||||
def gen_session_path(self):
|
|
||||||
date = self.session.date_start.strftime('%Y-%m-%d')
|
|
||||||
replay = {
|
|
||||||
"id": self.session.id,
|
|
||||||
# "width": 100,
|
|
||||||
# "heith": 100
|
|
||||||
}
|
|
||||||
if self.session.protocol == "ssh":
|
|
||||||
replay['type'] = "json"
|
|
||||||
replay['path'] = os.path.join(date, str(self.session.id) + '.gz')
|
|
||||||
return replay
|
|
||||||
elif self.session.protocol == "rdp":
|
|
||||||
replay['type'] = "mp4"
|
|
||||||
replay['path'] = os.path.join(date, str(self.session.id) + '.mp4')
|
|
||||||
return replay
|
|
||||||
else:
|
|
||||||
return replay
|
|
||||||
|
|
||||||
def retrieve(self, request, *args, **kwargs):
|
def retrieve(self, request, *args, **kwargs):
|
||||||
session_id = kwargs.get('pk')
|
session_id = kwargs.get('pk')
|
||||||
self.session = get_object_or_404(Session, id=session_id)
|
self.session = get_object_or_404(Session, id=session_id)
|
||||||
replay = self.gen_session_path()
|
path = self.gen_session_path()
|
||||||
|
data = {
|
||||||
|
'type': 'guacamole' if self.session.protocol == 'rdp' else 'json',
|
||||||
|
'src': '',
|
||||||
|
}
|
||||||
|
|
||||||
if replay.get("path", "") == "":
|
if default_storage.exists(path):
|
||||||
return HttpResponseNotFound()
|
url = default_storage.url(path)
|
||||||
|
data['src'] = url
|
||||||
if default_storage.exists(replay["path"]):
|
return Response(data)
|
||||||
replay["src"] = default_storage.url(replay["path"])
|
|
||||||
return Response(replay)
|
|
||||||
else:
|
else:
|
||||||
configs = settings.TERMINAL_REPLAY_STORAGE.items()
|
configs = settings.TERMINAL_REPLAY_STORAGE.items()
|
||||||
if not configs:
|
if not configs:
|
||||||
|
@ -345,13 +329,15 @@ class SessionReplayV2ViewSet(viewsets.ViewSet):
|
||||||
|
|
||||||
for name, config in configs:
|
for name, config in configs:
|
||||||
client = jms_storage.init(config)
|
client = jms_storage.init(config)
|
||||||
|
date = self.session.date_start.strftime('%Y-%m-%d')
|
||||||
|
file_path = os.path.join(date, str(self.session.id) + '.replay.gz')
|
||||||
|
target_path = default_storage.base_location + '/' + path
|
||||||
|
|
||||||
target_path = default_storage.base_location + '/' + replay["path"]
|
if client and client.has_file(file_path) and \
|
||||||
|
client.download_file(file_path, target_path):
|
||||||
if client and client.has_file(replay["path"]) and \
|
url = default_storage.url(path)
|
||||||
client.download_file(replay["path"], target_path):
|
data['src'] = url
|
||||||
replay["src"] = default_storage.url(replay["path"])
|
return Response(data)
|
||||||
return Response(replay)
|
|
||||||
return HttpResponseNotFound()
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,7 @@ class SessionListView(AdminUserRequiredMixin, DatetimeSearchMixin, ListView):
|
||||||
filter_kwargs['system_user'] = self.system_user
|
filter_kwargs['system_user'] = self.system_user
|
||||||
if filter_kwargs:
|
if filter_kwargs:
|
||||||
self.queryset = self.queryset.filter(**filter_kwargs)
|
self.queryset = self.queryset.filter(**filter_kwargs)
|
||||||
# Todo: 暂时隐藏rdp
|
return self.queryset
|
||||||
return self.queryset.filter(protocol='ssh')
|
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = {
|
context = {
|
||||||
|
|
Loading…
Reference in New Issue