pull/230/head
ibuler 2016-05-10 13:55:06 +08:00
commit 1338d25b4e
6 changed files with 200 additions and 125 deletions

View File

@ -518,7 +518,10 @@ class Nav(object):
@staticmethod
def get_max_asset_property_length(assets, property_='hostname'):
return max([len(getattr(asset, property_)) for asset in assets])
try:
return max([len(getattr(asset, property_)) for asset in assets])
except ValueError:
return 30
def print_search_result(self):
hostname_max_length = self.get_max_asset_property_length(self.search_result)

View File

@ -16,6 +16,7 @@ from jperm.ansible_api import MyTask
from jperm.perm_api import get_role_info, get_role_push_host
from jumpserver.api import my_render, get_object, CRYPTOR
# 设置PERM APP Log
from jumpserver.api import logger
#logger = set_log(LOG_LEVEL, filename='jumpserver_perm.log')
@ -416,6 +417,7 @@ def perm_role_detail(request):
users = role_info.get("users")
user_groups = role_info.get("user_groups")
pushed_asset, need_push_asset = get_role_push_host(get_object(PermRole, id=role_id))
except ServerError, e:
logger.warning(e)

View File

@ -30,13 +30,15 @@
<div class="ibox-content">
<div>
<div class="text-left">
<table class="table" id="ugedit" >
<td class="text-navy text-left">时间</td>
<td class="text-navy text-right">名称</td>
<table class="table" id="ugedit">
<td class="text-navy text-left">时间</td>
<td class="text-navy text-right">名称</td>
{% for rule in rules %}
<tr class="gradeX">
<td class="text-left"> {{ rule.date_added | date:"Y-m-d H:i:s"}} </td>
<td class="text-right"> <a href="{% url 'rule_detail' %}?id={{ rule.id }}">{{ rule.name }}</a> </td>
<td class="text-left"> {{ rule.date_added | date:"Y-m-d H:i:s" }} </td>
<td class="text-right"><a
href="{% url 'rule_detail' %}?id={{ rule.id }}">{{ rule.name }}</a>
</td>
</tr>
{% endfor %}
</table>
@ -44,8 +46,7 @@
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary"><b>授权用户/用户组</b></span>
@ -68,37 +69,39 @@
</div>
</div>
<div class="ibox-content">
<div class="text-center">
<table class="table" id="agedit" >
<td class="text-navy text-left">用户</td>
<td class="text-navy text-right">用户组</td>
<tr>
<td>
<table class="table progress-striped text-left">
<div class="text-center">
<table class="table" id="agedit">
<td class="text-navy text-left">用户</td>
<td class="text-navy text-right">用户组</td>
<tr>
<td>
<table class="table progress-striped text-left">
{% for user in users %}
<tr class="gradeX">
<td> <a href="{% url 'user_detail' %}?id={{ user.id }}">{{ user.name }}</a> </td>
<td>
<a href="{% url 'user_detail' %}?id={{ user.id }}">{{ user.name }}</a>
</td>
</tr>
{% endfor %}
</table>
</td>
<td>
<table class="table progress-striped text-right">
</table>
</td>
<td>
<table class="table progress-striped text-right">
{% for group in user_groups %}
<tr class="gradeX-">
<td> <a href="{% url 'user_group_list' %}?id={{ group.id }}">{{ group.name }}</a> </td>
<td>
<a href="{% url 'user_group_list' %}?id={{ group.id }}">{{ group.name }}</a>
</td>
</tr>
{% endfor %}
</table>
</td>
</table>
</td>
</tr>
</table>
</div>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
</div>
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary"><b>授权主机组/主机组</b></span>
@ -122,26 +125,30 @@
</div>
<div class="ibox-content">
<div class="text-center">
<table class="table" id="agedit" >
<table class="table" id="agedit">
<td class="text-navy text-left">主机</td>
<td class="text-navy text-right">主机组</td>
<tr>
<td>
<table class="table progress-striped text-left">
{% for asset in assets %}
<tr class="gradeX">
<td> <a href="{% url 'asset_detail' %}?id={{ asset.id }}">{{ asset.ip }}</a> </td>
</tr>
{% endfor %}
{% for asset in assets %}
<tr class="gradeX">
<td>
<a href="{% url 'asset_detail' %}?id={{ asset.id }}">{{ asset.ip }}</a>
</td>
</tr>
{% endfor %}
</table>
</td>
<td>
<table class="table progress-striped text-right">
{% for group in asset_groups %}
<tr class="gradeX-">
<td> <a href="{% url 'asset_list' %}?group_id={{ group.id }}">{{ group.name }}</a> </td>
</tr>
{% endfor %}
{% for group in asset_groups %}
<tr class="gradeX-">
<td>
<a href="{% url 'asset_list' %}?group_id={{ group.id }}">{{ group.name }}</a>
</td>
</tr>
{% endfor %}
</table>
</td>
</tr>
@ -150,9 +157,70 @@
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="col-sm-8">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-danger"><b>{{ role.name }} - 推送失败主机</b></span>
<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>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div>
<div class="text-left">
<table class="table table-striped" id="ugedit">
<a class="btn btn-xs btn-danger del_muti"> 删除 </a><span> </span>
<a class="btn btn-xs btn-primary re_push"> 重新推送 </a>
<thead>
<tr>
<th class="text-center">
<input type="checkbox" id="check_push"
onclick="checkAll('check_push', 'asset_id')">
</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 asset, info in pushed_asset.items %}
{% if not info.success %}
<tr class="gradeX">
<th class="text-center">
<input type="checkbox" name="asset_id" value="{{ asset.id }}">
</th>
<td class="text-center"> {{ asset.hostname }} </td>
<td class="text-center"> {{ info.key | yesno:"是,否,未知" }} </td>
{% if info.success %}
<td class="text-center"
style="color: #1ab394;">{{ info.success | yesno:"成功,失败,未知" }} </td>
{% else %}
<td class="text-center push_failed" style="color: #ec4758;cursor: help"
title="{{ info.result }}">{{ info.success | yesno:"成功,失败,未知" }} </td>
{% endif %}
<td class="text-center"><a class="fa fa-times del"
href="{% url 'role_recycle' %}?role_id={{ role.id }}&asset_id={{ asset.id }}"
style="color: #ec4758;"></a></td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary"><b>{{ role.name }} - 推送主机</b></span>
@ -177,20 +245,20 @@
<div class="ibox-content">
<div>
<div class="text-left">
<table class="table table-striped" id="ugedit" >
<table class="table table-striped" id="ugedit">
<a class="btn btn-xs btn-danger del_muti"> 删除 </a><span> </span>
<a class="btn btn-xs btn-primary re_push"> 重新推送 </a>
<thead>
<tr>
<th class="text-center">
<input type="checkbox" id="check_push" onclick="checkAll('check_push', 'asset_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>
</tr>
<tr>
<th class="text-center">
<input type="checkbox" id="check_push"
onclick="checkAll('check_push', 'asset_id')">
</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 asset, info in pushed_asset.items %}
@ -200,13 +268,19 @@
</th>
<td class="text-center"> {{ asset.hostname }} </td>
<td class="text-center"> {{ info.key | yesno:"是,否,未知" }} </td>
<td class="text-center"> {{ info.password | yesno:"是,否,未知" }} </td>
{% if info.success %}
<td class="text-center" style="color: #1ab394;" >{{ info.success | yesno:"成功,失败,未知" }} </td>
<td class="text-center"
style="color: #1ab394;">{{ info.success | yesno:"成功,失败,未知" }} </td>
{% else %}
<td class="text-center push_failed" style="color: #ec4758;cursor: help" title="{{ info.result }}">{{ info.success | yesno:"成功,失败,未知" }} </td>
<td class="text-center push_failed" style="color: #ec4758;cursor: help"
title="{{ info.result }}">{{ info.success | yesno:"成功,失败,未知" }} </td>
{% endif %}
<td class="text-center" ><a class="fa fa-times del" href="{% url 'role_recycle' %}?role_id={{ role.id }}&asset_id={{ asset.id }}" style="color: #ec4758;"></a></td>
<td class="text-center">
<a class="fa fa-times del"
href="{% url 'role_recycle' %}?role_id={{ role.id }}&asset_id={{ asset.id }}"
style="color: #ec4758;">
</a>
</td>
</tr>
{% endfor %}
</tbody>
@ -215,9 +289,7 @@
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-danger"><b>{{ role.name }} - 未推送主机</b></span>
@ -236,16 +308,17 @@
<div class="ibox-content">
<div>
<div class="text-left">
<table class="table table-striped" >
<table class="table table-striped">
<a class="btn btn-xs btn-primary push_muti"> 推送 </a>
<thead>
<tr>
<th class="text-center">
<input type="checkbox" id="check_no_push" onclick="checkAll('check_no_push', 'asset_no_push_id')">
</th>
<th class="text-center">主机</th>
<th class="text-center">IP</th>
</tr>
<tr>
<th class="text-center">
<input type="checkbox" id="check_no_push"
onclick="checkAll('check_no_push', 'asset_no_push_id')">
</th>
<th class="text-center">主机</th>
<th class="text-center">IP</th>
</tr>
</thead>
<tbody>
{% for asset in need_push_asset %}
@ -272,66 +345,65 @@
{% endblock %}
{% block self_footer_js %}
<script>
$(document).ready(function(){
$('.del').click(function(){
var url = $(this).attr('href');
$.get(
url,
{},
function(data){
location.reload()
<script>
$(document).ready(function () {
$('.del').click(function () {
var url = $(this).attr('href');
$.get(
url,
{},
function (data) {
location.reload()
}
);
return false;
});
$('.del_muti').click(function () {
var check_array = [];
if (confirm("确定删除")) {
$(".gradeX input[name='asset_id']:checked").each(function () {
check_array.push($(this).attr("value"))
});
var url = '/jperm/role/recycle/?role_id={{ role.id }}&asset_id=' + check_array.join(',');
console.log(check_array);
$.get(url,
{},
function (data) {
location.reload()
}
)
}
return false;
});
);
return false;
});
$('.del_muti').click(function(){
var check_array = [];
if (confirm("确定删除")) {
$(".gradeX input[name='asset_id']:checked").each(function() {
$('.push_muti').click(function () {
var check_array = [];
$(".gradeX input[name='asset_no_push_id']:checked").each(function () {
check_array.push($(this).attr("value"))
});
var url = '/jperm/role/recycle/?role_id={{ role.id }}&asset_id=' + check_array.join(',');
console.log(check_array);
$.get(url,
{},
function(data){
location.reload()
}
)
}
return false;
});
$('.push_muti').click(function(){
var check_array = [];
$(".gradeX input[name='asset_no_push_id']:checked").each(function() {
check_array.push($(this).attr("value"))
var url = '/jperm/role/push/?id={{ role.id }}&asset_id=' + check_array.join(',');
$(this).attr('href', url)
});
var url = '/jperm/role/push/?id={{ role.id }}&asset_id=' + check_array.join(',');
$(this).attr('href', url)
});
$('.re_push').click(function(){
var check_array = [];
$(".gradeX input[name='asset_id']:checked").each(function() {
check_array.push($(this).attr("value"))
$('.re_push').click(function () {
var check_array = [];
$(".gradeX input[name='asset_id']:checked").each(function () {
check_array.push($(this).attr("value"))
});
var url = '/jperm/role/push/?id={{ role.id }}&asset_id=' + check_array.join(',');
$(this).attr('href', url)
});
var url = '/jperm/role/push/?id={{ role.id }}&asset_id=' + check_array.join(',');
$(this).attr('href', url)
});
$('.push_failed').click(function() {
var fail_reason = $(this).attr('title');
layer.alert(fail_reason, {
skin: 'layui-layer-molv',
area: '500px'
})
});
$('.push_failed').click(function () {
var fail_reason = $(this).attr('title');
layer.alert(fail_reason, {
skin: 'layui-layer-molv',
area: '500px'
})
});
})
</script>
})
</script>
{% endblock %}

View File

@ -70,7 +70,7 @@
<div class="row">
<div class="col-sm-6">
<div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
Showing {{ users.start_index }} to {{ users.end_index }} of {{ p.count }} entries
Showing {{ roles.start_index }} to {{ roles.end_index }} of {{ p.count }} entries
</div>
</div>
{% include 'paginator.html' %}
@ -80,8 +80,6 @@
</div>
</div>
</div>
<script>
function remove_role(role_id){
$.ajax({

View File

@ -89,7 +89,7 @@
<div class="row">
<div class="col-sm-6">
<div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
Showing {{ users.start_index }} to {{ users.end_index }} of {{ p.count }} entries
Showing {{ rules.start_index }} to {{ rules.end_index }} of {{ p.count }} entries
</div>
</div>
{% include 'paginator.html' %}

View File

@ -72,7 +72,7 @@
<div class="row">
<div class="col-sm-6">
<div class="dataTables_info" id="editable_info" role="status" aria-live="polite">
Showing {{ users.start_index }} to {{ users.end_index }} of {{ p.count }} entries
Showing {{ sudos.start_index }} to {{ sudos.end_index }} of {{ p.count }} entries
</div>
</div>
{% include 'paginator.html' %}