mirror of https://github.com/jumpserver/jumpserver
修改首页
parent
25ce24a17d
commit
2b14fefb5c
|
@ -9,7 +9,7 @@ database = jumpserver
|
|||
|
||||
[ldap]
|
||||
ldap_enable = 1
|
||||
host_url = ldap://192.168.8.230:389
|
||||
host_url = ldap://127.0.0.1:389
|
||||
base_dn = dc=jumpserver, dc=org
|
||||
root_dn = cn=admin,dc=jumpserver,dc=org
|
||||
root_pw = secret234
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
from django.conf.urls import patterns, include, url
|
||||
from api import view_splitter
|
||||
from views import index, admin_index
|
||||
from views import index
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# Examples:
|
||||
# url(r'^$', 'jumpserver.views.home', name='home'),
|
||||
# url(r'^blog/', include('blog.urls')),
|
||||
(r'^$', view_splitter, {'su': index, 'adm': admin_index}),
|
||||
(r'^$', index),
|
||||
(r'^api/user/$', 'jumpserver.api.api_user'),
|
||||
(r'^skin_config/$', 'jumpserver.views.skin_config'),
|
||||
(r'^install/$', 'jumpserver.views.install'),
|
||||
|
|
|
@ -2,13 +2,9 @@
|
|||
|
||||
from __future__ import division
|
||||
|
||||
import datetime
|
||||
|
||||
from django.db.models import Count
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from jasset.models import IDC
|
||||
from juser.models import DEPT
|
||||
from jperm.models import Apply
|
||||
from jumpserver.api import *
|
||||
|
||||
|
@ -69,68 +65,6 @@ def index_cu(request):
|
|||
return render_to_response('index_cu.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@require_login
|
||||
@require_super_user
|
||||
def index(request):
|
||||
if request.session.get('role_id') == 0:
|
||||
return index_cu(request)
|
||||
users = User.objects.all()
|
||||
hosts = Asset.objects.all()
|
||||
online = Log.objects.filter(is_finished=0)
|
||||
online_host = online.values('host').distinct()
|
||||
online_user = online.values('user').distinct()
|
||||
active_users = User.objects.filter(is_active=1)
|
||||
active_hosts = Asset.objects.filter(is_active=1)
|
||||
|
||||
# percent of dashboard
|
||||
percent_user = format(active_users.count() / users.count(), '.0%')
|
||||
percent_host = format(active_hosts.count() / hosts.count(), '.0%')
|
||||
percent_online_user = format(online_user.count() / users.count(), '.0%')
|
||||
percent_online_host = format(online_host.count() / hosts.count(), '.0%')
|
||||
|
||||
li_date, li_str = getDaysByNum(7)
|
||||
today = datetime.datetime.now().day
|
||||
from_week = datetime.datetime.now() - datetime.timedelta(days=7)
|
||||
week_data = Log.objects.filter(start_time__range=[from_week, datetime.datetime.now()])
|
||||
user_top_ten = week_data.values('user').annotate(times=Count('user')).order_by('-times')[:10]
|
||||
host_top_ten = week_data.values('host').annotate(times=Count('host')).order_by('-times')[:10]
|
||||
user_dic, host_dic = get_data(week_data, user_top_ten, 'user'), get_data(week_data, host_top_ten, 'host')
|
||||
|
||||
# a week data
|
||||
week_users = week_data.values('user').distinct().count()
|
||||
week_hosts = week_data.count()
|
||||
|
||||
user_top_five = week_data.values('user').annotate(times=Count('user')).order_by('-times')[:5]
|
||||
color = ['label-success', 'label-info', 'label-primary', 'label-default', 'label-warnning']
|
||||
|
||||
# perm apply latest 10
|
||||
perm_apply_10 = Apply.objects.order_by('-date_add')[:10]
|
||||
|
||||
# latest 10 login
|
||||
login_10 = Log.objects.order_by('-start_time')[:10]
|
||||
|
||||
# a week top 10
|
||||
for user_info in user_top_ten:
|
||||
username = user_info.get('user')
|
||||
last = Log.objects.filter(user=username).latest('start_time')
|
||||
user_info['last'] = last
|
||||
print user_top_ten
|
||||
|
||||
top = {'user': '娲昏穬鐢ㄦ埛鏁', 'host': '娲昏穬涓绘満鏁', 'times': '鐧诲綍娆℃暟'}
|
||||
top_dic = {}
|
||||
for key, value in top.items():
|
||||
li = []
|
||||
for t in li_date:
|
||||
year, month, day = t.year, t.month, t.day
|
||||
if key != 'times':
|
||||
times = week_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).values(key).distinct().count()
|
||||
else:
|
||||
times = week_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).count()
|
||||
li.append(times)
|
||||
top_dic[value] = li
|
||||
return render_to_response('index.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@require_admin
|
||||
def admin_index(request):
|
||||
user_id = request.session.get('user_id', '')
|
||||
|
@ -194,6 +128,74 @@ def admin_index(request):
|
|||
return render_to_response('index.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
@require_login
|
||||
def index(request):
|
||||
if is_common_user(request):
|
||||
return index_cu(request)
|
||||
|
||||
if is_group_admin(request):
|
||||
return admin_index(request)
|
||||
|
||||
users = User.objects.all()
|
||||
hosts = Asset.objects.all()
|
||||
online = Log.objects.filter(is_finished=0)
|
||||
online_host = online.values('host').distinct()
|
||||
online_user = online.values('user').distinct()
|
||||
active_users = User.objects.filter(is_active=1)
|
||||
active_hosts = Asset.objects.filter(is_active=1)
|
||||
|
||||
# percent of dashboard
|
||||
percent_user = format(active_users.count() / users.count(), '.0%')
|
||||
percent_host = format(active_hosts.count() / hosts.count(), '.0%')
|
||||
percent_online_user = format(online_user.count() / users.count(), '.0%')
|
||||
percent_online_host = format(online_host.count() / hosts.count(), '.0%')
|
||||
|
||||
li_date, li_str = getDaysByNum(7)
|
||||
today = datetime.datetime.now().day
|
||||
from_week = datetime.datetime.now() - datetime.timedelta(days=7)
|
||||
week_data = Log.objects.filter(start_time__range=[from_week, datetime.datetime.now()])
|
||||
user_top_ten = week_data.values('user').annotate(times=Count('user')).order_by('-times')[:10]
|
||||
host_top_ten = week_data.values('host').annotate(times=Count('host')).order_by('-times')[:10]
|
||||
user_dic, host_dic = get_data(week_data, user_top_ten, 'user'), get_data(week_data, host_top_ten, 'host')
|
||||
|
||||
# a week data
|
||||
week_users = week_data.values('user').distinct().count()
|
||||
week_hosts = week_data.count()
|
||||
|
||||
user_top_five = week_data.values('user').annotate(times=Count('user')).order_by('-times')[:5]
|
||||
color = ['label-success', 'label-info', 'label-primary', 'label-default', 'label-warnning']
|
||||
|
||||
# perm apply latest 10
|
||||
perm_apply_10 = Apply.objects.order_by('-date_add')[:10]
|
||||
|
||||
# latest 10 login
|
||||
login_10 = Log.objects.order_by('-start_time')[:10]
|
||||
|
||||
# a week top 10
|
||||
for user_info in user_top_ten:
|
||||
username = user_info.get('user')
|
||||
last = Log.objects.filter(user=username).latest('start_time')
|
||||
user_info['last'] = last
|
||||
print user_top_ten
|
||||
|
||||
top = {'user': '娲昏穬鐢ㄦ埛鏁', 'host': '娲昏穬涓绘満鏁', 'times': '鐧诲綍娆℃暟'}
|
||||
top_dic = {}
|
||||
for key, value in top.items():
|
||||
li = []
|
||||
for t in li_date:
|
||||
year, month, day = t.year, t.month, t.day
|
||||
if key != 'times':
|
||||
times = week_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).values(key).distinct().count()
|
||||
else:
|
||||
times = week_data.filter(start_time__year=year, start_time__month=month, start_time__day=day).count()
|
||||
li.append(times)
|
||||
top_dic[value] = li
|
||||
return render_to_response('index.html', locals(), context_instance=RequestContext(request))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def skin_config(request):
|
||||
return render_to_response('skin_config.html')
|
||||
|
||||
|
|
Loading鈥
Reference in New Issue