pull/6/head
halcyon 2015-04-04 12:47:07 +08:00
parent b35f1e6174
commit 6e976b0583
10 changed files with 296 additions and 58 deletions

View File

@ -27,4 +27,6 @@ urlpatterns = patterns('jperm.views',
(r'^apply/$', 'perm_apply'),
(r'^apply_show/(\w+)/$', 'perm_apply_log'),
(r'^apply_exec/$', 'perm_apply_exec'),
(r'^apply_info/$', 'perm_apply_info'),
(r'^apply_search/$', 'perm_apply_search'),
)

View File

@ -556,7 +556,6 @@ def perm_apply(request):
da = User.objects.get(id=da)
mail_address = da.email
mail_title = '%s - 权限申请' % username
# print da.username, applyer, group, hosts, datetime.datetime.now(), comment, url
group_lis = ', '.join(group)
hosts_lis = ', '.join(hosts)
time_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
@ -571,21 +570,28 @@ def perm_apply(request):
申请的主机: %s
申请时间: %s
申请说明: %s
请及时审批, 审批完成后点击以下链接,告知各位
请及时审批, 审批完成后点击以下链接,告知申请人
%s
""" % (da.username, applyer, group_lis, hosts_lis, time_now, comment, url)
send_mail(mail_title, mail_msg, 'jkfunshion@fun.tv', [mail_address], fail_silently=False)
send_mail(mail_title, mail_msg, 'jumpserver@163.com', [mail_address], fail_silently=False)
smg = "提交成功,已发邮件通知部门管理员。"
return render_to_response('jperm/perm_apply.html', locals(), context_instance=RequestContext(request))
return render_to_response('jperm/perm_apply.html', locals(), context_instance=RequestContext(request))
@require_admin
def perm_apply_exec(request):
header_title, path1, path2 = u'主机权限申请', u'权限管理', u'审批完成'
uuid = request.GET.get('uuid')
if uuid:
p_apply = Apply.objects.filter(uuid=str(uuid))
q_apply = Apply.objects.get(uuid=str(uuid))
if p_apply:
if q_apply.status == 1:
smg = '此权限已经审批完成, 请勿重复审批, 十秒钟后返回首页'
return render_to_response('jperm/perm_apply_exec.html', locals(), context_instance=RequestContext(request))
else:
user = User.objects.get(username=q_apply.applyer)
mail_address = user.email
time_now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
@ -596,6 +602,10 @@ def perm_apply_exec(request):
您所申请的权限已由 %s %s 审批完成, 请登录验证
""" % (q_apply.applyer, q_apply.approver, time_now)
send_mail(mail_title, mail_msg, 'jkfunshion@fun.tv', [mail_address], fail_silently=False)
smg = '授权完成, 已邮件通知申请人, 十秒钟后返回首页'
return render_to_response('jperm/perm_apply_exec.html', locals(), context_instance=RequestContext(request))
else:
smg = '没有此授权, 十秒钟后返回首页'
return render_to_response('jperm/perm_apply_exec.html', locals(), context_instance=RequestContext(request))
@ -623,6 +633,7 @@ def get_apply_posts(request, status, username, dept_name, keyword=None):
return posts
@require_login
def perm_apply_log(request, offset):
header_title, path1, path2 = u'权限申请记录', u'权限管理', u'申请记录'
keyword = request.GET.get('keyword')
@ -639,3 +650,59 @@ def perm_apply_log(request, offset):
posts = get_apply_posts(request, 1, username, dept_name, keyword)
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
return render_to_response('jperm/perm_log_offline.html', locals(), context_instance=RequestContext(request))
def perm_apply_info(request):
uuid = request.GET.get('uuid')
post = Apply.objects.get(uuid=uuid)
return render_to_response('jperm/perm_apply_info.html', locals(), context_instance=RequestContext(request))
def perm_apply_search(request):
keyword = request.GET.get('keyword')
env = request.GET.get('env')
dept_id = get_user_dept(request)
dept_name = DEPT.objects.get(id=dept_id).name
user_id = request.session.get('user_id')
username = User.objects.get(id=user_id).username
if is_super_user(request):
if env == 'online':
posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \
.filter(status=0).order_by('-date_add')
elif env == 'offline':
posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \
.filter(status=1).order_by('-date_add')
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
elif is_group_admin(request):
if env == 'online':
posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \
.filter(status=0).filter(dept_name=dept_name).order_by('-date_add')
elif env == 'offline':
posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \
.filter(status=1).filter(dept_name=dept_name).order_by('-date_add')
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
elif is_common_user(request):
if env == 'online':
posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \
.filter(status=0).filter(user=username).order_by('-date_add')
elif env == 'offline':
posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \
.filter(status=1).filter(applyer=username).order_by('-date_add')
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
return render_to_response('jperm/perm_apply_search.html', locals(), context_instance=RequestContext(request))

