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
ad2a4d2d
Commit
ad2a4d2d
authored
Mar 02, 2015
by
guanghongwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改 用户添加 和 组添加
parent
d90b5919
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
39 deletions
+42
-39
views.py
juser/views.py
+30
-17
group_list.html
templates/juser/group_list.html
+3
-5
user_add.html
templates/juser/user_add.html
+9
-17
No files found.
juser/views.py
View file @
ad2a4d2d
...
@@ -9,6 +9,7 @@ import subprocess
...
@@ -9,6 +9,7 @@ import subprocess
from
Crypto.PublicKey
import
RSA
from
Crypto.PublicKey
import
RSA
import
crypt
import
crypt
from
django.http
import
HttpResponseRedirect
from
django.http
import
HttpResponseRedirect
import
datetime
from
django.shortcuts
import
render_to_response
from
django.shortcuts
import
render_to_response
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.core.exceptions
import
ObjectDoesNotExist
...
@@ -93,12 +94,13 @@ def group_update_user(group_id, users_id):
...
@@ -93,12 +94,13 @@ def group_update_user(group_id, users_id):
def
db_add_user
(
**
kwargs
):
def
db_add_user
(
**
kwargs
):
groups_post
=
kwargs
.
pop
(
'groups'
)
groups_post
=
kwargs
.
pop
(
'groups'
)
user
=
User
(
**
kwargs
)
user
=
User
(
**
kwargs
)
user
.
save
()
if
groups_post
:
group_select
=
[]
group_select
=
[]
for
group_id
in
groups_post
:
for
group_id
in
groups_post
:
group
=
UserGroup
.
objects
.
filter
(
id
=
group_id
)
group
=
UserGroup
.
objects
.
filter
(
id
=
group_id
)
group_select
.
extend
(
group
)
group_select
.
extend
(
group
)
user
.
save
()
user
.
group
=
group_select
user
.
user_group
=
group_select
def
db_update_user
(
**
kwargs
):
def
db_update_user
(
**
kwargs
):
...
@@ -155,7 +157,11 @@ def server_del_user(username):
...
@@ -155,7 +157,11 @@ def server_del_user(username):
def
ldap_add_user
(
username
,
ldap_pwd
):
def
ldap_add_user
(
username
,
ldap_pwd
):
user_dn
=
"uid=
%
s,ou=People,
%
s"
%
(
username
,
LDAP_BASE_DN
)
user_dn
=
"uid=
%
s,ou=People,
%
s"
%
(
username
,
LDAP_BASE_DN
)
password_sha512
=
gen_sha512
(
gen_rand_pwd
(
6
),
ldap_pwd
)
password_sha512
=
gen_sha512
(
gen_rand_pwd
(
6
),
ldap_pwd
)
user
=
User
.
objects
.
get
(
username
=
username
)
user
=
User
.
objects
.
filter
(
username
=
username
)
if
user
:
user
=
user
[
0
]
else
:
raise
AddError
(
u'用户
%
s 不存在'
%
username
)
user_attr
=
{
'uid'
:
[
str
(
username
)],
user_attr
=
{
'uid'
:
[
str
(
username
)],
'cn'
:
[
str
(
username
)],
'cn'
:
[
str
(
username
)],
...
@@ -278,14 +284,17 @@ def group_add(request, group_type_select='A'):
...
@@ -278,14 +284,17 @@ def group_add(request, group_type_select='A'):
error
=
u'组名 或 部门 不能为空'
error
=
u'组名 或 部门 不能为空'
raise
AddError
(
error
)
raise
AddError
(
error
)
group_db_add
(
name
=
group_name
,
comment
=
comment
)
dept
=
DEPT
.
objects
.
filter
(
id
=
dept_id
)
for
user_id
in
users_selected
:
if
dept
:
group_add_user
(
group_name
,
user_id
=
user_id
)
dept
=
dept
[
0
]
else
:
AddError
(
u'部门不存在'
)
db_add_group
(
name
=
group_name
,
dept
=
dept
,
comment
=
comment
)
except
AddError
:
except
AddError
:
pass
pass
except
TypeError
:
except
TypeError
:
error
=
u'保存
用户
组失败'
error
=
u'保存
小
组失败'
else
:
else
:
msg
=
u'添加组
%
s 成功'
%
group_name
msg
=
u'添加组
%
s 成功'
%
group_name
...
@@ -294,7 +303,7 @@ def group_add(request, group_type_select='A'):
...
@@ -294,7 +303,7 @@ def group_add(request, group_type_select='A'):
def
group_list
(
request
):
def
group_list
(
request
):
header_title
,
path1
,
path2
=
'查看属组 | Show Group'
,
'用户管理'
,
'查看用户组'
header_title
,
path1
,
path2
=
'查看属组 | Show Group'
,
'用户管理'
,
'查看用户组'
groups
=
contact_list
=
UserGroup
.
objects
.
filter
(
Q
(
type
=
'M'
)
|
Q
(
type
=
'A'
))
.
order_by
(
'type'
)
contact_list
=
UserGroup
.
objects
.
all
(
)
p
=
paginator
=
Paginator
(
contact_list
,
10
)
p
=
paginator
=
Paginator
(
contact_list
,
10
)
try
:
try
:
...
@@ -476,14 +485,15 @@ def user_add(request):
...
@@ -476,14 +485,15 @@ def user_add(request):
header_title
,
path1
,
path2
=
'添加用户 | User Add'
,
'用户管理'
,
'添加用户'
header_title
,
path1
,
path2
=
'添加用户 | User Add'
,
'用户管理'
,
'添加用户'
user_role
=
{
'SU'
:
u'超级管理员'
,
'DA'
:
u'部门管理员'
,
'CU'
:
u'普通用户'
}
user_role
=
{
'SU'
:
u'超级管理员'
,
'DA'
:
u'部门管理员'
,
'CU'
:
u'普通用户'
}
dept_all
=
DEPT
.
objects
.
all
()
dept_all
=
DEPT
.
objects
.
all
()
group_all
=
UserGroup
.
objects
.
all
()
if
request
.
method
==
'POST'
:
if
request
.
method
==
'POST'
:
username
=
request
.
POST
.
get
(
'username'
,
None
)
username
=
request
.
POST
.
get
(
'username'
,
''
)
password
=
request
.
POST
.
get
(
'password'
,
''
)
password
=
request
.
POST
.
get
(
'password'
,
''
)
name
=
request
.
POST
.
get
(
'name'
,
None
)
name
=
request
.
POST
.
get
(
'name'
,
''
)
email
=
request
.
POST
.
get
(
'email'
,
''
)
email
=
request
.
POST
.
get
(
'email'
,
''
)
dept_id
=
request
.
POST
.
get
(
'dept_id'
)
dept_id
=
request
.
POST
.
get
(
'dept_id'
)
auth_groups
=
request
.
POST
.
getlist
(
'groups'
,
None
)
groups
=
request
.
POST
.
getlist
(
'groups'
,
[]
)
role_post
=
request
.
POST
.
get
(
'role'
,
'CU'
)
role_post
=
request
.
POST
.
get
(
'role'
,
'CU'
)
ssh_key_pwd
=
request
.
POST
.
get
(
'ssh_key_pwd'
,
''
)
ssh_key_pwd
=
request
.
POST
.
get
(
'ssh_key_pwd'
,
''
)
is_active
=
request
.
POST
.
get
(
'is_active'
,
'1'
)
is_active
=
request
.
POST
.
get
(
'is_active'
,
'1'
)
...
@@ -498,24 +508,27 @@ def user_add(request):
...
@@ -498,24 +508,27 @@ def user_add(request):
error
=
u'用户
%
s 已存在'
%
username
error
=
u'用户
%
s 已存在'
%
username
raise
AddError
raise
AddError
dept
=
DEPT
.
objects
.
filter
(
id
=
dept_id
)
if
dept
:
dept
=
dept
[
0
]
else
:
error
=
u'部门不存在'
raise
AddError
(
error
)
except
AddError
:
except
AddError
:
pass
pass
else
:
else
:
time_now
=
time
.
time
()
try
:
try
:
db_add_user
(
username
=
username
,
db_add_user
(
username
=
username
,
password
=
md5_crypt
(
password
),
password
=
md5_crypt
(
password
),
name
=
name
,
email
=
email
,
name
=
name
,
email
=
email
,
dept
=
dept
,
groups
=
groups
,
role
=
role_post
,
groups
=
groups
,
role
=
role_post
,
ssh_pwd
=
CRYPTOR
.
encrypt
(
ssh_pwd
)
if
ssh_pwd
else
''
,
ssh_key_pwd
=
CRYPTOR
.
encrypt
(
ssh_key_pwd
),
ssh_key_pwd
=
CRYPTOR
.
encrypt
(
ssh_key_pwd
),
ldap_pwd
=
CRYPTOR
.
encrypt
(
ldap_pwd
),
ldap_pwd
=
CRYPTOR
.
encrypt
(
ldap_pwd
),
is_active
=
is_active
,
is_active
=
is_active
,
date_joined
=
time_now
)
date_joined
=
datetime
.
datetime
.
now
()
)
server_add_user
(
username
,
password
,
ssh_key_pwd
)
server_add_user
(
username
,
password
,
ssh_key_pwd
)
group_db_add
(
name
=
username
,
comment
=
username
,
type
=
'P'
)
group_add_user
(
group_name
=
username
,
username
=
username
)
if
LDAP_ENABLE
:
if
LDAP_ENABLE
:
ldap_add_user
(
username
,
ldap_pwd
)
ldap_add_user
(
username
,
ldap_pwd
)
msg
=
u'添加用户
%
s 成功!'
%
username
msg
=
u'添加用户
%
s 成功!'
%
username
...
...
templates/juser/group_list.html
View file @
ad2a4d2d
...
@@ -36,9 +36,8 @@
...
@@ -36,9 +36,8 @@
<table
class=
"table table-striped table-bordered table-hover "
id=
"editable"
>
<table
class=
"table table-striped table-bordered table-hover "
id=
"editable"
>
<thead>
<thead>
<tr>
<tr>
<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"
>
成员数量
</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"
>
操作
</th>
...
@@ -47,10 +46,9 @@
...
@@ -47,10 +46,9 @@
<tbody>
<tbody>
{% for group in contacts.object_list %}
{% for group in contacts.object_list %}
<tr
class=
"gradeX"
>
<tr
class=
"gradeX"
>
<td
class=
"text-center"
>
{{ group.id }}
</td>
<td
class=
"text-center"
>
{{ group.name }}
</td>
<td
class=
"text-center"
>
{{ group.name }}
</td>
<td
class=
"text-center"
>
{{ group.
type|group_type_to_str
}}
</td>
<td
class=
"text-center"
>
{{ group.
dept.name
}}
</td>
<td
class=
"text-center"
>
{{ group.
id|member_count
}}
</td>
<td
class=
"text-center"
>
{{ group.
name
}}
</td>
<td
class=
"text-center"
>
{{ group.comment }}
</td>
<td
class=
"text-center"
>
{{ group.comment }}
</td>
<td
class=
"text-center"
>
<td
class=
"text-center"
>
<a
title=
"[ {{ group.name }} ] 成员信息"
href=
"../group_detail/?id={{ group.id }}"
class=
"iframe btn btn-xs btn-primary"
>
成员
</a>
<a
title=
"[ {{ group.name }} ] 成员信息"
href=
"../group_detail/?id={{ group.id }}"
class=
"iframe btn btn-xs btn-primary"
>
成员
</a>
...
...
templates/juser/user_add.html
View file @
ad2a4d2d
...
@@ -39,14 +39,14 @@
...
@@ -39,14 +39,14 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"username"
class=
"col-sm-2 control-label"
>
用户名
<span
class=
"red-fonts"
>
*
</span></label>
<label
for=
"username"
class=
"col-sm-2 control-label"
>
用户名
<span
class=
"red-fonts"
>
*
</span></label>
<div
class=
"col-sm-8"
>
<div
class=
"col-sm-8"
>
<input
id=
"username"
name=
"username"
placeholder=
"Username"
type=
"text"
class=
"form-control"
value=
{{
username
}}
{{
readonly
}
}
>
<input
id=
"username"
name=
"username"
placeholder=
"Username"
type=
"text"
class=
"form-control"
{%
if
error
%}
value=
"{{ username }}"
{%
endif
%
}
>
</div>
</div>
</div>
</div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"password"
class=
"col-sm-2 control-label"
>
密码
<span
class=
"red-fonts"
>
*
</span></label>
<label
for=
"password"
class=
"col-sm-2 control-label"
>
密码
<span
class=
"red-fonts"
>
*
</span></label>
<div
class=
"col-sm-8"
>
<div
class=
"col-sm-8"
>
<input
id=
"password"
name=
"password"
placeholder=
"Password"
type=
"password"
class=
"form-control"
value=
{{
password
}
}
>
<input
id=
"password"
name=
"password"
placeholder=
"Password"
type=
"password"
class=
"form-control"
{%
if
error
%}
value=
"{{ password }}"
{%
endif
%
}
>
<span
class=
"help-block m-b-none"
>
<span
class=
"help-block m-b-none"
>
登陆web的密码
登陆web的密码
</span>
</span>
...
@@ -56,7 +56,7 @@
...
@@ -56,7 +56,7 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"ssh_key_pwd"
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"
>
<div
class=
"col-sm-8"
>
<input
id=
"ssh_key_pwd"
name=
"ssh_key_pwd"
placeholder=
"SSH Key Password"
type=
"password"
class=
"form-control"
value=
"{{ ssh_key_pwd }}"
>
<input
id=
"ssh_key_pwd"
name=
"ssh_key_pwd"
placeholder=
"SSH Key Password"
type=
"password"
class=
"form-control"
{%
if
error
%}
value=
"{{ ssh_key_pwd }}"
{%
endif
%}
>
<span
class=
"help-block m-b-none"
>
<span
class=
"help-block m-b-none"
>
登陆 Jumpserver 使用的SSH密钥的密码
登陆 Jumpserver 使用的SSH密钥的密码
</span>
</span>
...
@@ -66,14 +66,14 @@
...
@@ -66,14 +66,14 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"name"
class=
"col-sm-2 control-label"
>
姓名
<span
class=
"red-fonts"
>
*
</span></label>
<label
for=
"name"
class=
"col-sm-2 control-label"
>
姓名
<span
class=
"red-fonts"
>
*
</span></label>
<div
class=
"col-sm-8"
>
<div
class=
"col-sm-8"
>
<input
id=
"name"
name=
"name"
placeholder=
"Name"
type=
"text"
class=
"form-control"
value=
{{
name
}
}
>
<input
id=
"name"
name=
"name"
placeholder=
"Name"
type=
"text"
class=
"form-control"
{%
if
error
%}
value=
"{{ name }}"
{%
endif
%
}
>
</div>
</div>
</div>
</div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"
manage_group
"
class=
"col-lg-2 control-label"
>
部门
<span
class=
"red-fonts"
>
*
</span></label>
<label
for=
"
dept_id
"
class=
"col-lg-2 control-label"
>
部门
<span
class=
"red-fonts"
>
*
</span></label>
<div
class=
"col-sm-8"
>
<div
class=
"col-sm-8"
>
<select
id=
"
manage_group"
name=
"manage_group
"
class=
"form-control m-b"
>
<select
id=
"
dept_id"
name=
"dept_id
"
class=
"form-control m-b"
>
{% for dept in dept_all %}
{% for dept in dept_all %}
<option
value=
"{{ dept.id }}"
>
{{ dept.name }}
</option>
<option
value=
"{{ dept.id }}"
>
{{ dept.name }}
</option>
{% endfor %}
{% endfor %}
...
@@ -85,20 +85,12 @@
...
@@ -85,20 +85,12 @@
<label
for=
"groups"
class=
"col-lg-2 control-label"
>
小组
</label>
<label
for=
"groups"
class=
"col-lg-2 control-label"
>
小组
</label>
<div
class=
"col-sm-8"
>
<div
class=
"col-sm-8"
>
<select
id=
"groups"
name=
"groups"
class=
"form-control m-b"
multiple
size=
"12"
>
<select
id=
"groups"
name=
"groups"
class=
"form-control m-b"
multiple
size=
"12"
>
{% for group in groups %}
{% for group in group_all %}
{% if groups_str %}
{% if group.id|int2str in groups_str %}
<option
value=
"{{ group.id }}"
selected
>
{{ group.name }}
</option>
{% else %}
<option
value=
"{{ group.id }}"
>
{{ group.name }}
</option>
{% endif %}
{% else %}
{% if forloop.first %}
{% if forloop.first %}
<option
value=
"{{ group.id }}"
selected
>
{{ group.name }}
</option>
<option
value=
"{{ group.id }}"
selected
>
{{ group.name }}
</option>
{% else %}
{% else %}
<option
value=
"{{ group.id }}"
>
{{ group.name }}
</option>
<option
value=
"{{ group.id }}"
>
{{ group.name }}
</option>
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
</select>
</select>
</div>
</div>
...
@@ -122,7 +114,7 @@
...
@@ -122,7 +114,7 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
for=
"email"
class=
"col-sm-2 control-label"
>
Email
<span
class=
"red-fonts"
>
*
</span></label>
<label
for=
"email"
class=
"col-sm-2 control-label"
>
Email
<span
class=
"red-fonts"
>
*
</span></label>
<div
class=
"col-sm-8"
>
<div
class=
"col-sm-8"
>
<input
id=
"email"
name=
"email"
type=
"email"
placeholder=
"Email"
class=
"form-control"
value=
"{{ email }}"
>
<input
id=
"email"
name=
"email"
type=
"email"
placeholder=
"Email"
class=
"form-control"
{%
if
error
%}
value=
"{{ email }}"
{%
endif
%}
>
</div>
</div>
</div>
</div>
<div
class=
"hr-line-dashed"
></div>
<div
class=
"hr-line-dashed"
></div>
...
@@ -180,7 +172,7 @@ $('#userForm').validator({
...
@@ -180,7 +172,7 @@ $('#userForm').validator({
ok
:
""
,
ok
:
""
,
msg
:
{
required
:
"必须填写"
}
msg
:
{
required
:
"必须填写"
}
},
},
"
manage_group
"
:
{
"
dept_id
"
:
{
rule
:
"checked"
,
rule
:
"checked"
,
tip
:
"选择部门"
,
tip
:
"选择部门"
,
ok
:
""
,
ok
:
""
,
...
...
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