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
c460323c
Commit
c460323c
authored
Jan 25, 2015
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改授权web
映射去掉 user_common 和 password_common ===
parent
569e12e8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
49 deletions
+51
-49
connect.py
connect.py
+3
-18
models.py
jasset/models.py
+2
-4
models.py
jperm/models.py
+0
-9
views.py
jperm/views.py
+19
-1
perm_edit.html
templates/jperm/perm_edit.html
+27
-17
No files found.
connect.py
View file @
c460323c
...
@@ -240,28 +240,13 @@ def get_connect_item(username, ip):
...
@@ -240,28 +240,13 @@ def get_connect_item(username, ip):
if
asset
.
login_type
in
login_type_dict
:
if
asset
.
login_type
in
login_type_dict
:
password
=
cryptor
.
decrypt
(
login_type_dict
[
asset
.
login_type
])
password
=
cryptor
.
decrypt
(
login_type_dict
[
asset
.
login_type
])
return
username
,
password
,
ip
,
port
return
username
,
password
,
ip
,
port
elif
asset
.
login_type
==
'M'
:
elif
asset
.
login_type
==
'M'
:
perms
=
asset
.
permission_set
.
filter
(
user
=
user
)
username
=
asset
.
username
if
perms
:
password
=
cryptor
.
decrypt
(
asset
.
password
)
perm
=
perms
[
0
]
return
username
,
password
,
ip
,
port
else
:
raise
ServerError
(
'Permission
%
s to
%
s does not exist.'
%
(
username
,
ip
))
if
perm
.
role
==
'SU'
:
username_super
=
asset
.
username_super
password_super
=
cryptor
.
decrypt
(
asset
.
password_super
)
return
username_super
,
password_super
,
ip
,
port
elif
perm
.
role
==
'CU'
:
username_common
=
asset
.
username_common
password_common
=
asset
.
password_common
return
username_common
,
password_common
,
ip
,
port
else
:
raise
ServerError
(
'Perm in
%
s for
%
s map role is not in ["SU", "CU"].'
%
(
ip
,
username
))
else
:
else
:
raise
ServerError
(
'Login type is not in ["L", "S", "P", "M"]'
)
raise
ServerError
(
'Login type is not in ["L", "S", "P", "M"]'
)
...
...
jasset/models.py
View file @
c460323c
...
@@ -32,10 +32,8 @@ class Asset(models.Model):
...
@@ -32,10 +32,8 @@ class Asset(models.Model):
user_group
=
models
.
ManyToManyField
(
UserGroup
)
user_group
=
models
.
ManyToManyField
(
UserGroup
)
bis_group
=
models
.
ManyToManyField
(
BisGroup
)
bis_group
=
models
.
ManyToManyField
(
BisGroup
)
login_type
=
models
.
CharField
(
max_length
=
1
,
choices
=
LOGIN_TYPE_CHOICES
,
default
=
'L'
)
login_type
=
models
.
CharField
(
max_length
=
1
,
choices
=
LOGIN_TYPE_CHOICES
,
default
=
'L'
)
username_common
=
models
.
CharField
(
max_length
=
20
,
blank
=
True
,
null
=
True
)
username
=
models
.
CharField
(
max_length
=
20
,
blank
=
True
,
null
=
True
)
password_common
=
models
.
CharField
(
max_length
=
80
,
blank
=
True
,
null
=
True
)
password
=
models
.
CharField
(
max_length
=
80
,
blank
=
True
,
null
=
True
)
username_super
=
models
.
CharField
(
max_length
=
20
,
blank
=
True
,
null
=
True
)
password_super
=
models
.
CharField
(
max_length
=
80
,
blank
=
True
,
null
=
True
)
date_added
=
models
.
DateTimeField
(
auto_now
=
True
,
default
=
datetime
.
datetime
.
now
(),
null
=
True
)
date_added
=
models
.
DateTimeField
(
auto_now
=
True
,
default
=
datetime
.
datetime
.
now
(),
null
=
True
)
is_active
=
models
.
BooleanField
(
default
=
True
)
is_active
=
models
.
BooleanField
(
default
=
True
)
comment
=
models
.
CharField
(
max_length
=
100
,
blank
=
True
,
null
=
True
)
comment
=
models
.
CharField
(
max_length
=
100
,
blank
=
True
,
null
=
True
)
...
...
jperm/models.py
View file @
c460323c
...
@@ -4,16 +4,8 @@ from jasset.models import Asset
...
@@ -4,16 +4,8 @@ from jasset.models import Asset
class
Perm
(
models
.
Model
):
class
Perm
(
models
.
Model
):
USER_ROLE_CHOICES
=
(
(
'SU'
,
'SuperUser'
),
(
'CU'
,
'CommonUser'
),
)
user
=
models
.
ForeignKey
(
User
)
user
=
models
.
ForeignKey
(
User
)
asset
=
models
.
ForeignKey
(
Asset
)
asset
=
models
.
ForeignKey
(
Asset
)
role
=
models
.
CharField
(
choices
=
USER_ROLE_CHOICES
,
max_length
=
2
,
blank
=
True
,
null
=
True
)
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
'
%
s_
%
s'
%
(
self
.
user
.
username
,
self
.
asset
.
ip
)
return
'
%
s_
%
s'
%
(
self
.
user
.
username
,
self
.
asset
.
ip
)
\ No newline at end of file
jperm/views.py
View file @
c460323c
# coding: utf-8
# coding: utf-8
from
django.shortcuts
import
render_to_response
from
django.shortcuts
import
render_to_response
from
django.http
import
HttpResponseRedirect
from
django.http
import
HttpResponseRedirect
,
HttpResponse
from
juser.models
import
User
,
UserGroup
from
juser.models
import
User
,
UserGroup
from
jasset.models
import
Asset
from
jasset.models
import
Asset
from
jperm.models
import
Perm
from
jperm.models
import
Perm
...
@@ -28,6 +28,13 @@ def perm_host(request):
...
@@ -28,6 +28,13 @@ def perm_host(request):
return
render_to_response
(
'jperm/perm_host.html'
,
locals
())
return
render_to_response
(
'jperm/perm_host.html'
,
locals
())
def
perm_user_host
(
username
,
ip
):
user
=
User
.
objects
.
get
(
username
=
username
)
asset
=
Asset
.
objects
.
get
(
ip
=
ip
)
if
not
Perm
.
objects
.
filter
(
user
=
user
,
asset
=
asset
):
Perm
.
objects
.
create
(
user
=
user
,
asset
=
asset
)
def
perm_edit
(
request
):
def
perm_edit
(
request
):
header_title
,
path1
,
path2
=
u'授权编辑 | Perm Edit.'
,
u'jperm'
,
u'perm_edit'
header_title
,
path1
,
path2
=
u'授权编辑 | Perm Edit.'
,
u'jperm'
,
u'perm_edit'
if
request
.
method
==
'GET'
:
if
request
.
method
==
'GET'
:
...
@@ -35,7 +42,18 @@ def perm_edit(request):
...
@@ -35,7 +42,18 @@ def perm_edit(request):
user_id
=
request
.
GET
.
get
(
'id'
)
user_id
=
request
.
GET
.
get
(
'id'
)
user
=
User
.
objects
.
get
(
id
=
user_id
)
user
=
User
.
objects
.
get
(
id
=
user_id
)
assets
=
Asset
.
objects
.
all
()
assets
=
Asset
.
objects
.
all
()
assets_permed
=
[]
for
perm
in
user
.
perm_set
.
all
():
assets_permed
.
append
(
perm
.
asset
)
assets_unperm
=
list
(
set
(
assets
)
-
set
(
assets_permed
))
return
render_to_response
(
'jperm/perm_edit.html'
,
locals
())
return
render_to_response
(
'jperm/perm_edit.html'
,
locals
())
else
:
host_ips
=
request
.
POST
.
getlist
(
'host_permed'
,
''
)
username
=
request
.
POST
.
get
(
'username'
)
for
ip
in
host_ips
:
perm_user_host
(
username
,
ip
)
return
HttpResponseRedirect
(
'/jperm/perm_host/'
)
def
perm_add
(
request
):
def
perm_add
(
request
):
...
...
templates/jperm/perm_edit.html
View file @
c460323c
...
@@ -21,7 +21,12 @@
...
@@ -21,7 +21,12 @@
function
search_host
(
text
){
function
search_host
(
text
){
$
(
"#host_unperm"
).
children
().
each
(
function
(){
$
(
this
).
remove
();});
$
(
"#host_unperm"
).
children
().
each
(
function
(){
$
(
this
).
remove
();});
$
(
"#host_all"
).
children
().
each
(
function
(){
$
(
"#host_all"
).
children
().
each
(
function
(){
if
(
$
(
this
).
text
().
search
(
text
)
!=
-
1
)
{
if
(
$
(
this
).
text
().
search
(
text
)
!=
-
1
){
{
#
$
(
"#host_permed"
).
children
().
each
(
function
(){
#
}
{
#
if
(
$
(
this
).
text
().
search
(
text
)
==
-
1
){
#
}
{
#
$
(
"#host_unperm"
).
append
(
$
(
this
).
clone
())
#
}
{
#
}
#
}
{
#
});
#
}
$
(
"#host_unperm"
).
append
(
$
(
this
).
clone
())
$
(
"#host_unperm"
).
append
(
$
(
this
).
clone
())
}
}
});
});
...
@@ -35,7 +40,7 @@
...
@@ -35,7 +40,7 @@
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox float-e-margins"
>
<!-- title -->
<!-- title -->
<div
class=
"ibox-title"
>
<div
class=
"ibox-title"
>
<h5>
Basic form
<small>
Simple login form example
</small></h5>
<h5>
授权编辑表单
<small>
Edit perm of user
</small></h5>
<div
class=
"ibox-tools"
>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
<i
class=
"fa fa-chevron-up"
></i>
...
@@ -60,7 +65,7 @@
...
@@ -60,7 +65,7 @@
<div
class=
"col-sm-5 "
>
<div
class=
"col-sm-5 "
>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label></label>
<label></label>
<input
type=
"text"
id=
"host_filter"
placeholder=
"
过滤
"
class=
"form-control"
value=
""
oninput=
"search_host(this.value)"
>
<input
type=
"text"
id=
"host_filter"
placeholder=
"
Search
"
class=
"form-control"
value=
""
oninput=
"search_host(this.value)"
>
</div>
</div>
</div>
</div>
<div
class=
"col-sm-1 "
>
<div
class=
"col-sm-1 "
>
...
@@ -77,6 +82,7 @@
...
@@ -77,6 +82,7 @@
</div>
</div>
<form
method=
"post"
action=
""
>
<form
method=
"post"
action=
""
>
<input
type=
"text"
name=
"username"
class=
"form-control"
value=
"{{ user.username }}"
style=
"display: none"
>
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-sm-5"
><h4>
未授权主机
</h4>
<div
class=
"col-sm-5"
><h4>
未授权主机
</h4>
<div>
<div>
...
@@ -86,7 +92,7 @@
...
@@ -86,7 +92,7 @@
{% endfor %}
{% endfor %}
</select>
</select>
<select
id=
"host_unperm"
name=
"host_unperm"
class=
"form-control m-b"
size=
"12"
multiple
>
<select
id=
"host_unperm"
name=
"host_unperm"
class=
"form-control m-b"
size=
"12"
multiple
>
{% for asset in assets %}
{% for asset in assets
_unperm
%}
<option
value=
"{{ asset.ip }}"
>
{{ asset.ip }}
</option>
<option
value=
"{{ asset.ip }}"
>
{{ asset.ip }}
</option>
{% endfor %}
{% endfor %}
</select>
</select>
...
@@ -100,9 +106,12 @@
...
@@ -100,9 +106,12 @@
</div>
</div>
</div>
</div>
<div
class=
"col-sm-5"
><h4>
已
授权主机
</h4>
<div
class=
"col-sm-5"
><h4>
授权主机
</h4>
<div>
<div>
<select
id=
"host_permed"
name=
"host_permed"
class=
"form-control m-b"
size=
"12"
multiple
>
<select
id=
"host_permed"
name=
"host_permed"
class=
"form-control m-b"
size=
"12"
multiple
>
{% for asset in assets_permed %}
<option
value=
"{{ asset.ip }}"
>
{{ asset.ip }}
</option>
{% endfor %}
</select>
</select>
</div>
</div>
</div>
</div>
...
@@ -111,7 +120,7 @@
...
@@ -111,7 +120,7 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
<div
class=
"col-sm-4 col-sm-offset-2"
>
<button
class=
"btn btn-white"
type=
"submit"
>
取消
</button>
<button
class=
"btn btn-white"
type=
"submit"
>
取消
</button>
<button
class=
"btn btn-primary"
type=
"submit"
>
确认保存
</button>
<button
class=
"btn btn-primary"
type=
"submit"
onclick=
"javascript: (function(){$('#host_permed option').each(function(){$(this).prop('selected', true)})})()"
>
确认保存
</button>
</div>
</div>
</div>
</div>
</div>
</div>
...
@@ -128,16 +137,16 @@
...
@@ -128,16 +137,16 @@
$
(
"#"
+
str
).
addClass
(
'active'
);
$
(
"#"
+
str
).
addClass
(
'active'
);
$
(
"#"
+
str1
).
addClass
(
'active'
);
$
(
"#"
+
str1
).
addClass
(
'active'
);
</script>
</script>
<script
type=
"text/javascript"
>
{#
<script
type=
"text/javascript"
>
#
}
$
(
"#host_permed"
).
children
().
each
(
function
(){
{
#
$
(
"#host_permed"
).
children
().
each
(
function
(){
#
}
$
(
"#host_all"
).
append
(
$
(
this
).
clone
());
{
#
$
(
"#host_all"
).
append
(
$
(
this
).
clone
());
#
}
{
##
}
if
(
$
(
this
).
prop
(
"selected"
)
==
false
)
{
{
#
if
(
$
(
this
).
prop
(
"selected"
)
==
false
)
{
#
}
$
(
"#host_unperm"
).
append
(
this
);
{
#
$
(
"#host_unperm"
).
append
(
this
);
#
}
}
{
#
}
#
}
{
##
}
$
(
"#host_all"
).
children
().
each
(
function
(){
$
(
this
).
prop
(
"selected"
,
false
)});
{
#
$
(
"#host_all"
).
children
().
each
(
function
(){
$
(
this
).
prop
(
"selected"
,
false
)});
#
}
});
{
#
});
#
}
</script>
{
#
</script>
#}
{% endblock %}
{% endblock %}
\ No newline at end of file
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