用户详情和普通用户

pull/6/head
guanghongwei 2015-04-06 23:04:31 +08:00
parent 7e53228359
commit bd0fd90e2d
14 changed files with 402 additions and 98 deletions

View File

@ -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()

View File

@ -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

View File

@ -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')

View File

@ -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/

View File

@ -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

View File

@ -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)

View File

@ -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 = ''

38
templates/index_cu.html Normal file
View File

@ -0,0 +1,38 @@
{% extends 'base.html' %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content">
<div class="row">
<div class="col-lg-8">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5> 浣跨敤璇存槑 </h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#">鏈惎鐢 1</a>
</li>
<li><a href="#">鏈惎鐢 2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
helo
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -8,7 +8,7 @@
<div class="col-lg-6">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>鎺堟潈鐢ㄦ埛 <small> User.</small></h5>
<h5>鐢ㄦ埛璇︽儏</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>

View File

@ -0,0 +1,82 @@
{% load mytags %}
<html>
<head>
{% include 'link_css.html' %}
<style type="text/css">
body
{
background: #FFFFFF;
}
</style>
</head>
<body>
<div class="row">
<div class="contact-box">
<h2 class="text-center">{{ user.name }} 鐢ㄦ埛璇︽儏</h2>
<div class="ibox-content">
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<td class="text-center" width="120">ID</td>
<td class="text-center">鐢ㄦ埛鍚</td>
<td class="text-center">濮撳悕</td>
<td class="text-center">瑙掕壊</td>
<td class="text-center">閮ㄩ棬</td>
<td class="text-center">Email</td>
<td class="text-center">婵娲</td>
{# <td class="text-center">娣诲姞鏃堕棿</td>#}
{# <td class="text-center">鏈鍚庣櫥褰</td>#}
</tr>
</thead>
<tbody>
<tr class="gradeX">
<td class="text-center">{{ user.id }}</td>
<td class="text-center">{{ user.username }}</td>
<td class="text-center">{{ user.name }}</td>
<td class="text-center">{{ user.id | get_role }}</td>
<td class="text-center">{{ user.dept.name }}</td>
<td class="text-center">{{ user.email }}</td>
<td class="text-center">{{ user.is_active|bool2str }}</td>
{# <td class="text-center">{{ user.date_joined }}</td>#}
{# <td class="text-center">{{ user.last_login }}</td>#}
</tr>
<tr>
<td class="text-center">娣诲姞鏃ユ湡锛 </td>
<td colspan="2" class="text-center">{{ user.date_joined }}</td>
<td class="text-center">鏈鍚庣櫥褰曪細 </td>
<td colspan="3" class="text-center">{{ user.last_login }}</td>
</tr>
<tr>
<td colspan="1" class="text-center">鐢ㄦ埛缁勶細</td>
<td colspan="6" class="text-center">
{% for group in user.group.all %}
<b>{{ group.name }}</b>
{% endfor %}
</td>
</tr>
{# <tr>#}
{# <td colspan="1" class="text-center">鎺堟潈涓绘満缁:</td>#}
{# <td colspan="6" class="text-center">#}
{# {% for group in user|get_user_asset_group %}#}
{# <b>{{ group.name }}</b>#}
{# {% endfor %}#}
{# </td>#}
{# </tr>#}
{# #}
{# <tr class="gradeX">#}
{# <td class="text-center">鎺堟潈涓绘満缁</td>#}
{# <td class="text-center">#}
{# {% for asset_group in asset_group_permed %}#}
{# {{ asset_group.name }}#}
{# {% endfor %}#}
{# </td>#}
{# </tr>#}
</table>
</div>
</div>
</body>
</html>

View File

@ -1,82 +1,212 @@
{% extends 'base.html' %}
{% load mytags %}
<html>
<head>
{% include 'link_css.html' %}
<style type="text/css">
body
{
background: #FFFFFF;
}
</style>
</head>
<body>
{% block content %}
{% include 'nav_cat_bar.html' %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="contact-box">
<h2 class="text-center">{{ user.name }} 鐢ㄦ埛璇︽儏</h2>
<div class="ibox-content">
<table class="table table-striped table-bordered table-hover " id="editable" >
<thead>
<tr>
<td class="text-center" width="120">ID</td>
<td class="text-center">鐢ㄦ埛鍚</td>
<td class="text-center">濮撳悕</td>
<td class="text-center">瑙掕壊</td>
<td class="text-center">閮ㄩ棬</td>
<td class="text-center">Email</td>
<td class="text-center">婵娲</td>
{# <td class="text-center">娣诲姞鏃堕棿</td>#}
{# <td class="text-center">鏈鍚庣櫥褰</td>#}
</tr>
</thead>
<tbody>
<tr class="gradeX">
<td class="text-center">{{ user.id }}</td>
<td class="text-center">{{ user.username }}</td>
<td class="text-center">{{ user.name }}</td>
<td class="text-center">{{ user.id | get_role }}</td>
<td class="text-center">{{ user.dept.name }}</td>
<td class="text-center">{{ user.email }}</td>
<td class="text-center">{{ user.is_active|bool2str }}</td>
{# <td class="text-center">{{ user.date_joined }}</td>#}
{# <td class="text-center">{{ user.last_login }}</td>#}
</tr>
<tr>
<td class="text-center">娣诲姞鏃ユ湡锛 </td>
<td colspan="2" class="text-center">{{ user.date_joined }}</td>
<td class="text-center">鏈鍚庣櫥褰曪細 </td>
<td colspan="3" class="text-center">{{ user.last_login }}</td>
</tr>
<tr>
<td colspan="1" class="text-center">鐢ㄦ埛缁勶細</td>
<td colspan="6" class="text-center">
{% for group in user.group.all %}
<b>{{ group.name }}</b>
{% endfor %}
</td>
</tr>
<tr>
<td colspan="1" class="text-center">鎺堟潈涓绘満缁:</td>
<td colspan="6" class="text-center">
{% for group in user|get_user_asset_group %}
<b>{{ group.name }}</b>
{% endfor %}
</td>
</tr>
{# #}
{# <tr class="gradeX">#}
{# <td class="text-center">鎺堟潈涓绘満缁</td>#}
{# <td class="text-center">#}
{# {% for asset_group in asset_group_permed %}#}
{# {{ asset_group.name }}#}
{# {% endfor %}#}
{# </td>#}
{# </tr>#}
</table>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<span class="label label-primary"><b>{{ user.name }}</b></span>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#"></a>
</li>
<li><a href="#"></a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div>
<div class="text-left">
<table class="table">
<tr>
<td class="text-navy">ID</td>
<td>{{ user.id }}</td>
</tr>
<tr>
<td class="text-navy">鐢ㄦ埛鍚</td>
<td>{{ user.username }}</td>
</tr>
<tr>
<td class="text-navy">濮撳悕</td>
<td>{{ user.name }}</td>
</tr>
<tr>
<td class="text-navy">瑙掕壊</td>
<td>{{ user.id | get_role }}</td>
</tr>
<tr>
<td class="text-navy">閮ㄩ棬</td>
<td>{{ user.dept.name }}</td>
</tr>
<tr>
<td class="text-navy">Email</td>
<td>{{ user.email }}</td>
</tr>
<tr>
<td class="text-navy">婵娲</td>
<td>{{ user.is_active|bool2str }}</td>
</tr>
<tr>
<td class="text-navy">娣诲姞鏃ユ湡</td>
<td>{{ user.date_joined|date:"Y-m-d H:i:s" }}</td>
</tr>
<tr>
<td class="text-navy">鏈鍚庣櫥褰</td>
<td>{{ user.last_login|date:"Y-m-d H:i:s" }}</td>
</tr>
<tr>
<td class="text-navy">鎵鍦ㄧ敤鎴风粍</td>
<td>
<table class="table">
{% for group in user.group.all %}
<tr>
<td>{{ group.name }}</td>
</tr>
{% endfor %}
</table>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>鎺堟潈涓绘満/缁</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-wrench"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li><a href="#">Config option 1</a>
</li>
<li><a href="#">Config option 2</a>
</li>
</ul>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content ibox-heading">
<h3>鐢ㄦ埛鐨勬墍鏈夋巿鏉冧富鏈</h3>
<small><i class="fa fa-map-marker"></i> 杩欓噷鍖呭惈浜嗙敤鎴锋墍鏈夌殑涓绘満缁勫拰缁勪笅鐨勪富鏈.</small>
</div>
<div class="ibox-content inspinia-timeline">
{% for group in user|get_user_asset_group %}
<div class="timeline-item">
<div class="row">
<div class="col-xs-3 date">
<i class="fa fa-repeat"></i>
<b>{{ group.name }}</b>
<br>
<small class="text-navy">鍏: {{ group | group_asset_list_count }}鍙</small>
</div>
<div class="col-xs-7 content no-top-border">
<p class="m-b-xs"><strong>{{ group.comment }}</strong></p>
<p>
{% for asset in group|group_asset_list %}
{{ asset.ip }}<br>
{% endfor %}
</p>
<p></p>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
<div class="col-lg-4">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>鐧诲綍璁板綍</h5>
<div class="ibox-tools">
<span class="label label-warning-light">鏈杩戠櫥褰</span>
</div>
</div>
<div class="ibox-content">
<div id="last">
<div class="feed-activity-list" >
{% for log in logs_last %}
<div class="feed-element">
<a href="profile.html" class="pull-left">
<img alt="image" class="img-circle" src="/static/img/{{ session_role_id | to_avatar }}.png">
</a>
<div class="media-body ">
<small class="pull-right">{{ log.start_time|time_delta }}</small>
<strong>{{ log.user }}</strong> 鐧诲綍浜 <span class="text-navy">{{ log.host }}. </span><br>
<small class="text-muted">{{ log.start_time|date:"Y-m-d H:i:s" }}</small>
</div>
</div>
{% endfor %}
</div>
<button id="show" class="btn btn-primary btn-block m-t"><i class="fa fa-arrow-down"></i> Show All</button>
</div>
<div id="all" style="display: none">
<div class="feed-activity-list" >
{% for log in logs_all %}
<div class="feed-element">
<a href="profile.html" class="pull-left">
<img alt="image" class="img-circle" src="/static/img/{{ session_role_id | to_avatar }}.png">
</a>
<div class="media-body ">
<small class="pull-right">{{ log.start_time|time_delta }}</small>
<strong>{{ log.user }}</strong> 鐧诲綍浜 <span class="text-navy">{{ log.host }}. </span><br>
<small class="text-muted">{{ log.start_time|date:"Y-m-d H:i:s" }}</small>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('#show').click(function(){
$('#last').css('display', 'none');
$('#all').css('display', 'block');
})
})
</script>
{% endblock %}

View File

@ -56,6 +56,7 @@
<th class="text-center">灏忕粍</th>
<th class="text-center">瑙掕壊</th>
<th class="text-center">婵娲</th>
<th class="text-center">涓嬭浇瀵嗛挜</th>
<th class="text-center">鎿嶄綔</th>
</tr>
</thead>
@ -71,8 +72,9 @@
<td class="text-center" title="{% for user_group in user.group.all %} {{ user_group.name }} {% endfor %}"> {{ user.group.all | group_str2 }} </td>
<td class="text-center"> {{ user.id | get_role }}</td>
<td class="text-center">{{ user.is_active|bool2str }}</td>
<td class="text-center"><a href="/static/jumpserver/{{ user.username }}.pem">涓嬭浇</a></td>
<td class="text-center">
<a title="[ {{ user.name }} ] 璇︽儏" value="../user_detail/?id={{ user.id }}" class="iframe btn btn-xs btn-primary">璇︽儏</a>
<a href="../user_detail/?id={{ user.id }}" class="btn btn-xs btn-primary">璇︽儏</a>
{% ifequal session_role_id 2 %}
<a href="../user_edit/?id={{ user.id }}" class="btn btn-xs btn-info">缂栬緫</a>
<a href="../user_del/?id={{ user.id }}" class="btn btn-xs btn-danger">鍒犻櫎</a>

View File

@ -19,7 +19,7 @@
<li class="dept_add"><a href="/juser/dept_add/">娣诲姞閮ㄩ棬</a></li>
<li class="group_list group_edit"><a href="/juser/group_list/">鏌ョ湅灏忕粍</a></li>
<li class="group_add"><a href="/juser/group_add/">娣诲姞灏忕粍</a></li>
<li class="user_list user_edit"><a href="/juser/user_list/">鏌ョ湅鐢ㄦ埛<span class="label {% ifequal user_active_num user_total_num %}label-primary {% else %}label-warning {% endifequal %}pull-right">{{ user_active_num }}/{{ user_total_num }}</span></a></li>
<li class="user_list user_edit user_detail"><a href="/juser/user_list/">鏌ョ湅鐢ㄦ埛<span class="label {% ifequal user_active_num user_total_num %}label-primary {% else %}label-warning {% endifequal %}pull-right">{{ user_active_num }}/{{ user_total_num }}</span></a></li>
<li class="user_add"><a href="/juser/user_add/">娣诲姞鐢ㄦ埛</a></li>
</ul>
</li>
@ -137,7 +137,7 @@
<a href="/"><i class="fa fa-th-large"></i> <span class="nav-label">浠〃鐩</span><span class="label label-info pull-right"></span></a>
</li>
<li>
<a href="/"><i class="fa fa-rebel"></i> <span class="nav-label">涓汉淇℃伅</span><span class="label label-info pull-right"></span></a>
<a href="/juser/user_detail/?id={{ session_user_id }}"><i class="fa fa-rebel"></i> <span class="nav-label">涓汉淇℃伅</span><span class="label label-info pull-right"></span></a>
</li>
<li id="jasset">
<a href="/jasset/host_list/"><i class="fa fa-cube"></i> <span class="nav-label">鏌ョ湅涓绘満</span><span class="label label-info pull-right"></span></a>

View File

@ -8,7 +8,7 @@
<span class="clear"> <span class="block m-t-xs"> <strong class="font-bold">{{ session_user_id | to_name}}</strong>
</span> <span class="text-muted text-xs block">{{ session_role_id | to_role_name }} <b class="caret"></b></span> </span> </a>
<ul class="dropdown-menu animated fadeInRight m-t-xs">
<li><a value="/juser/user_detail/?id={{ session_user_id }}" class="iframe">涓汉淇℃伅</a></li>
<li><a value="/juser/profile/?id={{ session_user_id }}" class="iframe">涓汉淇℃伅</a></li>
<li><a href="/juser/chg_info/">淇敼淇℃伅</a></li>
<li><a href="/juser/chg_role/">鍒囨崲瑙掕壊</a></li>