just do it

This commit is contained in:
halcyon
2015-11-08 22:39:30 +08:00
parent 159398b391
commit e77ec102d9
22 changed files with 637 additions and 361 deletions

View File

@@ -50,11 +50,9 @@
<div class="hr-line-dashed"></div>
{{ af.idc|bootstrap_horizontal }}
{# {{ af.use_default_auth|bootstrap_horizontal }}#}
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="j_group" class="col-sm-2 control-label">管理账号</label>
<label for="j_group" class="col-sm-2 control-label">管理账号<span class="red-fonts"> *</span></label>
<div class="col-sm-2">
<div class="radio i-checks">
<label>
@@ -79,21 +77,17 @@
<div class="hr-line-dashed"></div>
{{ af.group|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
{{ af.is_active|bootstrap_horizontal }}
{# <div class="hr-line-dashed"></div>#}
{# <div class="form-group"><label class="col-sm-2 control-label"> 是否激活<span class="red-fonts">*</span> </label>#}
{# <div class="col-sm-8">#}
{# <div class="radio i-checks">#}
{# <label> <input type="radio" checked="" name="is_active">激活 </label>#}
{# <label> <input type="radio" name="is_active"> 禁用</label>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# {{ af.is_active|bootstrap_horizontal }}#}
<div class="hr-line-dashed"></div>
{{ af.comment|bootstrap_horizontal }}
<div class="form-group"><label class="col-sm-2 control-label"> 是否激活<span class="red-fonts"> *</span> </label>
<div class="col-sm-8">
<div class="radio i-checks">
<label> <input type="radio" checked="" value="1" name="is_active">激活 </label>
<label> <input type="radio" value="0" name="is_active"> 禁用</label>
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
@@ -116,43 +110,47 @@
{% block self_footer_js %}
<script>
$('document').ready(function(){
$('#id_use_default_auth').click(function(){
if ($(this).is(':checked')){
$('#admin_account').css('display', 'none')
}
else {
$('#admin_account').css('display', 'block')
}
})
});
$('document').ready(function(){
$('#id_use_default_auth').click(function(){
if ($(this).is(':checked')){
$('#admin_account').css('display', 'none')
}
else {
$('#admin_account').css('display', 'block')
}
})
});
var required_fields = ["id_hostname", "id_ip", "id_port"];
required_fields.forEach(function(field) {
$('label[for="' + field + '"]').parent().addClass("required");
});
$('#assetForm').validator({
timely: 2,
theme: "yellow_right_effect",
rules: {
check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],
check_port: [/^\d{1,5}$/, '端口号不正确'],
},
fields: {
"ip": {
rule: "required;check_ip",
tip: "输入IP",
ok: "",
msg: {required: "必须填写!"}
$('#assetForm').validator({
timely: 2,
theme: "yellow_right_effect",
rules: {
check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],
check_port: [/^\d{1,5}$/, '端口号不正确'],
},
"port": {
rule: "required;check_port",
tip: "输入端口号",
ok: "",
msg: {required: "必须填写!"}
fields: {
"ip": {
rule: "required;check_ip",
tip: "输入IP",
ok: "",
msg: {required: "必须填写!"}
},
"port": {
rule: "required;check_port",
tip: "输入端口号",
ok: "",
msg: {required: "必须填写!"}
}
},
valid: function(form) {
form.submit();
}
},
valid: function(form) {
form.submit();
}
});
});
</script>

View File

@@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% load mytags %}
{% load humanize %}
{% block content %}
{% include 'nav_cat_bar.html' %}
@@ -60,7 +60,8 @@
</tr>
<tr>
<td class="text-navy">使用默认管理账号</td>
<td>{{ asset.use_default_auth|bool2str }}</td>
{# <td>{{ asset.use_default_auth|bool2str }}</td>#}
<td>{{ asset.use_default_auth|bool2str }} {% if not asset.use_default_auth %} <span class="text-info">{{ asset.username }}</span> {% endif %}</td>
</tr>
<tr>
<td class="text-navy">机房</td>
@@ -152,8 +153,8 @@
</div>
<div class="ibox-content">
<div>
<div class="text-left">
<table class="table">
{# <div class="text-left">#}
{# <table class="table">#}
{# {% if user_permed_list %}#}
{# {% for user in user_permed_list %}#}
{# <tr>#}
@@ -165,8 +166,48 @@
{# {% else %}#}
{# <p class="text-center">(暂无)</p>#}
{# {% endif %}#}
</table>
</div>
{# </table>#}
{# </div>#}
</div>
</div>
<div 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">
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content ibox-heading">
<h3>主机修改记录</h3>
<small><i class="fa fa-map-marker"></i> 包含了此主机所有历史修改记录.</small>
</div>
<div class="ibox-content">
<div class="feed-activity-list">
{% if asset_record %}
{% for r in asset_record %}
<div class="feed-element">
<div>
<small class="pull-right">{{ r.alert_time|naturaltime }}</small>
<strong class="text-navy">{{ r.username }}</strong>
{% for i in r.content|str_to_list %}
<div>{{ i.0 }} 由 <span class="text-success">{{ i.1|str_to_code }}</span> 改为 <span class="text-warning">{{ i.2|str_to_code }}</span></div>
{% endfor %}
<small class="text-success">{{ r.alert_time }}</small>
</div>
</div>
{% endfor %}
{% else %}
<p class="text-center">(暂无)</p>
{% endif %}
</div>
</div>
</div>

View File

@@ -39,6 +39,9 @@
<div class="hr-line-dashed"></div>
{{ af.hostname|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
{{ af.other_ip|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
{{ af.remote_ip|bootstrap_horizontal }}
@@ -47,25 +50,25 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="j_group" class="col-sm-2 control-label">管理账号</label>
<label for="j_group" class="col-sm-2 control-label">管理账号 <span class="red-fonts">*</span></label>
<div class="col-sm-2">
<div class="radio i-checks">
<label>
<input type="checkbox" checked="" id="id_use_default_auth" name="use_default_auth"><span> 使用默认 </span>
<input type="checkbox" {% if asset.use_default_auth %} checked="" {% endif %} id="id_use_default_auth" name="use_default_auth"><span> 使用默认 </span>
</label>
</div>
</div>
</div>
<div class="form-group" id="admin_account" style="display: none">
<label class="col-sm-2 control-label"> 管理用户名<span class="red-fonts">*</span> </label>
<div class="form-group" id="admin_account" {% if asset.use_default_auth %} style="display: none" {% endif %}>
<label class="col-sm-2 control-label"> 管理用户名 <span class="red-fonts">*</span> </label>
<div class="col-sm-3">
<input type="text" placeholder="Username" name="username" class="form-control">
<input type="text" value="{{ asset.username }}" name="username" class="form-control">
</div>
<label class="col-sm-1 control-label"> 密码<span class="red-fonts">*</span> </label>
<div class="col-sm-4">
<input type="password" placeholder="Password" name="password" class="form-control">
<input type="password" value="{{ asset.password }}" name="password" class="form-control">
</div>
</div>
@@ -109,23 +112,23 @@
<div class="hr-line-dashed"></div>
{{ af.status|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
{{ af.is_active|bootstrap_horizontal }}
{# <div class="hr-line-dashed"></div>#}
{# <div class="form-group"><label class="col-sm-2 control-label"> 是否激活<span class="red-fonts">*</span> </label>#}
{# <div class="col-sm-8">#}
{# <div class="radio i-checks">#}
{# {% ifequal asset.is_active 1 %}#}
{# <label> <input type="radio" checked="" value="1" name="is_active">激活 </label>#}
{# <label> <input type="radio" value="0" name="is_active"> 禁用</label>#}
{# {% else %}#}
{# <label> <input type="radio" value="1" name="is_active">激活 </label>#}
{# <label> <input type="radio" checked="" value="0" name="is_active"> 禁用</label>#}
{# {% endifequal %}#}
{# </div>#}
{# </div>#}
{# </div>#}
{# {{ af.is_active|bootstrap_horizontal }}#}
<div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-2 control-label"> 是否激活<span class="red-fonts">*</span> </label>
<div class="col-sm-8">
<div class="radio i-checks">
{% ifequal asset.is_active 1 %}
<label> <input type="radio" checked="" value="1" name="is_active">激活 </label>
<label> <input type="radio" value="0" name="is_active"> 禁用</label>
{% else %}
<label> <input type="radio" value="1" name="is_active">激活 </label>
<label> <input type="radio" checked="" value="0" name="is_active"> 禁用</label>
{% endifequal %}
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
{{ af.comment|bootstrap_horizontal }}
@@ -151,43 +154,47 @@
{% block self_footer_js %}
<script>
$('document').ready(function(){
$('#id_use_default_auth').click(function(){
if ($(this).is(':checked')){
$('#admin_account').css('display', 'none')
}
else {
$('#admin_account').css('display', 'block')
}
})
});
$('document').ready(function(){
$('#id_use_default_auth').click(function(){
if ($(this).is(':checked')){
$('#admin_account').css('display', 'none')
}
else {
$('#admin_account').css('display', 'block')
}
})
});
var required_fields = ["id_ip", "id_port"];
required_fields.forEach(function(field) {
$('label[for="' + field + '"]').parent().addClass("required");
});
$('#assetForm').validator({
timely: 2,
theme: "yellow_right_effect",
rules: {
check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],
check_port: [/^\d{1,5}$/, '端口号不正确'],
},
fields: {
"ip": {
rule: "required;check_ip",
tip: "输入IP",
ok: "",
msg: {required: "必须填写!"}
$('#assetForm').validator({
timely: 2,
theme: "yellow_right_effect",
rules: {
check_ip: [/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/, 'ip地址不正确'],
check_port: [/^\d{1,5}$/, '端口号不正确'],
},
"port": {
rule: "required;check_port",
tip: "输入端口号",
ok: "",
msg: {required: "必须填写!"}
fields: {
"ip": {
rule: "required;check_ip",
tip: "输入IP",
ok: "",
msg: {required: "必须填写!"}
},
"port": {
rule: "required;check_port",
tip: "输入端口号",
ok: "",
msg: {required: "必须填写!"}
}
},
valid: function(form) {
form.submit();
}
},
valid: function(form) {
form.submit();
}
});
});
</script>

View File

@@ -0,0 +1,180 @@
<html>
<head>
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/font-awesome/css/font-awesome.css" rel="stylesheet">
<link href="/static/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="/static/css/animate.css" rel="stylesheet">
<link href="/static/css/style.css" rel="stylesheet">
<script src="/static/js/jquery-2.1.1.js"></script>
{# <style>#}
{# body {background: #ffffff;}#}
{# </style>#}
</head>
{% load bootstrap %}
{% block content %}
<body>
<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 class="text-center"> 填写修改主机信息. </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"></ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<form class="form-horizontal" action="" id="signupForm" method="post" name="horizontal" role="form" autocomplete="off">
{% csrf_token %}
<input id="ids" style="display: none">
{{ af.env|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
{{ af.idc|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
{{ af.port|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="j_group" class="col-sm-2 control-label">管理账号</label>
<div class="col-sm-2">
<div class="radio i-checks">
<label>
<input type="radio" checked="" value="no_action" name="use_default_auth"><span> 不修改 </span>
</label>
</div>
<div class="radio i-checks">
<label>
<input type="radio" name="use_default_auth"><span> 使用默认 </span>
</label>
</div>
<div class="radio i-checks">
<label>
<input type="radio" id="id_use_default_auth" name="use_default_auth"><span> 用户名密码 </span>
</label>
</div>
</div>
</div>
<div class="form-group" id="admin_account" style="display: none">
<label class="col-sm-2 control-label"> 管理用户名<span class="red-fonts"> *</span></label>
<div class="col-sm-3">
<input type="text" placeholder="Username" name="username" class="form-control">
</div>
<label class="col-sm-1 control-label"> 密码<span class="red-fonts">*</span> </label>
<div class="col-sm-4">
<input type="password" placeholder="Password" name="password" class="form-control">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="groups" class="col-sm-2 control-label">所属主机组</label>
<div class="col-sm-3">
<select id="groups" size="10" class="form-control m-b" multiple>
{% for asset_group in asset_group_all %}
<option value="{{ asset_group.id }}">{{ asset_group.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_right('groups', 'groups_selected')"><i class="fa fa-chevron-right"></i></button>
<button type="button" class="btn btn-white" onclick="move_left('groups_selected', 'groups')"><i class="fa fa-chevron-left"></i> </button>
</div>
</div>
<div class="col-sm-3">
<div>
<select id="groups_selected" name="project" class="form-control m-b" size="10" multiple>
</select>
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
{{ af.cabinet|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
{{ af.comment|bootstrap_horizontal }}
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-5">
<button class="btn btn-white" type="submit"> 重置 </button>
<button class="btn btn-primary" id="host_edit"> 提交 </button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('#host_edit').click(function () {
var args = {};
var match = null;
var uuid = decodeURIComponent(location.search.substring(1));
var reg = /(?:([^&amp;]+)=([^&amp;]+))/g;
while((match = reg.exec(uuid))!==null){
args[match[1]] = match[2];
}
var ids = args['uuid'];
$('#uuid').val(ids)
});
$('#id_use_default_auth').click(function(){
if ($(this).is(':checked')){
$('#admin_account').css('display', 'block')
}
else {
$('#admin_account').css('display', 'none')
}
})
});
function move_left(from, to) {
$("#"+from+" option").each(function(){
if ( $(this).prop("selected") == true ) {
$("#"+to).append(this);
$(this).attr("selected",'false');
}
$(this).attr("selected",'true');
});
}
function move_right(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>
{% endblock content %}
</body>
</html>

View File

@@ -0,0 +1,7 @@
<div class="col-md-12 column">
<div class="alert alert-success alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4>
</h4> <strong>Nice!</strong> excel文件已生成请点击 <a href="/static/files/excels/{{ file_name }}" target="_blank" class="alert-link">下载</a>
</div>
</div>

View File

@@ -41,7 +41,7 @@
<div class="col-sm-2">
<label>
<select name="group" class="form-control m-b" onchange="change_info()">
<option value="all">主机组</option>
<option value="">主机组</option>
{% for asset_group in asset_group_all %}
{% ifequal asset_group.name group_name %}
<option value="{{ asset_group.name }}" selected> {{ asset_group.name }} </option>
@@ -55,9 +55,9 @@
<div class="col-sm-2">
<label>
<select name="server_type" class="form-control m-b" onchange="change_info()">
<select name="asset_type" class="form-control m-b" onchange="change_info()">
<option value="">所有类型</option>
{% for type in asset_type %}
{% for type in asset_types %}
{% ifequal type.0|int2str asset_type %}
<option value="{{ type.0 }}" selected> {{ type.1 }}</option>
{% else %}
@@ -71,35 +71,37 @@
<label>
<select name="status" class="form-control m-b" onchange="change_info()">
<option value="">状态</option>
{% for status in asset_status %}
{% ifequal status.0|int2str status %}
<option value="{{ status.0 }}" selected> {{ status.1 }}</option>
{% for s in asset_status %}
{% ifequal s.0|int2str status %}
<option value="{{ s.0 }}" selected> {{ s.1 }}</option>
{% else %}
<option value="{{ status.0 }}"> {{ status.1 }}</option>
<option value="{{ s.0 }}"> {{ s.1 }}</option>
{% endifequal %}
{% endfor %}
</select>
</label>
</div>
<div>
<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 type="submit" class="btn btn-sm btn-primary">
- 搜索 -
</button>
</div>
<div class="col-sm-4">
<div class="input-group">
<input type="text" class="form-control m-b" id="search_input" name="keyword" value="{{ keyword }}" placeholder="Search">
<input type="text" style="display: none">
<div class="input-group-btn">
<button id='search_btn' href="/jasset/asset_list/?search=true" type="button" class="btn btn-xm btn-primary search-btn" onclick="change_info()">
- 搜索 -
</button>
<button type="button" href="/jasset/asset_list/?export=true" name="export" class="btn btn-xm btn-success search-btn-excel" onclick="return false">
- 导出 -
</button>
</div>
</form>
</div>
</div>
<div id="export"></div>
<table class="table table-striped table-bordered table-hover " id="editable" name="editable">
<thead>
<tr>
<th class="text-center">
<input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('contents_form')">
<input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('asset_form')">
</th>
<th class="text-center" name="ip"> IP地址 </th>
<th class="text-center"> 主机名 </th>
@@ -119,7 +121,7 @@
<td class="text-center"> {{ asset.ip }} </td>
<td class="text-center"> {{ asset.hostname }} </td>
<td class="text-center"> {{ asset.idc.name }} </td>
<td class="text-center">{{ asset.port }}</td>
<td class="text-center">{{ asset.group.all|group_str2 }}</td>
<td class="text-center">{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}</td>
<td class="text-center"> {{ asset.use_default_auth|bool2str }} </td>
<td class="text-center" data-editable='false'>
@@ -136,12 +138,12 @@
<div class="row">
<div class="col-sm-6">
<input type="button" id="asset_del" class="btn btn-danger btn-sm" name="del_button" value="删除"/>
<input type="button" id="alter_button" class="btn btn-warning btn-sm" name="alter_button" value="修改" onclick="alter('contents_form')" />
<a value="/jasset/asset_edit_batch/" type="button" class="btn btn-sm btn-warning iframe">修改</a>
</div>
{% include 'paginator.html' %}
</div>
</div>
</form>
</form>
</div>
</div>
</div>
</div>
@@ -178,23 +180,41 @@
})
});
function alter(form) {
selectData = GetTableDataBox();
console.log(selectData[0])
if (selectData[1] != 0) {
$.ajax({
type: "post",
url: "/jasset/host_edit/batch/",
data: {"editable": selectData[0], "len_table": selectData[1]},
success: function (data) {
alert("修改成功");
window.open("/jasset/host_list/", "_self");
error: window.open("/jasset/host_list/", "_self");
$(".iframe").on('click', function(){
var ids = getIDall();
if (ids == ''){
alert("请至少选择一行!");
return false;
}
var url= $(this).attr("value") + '?id=' + ids;
index = $.layer({
type: 2,
title: 'JumpServer - 批量修改主机',
maxmin: true,
shift: 'top',
border: [2, 0.3, '#1AB394'],
shade: [0.5, '#000000'],
shadeClose: true,
area : ['800px' , '600px'],
iframe: {src: url},
close: function(){
location.replace(location.href);
}
});
}
}
});
$('.search-btn-excel').unbind('click').bind('click',function(){
var url= $(this).attr("href");
console.log(url);
$.ajax({
type: "GET",
url: url,
data: $("#asset_form").serialize(),
success: function (data) {
$("#export").html(data);
}
});
});
$('#asset_del').click(function () {
var asset_id_all = getIDall();
@@ -218,13 +238,12 @@
function change_info(){
var args = $("#asset_form").serialize();
window.location = "/jasset/asset_search/?" + args
window.location = "/jasset/asset_list/?" + args
}
$("#search_input").keydown(function(e){
if(e.keyCode==13){
host_search()
change_info()
}
});
@@ -234,7 +253,6 @@
$.ajax({
type: "GET",
url: url,
// data: $("#search_form").serialize(),
success: function (data) {
$("#j_group_" + id).html(data);