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
35f64674
Commit
35f64674
authored
Jul 19, 2018
by
BaiJiangJie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feature] 添加用户访问控制,远程管理方式(web/ssh), 限制ip访问
parent
c94d018d
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
3 deletions
+44
-3
django.mo
apps/i18n/zh/LC_MESSAGES/django.mo
+0
-0
django.po
apps/i18n/zh/LC_MESSAGES/django.po
+0
-0
settings.py
apps/jumpserver/settings.py
+15
-0
api.py
apps/users/api.py
+5
-1
login.html
apps/users/templates/users/login.html
+3
-1
utils.py
apps/users/utils.py
+15
-0
login.py
apps/users/views/login.py
+6
-1
No files found.
apps/i18n/zh/LC_MESSAGES/django.mo
View file @
35f64674
No preview for this file type
apps/i18n/zh/LC_MESSAGES/django.po
View file @
35f64674
This diff is collapsed.
Click to expand it.
apps/jumpserver/settings.py
View file @
35f64674
...
@@ -422,3 +422,18 @@ TOKEN_EXPIRATION = CONFIG.TOKEN_EXPIRATION or 3600
...
@@ -422,3 +422,18 @@ TOKEN_EXPIRATION = CONFIG.TOKEN_EXPIRATION or 3600
DISPLAY_PER_PAGE
=
CONFIG
.
DISPLAY_PER_PAGE
or
25
DISPLAY_PER_PAGE
=
CONFIG
.
DISPLAY_PER_PAGE
or
25
DEFAULT_EXPIRED_YEARS
=
70
DEFAULT_EXPIRED_YEARS
=
70
USER_GUIDE_URL
=
""
USER_GUIDE_URL
=
""
# Restrict Access
MODE_WEB
=
'web'
MODE_SSH
=
'ssh'
RESTRICT_ACCESS
=
{
'admin'
:
{
'ip'
:
[
'*'
],
'mode'
:
[
MODE_WEB
,
],
},
'michael'
:
{
'ip'
:
[
'127.0.0.1'
],
'mode'
:
[
MODE_SSH
,
]
}
}
apps/users/api.py
View file @
35f64674
...
@@ -19,7 +19,8 @@ from .models import User, UserGroup, LoginLog
...
@@ -19,7 +19,8 @@ from .models import User, UserGroup, LoginLog
from
.permissions
import
IsSuperUser
,
IsValidUser
,
IsCurrentUserOrReadOnly
,
\
from
.permissions
import
IsSuperUser
,
IsValidUser
,
IsCurrentUserOrReadOnly
,
\
IsSuperUserOrAppUser
IsSuperUserOrAppUser
from
.utils
import
check_user_valid
,
generate_token
,
get_login_ip
,
\
from
.utils
import
check_user_valid
,
generate_token
,
get_login_ip
,
\
check_otp_code
,
set_user_login_failed_count_to_cache
,
is_block_login
check_otp_code
,
set_user_login_failed_count_to_cache
,
is_block_login
,
\
is_restrict_access
from
common.mixins
import
IDInFilterMixin
from
common.mixins
import
IDInFilterMixin
from
common.utils
import
get_logger
from
common.utils
import
get_logger
...
@@ -222,6 +223,9 @@ class UserAuthApi(APIView):
...
@@ -222,6 +223,9 @@ class UserAuthApi(APIView):
ip
=
ip
if
ip
else
get_login_ip
(
request
)
ip
=
ip
if
ip
else
get_login_ip
(
request
)
key_limit
=
self
.
key_prefix_limit
.
format
(
username
,
ip
)
key_limit
=
self
.
key_prefix_limit
.
format
(
username
,
ip
)
key_block
=
self
.
key_prefix_block
.
format
(
username
)
key_block
=
self
.
key_prefix_block
.
format
(
username
)
if
is_restrict_access
(
username
,
ip
,
'ssh'
):
msg
=
_
(
"Restrict access"
)
return
Response
({
'msg'
:
msg
},
status
=
401
)
if
is_block_login
(
key_limit
):
if
is_block_login
(
key_limit
):
msg
=
_
(
"Log in frequently and try again later"
)
msg
=
_
(
"Log in frequently and try again later"
)
return
Response
({
'msg'
:
msg
},
status
=
401
)
return
Response
({
'msg'
:
msg
},
status
=
401
)
...
...
apps/users/templates/users/login.html
View file @
35f64674
...
@@ -46,7 +46,9 @@
...
@@ -46,7 +46,9 @@
<form
class=
"m-t"
role=
"form"
method=
"post"
action=
""
>
<form
class=
"m-t"
role=
"form"
method=
"post"
action=
""
>
{% csrf_token %}
{% csrf_token %}
{% if block_login %}
{% if restrict_access %}
<p
class=
"red-fonts"
>
{% trans 'Restrict access!' %}
</p>
{% elif block_login %}
<p
class=
"red-fonts"
>
{% trans 'Log in frequently and try again later' %}
</p>
<p
class=
"red-fonts"
>
{% trans 'Log in frequently and try again later' %}
</p>
{% elif form.errors %}
{% elif form.errors %}
{% if 'captcha' in form.errors %}
{% if 'captcha' in form.errors %}
...
...
apps/users/utils.py
View file @
35f64674
...
@@ -372,3 +372,18 @@ def is_need_unblock(key_block):
...
@@ -372,3 +372,18 @@ def is_need_unblock(key_block):
if
not
cache
.
get
(
key_block
):
if
not
cache
.
get
(
key_block
):
return
False
return
False
return
True
return
True
def
is_restrict_access
(
username
,
ip
,
mode
):
user
=
settings
.
RESTRICT_ACCESS
.
get
(
username
,
None
)
if
not
user
:
return
False
ips
=
user
.
get
(
'ip'
,
[])
modes
=
user
.
get
(
'mode'
,
[])
if
(
'*'
not
in
ips
)
and
(
ip
not
in
ips
):
return
True
elif
(
'*'
not
in
modes
)
and
(
mode
not
in
modes
):
return
True
else
:
return
False
apps/users/views/login.py
View file @
35f64674
...
@@ -28,7 +28,7 @@ from ..models import User, LoginLog
...
@@ -28,7 +28,7 @@ from ..models import User, LoginLog
from
..utils
import
send_reset_password_mail
,
check_otp_code
,
get_login_ip
,
\
from
..utils
import
send_reset_password_mail
,
check_otp_code
,
get_login_ip
,
\
redirect_user_first_login_or_index
,
get_user_or_tmp_user
,
\
redirect_user_first_login_or_index
,
get_user_or_tmp_user
,
\
set_tmp_user_to_cache
,
get_password_check_rules
,
check_password_rules
,
\
set_tmp_user_to_cache
,
get_password_check_rules
,
check_password_rules
,
\
is_block_login
,
set_user_login_failed_count_to_cache
is_block_login
,
set_user_login_failed_count_to_cache
,
is_restrict_access
from
..tasks
import
write_login_log_async
from
..tasks
import
write_login_log_async
from
..
import
forms
from
..
import
forms
...
@@ -65,6 +65,11 @@ class UserLoginView(FormView):
...
@@ -65,6 +65,11 @@ class UserLoginView(FormView):
# limit login authentication
# limit login authentication
ip
=
get_login_ip
(
request
)
ip
=
get_login_ip
(
request
)
username
=
self
.
request
.
POST
.
get
(
'username'
)
username
=
self
.
request
.
POST
.
get
(
'username'
)
# check restrict access
if
is_restrict_access
(
username
,
ip
,
'web'
):
return
self
.
render_to_response
(
self
.
get_context_data
(
restrict_access
=
True
))
key_limit
=
self
.
key_prefix_limit
.
format
(
username
,
ip
)
key_limit
=
self
.
key_prefix_limit
.
format
(
username
,
ip
)
if
is_block_login
(
key_limit
):
if
is_block_login
(
key_limit
):
return
self
.
render_to_response
(
self
.
get_context_data
(
block_login
=
True
))
return
self
.
render_to_response
(
self
.
get_context_data
(
block_login
=
True
))
...
...
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