diff --git a/jasset/models.py b/jasset/models.py index 5c2be96b2..ab65792da 100644 --- a/jasset/models.py +++ b/jasset/models.py @@ -1,6 +1,6 @@ import datetime from django.db import models -from juser.models import UserGroup, DEPT +from juser.models import User, UserGroup, DEPT class IDC(models.Model): @@ -43,4 +43,13 @@ class Asset(models.Model): comment = models.CharField(max_length=100, blank=True, null=True) def __unicode__(self): - return self.ip \ No newline at end of file + return self.ip + + +class AssetAlias(models.Model): + user = models.ForeignKey(User) + host = models.ForeignKey(Asset) + alias = models.CharField(max_length=100, blank=True, null=True) + + def __unicode__(self): + return self.comment \ No newline at end of file diff --git a/jasset/urls.py b/jasset/urls.py index cf78be50e..1002ee691 100644 --- a/jasset/urls.py +++ b/jasset/urls.py @@ -22,4 +22,5 @@ urlpatterns = patterns('', url(r'^host_del/(\w+)/$', host_del), url(r'^host_edit/$', host_edit), url(r'^host_edit/batch/$', batch_host_edit), + url(r'^host_edit_common/batch/$', batch_host_edit_common), ) \ No newline at end of file diff --git a/jasset/views.py b/jasset/views.py index ea5e32fec..913ef5927 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -6,9 +6,9 @@ from django.db.models import Q from django.template import RequestContext from django.shortcuts import render_to_response -from jasset.models import IDC, Asset, BisGroup +from jasset.models import IDC, Asset, BisGroup, AssetAlias from juser.models import UserGroup, DEPT -from jperm.models import Perm +from jperm.models import Perm, SudoPerm from jumpserver.views import pages from jumpserver.api import * @@ -88,6 +88,7 @@ def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_dept, j_activ a.dept = depts a.save() + @require_admin def add_host(request): login_types = {'L': 'LDAP', 'M': 'MAP'} @@ -189,12 +190,6 @@ def batch_host_edit(request): j_group = request.POST.getlist(j_group) j_active = request.POST.get(j_active).strip() j_comment = request.POST.get(j_comment).strip() - print j_dept, j_group - # - # if is_group_admin(request) and not validate(request, asset=[j_id]): - # emg = u'删除失败,您无权操作!' - # print 'hehe' - # return HttpResponseRedirect('/jasset/host_list/') if j_type == 'M': j_user = "editable[" + str(i) + "][j_user]" @@ -202,13 +197,36 @@ def batch_host_edit(request): j_user = request.POST.get(j_user).strip() password = request.POST.get(j_password).strip() j_password = cryptor.encrypt(password) - jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_dept, j_active, j_comment, j_user, j_password) + jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_dept, j_active, j_comment, j_user, + j_password) else: jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_dept, j_active, j_comment) return render_to_response('jasset/host_list.html') +@require_login +def batch_host_edit_common(request): + user_id = request.session.get('user_id', '') + u = User.objects.get(id=user_id) + if request.method == 'POST': + len_table = request.POST.get('len_table') + for i in range(int(len_table)): + j_id = "editable[" + str(i) + "][j_id]" + j_alias = "editable[" + str(i) + "][j_alias]" + j_id = request.POST.get(j_id).strip() + j_alias = request.POST.get(j_alias).strip() + a = Asset.objects.get(id=j_id) + asset_alias = AssetAlias.objects.filter(user=u, host=a) + if asset_alias: + asset_alias = asset_alias[0] + asset_alias.alias = j_alias + asset_alias.save() + else: + AssetAlias.objects.create(user=u, host=a, alias=j_alias) + return render_to_response('jasset/host_list_common.html') + + @require_login def list_host(request): header_title, path1, path2 = u'查看主机', u'资产管理', u'查看主机' @@ -222,6 +240,8 @@ def list_host(request): if did: dept = DEPT.objects.get(id=did) posts = dept.asset_set.all() + return render_to_response('jasset/host_list_nop.html', locals(), context_instance=RequestContext(request)) + elif gid: posts = [] user_group = UserGroup.objects.get(id=gid) @@ -230,32 +250,47 @@ def list_host(request): for post in perm.asset_group.asset_set.all(): posts.append(post) posts = list(set(posts)) + return render_to_response('jasset/host_list_nop.html', locals(), context_instance=RequestContext(request)) + elif sid: - pass + posts = [] + user_group = UserGroup.objects.get(id=sid) + perms = Perm.objects.filter(user_group=user_group) + for perm in perms: + for post in perm.asset_group.asset_set.all(): + posts.append(post) + posts = list(set(posts)) + return render_to_response('jasset/host_list_nop.html', locals(), context_instance=RequestContext(request)) else: if is_super_user(request): if keyword: 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') + Q(bis_group__name__contains=keyword) | Q( + comment__contains=keyword)).distinct().order_by('ip') else: posts = Asset.objects.all().order_by('ip') + 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)) elif is_group_admin(request): if keyword: posts = Asset.objects.filter(Q(ip__contains=keyword) | Q(idc__name__contains=keyword) | - Q(bis_group__name__contains=keyword) | Q(comment__contains=keyword)).filter(dept=dept).distinct().order_by('ip') + Q(bis_group__name__contains=keyword) | Q( + comment__contains=keyword)).filter(dept=dept).distinct().order_by('ip') else: posts = Asset.objects.all().filter(dept=dept).order_by('ip') + 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)) + elif is_common_user(request): user_id = request.session.get('user_id') username = User.objects.get(id=user_id).name posts = user_perm_asset_api(username) - - 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)) + contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) + return render_to_response('jasset/host_list_common.html', locals(), + context_instance=RequestContext(request)) @require_admin @@ -478,21 +513,32 @@ def list_group(request): dept = DEPT.objects.get(id=dept_id) keyword = request.GET.get('keyword', '') gid = request.GET.get('gid') + sid = request.GET.get('sid') if gid: posts = [] user_group = UserGroup.objects.get(id=gid) perms = Perm.objects.filter(user_group=user_group) for perm in perms: posts.append(perm.asset_group) + + elif sid: + posts = [] + user_group = UserGroup.objects.get(id=sid) + perms = Perm.objects.filter(user_group=user_group) + for perm in perms: + posts.append(perm.asset_group) + else: if is_super_user(request): if keyword: - posts = BisGroup.objects.exclude(name='ALL').filter(Q(name__contains=keyword) | Q(comment__contains=keyword)) + posts = BisGroup.objects.exclude(name='ALL').filter( + Q(name__contains=keyword) | Q(comment__contains=keyword)) else: posts = BisGroup.objects.exclude(name='ALL').order_by('id') elif is_group_admin(request): if keyword: - posts = BisGroup.objects.filter(Q(name__contains=keyword) | Q(comment__contains=keyword)).filter(dept=dept) + posts = BisGroup.objects.filter(Q(name__contains=keyword) | Q(comment__contains=keyword)).filter( + dept=dept) else: posts = BisGroup.objects.filter(dept=dept).order_by('id') contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) @@ -506,7 +552,7 @@ def edit_group(request): group = BisGroup.objects.get(id=group_id) all = Asset.objects.all() dept_id = get_user_dept(request) - eposts = contact_list = Asset.objects.filter(bis_group=group).order_by('ip') + eposts = Asset.objects.filter(bis_group=group).order_by('ip') if is_super_user(request): edept = DEPT.objects.all() @@ -552,6 +598,7 @@ def detail_group(request): return render_to_response('jasset/group_detail.html', locals(), context_instance=RequestContext(request)) +@require_admin def detail_idc(request): header_title, path1, path2 = u'IDC详情', u'资产管理', u'IDC详情' login_types = {'L': 'LDAP', 'M': 'MAP'} @@ -605,6 +652,7 @@ def group_del(request, offset): return HttpResponseRedirect('/jasset/jgroup_list/') +@require_login def host_search(request): keyword = request.GET.get('keyword') login_types = {'L': 'LDAP', 'M': 'MAP'} @@ -618,6 +666,15 @@ 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)).filter(dept=dept).distinct().order_by('ip') + elif is_common_user(request): + user_id = request.session.get('user_id') + username = User.objects.get(id=user_id).name + post_perm = user_perm_asset_api(username) + post_all = 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') + posts = list(set(post_all) & set(post_perm)) + print posts 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)) \ No newline at end of file diff --git a/jumpserver.conf b/jumpserver.conf index 148d51eb7..78b98001d 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -9,7 +9,7 @@ database = jumpserver [ldap] ldap_enable = 1 -host_url = ldap://192.168.173.129:389 +host_url = ldap://192.168.8.230:389 base_dn = dc=jumpserver, dc=org root_dn = cn=admin,dc=jumpserver,dc=org root_pw = secret234 diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index 7b61693ea..159bbd5e3 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -7,6 +7,7 @@ import time from django import template from juser.models import User, UserGroup, DEPT from jumpserver.api import * +from jasset.models import AssetAlias register = template.Library() @@ -162,6 +163,17 @@ def ugrp_perm_asset_count(user_group_id): return len(set(assets)) +@register.filter(name='get_user_alias') +def get_user_alias(post, user_id): + user = User.objects.get(id=user_id) + host = Asset.objects.get(id=post.id) + alias = AssetAlias.objects.filter(user=user, host=host) + if alias: + return alias[0].alias + else: + return '' + + @register.filter(name='group_type_to_str') def group_type_to_str(type_name): group_types = { @@ -187,25 +199,11 @@ def ast_to_list_1(lis): return ast.literal_eval(lis) -# @register.filter(name='perm_asset_count') -# def perm_asset_count(user_id): -# return len(perm_user_asset(user_id)) - @register.filter(name='string_length') def string_length(string, length): return '%s ...' % string[0:length] -@register.filter(name='get_dic_user') -def get_dic_user(dic): - return dic.get('user') - - -@register.filter(name='get_dic_times') -def get_dic_times(dic): - return dic.get('times') - - @register.filter(name='to_name') def to_name(user_id): try: diff --git a/jumpserver/views.py b/jumpserver/views.py index 8cd1f76c9..3dc7b7e77 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -83,7 +83,6 @@ def index(request): login_10 = Log.objects.order_by('-start_time')[:10] # a week top 10 - # user_top_ten_more = [] for user_info in user_top_ten: username = user_info.get('user') last = Log.objects.filter(user=username).latest('start_time') diff --git a/templates/index.html b/templates/index.html index aa62330bf..c7b5829fe 100644 --- a/templates/index.html +++ b/templates/index.html @@ -69,9 +69,9 @@ {% for data in user_top_five %}
  • - {{ data|get_dic_times }}次/周 + {{ data.times }}次/周 - {{ forloop.counter }} {{ data|get_dic_user }} + {{ forloop.counter }} {{ data.user }}
  • {% endfor %} @@ -95,8 +95,8 @@
    -

    New messages

    - You have 22 new messages and 16 waiting in draft folder. +

    权限申请记录

    + 最近十条权限申请记录信息.
    @@ -124,11 +124,14 @@
    最近十次登录
    - 10 Messages + 10 Messages
    +
    +

    登录记录

    + 最近十次登录记录. +
    -
    {% for login in login_10 %} @@ -150,7 +153,7 @@ {% endfor %}
    - +
    @@ -181,8 +184,8 @@
    -

    You have meeting today!

    - Meeting is on 6:00am. Check your schedule to see detail. +

    一周Top10用户

    + 一周Top10用户登录次数及最近一次登录记录.
    {% for data in user_top_ten %} @@ -190,9 +193,9 @@
    - {{ data|get_dic_user }} + {{ data.user }}
    - {{ data|get_dic_times }}次 + {{ data.times }}次

    最近一次登录

    diff --git a/templates/jasset/group_add.html b/templates/jasset/group_add.html index d3defd781..b7c42d7cb 100644 --- a/templates/jasset/group_add.html +++ b/templates/jasset/group_add.html @@ -45,28 +45,36 @@
    - -
    - -
    -
    -
    - - -
    -
    -
    -
    - + +
    + +
    +
    +
    +
    + + +
    +
    +
    +

    已选中主机

    +
    + +
    +
    @@ -113,6 +121,17 @@ $(this).prop('selected', true) }) } + + + $('#search').keyup(function() { + var $rows = $('#groups option'); + var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase(); + + $rows.show().filter(function() { + var text = $(this).text().replace(/\s+/g, ' ').toLowerCase(); + return !~text.indexOf(val); + }).hide(); + }); {% endblock %} \ No newline at end of file diff --git a/templates/jasset/host_list_common.html b/templates/jasset/host_list_common.html new file mode 100644 index 000000000..abd2ba6fc --- /dev/null +++ b/templates/jasset/host_list_common.html @@ -0,0 +1,172 @@ +{% extends 'base.html' %} +{% load mytags %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
    +
    +
    +
    +
    +
    主机详细信息列表
    + +
    + +
    +
    + 点击别名栏修改主机别名, 可在跳板机上使用别名直接登录. + +
    + +
    + + + + + + + + + + + + + + + + + {% for post in contacts.object_list %} + + + + + + + + + + + + + {% endfor %} + +
    IP地址 端口号 登录方式 所属IDC 所属部门 所属主机组 别名 备注 操作
    {{ post.ip }} {{ post.port }} {{ login_types|get_item:post.login_type }} {{ post.idc.name }} {{ post.dept.all | group_str2 }}{{ post.bis_group.all | group_str2_all }} {{ post|get_user_alias:user_id }} {{ post.comment }} + 详情 +
    +
    +
    + +
    + {% include 'paginator.html' %} +
    +
    +
    +
    +
    +
    +
    + + + +{% endblock %} \ No newline at end of file diff --git a/templates/jasset/host_list_nop.html b/templates/jasset/host_list_nop.html new file mode 100644 index 000000000..7593f939e --- /dev/null +++ b/templates/jasset/host_list_nop.html @@ -0,0 +1,177 @@ +{% extends 'base.html' %} +{% load mytags %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
    +
    +
    +
    +
    +
    主机详细信息列表
    + +
    + +
    +
    + 添加 + + + + + + + + + + + +
    + +
    + + + + + + + + + + + + + + + + + {% for post in posts %} + + + + + + + + + + + + + {% endfor %} + +
    IP地址 端口号 登录方式 所属IDC 所属部门 所属主机组 是否激活 备注 操作
    {{ post.ip }} {{ post.port }} {{ login_types|get_item:post.login_type }} {{ post.idc.name }} {{ post.dept.all | group_str2 }}{{ post.bis_group.all | group_str2_all }} {{ post.is_active|bool2str }} {{ post.comment }} + 详情 + {% ifnotequal session_role_id 0 %} + 编辑 + 删除 + {% endifnotequal %} +
    +
    +
    + + +
    + +
    +
    +
    +
    +
    +
    +
    + + + +{% endblock %} \ No newline at end of file diff --git a/templates/jasset/host_search.html b/templates/jasset/host_search.html index a160a1160..8921e73c8 100644 --- a/templates/jasset/host_search.html +++ b/templates/jasset/host_search.html @@ -8,7 +8,11 @@ 登录方式 所属IDC 所属业务组 - 是否激活 + {% ifnotequal session_role_id 0 %} + 是否激活 + {% else %} + 别名 + {% endifnotequal %} 添加时间 备注 操作 @@ -23,13 +27,19 @@ {{ login_types|get_item:post.login_type }} {{ post.idc.name }} {{ post.bis_group.all | group_str2 }} - {{ post.is_active|bool2str }} + {% ifnotequal session_role_id 0 %} + {{ post.is_active|bool2str }} + {% else %} + {{ post|get_user_alias:user_id }} + {% endifnotequal %} {{ post.date_added|date:"Y-m-d H:i:s" }} {{ post.comment }} 详情 - 编辑 - 删除 + {% ifnotequal session_role_id 0 %} + 编辑 + 删除 + {% endifnotequal %} {% endfor %} diff --git a/templates/jperm/perm_apply.html b/templates/jperm/perm_apply.html index 52a01fb6c..4b0f049b7 100644 --- a/templates/jperm/perm_apply.html +++ b/templates/jperm/perm_apply.html @@ -74,7 +74,7 @@
    - +