From bd0fd90e2d7cecaf8bd2b1ff80e7aaca0b3d03db Mon Sep 17 00:00:00 2001 From: guanghongwei Date: Mon, 6 Apr 2015 23:04:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=AF=A6=E6=83=85=E5=92=8C?= =?UTF-8?q?=E6=99=AE=E9=80=9A=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/AddUserAsset.py | 14 +- jumpserver/api.py | 1 + jumpserver/context_processors.py | 1 + jumpserver/settings.py | 1 + jumpserver/templatetags/mytags.py | 36 +++- jumpserver/views.py | 7 + juser/views.py | 24 ++- templates/index_cu.html | 38 ++++ templates/jperm/perm_detail.html | 2 +- templates/juser/profile.html | 82 +++++++++ templates/juser/user_detail.html | 284 ++++++++++++++++++++++-------- templates/juser/user_list.html | 4 +- templates/nav.html | 4 +- templates/nav_li_profile.html | 2 +- 14 files changed, 402 insertions(+), 98 deletions(-) create mode 100644 templates/index_cu.html create mode 100644 templates/juser/profile.html diff --git a/docs/AddUserAsset.py b/docs/AddUserAsset.py index 6c9a00e70..f8faea53a 100644 --- a/docs/AddUserAsset.py +++ b/docs/AddUserAsset.py @@ -127,13 +127,13 @@ def test_add_log(): if __name__ == '__main__': - install() - test_add_dept() - test_add_group() - test_add_user() - test_add_idc() - test_add_asset_group() - test_add_asset() + #install() + #test_add_dept() + #test_add_group() + #test_add_user() + #test_add_idc() + #test_add_asset_group() + #test_add_asset() test_add_log() diff --git a/jumpserver/api.py b/jumpserver/api.py index 537843aed..08d131476 100644 --- a/jumpserver/api.py +++ b/jumpserver/api.py @@ -10,6 +10,7 @@ from binascii import b2a_hex, a2b_hex import ldap from ldap import modlist import hashlib +import datetime from django.core.paginator import Paginator, EmptyPage, InvalidPage from django.http import HttpResponse, Http404 from juser.models import User, UserGroup diff --git a/jumpserver/context_processors.py b/jumpserver/context_processors.py index 6fdd4d07f..baa3f091b 100644 --- a/jumpserver/context_processors.py +++ b/jumpserver/context_processors.py @@ -2,6 +2,7 @@ from juser.models import User from jasset.models import Asset from jumpserver.api import * + def name_proc(request): user_id = request.session.get('user_id') role_id = request.session.get('role_id') diff --git a/jumpserver/settings.py b/jumpserver/settings.py index 50b6ae0db..c3c4ad509 100644 --- a/jumpserver/settings.py +++ b/jumpserver/settings.py @@ -108,6 +108,7 @@ TEMPLATE_DIRS = ( STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), + os.path.join(BASE_DIR, "keys"), ) # Internationalization # https://docs.djangoproject.com/en/1.7/topics/i18n/ diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index 52ca04b76..42cc1ec28 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -56,7 +56,7 @@ def groups_str2(group_list): @register.filter(name='group_str2_all') -def groups_str2(group_list): +def group_str2_all(group_list): group_lis = [] for i in group_list: if str(i) != 'ALL': @@ -106,6 +106,12 @@ def member_count(group_id): return group.user_set.count() +@register.filter(name='group_user_count') +def group_user_count(group_id): + group = UserGroup.objects.get(id=group_id) + return group.user_set.count() + + @register.filter(name='dept_user_num') def dept_user_num(dept_id): dept = DEPT.objects.filter(id=dept_id) @@ -217,3 +223,31 @@ def to_avatar(role_id='0'): @register.filter(name='get_user_asset_group') def get_user_asset_group(user): return user_perm_group_api(user) + + +@register.filter(name='group_asset_list') +def group_asset_list(group): + return group.asset_set.all() + + +@register.filter(name='group_asset_list_count') +def group_asset_list_count(group): + return group.asset_set.all().count() + + +@register.filter(name='time_delta') +def time_delta(time_before): + delta = datetime.datetime.now() - time_before + days = delta.days + if days: + return "%s 天前" % days + else: + hours = delta.seconds/3600 + if hours: + return "%s 小时前" % hours + else: + mins = delta.seconds/60 + if mins: + return '%s 分钟前' % mins + else: + return '%s 秒前' % delta.seconds diff --git a/jumpserver/views.py b/jumpserver/views.py index 5f4f82226..2a6fdd037 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -42,8 +42,15 @@ def get_data(data, items, option): return dic +@require_login +def index_cu(request): + return render_to_response('index_cu.html', locals(), context_instance=RequestContext(request)) + + @require_login def index(request): + if request.session.get('role_id') == 0: + return index_cu(request) users = User.objects.all() hosts = Asset.objects.all() online_host = Log.objects.filter(is_finished=0) diff --git a/juser/views.py b/juser/views.py index eb0a361ec..987ecdd4a 100644 --- a/juser/views.py +++ b/juser/views.py @@ -109,7 +109,7 @@ def db_del_user(username): def gen_ssh_key(username, password=None, length=2048): private_key_dir = os.path.join(BASE_DIR, 'keys/jumpserver/') - private_key_file = os.path.join(private_key_dir, username) + private_key_file = os.path.join(private_key_dir, username+".pem") public_key_dir = '/home/%s/.ssh/' % username public_key_file = os.path.join(public_key_dir, 'authorized_keys') is_dir(private_key_dir) @@ -775,18 +775,26 @@ def user_list_adm(request): return render_to_response('juser/user_list.html', locals(), context_instance=RequestContext(request)) -@require_admin +@require_login def user_detail(request): - user_id = request.GET.get('id', '') + header_title, path1, path2 = '查看用户', '用户管理', '用户详情' + if request.session.get('role_id') == 0: + user_id = request.session.get('user_id') + else: + user_id = request.GET.get('id', '') + if request.session.get('role_id') == 1: + user, dept = get_session_user_dept(request) + if not validate(request, user=[user_id]): + return HttpResponseRedirect('/') if not user_id: return HttpResponseRedirect('/juser/user_list/') - if request.session.get('role_id', '') == '1': - if not validate(request, user=[user_id]): - return HttpResponseRedirect('/juser/user_list/') + user = User.objects.filter(id=user_id) if user: user = user[0] asset_group_permed = user_perm_group_api(user) + logs_last = Log.objects.filter(user=user.name).order_by('-start_time')[0:10] + logs_all = Log.objects.filter(user=user.name).order_by('-start_time') return render_to_response('juser/user_detail.html', locals(), context_instance=RequestContext(request)) @@ -953,11 +961,11 @@ def profile(request): if not user_id: return HttpResponseRedirect('/') user = User.objects.get(id=user_id) - return render_to_response('juser/user_detail.html', locals(), context_instance=RequestContext(request)) + return render_to_response('juser/profile.html', locals(), context_instance=RequestContext(request)) def chg_info(request): - header_title, path1, path2 = '修改信息 | Edit Info', '用户管理', '修改个人信息' + header_title, path1, path2 = '修改信息', '用户管理', '修改个人信息' user_id = request.session.get('user_id') user_set = User.objects.filter(id=user_id) error = '' diff --git a/templates/index_cu.html b/templates/index_cu.html new file mode 100644 index 000000000..b1a602230 --- /dev/null +++ b/templates/index_cu.html @@ -0,0 +1,38 @@ +{% extends 'base.html' %} +{% block content %} +{% include 'nav_cat_bar.html' %} + +
+
+
+
+
+
使用说明
+ +
+ +
+ helo +
+
+
+
+ + +{% endblock %} \ No newline at end of file diff --git a/templates/jperm/perm_detail.html b/templates/jperm/perm_detail.html index dac9b254d..039151aad 100644 --- a/templates/jperm/perm_detail.html +++ b/templates/jperm/perm_detail.html @@ -8,7 +8,7 @@
-
授权用户 User.
+
用户详情
diff --git a/templates/juser/profile.html b/templates/juser/profile.html new file mode 100644 index 000000000..7be33cce4 --- /dev/null +++ b/templates/juser/profile.html @@ -0,0 +1,82 @@ +{% load mytags %} + + + {% include 'link_css.html' %} + + + + + +
+
+

