Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
536be117
Unverified
Commit
536be117
authored
Apr 24, 2018
by
liuzheng712
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: replay api update
make a v2 session replay api, get the json response
parent
02ca8c31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
1 deletion
+57
-1
api.py
apps/terminal/api.py
+51
-0
api_urls.py
apps/terminal/urls/api_urls.py
+6
-1
No files found.
apps/terminal/api.py
View file @
536be117
...
...
@@ -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
,)
...
...
apps/terminal/urls/api_urls.py
View file @
536be117
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment