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
dda367a9
Commit
dda367a9
authored
Nov 19, 2018
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 修改common settings配置
parent
c9aab608
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
41 additions
and
78 deletions
+41
-78
forms.py
apps/common/forms.py
+6
-7
models.py
apps/common/models.py
+6
-2
utils.py
apps/common/utils.py
+15
-48
views.py
apps/common/views.py
+2
-4
settings.py
apps/jumpserver/settings.py
+4
-4
__init__.py
apps/terminal/backends/__init__.py
+1
-1
forms.py
apps/terminal/forms.py
+2
-2
models.py
apps/terminal/models.py
+1
-2
utils.py
apps/users/utils.py
+4
-8
No files found.
apps/common/forms.py
View file @
dda367a9
...
...
@@ -4,11 +4,10 @@ import json
from
django
import
forms
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.db
import
transaction
from
django.conf
import
settings
from
.models
import
Setting
,
common_settings
from
.fields
import
FormDictField
,
FormEncryptCharField
,
\
FormEncryptMixin
,
FormEncryptDictField
FormEncryptMixin
class
BaseForm
(
forms
.
Form
):
...
...
@@ -16,17 +15,17 @@ class BaseForm(forms.Form):
super
()
.
__init__
(
*
args
,
**
kwargs
)
for
name
,
field
in
self
.
fields
.
items
():
db_value
=
getattr
(
common_settings
,
name
)
django_value
=
getattr
(
settings
,
name
)
if
hasattr
(
settings
,
name
)
else
None
#
django_value = getattr(settings, name) if hasattr(settings, name) else None
if
db_value
is
None
and
django_value
is
None
:
if
db_value
is
None
:
#
and django_value is None:
continue
if
db_value
is
False
or
db_valu
e
:
if
db_value
is
not
Non
e
:
if
isinstance
(
db_value
,
dict
):
db_value
=
json
.
dumps
(
db_value
)
initial_value
=
db_value
elif
django_value
is
False
or
django_value
:
initial_value
=
django_value
#
elif django_value is False or django_value:
#
initial_value = django_value
else
:
initial_value
=
''
field
.
initial
=
initial_value
...
...
apps/common/models.py
View file @
dda367a9
...
...
@@ -40,11 +40,15 @@ class Setting(models.Model):
return
self
.
name
def
__getattr__
(
self
,
item
):
instances
=
self
.
__class__
.
objects
.
filter
(
name
=
item
)
default
=
getattr
(
settings
,
item
,
None
)
try
:
instances
=
self
.
__class__
.
objects
.
filter
(
name
=
item
)
except
Exception
:
return
default
if
len
(
instances
)
==
1
:
return
instances
[
0
]
.
cleaned_value
else
:
return
None
return
default
@property
def
cleaned_value
(
self
):
...
...
apps/common/utils.py
View file @
dda367a9
...
...
@@ -38,7 +38,7 @@ def reverse(view_name, urlconf=None, args=None, kwargs=None,
if
external
:
from
common.models
import
common_settings
site_url
=
common_settings
.
SITE_URL
or
settings
.
SITE_URL
site_url
=
common_settings
.
SITE_URL
url
=
site_url
.
strip
(
'/'
)
+
url
return
url
...
...
@@ -389,53 +389,20 @@ def get_request_ip(request):
return
login_ip
def
get_command_storage_or_create_default_storage
():
from
common.models
import
common_settings
,
Setting
name
=
'TERMINAL_COMMAND_STORAGE'
default
=
{
'default'
:
{
'TYPE'
:
'server'
}}
try
:
command_storage
=
common_settings
.
TERMINAL_COMMAND_STORAGE
except
Exception
:
return
default
if
command_storage
is
None
:
obj
=
Setting
()
obj
.
name
=
name
obj
.
encrypted
=
True
obj
.
cleaned_value
=
default
obj
.
save
()
if
isinstance
(
command_storage
,
dict
)
and
not
command_storage
:
obj
=
Setting
.
objects
.
get
(
name
=
name
)
value
=
obj
.
cleaned_value
value
.
update
(
default
)
obj
.
cleaned_value
=
value
obj
.
save
()
command_storage
=
common_settings
.
TERMINAL_COMMAND_STORAGE
return
command_storage
def
get_replay_storage_or_create_default_storage
():
from
common.models
import
common_settings
,
Setting
name
=
'TERMINAL_REPLAY_STORAGE'
default
=
{
'default'
:
{
'TYPE'
:
'server'
}}
try
:
replay_storage
=
common_settings
.
TERMINAL_REPLAY_STORAGE
except
Exception
:
return
default
if
replay_storage
is
None
:
obj
=
Setting
()
obj
.
name
=
name
obj
.
encrypted
=
True
obj
.
cleaned_value
=
default
obj
.
save
()
replay_storage
=
common_settings
.
TERMINAL_REPLAY_STORAGE
if
isinstance
(
replay_storage
,
dict
)
and
not
replay_storage
:
obj
=
Setting
.
objects
.
get
(
name
=
name
)
value
=
obj
.
cleaned_value
value
.
update
(
default
)
obj
.
cleaned_value
=
value
obj
.
save
()
replay_storage
=
common_settings
.
TERMINAL_REPLAY_STORAGE
return
replay_storage
def
get_command_storage_setting
():
from
common.models
import
common_settings
default
=
settings
.
TERMINAL_COMMAND_STORAGE
value
=
common_settings
.
TERMINAL_COMMAND_STORAGE
value
.
update
(
default
)
return
value
def
get_replay_storage_setting
():
from
common.models
import
common_settings
default
=
settings
.
TERMINAL_REPLAY_STORAGE
value
=
common_settings
.
TERMINAL_REPLAY_STORAGE
value
.
update
(
default
)
return
value
class
TeeObj
:
...
...
apps/common/views.py
View file @
dda367a9
...
...
@@ -2,9 +2,7 @@ from django.views.generic import TemplateView
from
django.shortcuts
import
render
,
redirect
from
django.contrib
import
messages
from
django.utils.translation
import
ugettext
as
_
from
django.conf
import
settings
from
common.models
import
common_settings
from
.forms
import
EmailSettingForm
,
LDAPSettingForm
,
BasicSettingForm
,
\
TerminalSettingForm
,
SecuritySettingForm
from
common.permissions
import
SuperUserRequiredMixin
...
...
@@ -97,8 +95,8 @@ class TerminalSettingView(SuperUserRequiredMixin, TemplateView):
template_name
=
"common/terminal_setting.html"
def
get_context_data
(
self
,
**
kwargs
):
command_storage
=
utils
.
get_command_storage_
or_create_default_storage
()
replay_storage
=
utils
.
get_replay_storage_
or_create_default_storage
()
command_storage
=
utils
.
get_command_storage_
setting
()
replay_storage
=
utils
.
get_replay_storage_
setting
()
context
=
{
'app'
:
_
(
'Settings'
),
...
...
apps/jumpserver/settings.py
View file @
dda367a9
...
...
@@ -471,10 +471,10 @@ TERMINAL_REPLAY_STORAGE = {
}
DEFAULT
_PASSWORD_MIN_LENGTH
=
6
DEFAULT
_LOGIN_LIMIT_COUNT
=
7
DEFAULT
_LOGIN_LIMIT_TIME
=
30
# Unit: minute
DEFAULT_
SECURITY_MAX_IDLE_TIME
=
30
# Unit: minute
SECURITY
_PASSWORD_MIN_LENGTH
=
6
SECURITY
_LOGIN_LIMIT_COUNT
=
7
SECURITY
_LOGIN_LIMIT_TIME
=
30
# Unit: minute
SECURITY_MAX_IDLE_TIME
=
30
# Unit: minute
# Django bootstrap3 setting, more see http://django-bootstrap3.readthedocs.io/en/latest/settings.html
BOOTSTRAP3
=
{
...
...
apps/terminal/backends/__init__.py
View file @
dda367a9
...
...
@@ -18,7 +18,7 @@ def get_command_storage():
def
get_terminal_command_storages
():
storage_list
=
{}
command_storage
=
utils
.
get_command_storage_
or_create_default_storage
()
command_storage
=
utils
.
get_command_storage_
setting
()
for
name
,
params
in
command_storage
.
items
():
tp
=
params
[
'TYPE'
]
...
...
apps/terminal/forms.py
View file @
dda367a9
...
...
@@ -9,14 +9,14 @@ from .models import Terminal
def
get_all_command_storage
():
from
common
import
utils
command_storage
=
utils
.
get_command_storage_
or_create_default_storage
()
command_storage
=
utils
.
get_command_storage_
setting
()
for
k
,
v
in
command_storage
.
items
():
yield
(
k
,
k
)
def
get_all_replay_storage
():
from
common
import
utils
replay_storage
=
utils
.
get_replay_storage_
or_create_default_storage
()
replay_storage
=
utils
.
get_replay_storage_
setting
()
for
k
,
v
in
replay_storage
.
items
():
yield
(
k
,
k
)
...
...
apps/terminal/models.py
View file @
dda367a9
...
...
@@ -64,8 +64,7 @@ class Terminal(models.Model):
configs
.
update
(
self
.
get_common_storage
())
configs
.
update
(
self
.
get_replay_storage
())
configs
.
update
({
'SECURITY_MAX_IDLE_TIME'
:
common_settings
.
SECURITY_MAX_IDLE_TIME
or
settings
.
DEFAULT_SECURITY_MAX_IDLE_TIME
,
'SECURITY_MAX_IDLE_TIME'
:
common_settings
.
SECURITY_MAX_IDLE_TIME
})
return
configs
...
...
apps/users/utils.py
View file @
dda367a9
...
...
@@ -307,8 +307,7 @@ def check_password_rules(password):
lower_field_name
=
'SECURITY_PASSWORD_LOWER_CASE'
number_field_name
=
'SECURITY_PASSWORD_NUMBER'
special_field_name
=
'SECURITY_PASSWORD_SPECIAL_CHAR'
min_length
=
getattr
(
common_settings
,
min_field_name
)
or
\
settings
.
DEFAULT_PASSWORD_MIN_LENGTH
min_length
=
getattr
(
common_settings
,
min_field_name
)
password_setting
=
Setting
.
objects
.
filter
(
name__startswith
=
'SECURITY_PASSWORD'
)
if
not
password_setting
:
...
...
@@ -340,8 +339,7 @@ def increase_login_failed_count(username, ip):
count
=
cache
.
get
(
key_limit
)
count
=
count
+
1
if
count
else
1
limit_time
=
common_settings
.
SECURITY_LOGIN_LIMIT_TIME
or
\
settings
.
DEFAULT_LOGIN_LIMIT_TIME
limit_time
=
common_settings
.
SECURITY_LOGIN_LIMIT_TIME
cache
.
set
(
key_limit
,
count
,
int
(
limit_time
)
*
60
)
...
...
@@ -357,10 +355,8 @@ def is_block_login(username, ip):
key_block
=
key_prefix_block
.
format
(
username
)
count
=
cache
.
get
(
key_limit
,
0
)
limit_count
=
common_settings
.
SECURITY_LOGIN_LIMIT_COUNT
or
\
settings
.
DEFAULT_LOGIN_LIMIT_COUNT
limit_time
=
common_settings
.
SECURITY_LOGIN_LIMIT_TIME
or
\
settings
.
DEFAULT_LOGIN_LIMIT_TIME
limit_count
=
common_settings
.
SECURITY_LOGIN_LIMIT_COUNT
limit_time
=
common_settings
.
SECURITY_LOGIN_LIMIT_TIME
if
count
>=
limit_count
:
cache
.
set
(
key_block
,
1
,
int
(
limit_time
)
*
60
)
...
...
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