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

Conflicts:
	static/js/base.js
	templates/head_script.html
pull/6/head
guanghongwei 10 years ago
commit 121b76284a

@ -13,8 +13,10 @@ urlpatterns = patterns('',
url(r'^idc_detail/(\d+)$', idc_detail),
url(r'^idc_del/(\d+)/$', idc_del),
url(r'^group_add/$', jadd_group),
url(r'^group_edit/(\d+)/$', group_edit),
url(r'^group_list/$', jlist_group),
url(r'^group_detail/(\d)/$', group_detail),
url(r'^group_detail/(\d+)/$', group_detail),
url(r'^group_del_host/(\w+)/$', group_del_host),
url(r'^group_del/(\d+)/$', group_del),
url(r'^host_del/(\w+)/$', host_del),
url(r'^host_edit/(\d+)$', host_edit),

@ -163,7 +163,6 @@ def jlist_host(request):
def host_del(request, offset):
print offset
if offset == 'multi':
len_list = request.POST.get("len_list")
for i in range(int(len_list)):
@ -197,13 +196,11 @@ def host_edit(request, offset):
j_active = request.POST.get('j_active')
j_comment = request.POST.get('j_comment')
j_idc = IDC.objects.get(name=j_idc)
print j_group
for group in j_group:
c = BisGroup.objects.get(name=group)
groups.append(c)
a = Asset.objects.get(id=int(offset))
if j_type == 'M':
j_user = request.POST.get('j_user')
j_password = cryptor.encrypt(request.POST.get('j_password'))
@ -211,7 +208,7 @@ def host_edit(request, offset):
a.port = j_port
a.login_type = j_type
a.idc = j_idc
a.is_active = j_active
a.is_active = int(j_active)
a.comment = j_comment
a.username = j_user
a.password = j_password
@ -220,7 +217,7 @@ def host_edit(request, offset):
a.port = j_port
a.idc = j_idc
a.login_type = j_type
a.is_active = j_active
a.is_active = int(j_active)
a.comment = j_comment
a.save()
@ -234,7 +231,6 @@ def host_edit(request, offset):
def jlist_ip(request, offset):
header_title, path1, path2 = u'主机详细信息 | Host Detail.', u'资产管理', u'主机详情'
print offset
post = contact_list = Asset.objects.get(ip=str(offset))
return render_to_response('jasset/jlist_ip.html', locals(), context_instance=RequestContext(request))
@ -244,8 +240,6 @@ def jadd_idc(request):
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/idc_add.html', locals(), context_instance=RequestContext(request))
@ -269,16 +263,22 @@ def idc_del(request, offset):
def jadd_group(request):
header_title, path1, path2 = u'添加主机组 | Add Group', u'资产管理', u'添加主机组'
posts = Asset.objects.all()
if request.method == 'POST':
j_group = request.POST.get('j_group')
j_hosts = request.POST.getlist('j_hosts')
j_comment = request.POST.get('j_comment')
if BisGroup.objects.filter(name=j_group):
emg = u'该主机组已存在!'
return render_to_response('jasset/group_add.html', locals(), context_instance=RequestContext(request))
else:
smg = u'主机组%s添加成功' %j_group
BisGroup.objects.create(name=j_group, comment=j_comment, type='A')
group = BisGroup.objects.get(name=j_group)
for host in j_hosts:
g = Asset.objects.get(id=host)
group.asset_set.add(g)
smg = u'主机组%s添加成功' %j_group
return render_to_response('jasset/group_add.html', locals(), context_instance=RequestContext(request))
@ -289,6 +289,28 @@ def jlist_group(request):
return render_to_response('jasset/group_list.html', locals(), context_instance=RequestContext(request))
def group_edit(request, offset):
header_title, path1, path2 = u'编辑主机组 | Edit Group', u'资产管理', u'编辑主机组'
group = BisGroup.objects.get(id=offset)
all = Asset.objects.all()
eposts = contact_list = Asset.objects.filter(bis_group=group).order_by('ip')
posts = [g for g in all if g not in eposts]
if request.method == 'POST':
j_group = request.POST.get('j_group')
j_hosts = request.POST.getlist('j_hosts')
j_comment = request.POST.get('j_comment')
group = BisGroup.objects.get(name=j_group)
group.asset_set.clear()
for host in j_hosts:
g = Asset.objects.get(id=host)
group.asset_set.add(g)
smg = u'主机组%s修改成功' %j_group
return HttpResponseRedirect('/jasset/group_detail/%s' %offset)
return render_to_response('jasset/group_add.html', locals(), context_instance=RequestContext(request))
def group_detail(request, offset):
header_title, path1, path2 = u'主机组详情 | Group Detail', u'资产管理', u'主机组详情'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
@ -327,6 +349,27 @@ def idc_detail(request, offset):
return render_to_response('jasset/idc_detail.html', locals(), context_instance=RequestContext(request))
def group_del_host(request, offset):
if request.method == 'POST':
group_name = request.POST.get('group_name')
print group_name
if offset == 'group':
group = BisGroup.objects.get(name=group_name)
elif offset == 'idc':
group = IDC.objects.get(name=group_name)
len_list = request.POST.get("len_list")
for i in range(int(len_list)):
key = "id_list["+str(i)+"]"
print key
jid = request.POST.get(key)
print jid
g = Asset.objects.get(id=jid)
print g
group.asset_set.remove(g)
print 'ok'
return HttpResponseRedirect('/jasset/%s_detail/%s' %(offset, group.id))
def group_del(request, offset):
BisGroup.objects.filter(id=offset).delete()
return HttpResponseRedirect('/jasset/group_list/')

@ -32,7 +32,6 @@ def jasset_group_add(name, comment, type):
def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment):
print 'ok'
groups = []
is_active = {u'': '1', u'': '2'}
login_types = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'}

