mirror of https://github.com/jumpserver/jumpserver
feat: replay api update
make a v2 session replay api, get the json responsepull/1248/head
parent
02ca8c3139
commit
536be1175a
|
@ -304,6 +304,57 @@ class SessionReplayViewSet(viewsets.ViewSet):
|
|||
return HttpResponseNotFound()
|
||||
|
||||
|
||||
class SessionReplayV2ViewSet(viewsets.ViewSet):
|
||||
serializer_class = ReplaySerializer
|
||||
permission_classes = (IsSuperUserOrAppUser,)
|
||||
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):
|
||||
session_id = kwargs.get('pk')
|
||||
self.session = get_object_or_404(Session, id=session_id)
|
||||
replay = self.gen_session_path()
|
||||
|
||||
if replay.get("path", "") == "":
|
||||
return HttpResponseNotFound()
|
||||
|
||||
if default_storage.exists(replay["path"]):
|
||||
replay["src"] = default_storage.url(replay["path"])
|
||||
return Response(replay)
|
||||
else:
|
||||
configs = settings.TERMINAL_REPLAY_STORAGE.items()
|
||||
if not configs:
|
||||
return HttpResponseNotFound()
|
||||
|
||||
for name, config in configs:
|
||||
client = jms_storage.init(config)
|
||||
|
||||
target_path = default_storage.base_location + '/' + replay["path"]
|
||||
|
||||
if client and client.has_file(replay["path"]) and \
|
||||
client.download_file(replay["path"], target_path):
|
||||
replay["src"] = default_storage.url(replay["path"])
|
||||
return Response(replay)
|
||||
return HttpResponseNotFound()
|
||||
|
||||
|
||||
class TerminalConfig(APIView):
|
||||
permission_classes = (IsAppUser,)
|
||||
|
||||
|
|
|
@ -23,8 +23,13 @@ urlpatterns = [
|
|||
api.SessionReplayViewSet.as_view({'get': 'retrieve', 'post': 'create'}),
|
||||
name='session-replay'),
|
||||
url(r'^v1/tasks/kill-session/', api.KillSessionAPI.as_view(), name='kill-session'),
|
||||
url(r'^v1/terminal/(?P<terminal>[a-zA-Z0-9\-]{36})/access-key', api.TerminalTokenApi.as_view(), name='terminal-access-key'),
|
||||
url(r'^v1/terminal/(?P<terminal>[a-zA-Z0-9\-]{36})/access-key', api.TerminalTokenApi.as_view(),
|
||||
name='terminal-access-key'),
|
||||
url(r'^v1/terminal/config', api.TerminalConfig.as_view(), name='terminal-config'),
|
||||
# v2: get session's replay
|
||||
url(r'^v2/sessions/(?P<pk>[0-9a-zA-Z\-]{36})/replay/$',
|
||||
api.SessionReplayV2ViewSet.as_view({'get': 'retrieve'}),
|
||||
name='session-replay-v2'),
|
||||
]
|
||||
|
||||
urlpatterns += router.urls
|
||||
|
|
Loading…
Reference in New Issue