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
5cd09a65
Commit
5cd09a65
authored
Jan 28, 2015
by
guanghongwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ʱӳԱ
parent
5d38a199
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
153 additions
and
186 deletions
+153
-186
mytags.py
jumpserver/templatetags/mytags.py
+17
-6
models.py
juser/models.py
+1
-1
views.py
juser/views.py
+36
-15
perm_user_edit.html
templates/jperm/perm_user_edit.html
+0
-13
group_add.html
templates/juser/group_add.html
+64
-1
group_detail.html
templates/juser/group_detail.html
+11
-12
group_list.html
templates/juser/group_list.html
+3
-1
user_add.html
templates/juser/user_add.html
+3
-3
user_list.html
templates/juser/user_list.html
+0
-2
user_list1.html
templates/juser/user_list1.html
+0
-131
script.html
templates/script.html
+18
-1
No files found.
jumpserver/templatetags/mytags.py
View file @
5cd09a65
...
...
@@ -2,7 +2,8 @@
import
time
from
django
import
template
from
juser.models
import
User
,
UserGroup
from
django.db.models
import
Q
from
juser.models
import
User
register
=
template
.
Library
()
...
...
@@ -24,16 +25,16 @@ def int2str(value):
def
get_role
(
user_id
):
user_role
=
{
'SU'
:
u'超级管理员'
,
'GA'
:
u'组管理员'
,
'CU'
:
u'普通用户'
}
user
=
User
.
objects
.
get
(
id
=
user_id
)
return
user_role
.
get
(
user
.
role
)
return
user_role
.
get
(
str
(
user
.
role
)
)
@register.filter
(
name
=
'groups_str'
)
def
groups_str
(
username
):
groups
=
[]
user
=
User
.
objects
.
get
(
username
=
username
)
for
group
in
user
.
user_group
.
filter
(
type
=
'M'
):
for
group
in
user
.
user_group
.
filter
(
Q
(
type
=
'A'
)
|
Q
(
type
=
'M'
)
):
groups
.
append
(
group
.
name
)
return
'
,
'
.
join
(
groups
)
return
'
'
.
join
(
groups
)
@register.filter
(
name
=
'get_item'
)
...
...
@@ -52,4 +53,15 @@ def bool2str(value):
@register.filter
(
name
=
'perm_count'
)
def
perm_count
(
user_id
):
user
=
User
.
objects
.
get
(
id
=
int
(
user_id
))
return
user
.
perm_set
.
all
()
.
count
()
\ No newline at end of file
return
user
.
perm_set
.
all
()
.
count
()
@register.filter
(
name
=
'group_type_to_str'
)
def
group_type_to_str
(
type_name
):
group_types
=
{
'P'
:
'私有组'
,
'M'
:
'管理组'
,
'A'
:
'授权组'
,
}
return
group_types
.
get
(
type_name
)
juser/models.py
View file @
5cd09a65
...
...
@@ -9,7 +9,7 @@ class UserGroup(models.Model):
)
name
=
models
.
CharField
(
max_length
=
80
,
unique
=
True
)
type
=
models
.
CharField
(
max_length
=
1
,
choices
=
GROUP_TYPE_CHOICES
,
default
=
'
U
'
)
type
=
models
.
CharField
(
max_length
=
1
,
choices
=
GROUP_TYPE_CHOICES
,
default
=
'
P
'
)
comment
=
models
.
CharField
(
max_length
=
160
,
blank
=
True
,
null
=
True
)
def
__unicode__
(
self
):
...
...
juser/views.py
View file @
5cd09a65
...
...
@@ -15,6 +15,7 @@ from django.http import HttpResponseRedirect
from
django.shortcuts
import
render_to_response
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.db.models
import
Q
from
juser.models
import
UserGroup
,
User
from
connect
import
PyCrypt
,
KEY
...
...
@@ -117,37 +118,57 @@ def group_db_add(**kwargs):
group_name
=
kwargs
.
get
(
'name'
)
group
=
UserGroup
.
objects
.
filter
(
name
=
group_name
)
if
group
:
raise
AddError
raise
AddError
(
'Group
%
s have been exist .'
%
group_name
)
UserGroup
.
objects
.
create
(
**
kwargs
)
def
user_group_add
(
username
,
group_name
):
user
=
User
.
objects
.
get
(
username
=
username
)
def
add_user_to_group
(
username
,
group_name
):
try
:
user
=
User
.
objects
.
get
(
username
=
username
)
group
=
UserGroup
.
objects
.
get
(
name
=
group_name
)
except
ObjectDoesNotExist
:
raise
AddError
(
'User
%
s or group
%
does not exit. '
%
username
,
group_name
)
else
:
groups
=
[
group
]
for
g
in
user
.
user_group
.
all
():
groups
.
append
(
g
)
user
.
user_group
=
groups
def
group_add_user
(
group_name
,
user_id
):
group
=
UserGroup
.
objects
.
get
(
name
=
group_name
)
groups
=
[
group
]
for
g
in
user
.
user_group
.
all
():
groups
.
append
(
g
)
user
.
user_group
=
groups
user
=
User
.
objects
.
get
(
id
=
user_id
)
group
.
user_set
.
add
(
user
)
def
group_add
(
request
):
error
=
''
msg
=
''
header_title
,
path1
,
path2
=
'添加属组 | Add Group'
,
'juser'
,
'group_add'
group_types
=
{
'P'
:
'私有组'
,
'M'
:
'管理组'
,
'A'
:
'授权组'
,
}
users
=
User
.
objects
.
all
()
if
request
.
method
==
'POST'
:
group_name
=
request
.
POST
.
get
(
'group_name'
,
None
)
comment
=
request
.
POST
.
get
(
'comment'
,
None
)
group_name
=
request
.
POST
.
get
(
'group_name'
,
''
)
group_type
=
request
.
POST
.
get
(
'group_type'
,
'A'
)
users_selected
=
request
.
POST
.
getlist
(
'users_selected'
,
''
)
comment
=
request
.
POST
.
get
(
'comment'
,
''
)
try
:
if
not
group_name
:
error
=
u'组名不能为空'
raise
AddError
group_db_add
(
name
=
group_name
,
comment
=
comment
,
type
=
'M'
)
group_db_add
(
name
=
group_name
,
comment
=
comment
,
type
=
group_type
)
for
user_id
in
users_selected
:
group_add_user
(
group_name
,
user_id
)
except
AddError
:
pass
except
TypeError
:
error
=
u'保存用户失败'
error
=
u'保存用户
组
失败'
else
:
msg
=
u'添加组
%
s 成功'
%
group_name
...
...
@@ -156,7 +177,7 @@ def group_add(request):
def
group_list
(
request
):
header_title
,
path1
,
path2
=
'查看属组 | Show Group'
,
'juser'
,
'group_list'
groups
=
contact_list
=
UserGroup
.
objects
.
filter
(
type
=
'M'
)
.
order_by
(
'id'
)
groups
=
contact_list
=
UserGroup
.
objects
.
filter
(
Q
(
type
=
'M'
)
|
Q
(
type
=
'A'
)
)
.
order_by
(
'id'
)
p
=
paginator
=
Paginator
(
contact_list
,
10
)
try
:
...
...
@@ -467,8 +488,8 @@ def user_add(request):
date_joined
=
time_now
)
server_add_user
(
username
,
password
,
ssh_key_pwd
)
group_db_add
(
name
=
username
,
comment
=
username
,
type
=
'
U
'
)
user_group_add
(
username
=
username
,
group_name
=
username
)
group_db_add
(
name
=
username
,
comment
=
username
,
type
=
'
P
'
)
add_user_to_group
(
username
=
username
,
group_name
=
username
)
if
LDAP_ENABLE
:
ldap_add_user
(
username
,
ldap_pwd
)
msg
=
u'添加用户
%
s 成功!'
%
username
...
...
templates/jperm/perm_user_edit.html
View file @
5cd09a65
...
...
@@ -4,19 +4,6 @@
{% block content %}
<script
type=
"text/javascript"
>
function
move
(
from
,
to
)
{
$
(
"#"
+
from
+
" option"
).
each
(
function
(){
if
(
$
(
this
).
prop
(
"selected"
)
==
true
)
{
$
(
"#"
+
to
).
append
(
this
);
}
});
}
function
move_all
(
from
,
to
){
$
(
"#"
+
from
).
children
().
each
(
function
(){
$
(
"#"
+
to
).
append
(
this
);
});
}
function
search_host
(
text
){
$
(
"#host_unperm"
).
children
().
each
(
function
(){
$
(
this
).
remove
();});
...
...
templates/juser/group_add.html
View file @
5cd09a65
...
...
@@ -27,7 +27,7 @@
</div>
</div>
<div
class=
"ibox-content"
>
<form
method=
"post"
class=
"form-horizontal"
action=
""
>
<form
id=
"groupForm"
method=
"post"
class=
"form-horizontal"
action=
""
>
{% if error %}
<div
class=
"alert alert-warning text-center"
>
{{ error }}
</div>
{% endif %}
...
...
@@ -47,6 +47,44 @@
</div>
</div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<label
for=
"group_type"
class=
"col-sm-2 control-label"
>
类型
<span
class=
"red-fonts"
>
*
</span></label>
<div
class=
"col-sm-8"
>
<select
id=
"group_type"
name=
"group_type"
class=
"form-control m-b"
>
{% for t, type_name in group_types.items %}
{% ifequal t type_name %}
<option
value=
"{{ t }}"
selected
>
{{ type_name }}
</option>
{% else %}
<option
value=
"{{ t }}"
>
{{ type_name }}
</option>
{% endifequal %}
{% endfor %}
</select>
</div>
</div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<label
for=
"groups"
class=
"col-lg-2 control-label"
>
用户
</label>
<div
class=
"col-sm-3"
>
<select
id=
"users"
name=
"users"
size=
"12"
class=
"form-control m-b"
multiple
>
{% for user in users %}
<option
value=
"{{ user.id }}"
>
{{ user.name }}
</option>
{% endfor %}
</select>
</div>
<div
class=
"col-sm-1"
>
<div
class=
"btn-group"
style=
"margin-top: 50px;"
>
<button
type=
"button"
class=
"btn btn-white"
onclick=
"move('users', 'users_selected')"
><i
class=
"fa fa-chevron-right"
></i></button>
<button
type=
"button"
class=
"btn btn-white"
onclick=
"move('users_selected', 'users')"
><i
class=
"fa fa-chevron-left"
></i>
</button>
</div>
</div>
<div
class=
"col-sm-3"
>
<div>
<select
id=
"users_selected"
name=
"users_selected"
class=
"form-control m-b"
size=
"12"
multiple
>
</select>
</div>
</div>
</div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<label
for=
"comment"
class=
"col-sm-2 control-label"
>
备注
</label>
<div
class=
"col-sm-8"
>
...
...
@@ -67,4 +105,28 @@
</div>
</div>
</div>
<script>
$
(
'#groupForm'
).
validator
({
timely
:
2
,
theme
:
"yellow_right_effect"
,
fields
:
{
"group_name"
:
{
rule
:
"required"
,
tip
:
"输入组名"
,
ok
:
""
,
msg
:
{
required
:
"必须填写!"
}
},
"group_type"
:
{
rule
:
"checked"
,
tip
:
"选择组类型"
,
ok
:
""
,
msg
:
{
required
:
"至少选择一个组!"
}
}
},
valid
:
function
(
form
)
{
form
.
submit
();
}
});
</script>
{% endblock %}
\ No newline at end of file
templates/juser/group_detail.html
View file @
5cd09a65
...
...
@@ -20,23 +20,22 @@
<table
class=
"table table-striped table-bordered table-hover "
id=
"editable"
>
<thead>
<tr>
<th
class=
"text-center"
>
属组
</th>
<th
class=
"text-center"
>
详情
</th>
<th
class=
"text-center"
>
用户名
</th>
<th
class=
"text-center"
>
姓名
</th>
<th
class=
"text-center"
>
角色
</th>
</tr>
</thead>
<tbody>
{% for user in users %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
ID
</td>
<td
class=
"text-center"
>
{{ group.id }}
</td>
</tr>
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
组名
</td>
<td
class=
"text-center"
>
{{ group.name }}
</td>
</tr>
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
备注
</td>
<td
class=
"text-center"
>
{{ group_comment }}
</td>
<td
class=
"text-center"
>
{{ user.username }}
</td>
<td
class=
"text-center"
>
{{ user.name }}
</td>
<td
class=
"text-center"
>
{{ user.id|get_role }}
</td>
</tr>
{% endfor %}
</tbody>
</tbody>
</table>
</div>
</div>
...
...
templates/juser/group_list.html
View file @
5cd09a65
...
...
@@ -39,6 +39,7 @@
<th
class=
"text-center"
><input
type=
"checkbox"
class=
"i-checks"
name=
""
></th>
<th
class=
"text-center"
>
ID
</th>
<th
class=
"text-center"
>
组名
</th>
<th
class=
"text-center"
>
类型
</th>
<th
class=
"text-center"
>
备注
</th>
<th
class=
"text-center"
>
操作
</th>
</tr>
...
...
@@ -49,9 +50,10 @@
<td
class=
"text-center"
><input
type=
"checkbox"
class=
"i-checks"
name=
""
></td>
<td
class=
"text-center"
>
{{ group.id }}
</td>
<td
class=
"text-center"
>
{{ group.name }}
</td>
<td
class=
"text-center"
>
{{ group.type|group_type_to_str }}
</td>
<td
class=
"text-center"
>
{{ group.comment }}
</td>
<td
class=
"text-center"
>
<a
href=
"../group_detail/?id={{ group.id }}"
class=
"iframe btn btn-xs btn-primary"
>
详情
</a>
<a
href=
"../group_detail/?id={{ group.id }}"
class=
"iframe btn btn-xs btn-primary"
>
成员
</a>
<a
href=
"../group_edit/?id={{ group.id }}"
class=
"btn btn-xs btn-info"
>
编辑
</a>
<a
href=
"../group_del/?id={{ group.id }}"
class=
"btn btn-xs btn-danger"
>
删除
</a>
</td>
...
...
templates/juser/user_add.html
View file @
5cd09a65
...
...
@@ -54,9 +54,9 @@
</div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<label
for=
"ssh_key_pwd
1
"
class=
"col-sm-2 control-label"
>
密钥密码
<span
class=
"red-fonts"
>
*
</span></label>
<label
for=
"ssh_key_pwd"
class=
"col-sm-2 control-label"
>
密钥密码
<span
class=
"red-fonts"
>
*
</span></label>
<div
class=
"col-sm-8"
>
<input
id=
"ssh_key_pwd
1"
name=
"ssh_key_pwd"
placeholder=
"SSH Key Password"
type=
"password"
class=
"form-control"
value=
"{{ ssh_key_pwd1
}}"
>
<input
id=
"ssh_key_pwd
"
name=
"ssh_key_pwd"
placeholder=
"SSH Key Password"
type=
"password"
class=
"form-control"
value=
"{{ ssh_key_pwd
}}"
>
<span
class=
"help-block m-b-none"
>
登陆 Jumpserver 使用的SSH密钥的密码
</span>
...
...
@@ -173,7 +173,7 @@ $('#userForm').validator({
ok
:
""
,
msg
:
{
required
:
"必须填写!"
}
},
"ssh_key_pwd
1
"
:
{
"ssh_key_pwd"
:
{
rule
:
"required;length[6~50]"
,
tip
:
"ssh私钥密码"
,
ok
:
""
,
...
...
templates/juser/user_list.html
View file @
5cd09a65
...
...
@@ -44,7 +44,6 @@
<th
class=
"text-center"
>
姓名
</th>
<th
class=
"text-center"
>
属组
</th>
<th
class=
"text-center"
>
角色
</th>
<th
class=
"text-center"
>
Email
</th>
<th
class=
"text-center"
>
激活
</th>
<th
class=
"text-center"
>
操作
</th>
</tr>
...
...
@@ -60,7 +59,6 @@
<td
class=
"text-center"
>
{{ user.name }}
</td>
<td
class=
"text-center"
>
{{ user.username|groups_str }}
</td>
<td
class=
"text-center"
>
{{ user.id|get_role }}
</td>
<td
class=
"text-center"
>
{{ user.email }}
</td>
<td
class=
"text-center"
>
{{ user.is_active|bool2str }}
</td>
<td
class=
"text-center"
>
<a
href=
"../user_detail/?id={{ user.id }}"
class=
"iframe btn btn-xs btn-primary"
>
详情
</a>
...
...
templates/juser/user_list1.html
deleted
100644 → 0
View file @
5d38a199
{% extends 'base.html' %}
{% load mytags %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div
class=
"wrapper wrapper-content animated fadeInRight"
>
<div
class=
"row"
>
<div
class=
"col-lg-10"
>
<div
class=
"ibox float-e-margins"
>
<div
class=
"ibox-title"
>
<h5>
查看用户
<small>
show user info.
</small>
</h5>
<div
class=
"ibox-tools"
>
<a
class=
"collapse-link"
>
<i
class=
"fa fa-chevron-up"
></i>
</a>
<a
class=
"dropdown-toggle"
data-toggle=
"dropdown"
href=
"#"
>
<i
class=
"fa fa-wrench"
></i>
</a>
<ul
class=
"dropdown-menu dropdown-user"
>
<li><a
href=
"#"
>
未启用 1
</a>
</li>
<li><a
href=
"#"
>
未启用 2
</a>
</li>
</ul>
<a
class=
"close-link"
>
<i
class=
"fa fa-times"
></i>
</a>
</div>
</div>
<div
class=
"ibox-content"
>
<div
class=
""
>
<a
target=
"_blank"
href=
"/juser/user_add/"
class=
"btn btn-sm btn-primary "
>
添加
</a>
</div>
<table
class=
"table table-striped table-bordered table-hover "
id=
"editable"
>
<thead>
<tr>
<th
class=
"text-center"
><input
type=
"checkbox"
class=
"i-checks"
name=
""
></th>
<th
class=
"text-center"
>
ID
</th>
<th
class=
"text-center"
>
用户名
</th>
<th
class=
"text-center"
>
姓名
</th>
<th
class=
"text-center"
>
属组
</th>
<th
class=
"text-center"
>
角色
</th>
<th
class=
"text-center"
>
Email
</th>
<th
class=
"text-center"
>
激活
</th>
<th
class=
"text-center"
>
操作
</th>
</tr>
</thead>
<tbody>
{% for user in contacts.object_list %}
<tr
class=
"gradeX"
>
<td
class=
"text-center"
><input
type=
"checkbox"
class=
"i-checks"
name=
""
></td>
<td
class=
"text-center"
>
{{ user.id }}
</td>
<td
class=
"text-center"
>
{{ user.username }}
</td>
<td
class=
"text-center"
>
{{ user.name }}
</td>
<td
class=
"text-center"
>
{{ user.username|groups_str }}
</td>
<td
class=
"text-center"
>
{{ user.id|get_role }}
</td>
<td
class=
"text-center"
>
{{ user.email }}
</td>
<td
class=
"text-center"
>
{{ user.is_active|bool2str }}
</td>
<td
class=
"text-center"
>
<a
href=
"../user_detail/?id={{ user.id }}"
class=
"iframe btn btn-xs btn-primary"
>
详情
</a>
<a
href=
"../user_edit/?id={{ user.id }}"
class=
"btn btn-xs btn-info"
>
编辑
</a>
<a
href=
"../user_del/?id={{ user.id }}"
class=
"btn btn-xs btn-danger"
>
删除
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div
class=
"row"
>
<div
class=
"col-sm-6"
>
<div
class=
"dataTables_info"
id=
"editable_info"
role=
"status"
aria-live=
"polite"
>
Showing {{ contacts.start_index }} to {{ contacts.end_index }} of {{ p.count }} entries
</div>
</div>
<div
class=
"col-sm-6"
>
<div
class=
"dataTables_paginate paging_simple_numbers"
id=
"editable_paginate"
>
<ul
class=
"pagination"
style=
"margin-top: 0; float: right"
>
{% if contacts.has_previous %}
<li
class=
"paginate_button previous"
aria-controls=
"editable"
tabindex=
"0"
id=
"editable_previous"
>
<a
href=
"?page={{ contacts.previous_page_number }}"
>
Previous
</a>
</li>
{% else %}
<li
class=
"paginate_button previous disabled"
aria-controls=
"editable"
tabindex=
"0"
id=
"editable_previous"
>
<a
href=
"#"
>
Previous
</a>
</li>
{% endif %}
{% for page in p.page_range %}
{% ifequal offset1 page %}
<li
class=
"paginate_button active"
aria-controls=
"editable"
tabindex=
"0"
><a
href=
"?page={{ page }}"
title=
"第{{ page }}页"
>
{{ page }}
</a></li>
{% else %}
<li
class=
"paginate_button"
aria-controls=
"editable"
tabindex=
"0"
><a
href=
"?page={{ page }}"
title=
"第{{ page }}页"
>
{{ page }}
</a></li>
{% endifequal %}
{% endfor %}
{% if contacts.has_next %}
<li
class=
"paginate_button next"
aria-controls=
"editable"
tabindex=
"0"
id=
"editable_next"
>
<a
href=
"?page={{ contacts.next_page_number }}"
>
Next
</a>
</li>
{% else %}
<li
class=
"paginate_button next disabled"
aria-controls=
"editable"
tabindex=
"0"
id=
"editable_next"
>
<a
href=
"#"
>
Next
</a>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$
(
document
).
ready
(
function
(){
$
(
".iframe"
).
colorbox
({
iframe
:
true
,
width
:
"70%"
,
height
:
"70%"
});
});
</script>
<script>
$
(
document
).
ready
(
function
(){
$
(
'input'
).
iCheck
({
checkboxClass
:
'icheckbox_square'
,
radioClass
:
'iradio_square'
,
increaseArea
:
'20%'
// optional
});
});
</script>
{% endblock %}
\ No newline at end of file
templates/script.html
View file @
5cd09a65
...
...
@@ -21,7 +21,7 @@
$
(
document
).
ready
(
function
(){
$
(
'.i-checks'
).
iCheck
({
checkboxClass
:
'icheckbox_square-green'
,
radioClass
:
'iradio_square-green'
,
radioClass
:
'iradio_square-green'
});
});
...
...
@@ -42,9 +42,26 @@
}
function
move
(
from
,
to
)
{
$
(
"#"
+
from
+
" option"
).
each
(
function
(){
if
(
$
(
this
).
prop
(
"selected"
)
==
true
)
{
$
(
"#"
+
to
).
append
(
this
);
}
});
}
function
move_all
(
from
,
to
){
$
(
"#"
+
from
).
children
().
each
(
function
(){
$
(
"#"
+
to
).
append
(
this
);
});
}
</script>
<!-- pop windows -->
<script
src=
"/static/js/jquery.colorbox.js"
></script>
...
...
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