Merge branches 'master' and 'wangyong' of gitcafe.com:ibuler/jumpserver

Conflicts:
	docs/AddUserAsset.py
pull/6/head
guanghongwei 2015-03-07 17:39:10 +08:00
commit c9928fc1f9
12 changed files with 156 additions and 57 deletions

View File

@ -108,11 +108,12 @@ def test_add_log():
if __name__ == '__main__':
#test_add_dept()
#test_add_group()
#test_add_user()
#test_add_idc()
#test_add_asset_group()
test_add_asset()
test_add_dept()
test_add_group()
test_add_user()
test_add_idc()
test_add_asset_group()
test_add_asset()
test_add_log()

View File

@ -13,9 +13,9 @@ urlpatterns = patterns('',
url(r'^idc_list/$', list_idc),
url(r'^idc_detail/$', detail_idc),
url(r'^idc_del/(\d+)/$', del_idc),
url(r'^group_add/$', add_group),
url(r'^jgroup_add/$', add_group),
url(r'^group_edit/$', edit_group),
url(r'^group_list/$', list_group),
url(r'^jgroup_list/$', list_group),
url(r'^group_detail/$', detail_group),
url(r'^group_del_host/(\w+)/$', group_del_host),
url(r'^group_del/(\d+)/$', group_del),

View File

@ -10,6 +10,7 @@ from juser.models import UserGroup
from connect import PyCrypt, KEY
from jlog.models import Log
from jumpserver.views import jasset_group_add, jasset_host_edit, pages
from jumpserver.api import asset_perm_api
cryptor = PyCrypt(KEY)
@ -143,7 +144,7 @@ def list_host(request):
header_title, path1, path2 = u'查看主机', u'资产管理', u'查看主机'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
posts = Asset.objects.all().order_by('ip')
contact_list, p, contacts, page_range, current_page = pages(posts, request)
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
return render_to_response('jasset/host_list.html', locals(), context_instance=RequestContext(request))
@ -223,6 +224,7 @@ def jlist_ip(request, offset):
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
post = contact_list = Asset.objects.get(ip=str(offset))
log = Log.objects.filter(host=str(offset))
user_permed_list = asset_perm_api(Asset.objects.get(ip=str(offset)))
return render_to_response('jasset/jlist_ip.html', locals(), context_instance=RequestContext(request))
@ -244,6 +246,8 @@ def add_idc(request):
def list_idc(request):
header_title, path1, path2 = u'查看IDC', u'资产管理', u'查看IDC'
posts = IDC.objects.all().order_by('id')
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
print contact_list, p, contacts, page_range, current_page, show_first, show_end
return render_to_response('jasset/idc_list.html', locals(), context_instance=RequestContext(request))
@ -277,6 +281,8 @@ def add_group(request):
def list_group(request):
header_title, path1, path2 = u'查看主机组', u'资产管理', u'查看主机组'
posts = BisGroup.objects.filter(type='A').order_by('id')
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
return render_to_response('jasset/group_list.html', locals(), context_instance=RequestContext(request))
@ -310,7 +316,7 @@ def detail_group(request):
group_name = BisGroup.objects.get(id=group_id).name
b = BisGroup.objects.get(id=group_id)
posts = Asset.objects.filter(bis_group=b).order_by('ip')
contact_list, p, contacts, page_range, current_page = pages(posts, request)
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
return render_to_response('jasset/group_detail.html', locals(), context_instance=RequestContext(request))
@ -322,7 +328,7 @@ def detail_idc(request):
idc_name = IDC.objects.get(id=idc_id).name
b = IDC.objects.get(id=idc_id)
posts = Asset.objects.filter(idc=b).order_by('ip')
contact_list, p, contacts, page_range, current_page = pages(posts, request)
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
return render_to_response('jasset/idc_detail.html', locals(), context_instance=RequestContext(request))
@ -359,7 +365,7 @@ def host_search(request):
posts = Asset.objects.filter(Q(ip__contains=keyword) | Q(idc__name__contains=keyword) |
Q(bis_group__name__contains=keyword) | Q(
comment__contains=keyword)).distinct().order_by('ip')
contact_list, p, contacts, page_range, current_page = pages(posts, request)
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
return render_to_response('jasset/host_search.html', locals(), context_instance=RequestContext(request))

View File

@ -8,7 +8,7 @@ password = mysql234
database = jumpserver
[ldap]
ldap_enable = 1
ldap_enable = 0
host_url = ldap://127.0.0.1:389
base_dn = dc=jumpserver, dc=org
root_dn = cn=admin,dc=jumpserver,dc=org

View File

@ -166,7 +166,7 @@ def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_com
def pages(posts, r):
"""分页公用函数"""
contact_list = posts
p = paginator = Paginator(contact_list, 20)
p = paginator = Paginator(contact_list, 10)
try:
current_page = int(r.GET.get('page', '1'))
except ValueError:
@ -179,7 +179,16 @@ def pages(posts, r):
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return contact_list, p, contacts, page_range, current_page
if current_page >= 5:
show_first = 1
else:
show_first = 0
if current_page <= (len(p.page_range) - 3):
show_end = 1
else:
show_end = 0
return contact_list, p, contacts, page_range, current_page, show_first, show_end
def login(request):

View File

@ -4,13 +4,6 @@
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="panel-options">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#tab-1" class="text-center"><i class="fa fa-laptop"></i> {{ path2 }} </a></li>
<li><a href="/jasset/idc_add" class="text-center"><i class="fa fa-bar-chart-o"></i> 添加IDC </a></li>
</ul>
</div>
<div class="ibox float-e-margins">
<div id="ibox-content" class="ibox-title">
<h5> 填写主机组基本信息 </h5>

View File

@ -5,22 +5,17 @@
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="panel-options">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#tab-1" class="text-center"><i class="fa fa-laptop"></i> 主机组列表 </a></li>
<li><a href="/jasset/idc_list" class="text-center"><i class="fa fa-bar-chart-o"></i> IDC列表 </a></li>
</ul>
</div>
<div class="ibox float-e-margins">
<div class="ibox-content">
<div class="">
<a target="_blank" href="/jasset/group_add" class="btn btn-sm btn-primary "> 添加 </a>
<a target="_blank" href="/jasset/jgroup_add" class="btn btn-sm btn-primary "> 添加主机组 </a>
</div>
<form id="contents_form" name="contents_form">
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<th class="text-center"> ID </th>
<th class="text-center"><input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('contents_form')"></th>
<th class="text-center"> 主机组名 </th>
<th class="text-center"> 主机数量 </th>
<th class="text-center"> 备注 </th>
@ -28,9 +23,9 @@
</tr>
</thead>
<tbody>
{% for post in posts %}
{% for post in contacts.object_list %}
<tr class="gradeX">
<td class="text-center"> {{ post.id }} </td>
<td class="text-center" name="j_id" value="{{ post.id }}" data-editable='false'><input name="id" value="{{ post.id }}" type="checkbox" class="i-checks"></td>
<td class="text-center"> {{ post.name }} </td>
<td class="text-center"> <a href="/jasset/group_detail/?id={{ post.id }}">{{ post.asset_set.count }}</a> </td>
<td class="text-center"> {{ post.comment }} </td>
@ -43,6 +38,51 @@
{% endfor %}
</tbody>
</table>
<div class="row">
<div class="col-sm-6">
<input type="button" id="del_button" class="btn btn-danger btn-sm" name="del_button" value="删除" onclick="del('contents_form')" />
<input type="button" id="alter_button" class="btn btn-warning btn-sm" name="alter_button" value="修改" onclick="alter('contents_form')" />
</div>
<div class="col-sm-6">
<div class="dataTables_paginate paging_simple_numbers" id="editable_paginate">
<ul class="pagination" style="margin-top: 0; float: right">
{% if contacts.has_previous %}
<li class="paginate_button previous" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="?page={{ contacts.previous_page_number }}">Previous</a>
</li>
{% else %}
<li class="paginate_button previous disabled" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="#">Previous</a>
</li>
{% endif %}
{% ifequal show_first 1 %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page=1" title="第1页">1...</a></li>
{% endifequal %}
{% for page in page_range %}
{% ifequal current_page page %}
<li class="paginate_button active" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% else %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% endifequal %}
{% endfor %}
{% ifequal show_end 1 %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ p.num_pages }}" title="第{{ page }}页">...{{ p.num_pages }}</a></li>
{% endifequal %}
{% if contacts.has_next %}
<li class="paginate_button next" aria-controls="editable" tabindex="0" id="editable_next">
<a href="?page={{ contacts.next_page_number }}">Next</a>
</li>
{% else %}
<li class="paginate_button next disabled" aria-controls="editable" tabindex="0" id="editable_next">
<a href="#">Next</a>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
</form>
</div>
</div>
</div>

