mirror of https://github.com/jumpserver/jumpserver
0402
parent
359f70b9f9
commit
e1b9134d7f
|
@ -42,6 +42,7 @@ class Apply(models.Model):
|
|||
bisgroup = models.CharField(max_length=500)
|
||||
asset = models.CharField(max_length=500)
|
||||
comment = models.TextField(blank=True, null=True)
|
||||
status = models.IntegerField(max_length=2)
|
||||
date_add = models.DateTimeField(default=datetime.datetime.now(), null=True)
|
||||
date_end = models.DateTimeField(null=True)
|
||||
|
||||
|
|
|
@ -25,5 +25,5 @@ urlpatterns = patterns('jperm.views',
|
|||
(r'^cmd_del/$', 'cmd_del'),
|
||||
(r'^cmd_edit/$', 'cmd_edit'),
|
||||
(r'^apply/$', 'perm_apply'),
|
||||
(r'^apply/online/$', 'perm_apply_log'),
|
||||
(r'^apply_show/(\w+)/$', 'perm_apply_log'),
|
||||
)
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
# coding: utf-8
|
||||
|
||||
import ast
|
||||
import datetime
|
||||
|
||||
|
||||
from django.core.mail import send_mail
|
||||
from django.shortcuts import render_to_response
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
from django.template import RequestContext
|
||||
|
@ -537,6 +542,7 @@ def perm_apply(request):
|
|||
dept = DEPT.objects.get(id=dept_id)
|
||||
posts = Asset.objects.filter(dept=dept)
|
||||
egroup = dept.bisgroup_set.all()
|
||||
mail_address = 'wangyong@fun.tv'
|
||||
|
||||
if request.method == 'POST':
|
||||
applyer = request.POST.get('applyer')
|
||||
|
@ -544,41 +550,65 @@ def perm_apply(request):
|
|||
group = request.POST.getlist('group')
|
||||
hosts = request.POST.getlist('hosts')
|
||||
comment = request.POST.get('comment')
|
||||
|
||||
Apply.objects.create(applyer=applyer, dept=dept, bisgroup=group, asset=hosts, comment=comment)
|
||||
print applyer, dept, group, hosts, comment
|
||||
url = 'http://127.0.0.1:8000/jperm/apply/exec/?id='
|
||||
mail_title = '权限申请'
|
||||
mail_msg = """
|
||||
Hi,%s:
|
||||
有新的权限申请, 详情如下:
|
||||
申请人: %s
|
||||
申请主机组: %s
|
||||
申请的主机: %s
|
||||
申请时间: %s
|
||||
申请说明: %s
|
||||
请及时审批, 审批完成后点击以下链接,告知各位。
|
||||
%s
|
||||
""" % (u'123', applyer, group, hosts, datetime.datetime.now(), comment, url)
|
||||
send_mail(mail_title, mail_msg, 'jkfunshion@fun.tv', [mail_address], fail_silently=False)
|
||||
smg = "提交成功,已转交运维上线。"
|
||||
|
||||
Apply.objects.create(applyer=applyer, dept=dept, bisgroup=group, asset=hosts, status=0, comment=comment)
|
||||
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))
|
||||
|
||||
|
||||
def perm_apply_log(request):
|
||||
def get_apply_posts(request, status, username, dept_name, keyword=None):
|
||||
if is_super_user(request):
|
||||
if keyword:
|
||||
posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \
|
||||
.filter(status=status).order_by('-date_add')
|
||||
else:
|
||||
posts = Apply.objects.filter(status=status).order_by('-date_add')
|
||||
|
||||
elif is_group_admin(request):
|
||||
if keyword:
|
||||
posts = Apply.objects.filter(Q(applyer__contains=keyword) | Q(approver__contains=keyword)) \
|
||||
.filter(status=status).filter(dept=dept_name).order_by('-date_add')
|
||||
else:
|
||||
posts = Log.objects.filter(status=status).filter(dept=dept_name).order_by('-date_add')
|
||||
|
||||
elif is_common_user(request):
|
||||
if keyword:
|
||||
posts = Apply.objects.filter(applyer=username).filter(status=status).filter(Q(applyer__contains=keyword) |
|
||||
Q(asset__contains=keyword)).order_by('-date_add')
|
||||
else:
|
||||
posts = Apply.objects.filter(applyer=username).filter(status=status).order_by('-date_add')
|
||||
return posts
|
||||
|
||||
|
||||
def perm_apply_log(request, offset):
|
||||
header_title, path1, path2 = u'权限申请记录', u'权限管理', u'申请记录'
|
||||
keyword = request.GET.get('keyword')
|
||||
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 keyword:
|
||||
posts = Log.objects.filter(Q(user__contains=keyword) | Q(host__contains=keyword)) \
|
||||
.filter(is_finished=1).order_by('-start_time')
|
||||
else:
|
||||
posts = Log.objects.filter(is_finished=1).order_by('-start_time')
|
||||
if offset == 'online':
|
||||
posts = get_apply_posts(request, 0, 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_online.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
elif is_group_admin(request):
|
||||
if keyword:
|
||||
posts = Log.objects.filter(Q(user__contains=keyword) | Q(host__contains=keyword)) \
|
||||
.filter(is_finished=1).filter(dept_name=dept_name).order_by('-start_time')
|
||||
else:
|
||||
posts = Log.objects.filter(is_finished=1).filter(dept_name=dept_name).order_by('-start_time')
|
||||
elif offset == 'offline':
|
||||
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)
|
||||
|
||||
elif is_common_user(request):
|
||||
if keyword:
|
||||
posts = Apply.objects.filter(applyer=username).filter(Q(applyer__contains=keyword) | Q(asset__contains=keyword))\
|
||||
.order_by('-date_add')
|
||||
else:
|
||||
posts = Apply.objects.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_log.html', locals(), context_instance=RequestContext(request))
|
||||
return render_to_response('jperm/perm_log_offline.html', locals(), context_instance=RequestContext(request))
|
||||
|
|
|
@ -20,3 +20,9 @@ web_socket_host = 127.0.0.1:3000
|
|||
[web]
|
||||
key = 88aaaf7ffe3c6c04
|
||||
|
||||
[mail]
|
||||
email_host = 'mail.funshion.com'
|
||||
email_port = '25'
|
||||
email_host_user = 'jkfunshion'
|
||||
email_host_password = 'jkmail%'
|
||||
email_use_tls = False
|
|
@ -121,3 +121,10 @@ USE_TZ = False
|
|||
|
||||
STATIC_URL = '/static/'
|
||||
|
||||
# mail config
|
||||
EMAIL_HOST = config.get('mail', 'email_host')
|
||||
EMAIL_PORT = config.get('mail', 'email_port')
|
||||
EMAIL_HOST_USER = config.get('mail', 'email_host_user')
|
||||
EMAIL_HOST_PASSWORD = config.get('mail', 'email_host_password')
|
||||
EMAIL_USE_TLS = config.get('mail', 'email_use_tls')
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# coding: utf-8
|
||||
|
||||
import re
|
||||
import ast
|
||||
import time
|
||||
|
||||
from django import template
|
||||
|
@ -160,6 +161,11 @@ def group_type_to_str(type_name):
|
|||
return group_types.get(type_name)
|
||||
|
||||
|
||||
@register.filter(name='ast_to_list')
|
||||
def ast_to_list(lis):
|
||||
return ast.literal_eval(lis)
|
||||
|
||||
|
||||
# @register.filter(name='perm_asset_count')
|
||||
# def perm_asset_count(user_id):
|
||||
# return len(perm_user_asset(user_id))
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
{% 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-12">
|
||||
<div 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">
|
||||
<div class="panel-options">
|
||||
<ul class="nav nav-tabs">
|
||||
<li><a href="/jperm/apply_show/online/" class="text-center"><i class="fa fa-laptop"></i> 未审批 </a></li>
|
||||
<li class="active"><a href="/jperm/apply_show/offline/" class="text-center"><i class="fa fa-bar-chart-o"></i> 已审批 </a></li>
|
||||
<li style="float: right">
|
||||
<form id="search_form" method="get" action="" class="pull-right mail-search">
|
||||
<div class="input-group">
|
||||
<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()">
|
||||
Search
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<br/>
|
||||
<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>
|
||||
|
||||
</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>
|
||||
<!--{% 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=""> {{ post.comment }} </td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
</div>
|
||||
{% include 'paginator.html' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -0,0 +1,93 @@
|
|||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
{% include 'nav_cat_bar.html' %}
|
||||
<div class="wrapper wrapper-content animated fadeInRight">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div 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">
|
||||
<div class="panel-options">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="/jperm/apply_show/online/" class="text-center"><i class="fa fa-laptop"></i> 未审批 </a></li>
|
||||
<li><a href="/jperm/apply_show/offline/" class="text-center"><i class="fa fa-bar-chart-o"></i> 已审批 </a></li>
|
||||
<li style="float: right">
|
||||
<form id="search_form" method="get" action="" class="pull-right mail-search">
|
||||
<div class="input-group">
|
||||
<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()">
|
||||
Search
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<br/>
|
||||
<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>
|
||||
|
||||
</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"> {{ 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="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>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
</div>
|
||||
{% include 'paginator.html' %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -143,8 +143,8 @@
|
|||
<li id="jperm">
|
||||
<a><i class="fa fa-cube"></i> <span class="nav-label">权限申请</span><span class="fa arrow"></span></a>
|
||||
<ul class="nav nav-second-level">
|
||||
<li class="apply host_add_multi"><a href="/jperm/apply/">申请主机</a></li>
|
||||
<li class="apply online"><a href="/jperm/apply/online/">申请记录</a></li>
|
||||
<li class="apply"><a href="/jperm/apply/">申请主机</a></li>
|
||||
<li class="apply_show online"><a href="/jperm/apply_show/online/">申请记录</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li id="jlog">
|
||||
|
|
Loading…
Reference in New Issue