View File

@ -56,6 +56,18 @@ def groups_str2(group_list):
return '%s ...' % ' '.join([group.name for group in group_list[0:2]])
@register.filter(name='group_str2_all')
def groups_str2(group_list):
group_lis = []
for i in group_list:
if str(i) != 'ALL':
group_lis.append(i)
if len(group_lis) < 3:
return ' '.join([group.name for group in group_lis])
else:
return '%s ...' % ' '.join([group.name for group in group_lis[0:2]])
@register.filter(name='group_manage_str')
def group_manage_str(username):
user = User.objects.get(username=username)
@ -163,6 +175,11 @@ def group_type_to_str(type_name):
@register.filter(name='ast_to_list')
def ast_to_list(lis):
return ast.literal_eval(lis)[0:2]
@register.filter(name='ast_to_list_1')
def ast_to_list_1(lis):
return ast.literal_eval(lis)

View File

@ -56,7 +56,6 @@
<th class="text-center"> 所属部门 </th>
<th class="text-center"> 所属主机组 </th>
<th class="text-center"> 是否激活 </th>
<!--<th class="text-center" name="j_time"> 添加时间 </th>-->
<th class="text-center" name="j_comment"> 备注 </th>
<th class="text-center"> 操作 </th>
</tr>
@ -70,9 +69,8 @@
<td class="text-center" name="j_type"> {{ login_types|get_item:post.login_type }} </td>
<td class="text-center" name="j_idc"> {{ post.idc.name }} </td>
<td class="text-center" name="j_dept">{{ post.dept.all | group_str2 }}</td>
<td class="text-center" name="j_group">{{ post.bis_group.all | group_str2 }}</td>
<td class="text-center" name="j_group">{{ post.bis_group.all | group_str2_all }}</td>
<td class="text-center" name="j_active"> {{ post.is_active|bool2str }} </td>
<!--<td class="text-center"> {{ post.date_added|date:"Y-m-d H:i:s" }} </td>-->
<td class="text-center" name="j_comment"> {{ post.comment }} </td>
<td class="text-center" data-editable='false'>
<a value="/jasset/{{ post.ip }}/" class="iframe btn btn-xs btn-primary">详情</a>

View File

@ -6,35 +6,26 @@
<div class="row">
<div class="col-lg-10">
<div id="add_asset" class="ibox float-e-margins">
<div id="ibox-content" class="ibox-title">
<h5> 填写要申请主机的基本信息 </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">
<h3>授权完成, 已邮件通知申请人, 五秒钟后关闭页面</h3>
<h2 id="jumpTo" class="text-center text-info"></h2>
</div>
</div>
</div>
</div>
</div>
<script>
<script>
function countDown(secs,surl){
var jumpTo = document.getElementById('jumpTo');
jumpTo.innerHTML='{{ smg }}......' + secs + '秒';
if(--secs>0){
setTimeout("countDown("+secs+",'"+surl+"')",1000);
}
else{
location.href=surl;
}
}
countDown(10,'/');
</script>
{% endblock content %}

View File