View File

@ -8,7 +8,7 @@
<div class="col-lg-12">
<div class="ibox float-e-margins" id="all">
<div class="ibox-title">
<h5> 主机详细信息列表 </h5>
<h5> 主机详细信息列表</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
@ -99,6 +99,9 @@
<a href="#">Previous</a>
</li>
{% endif %}
{% ifequal show_first 1 %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page=1" title="第1页">1...</a></li>
{% endifequal %}
{% for page in page_range %}
{% ifequal current_page page %}
<li class="paginate_button active" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
@ -106,7 +109,9 @@
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% endifequal %}
{% endfor %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ p.num_pages }}" title="第{{ page }}页">...{{ p.num_pages }}</a></li>
{% ifequal show_end 1 %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ p.num_pages }}" title="第{{ page }}页">...{{ p.num_pages }}</a></li>
{% endifequal %}
{% if contacts.has_next %}
<li class="paginate_button next" aria-controls="editable" tabindex="0" id="editable_next">
<a href="?page={{ contacts.next_page_number }}">Next</a>

View File

@ -4,12 +4,6 @@
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="panel-options">
<ul class="nav nav-tabs">
<li><a href="/jasset/group_add" class="text-center"><i class="fa fa-laptop"></i> 添加主机组 </a></li>
<li class="active"><a href="/jasset/idc_add" class="text-center"><i class="fa fa-bar-chart-o"></i> 添加IDC </a></li>
</ul>
</div>
<div class="ibox float-e-margins">
<div id="ibox-content" class="ibox-title">
<h5> 填写IDC基本信息 </h5>

