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
17181db8
Commit
17181db8
authored
Jan 21, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Plain Diff
[Feature] 支持es存储
parents
41f1c3f7
67001dd9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
103 additions
and
31 deletions
+103
-31
forms.py
apps/common/forms.py
+0
-3
views.py
apps/common/views.py
+2
-2
settings.py
apps/jumpserver/settings.py
+1
-0
django.mo
apps/locale/zh/LC_MESSAGES/django.mo
+0
-0
django.po
apps/locale/zh/LC_MESSAGES/django.po
+0
-0
api.py
apps/terminal/api.py
+5
-4
__init__.py
apps/terminal/backends/__init__.py
+7
-1
db.py
apps/terminal/backends/command/db.py
+1
-1
es.py
apps/terminal/backends/command/es.py
+38
-0
models.py
apps/terminal/backends/command/models.py
+6
-0
multi.py
apps/terminal/backends/command/multi.py
+28
-0
models.py
apps/terminal/models.py
+4
-3
serializers.py
apps/terminal/serializers.py
+3
-3
terminal_tags.py
apps/terminal/templatetags/terminal_tags.py
+3
-6
command.py
apps/terminal/views/command.py
+3
-6
session.py
apps/terminal/views/session.py
+2
-2
No files found.
apps/common/forms.py
View file @
17181db8
...
...
@@ -78,9 +78,6 @@ class BasicSettingForm(BaseForm):
max_length
=
1024
,
label
=
_
(
"Email Subject Prefix"
),
initial
=
"[Jumpserver] "
)
AUTH_LDAP
=
forms
.
BooleanField
(
label
=
_
(
"Enable LDAP Auth"
),
initial
=
False
,
required
=
False
)
class
EmailSettingForm
(
BaseForm
):
...
...
apps/common/views.py
View file @
17181db8
...
...
@@ -28,8 +28,6 @@ class BasicSettingView(AdminUserRequiredMixin, TemplateView):
form
=
self
.
form_class
(
request
.
POST
)
if
form
.
is_valid
():
form
.
save
()
if
"AUTH_LDAP"
in
form
.
cleaned_data
:
ldap_auth_enable
.
send
(
form
.
cleaned_data
[
"AUTH_LDAP"
])
msg
=
_
(
"Update setting successfully, please restart program"
)
messages
.
success
(
request
,
msg
)
return
redirect
(
'settings:basic-setting'
)
...
...
@@ -82,6 +80,8 @@ class LDAPSettingView(AdminUserRequiredMixin, TemplateView):
form
=
self
.
form_class
(
request
.
POST
)
if
form
.
is_valid
():
form
.
save
()
if
"AUTH_LDAP"
in
form
.
cleaned_data
:
ldap_auth_enable
.
send
(
form
.
cleaned_data
[
"AUTH_LDAP"
])
msg
=
_
(
"Update setting successfully, please restart program"
)
messages
.
success
(
request
,
msg
)
return
redirect
(
'settings:ldap-setting'
)
...
...
apps/jumpserver/settings.py
View file @
17181db8
...
...
@@ -391,6 +391,7 @@ TERMINAL_COMMAND_STORAGE = {
# }
}
# Django bootstrap3 setting, more see http://django-bootstrap3.readthedocs.io/en/latest/settings.html
BOOTSTRAP3
=
{
'horizontal_label_class'
:
'col-md-2'
,
...
...
apps/locale/zh/LC_MESSAGES/django.mo
View file @
17181db8
No preview for this file type
apps/locale/zh/LC_MESSAGES/django.po
View file @
17181db8
This diff is collapsed.
Click to expand it.
apps/terminal/api.py
View file @
17181db8
# -*- coding: utf-8 -*-
#
from
collections
import
OrderedDict
import
copy
import
logging
import
os
import
uuid
...
...
@@ -21,7 +20,8 @@ from .serializers import TerminalSerializer, StatusSerializer, \
SessionSerializer
,
TaskSerializer
,
ReplaySerializer
from
.hands
import
IsSuperUserOrAppUser
,
IsAppUser
,
\
IsSuperUserOrAppUserOrUserReadonly
from
.backends
import
get_terminal_command_store
,
SessionCommandSerializer
from
.backends
import
get_command_store
,
get_multi_command_store
,
\
SessionCommandSerializer
logger
=
logging
.
getLogger
(
__file__
)
...
...
@@ -196,7 +196,8 @@ class CommandViewSet(viewsets.ViewSet):
}
"""
command_store
=
get_terminal_command_store
()
command_store
=
get_command_store
()
multi_command_storage
=
get_multi_command_store
()
serializer_class
=
SessionCommandSerializer
permission_classes
=
(
IsSuperUserOrAppUser
,)
...
...
@@ -217,7 +218,7 @@ class CommandViewSet(viewsets.ViewSet):
return
Response
({
"msg"
:
msg
},
status
=
401
)
def
list
(
self
,
request
,
*
args
,
**
kwargs
):
queryset
=
list
(
self
.
command_store
.
all
()
)
queryset
=
self
.
multi_command_storage
.
filter
(
)
serializer
=
self
.
serializer_class
(
queryset
,
many
=
True
)
return
Response
(
serializer
.
data
)
...
...
apps/terminal/backends/__init__.py
View file @
17181db8
...
...
@@ -3,7 +3,7 @@ from django.conf import settings
from
.command.serializers
import
SessionCommandSerializer
TYPE_ENGINE_MAPPING
=
{
'elasticsearch'
:
'terminal.backends.command.
db
'
,
'elasticsearch'
:
'terminal.backends.command.
es
'
,
}
...
...
@@ -31,4 +31,10 @@ def get_terminal_command_store():
return
storage_list
def
get_multi_command_store
():
from
.command.multi
import
CommandStore
storage_list
=
get_terminal_command_store
()
.
values
()
storage
=
CommandStore
(
storage_list
)
return
storage
apps/terminal/backends/command/db.py
View file @
17181db8
...
...
@@ -73,7 +73,7 @@ class CommandStore(CommandBase):
session
=
session
,
)
queryset
=
self
.
model
.
objects
.
filter
(
**
filter_kwargs
)
return
queryset
return
[
command
.
to_dict
()
for
command
in
queryset
]
def
count
(
self
,
date_from
=
None
,
date_to
=
None
,
user
=
None
,
asset
=
None
,
system_user
=
None
,
...
...
apps/terminal/backends/command/es.py
0 → 100644
View file @
17181db8
# -*- coding: utf-8 -*-
#
from
jms_es_sdk
import
ESStore
from
.base
import
CommandBase
class
CommandStore
(
CommandBase
,
ESStore
):
def
__init__
(
self
,
params
):
hosts
=
params
.
get
(
'HOSTS'
,
[
'http://localhost'
])
ESStore
.
__init__
(
self
,
hosts
=
hosts
)
def
save
(
self
,
command
):
return
ESStore
.
save
(
self
,
command
)
def
bulk_save
(
self
,
commands
):
return
ESStore
.
bulk_save
(
self
,
commands
)
def
filter
(
self
,
date_from
=
None
,
date_to
=
None
,
user
=
None
,
asset
=
None
,
system_user
=
None
,
input
=
None
,
session
=
None
):
data
=
ESStore
.
filter
(
self
,
date_from
=
date_from
,
date_to
=
date_to
,
user
=
user
,
asset
=
asset
,
system_user
=
system_user
,
input
=
input
,
session
=
session
)
return
[
item
[
"_source"
]
for
item
in
data
[
"hits"
]
if
item
]
def
count
(
self
,
date_from
=
None
,
date_to
=
None
,
user
=
None
,
asset
=
None
,
system_user
=
None
,
input
=
None
,
session
=
None
):
amount
=
ESStore
.
count
(
self
,
date_from
=
date_from
,
date_to
=
date_to
,
user
=
user
,
asset
=
asset
,
system_user
=
system_user
,
input
=
input
,
session
=
session
)
return
amount
apps/terminal/backends/command/models.py
View file @
17181db8
...
...
@@ -33,5 +33,11 @@ class AbstractSessionCommand(models.Model):
commands
.
append
(
command
)
return
commands
def
to_dict
(
self
):
d
=
{}
for
field
in
self
.
_meta
.
fields
:
d
[
field
.
name
]
=
getattr
(
self
,
field
.
name
)
return
d
def
__str__
(
self
):
return
self
.
input
apps/terminal/backends/command/multi.py
0 → 100644
View file @
17181db8
# -*- coding: utf-8 -*-
#
from
.base
import
CommandBase
class
CommandStore
(
CommandBase
):
def
__init__
(
self
,
storage_list
):
self
.
storage_list
=
storage_list
def
filter
(
self
,
**
kwargs
):
queryset
=
[]
for
storage
in
self
.
storage_list
:
queryset
.
extend
(
storage
.
filter
(
**
kwargs
))
return
sorted
(
queryset
,
key
=
lambda
command
:
command
[
"timestamp"
])
def
count
(
self
,
**
kwargs
):
amount
=
0
for
storage
in
self
.
storage_list
:
amount
+=
storage
.
count
(
**
kwargs
)
return
amount
def
save
(
self
,
command
):
pass
def
bulk_save
(
self
,
commands
):
pass
\ No newline at end of file
apps/terminal/models.py
View file @
17181db8
...
...
@@ -11,10 +11,11 @@ from .backends.command.models import AbstractSessionCommand
def
get_all_command_storage
():
storage_choices
=
[]
# storage_choices = []
from
common.models
import
Setting
Setting
.
refresh_all_settings
()
for
k
,
v
in
settings
.
TERMINAL_COMMAND_STORAGE
.
items
():
storage_choices
.
append
((
k
,
k
))
return
storage_choices
yield
(
k
,
k
)
class
Terminal
(
models
.
Model
):
...
...
apps/terminal/serializers.py
View file @
17181db8
...
...
@@ -5,7 +5,7 @@ from django.utils import timezone
from
rest_framework
import
serializers
from
.models
import
Terminal
,
Status
,
Session
,
Task
from
.backends
import
get_
terminal
_command_store
from
.backends
import
get_
multi
_command_store
class
TerminalSerializer
(
serializers
.
ModelSerializer
):
...
...
@@ -43,14 +43,14 @@ class TerminalSerializer(serializers.ModelSerializer):
class
SessionSerializer
(
serializers
.
ModelSerializer
):
command_amount
=
serializers
.
SerializerMethodField
()
command_store
=
get_
terminal
_command_store
()
command_store
=
get_
multi
_command_store
()
class
Meta
:
model
=
Session
fields
=
'__all__'
def
get_command_amount
(
self
,
obj
):
return
len
(
self
.
command_store
.
filter
(
session
=
obj
.
session
))
return
self
.
command_store
.
count
(
session
=
str
(
obj
.
id
))
class
StatusSerializer
(
serializers
.
ModelSerializer
):
...
...
apps/terminal/templatetags/terminal_tags.py
View file @
17181db8
# ~*~ coding: utf-8 ~*~
from
django
import
template
from
..backends
import
get_
terminal
_command_store
from
..backends
import
get_
multi
_command_store
register
=
template
.
Library
()
command_store
_dict
=
get_terminal
_command_store
()
command_store
=
get_multi
_command_store
()
@register.filter
def
get_session_command_amount
(
session_id
):
amount
=
0
for
name
,
store
in
command_store_dict
.
items
():
amount
+=
store
.
count
(
session
=
str
(
session_id
))
return
amount
return
command_store
.
count
(
session
=
session_id
)
apps/terminal/views/command.py
View file @
17181db8
...
...
@@ -9,10 +9,10 @@ from django.utils.translation import ugettext as _
from
common.mixins
import
DatetimeSearchMixin
from
..models
import
Command
from
..
import
utils
from
..backends
import
get_
terminal
_command_store
from
..backends
import
get_
multi
_command_store
__all__
=
[
'CommandListView'
]
comm
and_store_list
=
get_terminal
_command_store
()
comm
on_storage
=
get_multi
_command_store
()
class
CommandListView
(
DatetimeSearchMixin
,
ListView
):
...
...
@@ -39,10 +39,7 @@ class CommandListView(DatetimeSearchMixin, ListView):
filter_kwargs
[
'system_user'
]
=
self
.
system_user
if
self
.
command
:
filter_kwargs
[
'input'
]
=
self
.
command
queryset
=
[]
for
store
in
command_store_list
:
queryset
.
extend
(
store
.
filter
(
**
filter_kwargs
))
queryset
=
sorted
(
queryset
,
key
=
lambda
c
:
c
.
timestamp
,
reverse
=
True
)
queryset
=
common_storage
.
filter
(
**
filter_kwargs
)
return
queryset
def
get_context_data
(
self
,
**
kwargs
):
...
...
apps/terminal/views/session.py
View file @
17181db8
...
...
@@ -10,7 +10,7 @@ from django.conf import settings
from
users.utils
import
AdminUserRequiredMixin
from
common.mixins
import
DatetimeSearchMixin
from
..models
import
Session
,
Command
,
Terminal
from
..backends
import
get_
terminal
_command_store
from
..backends
import
get_
multi
_command_store
from
..
import
utils
...
...
@@ -19,7 +19,7 @@ __all__ = [
'SessionDetailView'
,
]
command_store
=
get_
terminal
_command_store
()
command_store
=
get_
multi
_command_store
()
class
SessionListView
(
AdminUserRequiredMixin
,
DatetimeSearchMixin
,
ListView
):
...
...
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