{{ user.name }} 用户详情

+
+ + + + + + + + + + + +{# #} +{# #} + + + + + + + + + + + + +{# #} +{# #} + + + + + + + + + + + +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +{# #} +
ID用户名姓名角色部门Email激活添加时间最后登录
{{ user.id }}{{ user.username }}{{ user.name }}{{ user.id | get_role }}{{ user.dept.name }}{{ user.email }}{{ user.is_active|bool2str }}{{ user.date_joined }}{{ user.last_login }}
添加日期: {{ user.date_joined }}最后登录: {{ user.last_login }}
用户组: + {% for group in user.group.all %} + {{ group.name }} + {% endfor %} +
授权主机组:#} +{# {% for group in user|get_user_asset_group %}#} +{# {{ group.name }}#} +{# {% endfor %}#} +{#
授权主机组#} +{# {% for asset_group in asset_group_permed %}#} +{# {{ asset_group.name }}#} +{# {% endfor %}#} +{#
+
+
+ + \ No newline at end of file diff --git a/templates/juser/user_detail.html b/templates/juser/user_detail.html index 119aa028d..89218b115 100644 --- a/templates/juser/user_detail.html +++ b/templates/juser/user_detail.html @@ -1,82 +1,212 @@ +{% extends 'base.html' %} {% load mytags %} - - - {% include 'link_css.html' %} - - - +{% block content %} + {% include 'nav_cat_bar.html' %} +
-
-

{{ user.name }} 用户详情

-
- - \ No newline at end of file +
+
+
+
授权主机/组
+ +
+
+

用户的所有授权主机

+ 这里包含了用户所有的主机组和组下的主机. +
+
+ {% for group in user|get_user_asset_group %} +
+
+
+ + {{ group.name }} +
+ 共: {{ group | group_asset_list_count }}台 +
+
+

{{ group.comment }}

+ +

+ {% for asset in group|group_asset_list %} + {{ asset.ip }}
+ {% endfor %} +

+

+ +
+
+
+ {% endfor %} +
+
+
+ +
+
+
+
登录记录
+
+ 最近登录 +
+
+
+ +
+
+ {% for log in logs_last %} +
+ + image + +
+ {{ log.start_time|time_delta }} + {{ log.user }} 登录了 {{ log.host }}.
+ {{ log.start_time|date:"Y-m-d H:i:s" }} +
+
+ {% endfor %} +
+ + + +
+ + + +
+
+ +
+ +
+
+ + + + +{% endblock %} \ No newline at end of file diff --git a/templates/juser/user_list.html b/templates/juser/user_list.html index d6b362f00..43b45c70b 100644 --- a/templates/juser/user_list.html +++ b/templates/juser/user_list.html @@ -56,6 +56,7 @@ 小组 角色 激活 + 下载密钥 操作 @@ -71,8 +72,9 @@ {{ user.group.all | group_str2 }} {{ user.id | get_role }} {{ user.is_active|bool2str }} + 下载 - 详情 + 详情 {% ifequal session_role_id 2 %} 编辑 删除 diff --git a/templates/nav.html b/templates/nav.html index 8143c4130..b4d0b0a93 100644 --- a/templates/nav.html +++ b/templates/nav.html @@ -19,7 +19,7 @@
  • 添加部门
  • 查看小组
  • 添加小组
  • -
  • 查看用户{{ user_active_num }}/{{ user_total_num }}
  • +
  • 查看用户{{ user_active_num }}/{{ user_total_num }}
  • 添加用户
  • @@ -137,7 +137,7 @@ 仪表盘
  • - 个人信息 + 个人信息
  • 查看主机 diff --git a/templates/nav_li_profile.html b/templates/nav_li_profile.html index 9e9e6418d..522d431e4 100644 --- a/templates/nav_li_profile.html +++ b/templates/nav_li_profile.html @@ -8,7 +8,7 @@ {{ session_user_id | to_name}} {{ session_role_id | to_role_name }}