View File

@ -5,22 +5,16 @@
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-10">
<div class="panel-options">
<ul class="nav nav-tabs">
<li><a href="/jasset/group_list" class="text-center"><i class="fa fa-laptop"></i> 主机组列表 </a></li>
<li class="active"><a href="/jasset/idc_list" class="text-center"><i class="fa fa-bar-chart-o"></i> IDC列表 </a></li>
</ul>
</div>
<div class="ibox float-e-margins">
<div class="ibox-content">
<div class="">
<a target="_blank" href="/jasset/idc_add" class="btn btn-sm btn-primary "> 添加 </a>
<a target="_blank" href="/jasset/idc_add" class="btn btn-sm btn-primary "> 添加IDC </a>
</div>
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<th class="text-center"> ID </th>
<th class="text-center"><input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('contents_form')"></th>
<th class="text-center"> 机房名 </th>
<th class="text-center"> 主机数量 </th>
<th class="text-center"> 备注 </th>
@ -28,9 +22,9 @@
</tr>
</thead>
<tbody>
{% for post in posts %}
{% for post in contacts.object_list %}
<tr class="gradeX">
<td class="text-center"> {{ post.id }} </td>
<td class="text-center" name="j_id" value="{{ post.id }}" data-editable='false'><input name="id" value="{{ post.id }}" type="checkbox" class="i-checks"></td>
<td class="text-center"> {{ post.name }} </td>
<td class="text-center"> <a href="/jasset/idc_detail/?id={{ post.id }}">{{ post.asset_set.count }}</a> </td>
<td class="text-center"> {{ post.comment }} </td>
@ -42,6 +36,50 @@
{% endfor %}
</tbody>
</table>
<div class="row">
<div class="col-sm-6">
<input type="button" id="del_button" class="btn btn-danger btn-sm" name="del_button" value="删除" onclick="del('contents_form')" />
<input type="button" id="alter_button" class="btn btn-warning btn-sm" name="alter_button" value="修改" onclick="alter('contents_form')" />
</div>
<div class="col-sm-6">
<div class="dataTables_paginate paging_simple_numbers" id="editable_paginate">
<ul class="pagination" style="margin-top: 0; float: right">
{% if contacts.has_previous %}
<li class="paginate_button previous" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="?page={{ contacts.previous_page_number }}">Previous</a>
</li>
{% else %}
<li class="paginate_button previous disabled" aria-controls="editable" tabindex="0" id="editable_previous">
<a href="#">Previous</a>
</li>
{% endif %}
{% ifequal show_first 1 %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page=1" title="第1页">1...</a></li>
{% endifequal %}
{% for page in page_range %}
{% ifequal current_page page %}
<li class="paginate_button active" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% else %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% endifequal %}
{% endfor %}
{% ifequal show_end 1 %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?page={{ p.num_pages }}" title="第{{ page }}页">...{{ p.num_pages }}</a></li>
{% endifequal %}
{% if contacts.has_next %}
<li class="paginate_button next" aria-controls="editable" tabindex="0" id="editable_next">
<a href="?page={{ contacts.next_page_number }}">Next</a>
</li>
{% else %}
<li class="paginate_button next disabled" aria-controls="editable" tabindex="0" id="editable_next">
<a href="#">Next</a>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@ -40,6 +40,23 @@
</tr>
</tbody>
</table>
<h3 class="text-center">{{ offset }}主机用户权限详情</h3>
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<th> 用户名 </th>
</tr>
</thead>
<tbody>
<tr class="gradeX">
<td>
{% for user in user_permed_list %}
<a class="btn"> {{ user.name }} </a>
{% endfor %}
</td>
</tr>
</tbody>
</table>
<!--<a> 是否 激活: {{ post.is_active }}</a>-->
<h3 class="text-center">最近一周登录详情</h3>
<table class="table table-striped table-bordered table-hover ">
@ -49,7 +66,6 @@
<th class="text-center"> 登录时间 </th>
<th class="text-center"> 退出时间 </th>
<th class="text-center"> 详情 </th>
<th class="text-center"> 有权限用户</th>
</tr>
</thead>
<tbody>
@ -61,11 +77,6 @@
<td class="text-center">
<a class="log_command text-success" href="/jlog/history/?id={{ l.id }}">命令统计</a>
</td>
<td>
{% for user in user_permed_list %}
{{ user.name }}
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>

View File

@ -27,8 +27,10 @@
<ul class="nav nav-second-level">
<li id="host_add"><a href="/jasset/host_add/">添加资产</a></li>
<li id="host_list"><a href="/jasset/host_list/">查看资产&nbsp&nbsp</span><span class="label label-info pull-right">16/18</span></a></li>
<li id="group_add"><a href="/jasset/group_add/">添加IDC|主机组</a></li>
<li id="group_list"><a href="/jasset/group_list/">查看IDC|主机组</a></li>
<li id="jgroup_add"><a href="/jasset/jgroup_add/">添加主机组</a></li>
<li id="jgroup_list"><a href="/jasset/jgroup_list/">查看主机组</a></li>
<li id="idc_add"><a href="/jasset/idc_add/">添加IDC</a></li>
<li id="idc_list"><a href="/jasset/idc_list/">查看IDC</a></li>
</ul>
</li>
<li id="jperm">