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
7e65e44a
Commit
7e65e44a
authored
Jul 26, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 兼容guacamole手动模式上传system user是uuid
parent
74c3f122
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
7 deletions
+35
-7
user.py
apps/assets/models/user.py
+20
-0
api.py
apps/terminal/api.py
+9
-4
hands.py
apps/terminal/hands.py
+3
-2
session_list.html
apps/terminal/templates/terminal/session_list.html
+1
-1
terminal_tags.py
apps/terminal/templatetags/terminal_tags.py
+2
-0
No files found.
apps/assets/models/user.py
View file @
7e65e44a
...
...
@@ -118,6 +118,8 @@ class SystemUser(AssetUser):
shell
=
models
.
CharField
(
max_length
=
64
,
default
=
'/bin/bash'
,
verbose_name
=
_
(
'Shell'
))
login_mode
=
models
.
CharField
(
choices
=
LOGIN_MODE_CHOICES
,
default
=
AUTO_LOGIN
,
max_length
=
10
,
verbose_name
=
_
(
'Login mode'
))
cache_key
=
"__SYSTEM_USER_CACHED_{}"
def
__str__
(
self
):
return
'{0.name}({0.username})'
.
format
(
self
)
...
...
@@ -154,6 +156,24 @@ class SystemUser(AssetUser):
else
:
return
False
def
set_cache
(
self
):
cache
.
set
(
self
.
cache_key
.
format
(
self
.
id
),
self
,
3600
)
def
expire_cache
(
self
):
cache
.
delete
(
self
.
cache_key
.
format
(
self
.
id
))
@classmethod
def
get_system_user_by_id_or_cached
(
cls
,
sid
):
cached
=
cache
.
get
(
cls
.
cache_key
.
format
(
sid
))
if
cached
:
return
cached
try
:
system_user
=
cls
.
objects
.
get
(
id
=
sid
)
system_user
.
set_cache
()
return
system_user
except
cls
.
DoesNotExist
:
return
None
class
Meta
:
ordering
=
[
'name'
]
verbose_name
=
_
(
"System user"
)
...
...
apps/terminal/api.py
View file @
7e65e44a
...
...
@@ -4,7 +4,6 @@ from collections import OrderedDict
import
logging
import
os
import
uuid
import
copy
from
django.core.cache
import
cache
from
django.shortcuts
import
get_object_or_404
,
redirect
...
...
@@ -16,12 +15,13 @@ from django.conf import settings
import
jms_storage
from
rest_framework
import
viewsets
,
serializers
from
rest_framework
import
viewsets
from
rest_framework.views
import
APIView
,
Response
from
rest_framework.permissions
import
AllowAny
from
rest_framework_bulk
import
BulkModelViewSet
from
common.utils
import
get_object_or_none
from
common.utils
import
get_object_or_none
,
is_uuid
from
.hands
import
SystemUser
from
.models
import
Terminal
,
Status
,
Session
,
Task
from
.serializers
import
TerminalSerializer
,
StatusSerializer
,
\
SessionSerializer
,
TaskSerializer
,
ReplaySerializer
...
...
@@ -187,8 +187,13 @@ class SessionViewSet(viewsets.ModelViewSet):
return
self
.
queryset
def
perform_create
(
self
,
serializer
):
if
self
.
request
.
user
.
terminal
:
if
hasattr
(
self
.
request
.
user
,
'terminal'
)
:
serializer
.
validated_data
[
"terminal"
]
=
self
.
request
.
user
.
terminal
sid
=
serializer
.
validated_data
[
"system_user"
]
if
is_uuid
(
sid
):
_system_user
=
SystemUser
.
get_system_user_by_id_or_cached
(
sid
)
if
_system_user
:
serializer
.
validated_data
[
"system_user"
]
=
_system_user
.
name
return
super
()
.
perform_create
(
serializer
)
...
...
apps/terminal/hands.py
View file @
7e65e44a
...
...
@@ -4,4 +4,5 @@
from
users.models
import
User
from
users.permissions
import
IsSuperUserOrAppUser
,
IsAppUser
,
\
IsSuperUserOrAppUserOrUserReadonly
from
users.utils
import
AdminUserRequiredMixin
\ No newline at end of file
from
users.utils
import
AdminUserRequiredMixin
from
assets.models
import
SystemUser
\ No newline at end of file
apps/terminal/templates/terminal/session_list.html
View file @
7e65e44a
...
...
@@ -58,7 +58,7 @@
<div
class=
"input-group"
>
<div
class=
"input-group-btn"
>
<button
id=
'search_btn'
type=
"submit"
class=
"btn btn-sm btn-primary"
>
搜索
{% trans 'Search' %}
</button>
</div>
</div>
...
...
apps/terminal/templatetags/terminal_tags.py
View file @
7e65e44a
# ~*~ coding: utf-8 ~*~
from
django
import
template
from
..backends
import
get_multi_command_storage
register
=
template
.
Library
()
...
...
@@ -10,3 +11,4 @@ command_store = get_multi_command_storage()
@register.filter
def
get_session_command_amount
(
session_id
):
return
command_store
.
count
(
session
=
session_id
)
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