资产管理页面基本完成.

pull/6/head
halcyon 2015-01-11 19:27:21 +08:00
parent 94beae5282
commit acf508f074
11 changed files with 441 additions and 72 deletions

View File

@ -4,8 +4,10 @@ from jasset.views import *
urlpatterns = patterns('',
url(r'^$', index),
url(r'jadd', jadd),
url(r'jlist', jlist),
url(r'jadd_idc', jadd_idc),
url(r'jlist_idc', jlist_idc),
url(r'host_add', jadd_host),
url(r'host_list', jlist_host),
url(r'idc_add', jadd_idc),
url(r'idc_list', jlist_idc),
url(r'group_add', jadd_group),
url(r'group_list', jlist_group),
)

View File

@ -5,9 +5,9 @@ from django.http import HttpResponse
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.paginator import Paginator, EmptyPage
from models import IDC, Asset, Group
from models import IDC, Asset, BisGroup
from connect import PyCrypt, KEY
@ -15,14 +15,12 @@ def index(request):
return render_to_response('jasset/jasset.html', )
def jadd(request):
global j_passwd
def jadd_host(request):
header_title, path1, path2 = '添加主机 | Add Host', '资产管理', '添加主机'
groups = []
cryptor = PyCrypt(KEY)
eidc = IDC.objects.all()
egroup = Group.objects.all()
is_actived = {'active': 1, 'no_active': 0}
login_typed = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'}
egroup = BisGroup.objects.all()
if request.method == 'POST':
j_ip = request.POST.get('j_ip')
@ -32,27 +30,26 @@ def jadd(request):
j_group = request.POST.getlist('j_group')
j_active = request.POST.get('j_active')
j_comment = request.POST.get('j_comment')
j_idc = IDC.objects.get(name=j_idc)
for group in j_group:
c = BisGroup.objects.get(name=group)
groups.append(c)
if Asset.objects.filter(ip=str(j_ip)):
emg = u'该IP已存在!'
return render_to_response('jasset/jadd.html', locals(), context_instance=RequestContext(request))
if j_type == 'MAP':
j_user = request.POST.get('j_user')
j_password = cryptor.encrypt(request.POST.get('j_password'))
j_root = request.POST.get('j_root')
j_passwd = cryptor.encrypt(request.POST.get('j_passwd'))
j_idc = IDC.objects.get(name=j_idc)
for group in j_group:
c = Group.objects.get(name=group)
groups.append(c)
if Asset.objects.filter(ip=str(j_ip)):
emg = u'该IP已存在!'
return render_to_response('jasset/jadd.html', {'emg': emg, 'j_ip': j_ip})
elif j_type == 'MAP':
a = Asset(ip=j_ip,
port=j_port,
login_type=login_typed[j_type],
login_type=j_type,
idc=j_idc,
is_active=int(is_actived[j_active]),
is_active=int(j_active),
comment=j_comment,
username_common=j_user,
password_common=j_password,
@ -61,24 +58,19 @@ def jadd(request):
else:
a = Asset(ip=j_ip,
port=j_port,
login_type=login_typed[j_type],
login_type=j_type,
idc=j_idc,
is_active=int(is_actived[j_active]),
is_active=int(j_active),
comment=j_comment)
a.save()
a.group = groups
a.bis_group = groups
a.save()
return render_to_response('jasset/jadd.html',
{'header_title': u'添加主机 | Add Host',
'path1': '资产管理',
'path2': '添加主机',
'eidc': eidc,
'egroup': egroup, }
)
return render_to_response('jasset/jadd.html', locals(), context_instance=RequestContext(request))
def jlist(request):
def jlist_host(request):
header_title, path1, path2 = '查看主机 | List Host', '资产管理', '查看主机'
posts = contact_list = Asset.objects.all().order_by('ip')
print posts
paginator = Paginator(contact_list, 5)
@ -92,19 +84,49 @@ def jlist(request):
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return render_to_response('jasset/jlist.html',
{"contacts": contacts,
'p': paginator,
'posts': posts,
'header_title': u'查看主机 | List Host',
'path1': '资产管理',
'path2': '查看主机', },
context_instance=RequestContext(request))
return render_to_response('jasset/jlist.html', locals(), context_instance=RequestContext(request))
def jadd_idc(request):
pass
header_title, path1, path2 = '添加IDC | Add IDC', '资产管理', '添加IDC'
if request.method == 'POST':
j_idc = request.POST.get('j_idc')
j_comment = request.POST.get('j_comment')
print j_idc,j_comment
if IDC.objects.filter(name=j_idc):
emg = u'该IDC已存在!'
return render_to_response('jasset/jadd_idc.html',
{'emg': emg, 'j_idc': j_idc, 'j_comment': j_comment,},
context_instance=RequestContext(request))
else:
IDC.objects.create(name=j_idc, comment=j_comment)
return render_to_response('jasset/jadd_idc.html', locals(), context_instance=RequestContext(request))
def jlist_idc(request):
pass
header_title, path1, path2 = '查看IDC | List Host', '资产管理', '查看IDC'
posts = IDC.objects.all().order_by('id')
return render_to_response('jasset/jlist_idc.html', locals(), context_instance=RequestContext(request))
def jadd_group(request):
header_title, path1, path2 = '添加业务组 | Add Group', '资产管理', '添加业务组'
if request.method == 'POST':
j_group = request.POST.get('j_group')
j_comment = request.POST.get('j_comment')
if BisGroup.objects.filter(name=j_group):
emg = u'该业务组已存在!'
return render_to_response('jasset/jadd_group.html', locals(), context_instance=RequestContext(request))
else:
BisGroup.objects.create(name=j_group, comment=j_comment)
return render_to_response('jasset/jadd_group.html', locals(), context_instance=RequestContext(request))
def jlist_group(request):
header_title, path1, path2 = '添加业务组 | Add Group', '资产管理', '查看业务组'
posts = BisGroup.objects.all().order_by('id')
return render_to_response('jasset/jlist_group.html', locals(), context_instance=RequestContext(request))

View File

@ -8,10 +8,10 @@ password = mysql234
database = jumpserver
[ldap]
host_url = ldap://127.0.0.1:389
base_dn = dc=jumpserver,dc=org
root_dn = cn=admin,dc=jumpserver,dc=org
root_pw = secret234
host_url = ldap://192.168.8.60:389
base_dn = dc=fengxing,dc=org
root_dn = cn=admin,dc=fengxing,dc=org
root_pw = 123456
[web]
key = 88aaaf7ffe3c6c04

View File

@ -5,7 +5,13 @@
<div class="row">
<div class="col-lg-10">
<div class="ibox float-e-margins">
<div class="ibox-title">
<div class="text-center">
<span>请选择添加内容: </span>
<a href="#" class="btn btn-xs btn-primary" id="lightVersion">添加主机</a>
<a href="#" class="btn btn-xs btn-primary" id="darkVersion">添加IDC</a>
<a href="#" class="btn btn-xs btn-primary" id="leftVersion">添加业务组</a>
</div>
<div id="ibox-content" class="ibox-title">
<h5> 填写主机基本信息 </h5>
<div class="ibox-tools">
<a class="collapse-link">
@ -37,16 +43,16 @@
<div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-2 control-label"> 端口号 </label>
<div class="col-sm-8"><input type="text" value="{{ s_port }}" placeholder="22" name="j_port" class="form-control"></div>
<div class="col-sm-8"><input type="text" value="{{ j_port }}" placeholder="22" name="j_port" class="form-control"></div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-2 control-label"> 登录方式 </label>
<div class="col-sm-8">
<div class="radio i-checks"><label> <input type="radio" checked="" value="LDAP" name="j_type" onclick="show(this)"> <i> LDAP </i></label></div>
<div class="radio i-checks"><label> <input type="radio" value="SSH_KEY" name="j_type" onclick="show(this)"> <i> SSH_KEY </i></label></div>
<div class="radio i-checks"><label> <input type="radio" value="PASSWORD" name="j_type" onclick="show(this)"> <i> PASSWORD </i></label></div>
<div class="radio i-checks"><label> <input type="radio" value="MAP" name="j_type" onclick="show(this)"> <i> MAP </i></label></div>
<div class="radio i-checks"><label> <input type="radio" checked="" value="L" name="j_type" onclick="show(this)"> <i> LDAP </i></label></div>
<div class="radio i-checks"><label> <input type="radio" value="S" name="j_type" onclick="show(this)"> <i> SSH_KEY </i></label></div>
<div class="radio i-checks"><label> <input type="radio" value="P" name="j_type" onclick="show(this)"> <i> PASSWORD </i></label></div>
<div class="radio i-checks"><label> <input type="radio" value="M" name="j_type" onclick="show(this)"> <i> MAP </i></label></div>
</div>
<div name="a1" id=a1 style="display:none;">
@ -98,14 +104,14 @@
<div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-2 control-label"> 是否激活 </label>
<div class="col-sm-8">
<div class="radio i-checks"><label> <input type="radio" checked="" value="active" name="j_active"> <i> 激活 </i></label></div>
<div class="radio i-checks"><label> <input type="radio" value="no_active" name="j_active"> <i> 禁用 </i></label></div>
<div class="radio i-checks"><label> <input type="radio" checked="" value="1" name="j_active"> <i> 激活 </i></label></div>
<div class="radio i-checks"><label> <input type="radio" value="0" name="j_active"> <i> 禁用 </i></label></div>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-2 control-label"> 备注 </label>
<div class="col-sm-8"><input type="text" placeholder="hadoop01" name="j_comment" class="form-control"></div>
<div class="col-sm-8"><input type="text" value="{{ j_comment }}" placeholder="hadoop01" name="j_comment" class="form-control"></div>
</div>
<div class="hr-line-dashed"></div>
@ -123,7 +129,15 @@
</div>
<!-- Peity -->
<script src="static/js/plugins/peity/jquery.peity.min.js"></script>
<!-- Custom and plugin javascript -->
<script src="static/js/inspinia.js"></script>
<script src="static/js/plugins/pace/pace.min.js"></script>
<!-- Peity -->
<script src="static/js/demo/peity-demo.js"></script>
<script>
var showFlag={};
@ -135,7 +149,6 @@ var showFlag={};
else{
document.getElementById("a1").style.display="none";
}};
</script>
{% endblock %}

