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
477d23ea
Commit
477d23ea
authored
Jul 19, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix some bug
parent
61014c74
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
27 additions
and
17 deletions
+27
-17
forms.py
apps/assets/forms.py
+2
-3
asset.py
apps/assets/models/asset.py
+1
-1
_system_user.html
apps/assets/templates/assets/_system_user.html
+0
-5
system_user.py
apps/assets/views/system_user.py
+10
-0
utils.py
apps/common/utils.py
+5
-1
utils.py
apps/perms/utils.py
+9
-7
No files found.
apps/assets/forms.py
View file @
477d23ea
...
@@ -70,7 +70,6 @@ class AssetBulkUpdateForm(forms.ModelForm):
...
@@ -70,7 +70,6 @@ class AssetBulkUpdateForm(forms.ModelForm):
required
=
True
,
required
=
True
,
help_text
=
'* required'
,
help_text
=
'* required'
,
label
=
_
(
'Select assets'
),
label
=
_
(
'Select assets'
),
# choices=[(asset.id, asset.hostname) for asset in Asset.objects.all()],
widget
=
forms
.
SelectMultiple
(
widget
=
forms
.
SelectMultiple
(
attrs
=
{
attrs
=
{
'class'
:
'select2'
,
'class'
:
'select2'
,
...
@@ -182,7 +181,7 @@ class AdminUserForm(forms.ModelForm):
...
@@ -182,7 +181,7 @@ class AdminUserForm(forms.ModelForm):
# Form field name can not start with `_`, so redefine it,
# Form field name can not start with `_`, so redefine it,
password
=
forms
.
CharField
(
password
=
forms
.
CharField
(
widget
=
forms
.
PasswordInput
,
max_length
=
100
,
widget
=
forms
.
PasswordInput
,
max_length
=
100
,
min_length
=
8
,
strip
=
True
,
required
=
False
,
strip
=
True
,
required
=
False
,
help_text
=
_
(
'If also set private key, use that first'
),
help_text
=
_
(
'If also set private key, use that first'
),
)
)
# Need use upload private key file except paste private key content
# Need use upload private key file except paste private key content
...
@@ -239,7 +238,7 @@ class SystemUserForm(forms.ModelForm):
...
@@ -239,7 +238,7 @@ class SystemUserForm(forms.ModelForm):
auto_generate_key
=
forms
.
BooleanField
(
initial
=
True
,
required
=
False
)
auto_generate_key
=
forms
.
BooleanField
(
initial
=
True
,
required
=
False
)
# Form field name can not start with `_`, so redefine it,
# Form field name can not start with `_`, so redefine it,
password
=
forms
.
CharField
(
widget
=
forms
.
PasswordInput
,
required
=
False
,
password
=
forms
.
CharField
(
widget
=
forms
.
PasswordInput
,
required
=
False
,
max_length
=
100
,
min_length
=
8
,
strip
=
True
)
max_length
=
100
,
strip
=
True
)
# Need use upload private key file except paste private key content
# Need use upload private key file except paste private key content
private_key_file
=
forms
.
FileField
(
required
=
False
)
private_key_file
=
forms
.
FileField
(
required
=
False
)
...
...
apps/assets/models/asset.py
View file @
477d23ea
...
@@ -125,7 +125,7 @@ class Asset(models.Model):
...
@@ -125,7 +125,7 @@ class Asset(models.Model):
'method'
:
self
.
admin_user
.
become_method
,
'method'
:
self
.
admin_user
.
become_method
,
'user'
:
self
.
admin_user
.
become_user
,
'user'
:
self
.
admin_user
.
become_user
,
'pass'
:
self
.
admin_user
.
become_pass
,
'pass'
:
self
.
admin_user
.
become_pass
,
}
if
self
.
admin_user
.
become
else
{},
}
if
self
.
admin_user
and
self
.
admin_user
.
become
else
{},
}
}
class
Meta
:
class
Meta
:
...
...
apps/assets/templates/assets/_system_user.html
View file @
477d23ea
...
@@ -27,11 +27,6 @@
...
@@ -27,11 +27,6 @@
</div>
</div>
</div>
</div>
<div
class=
"ibox-content"
>
<div
class=
"ibox-content"
>
{% if form.no_field_errors %}
<div
class=
"alert alert-danger"
>
{{ form.non_field_errors }}
</div>
{% endif %}
<form
enctype=
"multipart/form-data"
method=
"post"
class=
"form-horizontal"
action=
""
>
<form
enctype=
"multipart/form-data"
method=
"post"
class=
"form-horizontal"
action=
""
>
{% csrf_token %}
{% csrf_token %}
{% if form.non_field_errors %}
{% if form.non_field_errors %}
...
...
apps/assets/views/system_user.py
View file @
477d23ea
...
@@ -13,6 +13,8 @@ from django.views.generic.detail import DetailView, SingleObjectMixin
...
@@ -13,6 +13,8 @@ from django.views.generic.detail import DetailView, SingleObjectMixin
from
..
import
forms
from
..
import
forms
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
IDC
,
SystemUser
from
..models
import
Asset
,
AssetGroup
,
AdminUser
,
IDC
,
SystemUser
from
..hands
import
AdminUserRequiredMixin
from
..hands
import
AdminUserRequiredMixin
from
perms.utils
import
associate_system_users_and_assets
__all__
=
[
'SystemUserCreateView'
,
'SystemUserUpdateView'
,
__all__
=
[
'SystemUserCreateView'
,
'SystemUserUpdateView'
,
'SystemUserDetailView'
,
'SystemUserDeleteView'
,
'SystemUserDetailView'
,
'SystemUserDeleteView'
,
...
@@ -74,6 +76,14 @@ class SystemUserUpdateView(AdminUserRequiredMixin, UpdateView):
...
@@ -74,6 +76,14 @@ class SystemUserUpdateView(AdminUserRequiredMixin, UpdateView):
kwargs
.
update
(
context
)
kwargs
.
update
(
context
)
return
super
(
SystemUserUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
return
super
(
SystemUserUpdateView
,
self
)
.
get_context_data
(
**
kwargs
)
def
form_valid
(
self
,
form
):
response
=
super
(
SystemUserUpdateView
,
self
)
.
form_valid
(
form
)
system_user
=
self
.
object
assets
=
system_user
.
assets
.
all
()
asset_groups
=
system_user
.
asset_groups
.
all
()
associate_system_users_and_assets
([
system_user
],
assets
,
asset_groups
,
force
=
True
)
return
response
def
get_success_url
(
self
):
def
get_success_url
(
self
):
success_url
=
reverse_lazy
(
'assets:system-user-detail'
,
success_url
=
reverse_lazy
(
'assets:system-user-detail'
,
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
kwargs
=
{
'pk'
:
self
.
object
.
pk
})
...
...
apps/common/utils.py
View file @
477d23ea
...
@@ -239,7 +239,11 @@ def ssh_key_gen(length=2048, type='rsa', password=None, username='jumpserver', h
...
@@ -239,7 +239,11 @@ def ssh_key_gen(length=2048, type='rsa', password=None, username='jumpserver', h
def
validate_ssh_private_key
(
text
):
def
validate_ssh_private_key
(
text
):
if
isinstance
(
text
,
bytes
):
if
isinstance
(
text
,
bytes
):
text
=
text
.
decode
(
"utf-8"
)
try
:
text
=
text
.
decode
(
"utf-8"
)
except
UnicodeDecodeError
:
return
False
key
=
ssh_key_string_to_obj
(
text
)
key
=
ssh_key_string_to_obj
(
text
)
if
key
is
None
:
if
key
is
None
:
return
False
return
False
...
...
apps/perms/utils.py
View file @
477d23ea
...
@@ -235,7 +235,7 @@ def push_system_user(assets, system_user):
...
@@ -235,7 +235,7 @@ def push_system_user(assets, system_user):
return
task
.
id
return
task
.
id
def
associate_system_users_and_assets
(
system_users
,
assets
,
asset_groups
):
def
associate_system_users_and_assets
(
system_users
,
assets
,
asset_groups
,
force
=
False
):
"""关联系统用户和资产, 目的是保存它们的关系, 然后新加入的资产或系统
"""关联系统用户和资产, 目的是保存它们的关系, 然后新加入的资产或系统
用户时,推送系统用户到资产
用户时,推送系统用户到资产
...
@@ -250,12 +250,14 @@ def associate_system_users_and_assets(system_users, assets, asset_groups):
...
@@ -250,12 +250,14 @@ def associate_system_users_and_assets(system_users, assets, asset_groups):
for
system_user
in
system_users
:
for
system_user
in
system_users
:
assets_need_push
=
[]
assets_need_push
=
[]
if
system_user
.
auto_push
:
if
system_user
.
auto_push
:
assets_need_push
.
extend
(
if
force
:
[
asset
for
asset
in
assets_all
assets_need_push
=
assets_all
if
asset
not
in
system_user
.
assets
.
all
()
else
:
]
assets_need_push
.
extend
(
)
[
asset
for
asset
in
assets_all
if
asset
not
in
system_user
.
assets
.
all
()
]
)
system_user
.
assets
.
add
(
*
(
tuple
(
assets_all
)))
system_user
.
assets
.
add
(
*
(
tuple
(
assets_all
)))
push_system_user
(
assets_need_push
,
system_user
)
push_system_user
(
assets_need_push
,
system_user
)
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