@ -0,0 +1,55 @@
{% load mytags %}
<html>
<head>
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<script src="/static/js/jquery-2.1.1.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<!--<link href="/static/css/style.css" rel="stylesheet">
<!--{% include 'head_script.html' %}
<!--<style type="text/css">-->
<!--body-->
<!--{-->
<!--background: #FFFFFF;-->
<!--}-->
<!--</style>-->
</head>
<body>
<div class="container">
<h3 class="text-center"><span class="text-success">{{ post.applyer }}</span>权限申请详情</h3>
<br/>
<div class="row">
<div class="col-xs-5">
<h6 class="text-right">申请人</h6>
<h6 class="text-right">所属部门</h6>
<h6 class="text-right">申请主机组</h6>
<h6 class="text-right">申请主机</h6>
{% for i in post.asset|ast_to_list_1 %}
<h6 class="text-right" style="color: #ffffff">Null</h6>
{% endfor %}
<h6 class="text-right">批准人</h6>
<h6 class="text-right">申请时间</h6>
<h6 class="text-right">批准时间</h6>
<h6 class="text-right">备注</h6>
</div>
<div class="col-xs-2">
<div class="col-sm-offset-6" style="width: 2; height: 70%; background-color: #1AB394; padding-top: 200px"></div>
</div>
<div class="col-xs-5">
<h6 class="text-left">{{ post.applyer }}</h6>
<h6 class="text-left">{{ post.dept }}</h6>
<h6 class="text-left">{% for i in post.bisgroup|ast_to_list_1 %} {{ i }} {% endfor %}</h6>
{% for i in post.asset|ast_to_list_1 %}
<h6 class="text-left">{{ i }}</h6>
{% endfor %}
<h6 class="text-right" style="color: #ffffff">Null</h6>
<h6 class="text-left">{{ post.approver }}1</h6>
<h6 class="text-left">{{ post.date_add|date:"Y-m-d H:i:s"}}</h6>
<h6 class="text-left"> {{ post.date_end|date:"Y-m-d H:i:s" }}1 </h6>
<h6 class="text-left"> {{ post.comment }} </h6>
</div>
</div>
</div>
</body>
</html>

View File

@ -0,0 +1,42 @@
{% load mytags %}
<div class="tab-content">
<table class="table table-striped table-bordered table-hover ">
<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>
<th class="text-center"> 申请时间 </th>
<!--<th class="text-center"> 批准时间 </th>-->
<th class="text-center"> 备注 </th>
<th class="text-center"> 详情 </th>
</tr>
</thead>
<tbody>
{% for post in contacts.object_list %}
<tr class="gradeX">
<td class="text-center" id="username"> {{ post.applyer }} </td>
<td class="text-center" id="dept"> {{ post.dept }} </td>
<td class="text-center" id="ip"> {% for i in post.bisgroup|ast_to_list %} {{ i }} {% endfor %}... </td>
<td class="text-center" id="remote_ip">{% for i in post.asset|ast_to_list %} {{ i }} {% endfor %}... </td>
<td class="text-center" id="approver"> {{ post.approver }} </td>
<td class="text-center" id="start_time"> {{ post.date_add|date:"Y-m-d H:i:s"}} </td>
<!--<td class="text-center" id="end_time"> {{ post.date_end|date:"Y-m-d H:i:s" }} </td>-->
<td class="text-center" id=""> {{ post.comment }} </td>
<td class="text-center" data-editable='false'>
<a value="/jperm/apply_info/?uuid={{ post.uuid }}" class="iframe btn btn-xs btn-primary">详情</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="row">
<div class="col-sm-6">
</div>
{% include 'paginator.html' %}
</div>
</div>
</div>

View File

@ -38,7 +38,7 @@
<input type="text" class="form-control input-sm" id="search_input" name="keyword" placeholder="Search">
<input type="text" style="display: none">
<div class="input-group-btn">
<button id='search_btn' type="button" class="btn btn-sm btn-primary" onclick="log_search()">
<button id='search_btn' type="button" class="btn btn-sm btn-primary" onclick="apply_search()">
Search
</button>
</div>
@ -58,8 +58,9 @@
<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>
</tr>
</thead>
@ -68,15 +69,15 @@
<tr class="gradeX">
<td class="text-center" id="username"> {{ post.applyer }} </td>
<td class="text-center" id="dept"> {{ post.dept }} </td>
<td class="text-center" id="ip"> {% for i in post.bisgroup|ast_to_list %} {{ i }} {% endfor %} </td>
<td class="text-center" id="remote_ip">{% for i in post.asset|ast_to_list %} {{ i }} {% endfor %} </td>
<td class="text-center" id="ip"> {% for i in post.bisgroup|ast_to_list %} {{ i }} {% endfor %}... </td>
<td class="text-center" id="remote_ip">{% for i in post.asset|ast_to_list %} {{ i }} {% endfor %}... </td>
<td class="text-center" id="approver"> {{ post.approver }} </td>
<!--{% ifnotequal session_role_id 0 %}-->
<!--<td class="text-center"><a href="/jlog/history/?id={{ post.id }}" class="log_command"> 命令统计 </td>-->
<!--{% endifnotequal %}-->
<td class="text-center" id="start_time"> {{ post.date_add|date:"Y-m-d H:i:s"}} </td>
<td class="text-center" id="end_time"> {{ post.date_end|date:"Y-m-d H:i:s" }} </td>
<!--<td class="text-center" id="end_time"> {{ post.date_end|date:"Y-m-d H:i:s" }} </td>-->
<td class="text-center" id=""> {{ post.comment }} </td>
<td class="text-center" data-editable='false'>
<a value="/jperm/apply_info/?uuid={{ post.uuid }}" class="iframe btn btn-xs btn-primary">详情</a>
</td>
</tr>
{% endfor %}
</tbody>
@ -93,4 +94,36 @@
</div>
</div>
<script>
$(".iframe").on('click', function(){
var url= $(this).attr("value");
$.layer({
type: 2,
title: '权限申请详情',
maxmin: true,
shift: 'top',
border: [2, 0.3, '#1AB394'],
shade: [0.5, '#000000'],
shadeClose: true,
area : ['800px' , '600px'],
iframe: {src: url}
});
});
function apply_search(){
$.ajax({
type: "GET",
url: "/jperm/apply_search/?env=offline",
data: $("#search_form").serialize(),
success: function (data) {
$(".tab-content").html(data);
}
});
}
$("#search_input").keydown(function(e){
if(e.keyCode==13){
apply_search()
}
})
</script>
{% endblock %}