View File

@ -0,0 +1,106 @@
{% extends 'base.html' %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<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">
{% if emg %}
<div class="alert alert-warning text-center">{{ emg }}</div>
{% endif %}
<form method="post" class="form-horizontal">
<div class="form-group"><label class="col-sm-2 control-label"> 业务组名 </label>
<div class="col-sm-8"><input type="text" value="{{ j_ip }}" placeholder="网站" name="j_group" class="form-control"></div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-2 control-label"> 备注 </label>
<div class="col-sm-8"><input type="text" value="{{ s_port }}" placeholder=包括web组所有主机 name="j_comment" class="form-control"></div>
</div>
<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" type="submit"> 提交 </button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Peity -->
<script src="static/js/plugins/peity/jquery.peity.min.js"></script>
<!-- Custom and plugin javascript -->
<script src="static/js/inspinia.js"></script>
<script src="static/js/plugins/pace/pace.min.js"></script>
<!-- Peity -->
<script src="static/js/demo/peity-demo.js"></script>
<script>
var showFlag={};
function show(o){
showFlag[o.name]=o.value;
if(showFlag.j_type=="MAP"){
document.getElementById("a1").style.display="";
}
else{
document.getElementById("a1").style.display="none";
}};
$(document).ready(function(){
// Local script for demo purpose only
$('#lightVersion').click(function(event) {
event.preventDefault()
$('#ibox-content').removeClass('ibox-content');
$('#vertical-timeline').removeClass('dark-timeline');
$('#vertical-timeline').addClass('light-timeline');
});
$('#darkVersion').click(function(event) {
event.preventDefault()
$('#ibox-content').addClass('ibox-content');
$('#vertical-timeline').removeClass('light-timeline');
$('#vertical-timeline').addClass('dark-timeline');
});
$('#leftVersion').click(function(event) {
event.preventDefault()
$('#vertical-timeline').toggleClass('center-orientation');
});
});
</script>
{% endblock %}

View File

@ -0,0 +1,106 @@
{% extends 'base.html' %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="ibox float-e-margins">
<div id="ibox-content" class="ibox-title">
<h5> 填写IDC基本信息 </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">
{% if emg %}
<div class="alert alert-warning text-center">{{ emg }}</div>
{% endif %}
<form method="post" class="form-horizontal">
<div class="form-group"><label class="col-sm-2 control-label"> IDC名 </label>
<div class="col-sm-8"><input type="text" value="{{ j_ip }}" placeholder="北京联通" name="j_idc" class="form-control"></div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group"><label class="col-sm-2 control-label"> 备注 </label>
<div class="col-sm-8"><input type="text" value="{{ s_port }}" placeholder="核心联通机房" name="j_comment" class="form-control"></div>
</div>
<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" type="submit"> 提交 </button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Peity -->
<script src="static/js/plugins/peity/jquery.peity.min.js"></script>
<!-- Custom and plugin javascript -->
<script src="static/js/inspinia.js"></script>
<script src="static/js/plugins/pace/pace.min.js"></script>
<!-- Peity -->
<script src="static/js/demo/peity-demo.js"></script>
<script>
var showFlag={};
function show(o){
showFlag[o.name]=o.value;
if(showFlag.j_type=="MAP"){
document.getElementById("a1").style.display="";
}
else{
document.getElementById("a1").style.display="none";
}};
$(document).ready(function(){
// Local script for demo purpose only
$('#lightVersion').click(function(event) {
event.preventDefault()
$('#ibox-content').removeClass('ibox-content');
$('#vertical-timeline').removeClass('dark-timeline');
$('#vertical-timeline').addClass('light-timeline');
});
$('#darkVersion').click(function(event) {
event.preventDefault()
$('#ibox-content').addClass('ibox-content');
$('#vertical-timeline').removeClass('light-timeline');
$('#vertical-timeline').addClass('dark-timeline');
});
$('#leftVersion').click(function(event) {
event.preventDefault()
$('#vertical-timeline').toggleClass('center-orientation');
});
});
</script>
{% endblock %}

View File

@ -52,7 +52,7 @@
<td> {{ post.login_type}} </td>
<td class="center"> {{ post.idc.name }} </td>
<td class="center">
{% for group in post.group.all %}
{% for group in post.bis_group.all %}
{{ group }}
{% endfor %}
</td>

View File

@ -0,0 +1,59 @@
{% extends 'base.html' %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<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> IDC详细信息列表 </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="">
<a onclick="fnClickAddRow();" href="javascript:void(0);" class="btn btn-primary "> 添加 </a>
</div>
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<th> ID </th>
<th> 机房名 </th>
<th> 备注 </th>
</tr>
</thead>
<tbody>
{% for post in posts %}
<tr class="gradeX">
<td> {{ post.id }} </td>
<td> {{ post.name }} </td>
<td> {{ post.comment }} </td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -0,0 +1,59 @@
{% extends 'base.html' %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<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> IDC详细信息列表 </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="">
<a onclick="fnClickAddRow();" href="javascript:void(0);" class="btn btn-primary "> 添加 </a>
</div>
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<th> ID </th>
<th> 机房名 </th>
<th> 备注 </th>
</tr>
</thead>
<tbody>
{% for post in posts %}
<tr class="gradeX">
<td> {{ post.id }} </td>
<td> {{ post.name }} </td>
<td> {{ post.comment }} </td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -23,10 +23,12 @@
<li>
<a href="mailbox.html"><i class="fa fa-cube"></i> <span class="nav-label">资产管理</span><span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li><a href="/jasset/jlist/">查看资产</a></li>
<li><a href="/jasset/jadd/">添加资产</a></li>
<li><a href="/idc/showlist/">查看机房</a></li>
<li><a href="/idc/add/">添加机房</a></li>
<li><a href="/jasset/host_list/">查看资产</a></li>
<li><a href="/jasset/host_add/">添加资产</a></li>
<li><a href="/jasset/idc_list/">查看机房</a></li>
<li><a href="/jasset/idc_add/">添加机房</a></li>
<li><a href="/jasset/group_list/">查看业务组</a></li>
<li><a href="/jasset/group_add/">添加业务组</a></li>
</ul>
</li>
<li>

View File

@ -17,12 +17,12 @@
<!-- Peity -->
<script src="/static/js/demo/peity-demo.js"></script>
<script>
$(document).ready(function(){
$('.i-checks').iCheck({
checkboxClass: 'icheckbox_square-green',
radioClass: 'iradio_square-green',
});
});
<!--<script>-->
<!--$(document).ready(function(){-->
<!--$('.i-checks').iCheck({-->
<!--checkboxClass: 'icheckbox_square-green',-->
<!--radioClass: 'iradio_square-green',-->
<!--});-->
<!--});-->
</script>
<!--</script>-->