Merge remote-tracking branch 'origin/guanghongwei' into guanghongwei

Conflicts:
	jperm/models.py
pull/6/head
guanghongwei 10 years ago
commit 80d4272ee5

@ -108,14 +108,13 @@ 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()
# test_add_log()

@ -12,13 +12,13 @@ urlpatterns = patterns('',
url(r'^idc_add/$', add_idc),
url(r'^idc_list/$', list_idc),
url(r'^idc_detail/$', detail_idc),
url(r'^idc_del/(\d+)/$', del_idc),
url(r'^idc_del/(\w+)/$', del_idc),
url(r'^jgroup_add/$', add_group),
url(r'^group_edit/$', edit_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),
url(r'^group_del/(\w+)/$', group_del),
url(r'^host_del/(\w+)/$', host_del),
url(r'^host_edit/$', host_edit),
url(r'^host_edit/batch/$', batch_host_edit),

@ -251,7 +251,15 @@ def list_idc(request):
def del_idc(request, offset):
IDC.objects.filter(id=offset).delete()
if offset == 'multi':
len_list = request.POST.get("len_list")
for i in range(int(len_list)):
key = "id_list[" + str(i) + "]"
gid = request.POST.get(key)
IDC.objects.filter(id=gid).delete()
else:
gid = int(offset)
IDC.objects.filter(id=gid).delete()
return HttpResponseRedirect('/jasset/idc_list/')
@ -354,8 +362,18 @@ def group_del_host(request, offset):
def group_del(request, offset):
BisGroup.objects.filter(id=offset).delete()
return HttpResponseRedirect('/jasset/group_list/')
if offset == 'multi':
len_list = request.POST.get("len_list")
for i in range(int(len_list)):
key = "id_list[" + str(i) + "]"
gid = request.POST.get(key)
BisGroup.objects.filter(id=gid).delete()
else:
gid = int(offset)
BisGroup.objects.filter(id=gid).delete()
return HttpResponseRedirect('/jasset/jgroup_list/')
def host_search(request):

@ -42,6 +42,8 @@ def perm_add(request):
if request.method == 'GET':
user_groups = UserGroup.objects.filter(id__gt=2)
asset_groups = BisGroup.objects.all()
users = User.objects.all()
assets = Asset.objects.all()
else:
name = request.POST.get('name', '')

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

@ -18,7 +18,7 @@ from django.template import RequestContext
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from django.template import RequestContext
from juser.models import User
from juser.models import User, UserGroup
from jlog.models import Log
from jasset.models import Asset, BisGroup, IDC
@ -301,6 +301,21 @@ class PyCrypt(object):
return plain_text.rstrip('\0')
def filter_ajax_api(request):
attr = request.GET.get('attr', 'user')
value = request.GET.get('value', '')
if attr == 'user':
contact_list = User.objects.filter(name__icontains=value)
elif attr == "user_group":
contact_list = UserGroup.objects.filter(name__icontains=value)
elif attr == "asset":
contact_list = Asset.objects.filter(ip__icontains=value)
elif attr == "asset":
contact_list = BisGroup.objects.filter(name__icontains=value)
return render_to_response('filter_ajax_api.html', locals())
# def perm_user_asset(user_id=None, username=None):
# if user_id:
# user = User.objects.get(id=user_id)

@ -0,0 +1,9 @@
{% for object in contact_list %}
{% ifequal attr "asset" %}
<option value="{{ contact_list.id }}">{{ contact_list.ip }}</option>
{% else %}
<option value="{{ contact_list.id }}">{{ contact_list.name }}</option>
{% endifequal %}
{% endfor %}

@ -38,7 +38,13 @@
{% endfor %}
</tbody>
</table>
{% include 'paginator.html' %}
<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>
{% include 'paginator.html' %}
</div>
</form>
</div>
</div>
@ -46,4 +52,28 @@
</div>
</div>
{% endblock %}
<script>
function del(form) {
var checkboxes = document.getElementById(form);
var id_list = {};
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") {
id_list[j] = checkboxes.elements[i].value;
j++;
}
}
if (confirm("确定删除")) {
$.ajax({
type: "POST",
url: "/jasset/group_del/multi/",
data: {"id_list": id_list, "len_list": j},
success: function (data) {
window.open("/jasset/jgroup_list/", "_self");
}
});
}
}
</script>
{% endblock %}

@ -68,7 +68,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|filter_private %} {{ group }} {% endfor %}</td>
<td class="text-center" name="j_group">{{ post.bis_group.all | group_str2}}</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>
@ -81,7 +81,13 @@
{% endfor %}
</tbody>
</table>
{% include 'paginator.html' %}
<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>
{% include 'paginator.html' %}
</div>
</form>
</div>
</div>

@ -40,38 +40,7 @@
<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="?id={{ group_id }}&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 %}
{% for page in page_range %}
{% ifequal current_page page %}
<li class="paginate_button active" aria-controls="editable" tabindex="0"><a href="?keyword={{ keyword }}&page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% else %}
<li class="paginate_button" aria-controls="editable" tabindex="0"><a href="?keyword={{ keyword }}&page={{ page }}" title="第{{ page }}页">{{ page }}</a></li>
{% endifequal %}
{% endfor %}
{% if contacts.has_next %}
<li class="paginate_button next" aria-controls="editable" tabindex="0" id="editable_next">
<a href="?id={{ group_id }}&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>
{% include 'paginator.html' %}
</div>
<script>

