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
2abb9efe
Commit
2abb9efe
authored
Jul 25, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] Org功能修改
parent
f17727de
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
16 deletions
+15
-16
asset.py
apps/assets/serializers/asset.py
+1
-1
utils.py
apps/common/utils.py
+1
-3
mixins.py
apps/orgs/mixins.py
+3
-2
api.py
apps/terminal/api.py
+4
-4
serializers.py
apps/terminal/backends/command/serializers.py
+1
-1
api_urls.py
apps/terminal/urls/api_urls.py
+5
-5
No files found.
apps/assets/serializers/asset.py
View file @
2abb9efe
...
...
@@ -43,7 +43,7 @@ class AssetGrantedSerializer(serializers.ModelSerializer):
fields
=
(
"id"
,
"hostname"
,
"ip"
,
"port"
,
"system_users_granted"
,
"is_active"
,
"system_users_join"
,
"os"
,
'domain'
,
"platform"
,
"comment"
,
"protocol"
,
"platform"
,
"comment"
,
"protocol"
,
"org_id"
,
)
@staticmethod
...
...
apps/common/utils.py
View file @
2abb9efe
...
...
@@ -68,10 +68,8 @@ class Signer(metaclass=Singleton):
self
.
secret_key
=
secret_key
def
sign
(
self
,
value
):
if
isinstance
(
value
,
bytes
):
value
=
value
.
decode
(
"utf-8"
)
s
=
JSONWebSignatureSerializer
(
self
.
secret_key
)
return
s
.
dumps
(
value
)
return
s
.
dumps
(
value
)
.
decode
()
def
unsign
(
self
,
value
):
if
value
is
None
:
...
...
apps/orgs/mixins.py
View file @
2abb9efe
...
...
@@ -3,6 +3,7 @@
from
threading
import
local
from
django.db
import
models
from
django.db.models
import
Q
from
django.shortcuts
import
redirect
import
warnings
from
django.forms
import
ModelForm
...
...
@@ -34,7 +35,7 @@ class OrgManager(models.Manager):
elif
current_org
.
is_real
():
kwargs
[
'org_id'
]
=
current_org
.
id
elif
current_org
.
is_default
():
queryset
=
queryset
.
filter
(
org_id
=
""
)
.
filter
(
org_id__isnull
=
True
)
queryset
=
queryset
.
filter
(
Q
(
org_id
=
""
)
|
Q
(
org_id__isnull
=
True
)
)
queryset
=
queryset
.
filter
(
**
kwargs
)
tl
.
times
+=
1
return
queryset
...
...
@@ -61,7 +62,7 @@ class OrgModelMixin(models.Model):
def
save
(
self
,
*
args
,
**
kwargs
):
if
current_org
and
current_org
.
is_real
():
self
.
org_id
=
current_org
.
id
return
super
(
OrgModelMixin
,
self
)
.
save
(
*
args
,
**
kwargs
)
return
super
()
.
save
(
*
args
,
**
kwargs
)
class
Meta
:
abstract
=
True
...
...
apps/terminal/api.py
View file @
2abb9efe
...
...
@@ -24,8 +24,7 @@ from common.utils import get_object_or_none
from
.models
import
Terminal
,
Status
,
Session
,
Task
from
.serializers
import
TerminalSerializer
,
StatusSerializer
,
\
SessionSerializer
,
TaskSerializer
,
ReplaySerializer
from
common.permissions
import
IsOrgAdmin
,
IsAppUser
,
IsOrgAdminOrAppUser
,
\
IsOrgAdminOrAppUserOrUserReadonly
from
common.permissions
import
IsAppUser
,
IsOrgAdminOrAppUser
from
.backends
import
get_command_storage
,
get_multi_command_storage
,
\
SessionCommandSerializer
...
...
@@ -35,7 +34,7 @@ logger = logging.getLogger(__file__)
class
TerminalViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Terminal
.
objects
.
filter
(
is_deleted
=
False
)
serializer_class
=
TerminalSerializer
permission_classes
=
(
IsOrgAdminOrAppUserOrUserReadonl
y
,)
permission_classes
=
(
AllowAn
y
,)
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
name
=
request
.
data
.
get
(
'name'
)
...
...
@@ -238,13 +237,14 @@ class CommandViewSet(viewsets.ViewSet):
def
create
(
self
,
request
,
*
args
,
**
kwargs
):
serializer
=
self
.
serializer_class
(
data
=
request
.
data
,
many
=
True
)
if
serializer
.
is_valid
():
print
(
serializer
.
validated_data
)
ok
=
self
.
command_store
.
bulk_save
(
serializer
.
validated_data
)
if
ok
:
return
Response
(
"ok"
,
status
=
201
)
else
:
return
Response
(
"Save error"
,
status
=
500
)
else
:
msg
=
"
N
ot valid: {}"
.
format
(
serializer
.
errors
)
msg
=
"
Command n
ot valid: {}"
.
format
(
serializer
.
errors
)
logger
.
error
(
msg
)
return
Response
({
"msg"
:
msg
},
status
=
401
)
...
...
apps/terminal/backends/command/serializers.py
View file @
2abb9efe
...
...
@@ -12,6 +12,6 @@ class SessionCommandSerializer(serializers.Serializer):
input
=
serializers
.
CharField
(
max_length
=
128
)
output
=
serializers
.
CharField
(
max_length
=
1024
,
allow_blank
=
True
)
session
=
serializers
.
CharField
(
max_length
=
36
)
org_id
=
serializers
.
CharField
(
max_length
=
36
)
org_id
=
serializers
.
CharField
(
max_length
=
36
,
required
=
False
,
default
=
''
)
timestamp
=
serializers
.
IntegerField
()
apps/terminal/urls/api_urls.py
View file @
2abb9efe
...
...
@@ -10,9 +10,9 @@ from .. import api
app_name
=
'terminal'
router
=
routers
.
DefaultRouter
()
router
.
register
(
r'terminal'
,
api
.
TerminalViewSet
,
'terminal2'
)
router
.
register
(
r'terminal/(?P<terminal>[a-zA-Z0-9\-]{36})?/?status'
,
api
.
StatusViewSet
,
'terminal-status'
)
router
.
register
(
r'terminal/(?P<terminal>[a-zA-Z0-9\-]{36})?/?sessions'
,
api
.
SessionViewSet
,
'terminal-sessions'
)
router
.
register
(
r'terminal'
,
api
.
TerminalViewSet
,
'terminal'
)
router
.
register
(
r'tasks'
,
api
.
TaskViewSet
,
'tasks'
)
router
.
register
(
r'command'
,
api
.
CommandViewSet
,
'command'
)
router
.
register
(
r'sessions'
,
api
.
SessionViewSet
,
'session'
)
...
...
@@ -20,16 +20,16 @@ router.register(r'status', api.StatusViewSet, 'session')
urlpatterns
=
[
url
(
r'^sessions/(?P<pk>[0-9a-zA-Z\-]{36})/replay/$'
,
api
.
SessionReplayViewSet
.
as_view
({
'get'
:
'retrieve'
,
'post'
:
'create'
}),
api
.
SessionReplayV
2V
iewSet
.
as_view
({
'get'
:
'retrieve'
,
'post'
:
'create'
}),
name
=
'session-replay'
),
url
(
r'^tasks/kill-session/'
,
api
.
KillSessionAPI
.
as_view
(),
name
=
'kill-session'
),
url
(
r'^terminal/(?P<terminal>[a-zA-Z0-9\-]{36})/access-key'
,
api
.
TerminalTokenApi
.
as_view
(),
name
=
'terminal-access-key'
),
url
(
r'^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'
),
#
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