@ -1,19 +1,9 @@
<script src="/static/js/jquery-2.1.1.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/base.js"></script>
<script>
{# $(document).ready(function(){#}
{# $('.i-checks').iCheck({#}
{# checkboxClass: 'icheckbox_square-green',#}
{# radioClass: 'iradio_square-green'#}
{# });#}
{# });#}
</script>
<!-- pop windows -->
<script src="/static/js/jquery.colorbox.js"></script>
<!-- validator js -->
<script src="/static/js/validator/jquery.validator.js"></script>

@ -6,7 +6,7 @@
<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 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>
@ -24,7 +24,34 @@
{% endif %}
<form id="assetForm" 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_group }}" placeholder="网站" name="j_group" class="form-control"></div>
<div class="col-sm-8"><input type="text" value="{{ group.name }}" placeholder="网站" name="j_group" class="form-control"></div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="groups" class="col-lg-2 control-label">主机</label>
<div class="col-sm-3">
<select id="groups" size="12" class="form-control m-b" multiple>
{% for post in posts %}
<option value="{{ post.id }}">{{ post.ip }}</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('groups', 'groups_selected')"><i class="fa fa-chevron-right"></i></button>
<button type="button" class="btn btn-white" onclick="move('groups_selected', 'groups')"><i class="fa fa-chevron-left"></i> </button>
</div>
</div>
<div class="col-sm-3">
<div>
<select id="groups_selected" name="j_hosts" class="form-control m-b" size="12" multiple>
{% for post in eposts %}
<option value="{{ post.id }}">{{ post.ip }}</option>
{% endfor %}
</select>
</div>
</div>
</div>
<div class="hr-line-dashed"></div>
@ -36,7 +63,7 @@
<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>
<button class="btn btn-primary" type="submit" onclick="on_submit('groups_selected') "> 提交 </button>
</div>
</div>
</form>
@ -63,6 +90,13 @@
form.submit();
}
});
function on_submit(id){
$('#'+id+' option').each(
function(){
$(this).prop('selected', true)
})
}
</script>
{% endblock %}

@ -42,8 +42,8 @@
<th class="text-center"> 端口号 </th>
<th class="text-center" name="j_type"> 登录方式 </th>
<th class="text-center" name="j_idc"> 所属IDC </th>
<th class="text-center"> 所属业务组 </th>
<th class="text-center"> 是否激活 </th>
<th class="text-center" id="j_group_name" value="{{ group_name }}"> 所属业务组 </th>
<th class="text-center"> 是否激活 </th>
<th class="text-center" name="j_time"> 添加时间 </th>
<th class="text-center" name="j_comment"> 备注 </th>
<th class="text-center"> 操作 </th>
@ -57,7 +57,7 @@
<td class="text-center" name="j_port"> {{ post.port }} </td>
<td class="text-center" name="j_type"> {{ login_types|get_item:post.login_type }} </td>
<td class="text-center" name="j_idc"> {{ post.idc.name }} </td>
<td class="text-center" name="j_group">{% for group in post.bis_group.all %} {{ group }} {% endfor %}</td>
<td class="text-center" name="j_group">{% for group in post.bis_group.all|filter_private %} {{ group }} {% endfor %}</td>
<td class="text-center" name="j_active"> {{ post.is_active|bool2str }} </td>
<td class="text-center"> {{ post.date_added|date:"Y-m-d H:i:s" }} </td>
<td class="text-center" name="j_comment"> {{ post.comment }} </td>
@ -128,6 +128,8 @@
function del(form) {
var checkboxes = document.getElementById(form);
var id_list = {};
var group_name = $('#j_group_name').attr("value");
console.log(group_name);
var j = 0;
for (var i = 0; i < checkboxes.elements.length; i++) {
if (checkboxes.elements[i].type == "checkbox" && checkboxes.elements[i].checked == true && checkboxes.elements[i].value != "checkall") {
@ -135,13 +137,13 @@
j++;
}
}
if (confirm("确定删除")) {
if (confirm("确定从主机组中删除")) {
$.ajax({
type: "POST",
url: "/jasset/host_del/",
data: {"id_list": id_list, "len_list": j},
url: "/jasset/group_del_host/group/",
data: {"id_list": id_list, "len_list": j, "group_name": group_name},
success: function (data) {
window.open("/jasset/host_list/", "_self");
window.open(window.location.pathname, "_self");
}
});
}

@ -36,6 +36,7 @@
<td class="text-center"> {{ post.comment }} </td>
<td class="text-center">
<a href="/jasset/group_detail/{{ post.id }}" class="btn btn-xs btn-info">详情</a>
<a href="/jasset/group_edit/{{ post.id }}" class="btn btn-xs btn-info">编辑</a>
<a href="/jasset/group_del/{{ post.id }}" class="btn btn-xs btn-danger">删除</a>
</td>
</tr>

@ -41,7 +41,7 @@
<th class="text-center" name="j_ip"> IP地址 </th>
<th class="text-center"> 端口号 </th>
<th class="text-center" name="j_type"> 登录方式 </th>
<th class="text-center" name="j_idc"> 所属IDC </th>
<th class="text-center" id="j_group_name" value="{{ idc_name }}"> 所属IDC </th>
<th class="text-center"> 所属业务组 </th>
<th class="text-center"> 是否激活 </th>
<th class="text-center" name="j_time"> 添加时间 </th>
@ -57,7 +57,7 @@
<td class="text-center" name="j_port"> {{ post.port }} </td>
<td class="text-center" name="j_type"> {{ login_types|get_item:post.login_type }} </td>
<td class="text-center" name="j_idc"> {{ post.idc.name }} </td>
<td class="text-center" name="j_group">{% for group in post.bis_group.all %} {{ group }} {% endfor %}</td>
<td class="text-center" name="j_group">{% for group in post.bis_group.all|filter_private %} {{ group }} {% endfor %}</td>
<td class="text-center" name="j_active"> {{ post.is_active|bool2str }} </td>
<td class="text-center"> {{ post.date_added|date:"Y-m-d H:i:s" }} </td>
<td class="text-center" name="j_comment"> {{ post.comment }} </td>
@ -111,21 +111,24 @@
function alter(form) {
selectData = GetTableDataBox();
if (selectData[1] != 0){
if (selectData[1] != 0) {
$.ajax({
type: "post",
url: "/jasset/host_edit/batch/",
data : {"editable":selectData[0],"len_table":selectData[1]},
success: function(data){
data: {"editable": selectData[0], "len_table": selectData[1]},
success: function (data) {
alert("修改成功");
window.open("/jasset/host_list/","_self");
window.open("/jasset/host_list/", "_self");
}
});
}
}
function del(form) {
function del(form) {
var checkboxes = document.getElementById(form);
var id_list = {};
var group_name = $('#j_group_name').attr("value");
console.log(group_name);
var j = 0;
for (var i = 0; i < checkboxes.elements.length; i++) {
if (checkboxes.elements[i].type == "checkbox" && checkboxes.elements[i].checked == true && checkboxes.elements[i].value != "checkall") {
@ -133,18 +136,17 @@
j++;
}
}
if (confirm("确定删除")) {
if (confirm("确定从该IDC中删除")) {
$.ajax({
type: "POST",
url: "/jasset/host_del/",
data: {"id_list": id_list, "len_list": j},
url: "/jasset/group_del_host/idc/",
data: {"id_list": id_list, "len_list": j, "group_name": group_name},
success: function (data) {
window.open("/jasset/host_list/", "_self");
window.open(window.location.pathname, "_self");
}
});
}
}
}
</script>
{% endblock %}

@ -39,7 +39,7 @@
<li id="jlog">
<a href="#"><i class="fa fa-files-o"></i> <span class="nav-label">日志审计</span><span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li id="log_list"><a href="/jlog/">查看日志</a></li>
<li id="log_list"><a href="/jlogb/">查看日志</a></li>
<li id="log_detail"><a href="/jlog/log_detail/">日志分析</a></li>
</ul>
</li>

@ -14,7 +14,7 @@
</ul>
</div>
<div class="logo-element">
JS+
JumpServer
</div>
</li>

Loading…
Cancel
Save