@ -11,6 +11,7 @@
<a target="_blank" href="/jasset/idc_add" class="btn btn-sm btn-primary "> 添加IDC </a>
</div>
<form id="contents_form" name="contents_form">
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
@ -36,11 +37,42 @@
{% endfor %}
</tbody>
</table>
{% include 'paginator.html' %}
<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>
{% include 'paginator.html' %}
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
function del(form) {
var checkboxes = document.getElementById(form);
var id_list = {};
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") {
id_list[j] = checkboxes.elements[i].value;
j++;
}
}
if (confirm("确定删除")) {
$.ajax({
type: "POST",
url: "/jasset/idc_del/multi/",
data: {"id_list": id_list, "len_list": j},
success: function (data) {
window.open("/jasset/idc_list/", "_self");
}
});
}
}
</script>
{% endblock %}

@ -96,7 +96,11 @@
{% endfor %}
</tbody>
</table>
{% include 'paginator.html' %}
<div class="row">
<div class="col-sm-6">
</div>
{% include 'paginator.html' %}
</div>
</div>
</div>
</div>

@ -96,7 +96,11 @@
{% endfor %}
</tbody>
</table>
{% include 'paginator.html' %}
<div class="row">
<div class="col-sm-6">
</div>
{% include 'paginator.html' %}
</div>
</div>
</div>
</div>

@ -36,18 +36,40 @@
{% if msg %}
<div class="alert alert-success text-center">{{ msg }}</div>
{% endif %}
<select multiple="multiple" id="user_all" style="display: none;">
{% for user in users %}
<option value="{{ user.id }}">{{ user.name }}</option>
{% endfor %}
</select>
<select multiple="multiple" id="user_group_all" style="display: none;">
{% for user_group in user_groups %}
<option value="{{ user_group.id }}">{{ user_group.name }}</option>
{% endfor %}
</select>
<select multiple="multiple" id="asset_all" style="display: none;">
{% for asset in assets %}
<option value="{{ asset.id }}">{{ asset.ip }}</option>
{% endfor %}
</select>
<select multiple="multiple" id="asset_group_all" style="display: none;" >
{% for asset_group in asset_groups %}
<option value="{{ asset_group.id }}">{{ asset_group.name }}</option>
{% endfor %}
</select>
</select>
<div class="row">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">授权名<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input id="name" name="name" placeholder="授权名称" type="text" class="form-control">
<span class="help-block m-b-none">取个名字方便辨识</span>
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="" class="col-sm-2 control-label">用户组<span class="red-fonts">*</span></label>
<label for="" class="col-sm-2 control-label" >
<select id="user_type" name="user_type" onchange="userChoice(this.value)">
<option value="1">用户组</option>
<option value="0">用户</option>
</select>
</label>
<div class="col-sm-4">
<div>
<select id="user_groups" name="user_groups" class="form-control" size="10" multiple>
@ -68,7 +90,7 @@
<div class="col-sm-3">
<div>
<select id="user_groups_select" name="user_groups_select" class="form-control m-b" size="5" multiple>
<select id="user_groups_select" name="user_groups_select" class="form-control m-b" size="10" multiple>
</select>
</div>
</div>
@ -77,7 +99,20 @@
<div class="hr-line-dashed"></div>
<div class="form-group">
<label for="" class="col-sm-2 control-label">主机组<span class="red-fonts">*</span></label>
<label for="" class="col-sm-2 control-label">
</label>
<div class="col-sm-4">
<input id="comment" name="comment" placeholder="过滤" type="text" class="form-control">
</div>
</div>
<div class="form-group">
<label for="" class="col-sm-2 control-label">
<select id="asset_type" name="user_type" onchange="assetChoice(this.value)" >
<option value="1">主机组</option>
<option value="0">主机</option>
</select>
</label>
<div class="col-sm-4">
<div>
<select id="asset_groups" name="asset_groups" class="form-control m-b" size="10" multiple>
@ -97,7 +132,7 @@
<div class="col-sm-3">
<div>
<select id="asset_groups_select" name="asset_groups_select" class="form-control m-b" size="5" multiple>
<select id="asset_groups_select" name="asset_groups_select" class="form-control m-b" size="10" multiple>
</select>
</div>
</div>
@ -168,6 +203,38 @@ $(document).ready(function(){
})
})
})
function userChoice(value){
if (value == "1"){
$("#user_groups").children().each(function(){$(this).remove()});
$("#user_groups_select").children().each(function(){$(this).remove()});
$("#user_group_all").children().each(function(){
$("#user_groups").append($(this).clone())
})
}
else
$("#user_groups").children().each(function(){$(this).remove()});
$("#user_groups_select").children().each(function(){$(this).remove()});
$("#user_all").children().each(function(){
$("#user_groups").append($(this).clone())
})
}
function assetChoice(value){
if (value == "1"){
$("#asset_groups").children().each(function(){$(this).remove()});
$("#asset_groups_select").children().each(function(){$(this).remove()});
$("#asset_group_all").children().each(function(){
$("#asset_groups").append($(this).clone())
})
}
else
$("#asset_groups").children().each(function(){$(this).remove()});
$("#asset_groups_select").children().each(function(){$(this).remove()});
$("#asset_all").children().each(function(){
$("#asset_groups").append($(this).clone())
})
}
</script>
{% endblock %}

@ -37,7 +37,7 @@
<div class="form-group">
<label for="group_name" class="col-sm-2 control-label">组名<span class="red-fonts">*</span></label>
<div class="col-sm-8">
<input name="group_id" type="text" class="form-control" value="{{ group.id }}">
<input name="group_id" type="text" class="form-control" value="{{ group.id }}" style="display: none">
<input id="group_name" name="group_name" placeholder="Group name" type="text" class="form-control" value="{{ group.name }}">
</div>
</div>

Loading…
Cancel
Save