View File

@ -1,4 +1,5 @@
{% extends 'base.html' %}
{% load mytags %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
@ -37,7 +38,7 @@
<input type="text" class="form-control input-sm" id="search_input" name="keyword" placeholder="Search">
<input type="text" style="display: none">
<div class="input-group-btn">
<button id='search_btn' type="button" class="btn btn-sm btn-primary" onclick="log_search()">
<button id='search_btn' type="button" class="btn btn-sm btn-primary" onclick="apply_search()">
Search
</button>
</div>
@ -56,8 +57,8 @@
<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>
</tr>
</thead>
@ -66,14 +67,13 @@
<tr class="gradeX">
<td class="text-center" id="username"> {{ post.applyer }} </td>
<td class="text-center" id="dept"> {{ post.dept }} </td>
<td class="text-center" id="ip"> {{ post.bisgroup }} </td>
<td class="text-center" id="remote_ip"> {{ post.asset }} </td>
<!--{% ifnotequal session_role_id 0 %}-->
<!--<td class="text-center"><a href="/jlog/history/?id={{ post.id }}" class="log_command"> 命令统计 </td>-->
<!--{% endifnotequal %}-->
<td class="text-center" id="ip"> {% for i in post.bisgroup|ast_to_list %} {{ i }} {% endfor %}... </td>
<td class="text-center" id="remote_ip"> {% for i in post.asset|ast_to_list %} {{ i }} {% endfor %}... </td>
<td class="text-center" id="start_time"> {{ post.date_add|date:"Y-m-d H:i:s"}} </td>
<td class="text-center" id="end_time"> {{ post.date_end|date:"Y-m-d H:i:s" }} </td>
<td class="text-center" id=""> {{ post.comment }} </td>
<td class="text-center" data-editable='false'>
<a value="/jperm/apply_info/?uuid={{ post.uuid }}" class="iframe btn btn-xs btn-primary">详情</a>
</td>
</tr>
{% endfor %}
</tbody>
@ -89,5 +89,36 @@
</div>
</div>
</div>
<script>
$(".iframe").on('click', function(){
var url= $(this).attr("value");
$.layer({
type: 2,
title: '权限申请详情',
maxmin: true,
shift: 'top',
border: [2, 0.3, '#1AB394'],
shade: [0.5, '#000000'],
shadeClose: true,
area : ['800px' , '600px'],
iframe: {src: url}
});
});
function apply_search(){
$.ajax({
type: "GET",
url: "/jperm/apply_search/?env=online",
data: $("#search_form").serialize(),
success: function (data) {
$(".tab-content").html(data);
}
});
}
$("#search_input").keydown(function(e){
if(e.keyCode==13){
apply_search()
}
})
</script>
{% endblock %}

View File

@ -48,6 +48,7 @@
<li class="sudo_list sudo_edit sudo_add cmd_list cmd_edit">
<a href="/jperm/sudo_list/">Sudo授权</a>
</li>
<li class="apply_show online"><a href="/jperm/apply_show/online/">权限审批</a></li>
</ul>
</li>
{# <li id="jlog">#}
@ -112,6 +113,7 @@
<li id="sudo_add">
<a href="/jperm/sudo_list/">Sudo授权</a>
</li>
<li class="apply_show online"><a href="/jperm/apply_show/online/">权限审批</a></li>
</ul>
</li>
<li id="jlog">