From 10bcae7cf0a752e079d1bef5d5075395f02b978a Mon Sep 17 00:00:00 2001
From: halcyon <864072399@qq.com>
Date: Tue, 10 Mar 2015 18:27:47 +0800
Subject: [PATCH 1/5] dashboard
---
jumpserver/api.py | 12 ++++++
jumpserver/urls.py | 2 +-
jumpserver/views.py | 4 --
templates/index.html | 98 +++++++++-----------------------------------
4 files changed, 33 insertions(+), 83 deletions(-)
diff --git a/jumpserver/api.py b/jumpserver/api.py
index b4fd70b55..07b5dd463 100644
--- a/jumpserver/api.py
+++ b/jumpserver/api.py
@@ -1,7 +1,12 @@
__author__ = 'guanghongwei'
+import json
+
+from django.http import HttpResponse
+
from juser.models import User, UserGroup
from jasset.models import Asset, BisGroup
+from jlog.models import Log
def user_perm_group_api(user):
@@ -46,3 +51,10 @@ def asset_perm_api(asset):
user_permed_list.extend(user_group.user_set.all())
return user_permed_list
+
+def api_user(request):
+ hosts = Log.objects.filter(is_finished=0).count()
+ users = Log.objects.filter(is_finished=0).values('user').distinct().count()
+ ret = {'users': users, 'hosts': hosts}
+ json_data = json.dumps(ret)
+ return HttpResponse(json_data)
diff --git a/jumpserver/urls.py b/jumpserver/urls.py
index 80fc8cf5b..86773da4f 100644
--- a/jumpserver/urls.py
+++ b/jumpserver/urls.py
@@ -6,7 +6,7 @@ urlpatterns = patterns('',
# url(r'^$', 'jumpserver.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
(r'^$', 'jumpserver.views.index'),
- (r'^api/user/$', 'jumpserver.views.api_user'),
+ (r'^api/user/$', 'jumpserver.api.api_user'),
(r'^skin_config/$', 'jumpserver.views.skin_config'),
(r'^install/$', 'jumpserver.views.install'),
(r'^base/$', 'jumpserver.views.base'),
diff --git a/jumpserver/views.py b/jumpserver/views.py
index 09afd48fa..991fc1c60 100644
--- a/jumpserver/views.py
+++ b/jumpserver/views.py
@@ -103,10 +103,6 @@ def index(request):
return render_to_response('index.html', locals(), context_instance=RequestContext(request))
-def api_user(request):
- users = Log.objects.filter(is_finished=0).count()
- ret = {'users': users}
- return HttpResponse(json.dumps(ret))
def skin_config(request):
diff --git a/templates/index.html b/templates/index.html
index d676a84e7..4bfd2e4e1 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -35,10 +35,10 @@
Today
-
在线用户
+ 实时在线用户
@@ -52,7 +52,7 @@
已连接服务器
@@ -208,85 +208,27 @@ $(function () {
]
});
-
- $(document).ready(function() {
- Highcharts.setOptions({
- global: {
- useUTC: false
+ function magic_number(value, id) {
+ var num = $("#"+id);
+ num.animate({count: value}, {
+ duration: 500,
+ step: function() {
+ num.text(String(parseInt(this.count)));
}
});
+ };
- var chart;
- $('#dynamic').highcharts({
- chart: {
- type: 'spline',
- animation: Highcharts.svg, // don't animate in old IE
- marginRight: 10,
- events: {
- load: function () {
- var series = this.series[0];
- setInterval(function () {
- jQuery.getJSON('api/user/', function (data) {
- var users = data.users;
- var x = (new Date()).getTime(), // current time
- y = users;
- console.log(users)
- series.addPoint([x, y], true, true);
- });
- }, 3000);
- }
- }
- },
- title: {
- text: '实时在线用户统计'
- },
- xAxis: {
- type: 'datetime',
- tickPixelInterval: 150
- },
- yAxis: {
- min: 0,
- title: {
- text: '用户数量'
- },
- plotLines: [{
- value: 0,
- width: 1,
- color: '#808080'
- }]
- },
- tooltip: {
- formatter: function() {
- return ''+ this.series.name +'
'+
- Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) +'
'+
- Highcharts.numberFormat(this.y);
- }
- },
- legend: {
- enabled: false
- },
- exporting: {
- enabled: false
- },
- series: [{
- name: '实时在线用户数量',
- data: (function() {
- // generate an array of random data
- var data = [],
- time = (new Date()).getTime(),
- i;
-
- for (i = -19; i <= 0; i++) {
- data.push({
- x: time + i * 1000,
- y: 0
- });
- }
- return data;
- })()
- }]
+ function update() {
+ $.getJSON('api/user/', function(data) {
+ var users = data.users;
+ var hosts = data.hosts;
+ magic_number(users, 'online_users');
+ magic_number(hosts, 'online_hosts')
});
- });
+ };
+
+ setInterval(update, 1000); //5秒钟执行一次
+ update();
});
From 75f06f9b62d580fe3dc495e239377abb5ae0e7a5 Mon Sep 17 00:00:00 2001
From: halcyon <864072399@qq.com>
Date: Wed, 11 Mar 2015 18:29:47 +0800
Subject: [PATCH 2/5] bugs
---
docs/AddUserAsset.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/docs/AddUserAsset.py b/docs/AddUserAsset.py
index b1750caf6..81748de68 100644
--- a/docs/AddUserAsset.py
+++ b/docs/AddUserAsset.py
@@ -108,13 +108,13 @@ def test_add_log():
if __name__ == '__main__':
- test_add_asset()
- test_add_dept()
- test_add_group()
- test_add_user()
- test_add_idc()
- test_add_asset_group()
- test_add_asset()
+ #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()
From fd490bd685d84f0338978ff3a9e43d6da2e4ec80 Mon Sep 17 00:00:00 2001
From: halcyon <864072399@qq.com>
Date: Thu, 12 Mar 2015 11:03:53 +0800
Subject: [PATCH 3/5] bugs
---
jasset/urls.py | 1 +
jasset/views.py | 44 ++++++++++++++++++++++++++----
jlog/views.py | 2 ++
jumpserver/views.py | 4 +--
templates/index.html | 38 ++++++++------------------
templates/jasset/group_detail.html | 6 ++++
templates/jasset/host_search.html | 40 ++++++++++++++++++++++++++-
templates/jasset/idc_add.html | 33 ++++++++++++++++++++--
templates/jasset/idc_list.html | 1 +
templates/jlog/log_online.html | 3 +-
templates/jlog/log_search.html | 22 ++-------------
templates/paginator.html | 34 +++++++++++++++++++++++
12 files changed, 169 insertions(+), 59 deletions(-)
diff --git a/jasset/urls.py b/jasset/urls.py
index 602ed6a69..ae8b89612 100644
--- a/jasset/urls.py
+++ b/jasset/urls.py
@@ -11,6 +11,7 @@ urlpatterns = patterns('',
url(r"^(\d+.\d+.\d+.\d+)/$", jlist_ip),
url(r'^idc_add/$', add_idc),
url(r'^idc_list/$', list_idc),
+ url(r'^idc_edit/$', edit_idc),
url(r'^idc_detail/$', detail_idc),
url(r'^idc_del/(\w+)/$', del_idc),
url(r'^jgroup_add/$', add_group),
diff --git a/jasset/views.py b/jasset/views.py
index 2b8b4bbda..c0e5e1805 100644
--- a/jasset/views.py
+++ b/jasset/views.py
@@ -143,10 +143,18 @@ def batch_host_edit(request):
def list_host(request):
header_title, path1, path2 = u'查看主机', u'资产管理', u'查看主机'
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
- posts = Asset.objects.all().order_by('ip')
- contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
+ keyword = request.GET.get('keyword', '')
+ 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')
+ 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))
+ return render_to_response('jasset/host_list.html', locals(), context_instance=RequestContext(request))
+ 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))
def host_del(request, offset):
@@ -250,6 +258,34 @@ def list_idc(request):
return render_to_response('jasset/idc_list.html', locals(), context_instance=RequestContext(request))
+def edit_idc(request):
+ header_title, path1, path2 = u'编辑IDC', u'资产管理', u'编辑IDC'
+ edit = 1
+ idc_id = request.GET.get('id')
+ j_idc = IDC.objects.get(id=idc_id)
+ default = IDC.objects.get(name='默认').asset_set.all()
+ eposts = contact_list = Asset.objects.filter(idc=j_idc).order_by('ip')
+ posts = [g for g in default if g not in eposts]
+ if request.method == 'POST':
+ j_group = request.POST.get('j_idc')
+ j_hosts = request.POST.getlist('j_hosts')
+ j_comment = request.POST.get('j_comment')
+ idc_default = request.POST.getlist('idc_default')
+
+ for host in j_hosts:
+ g = Asset.objects.get(id=host)
+ Asset.objects.filter(id=host).update(idc=j_idc)
+
+ for host in idc_default:
+ g = Asset.objects.get(id=host)
+ i = IDC.objects.get(name='默认')
+ Asset.objects.filter(id=host).update(idc=i)
+
+ return HttpResponseRedirect('/jasset/idc_detail/?id=%s' % idc_id)
+
+ return render_to_response('jasset/idc_add.html', locals(), context_instance=RequestContext(request))
+
+
def del_idc(request, offset):
if offset == 'multi':
len_list = request.POST.get("len_list")
@@ -374,8 +410,6 @@ def group_del(request, offset):
return HttpResponseRedirect('/jasset/jgroup_list/')
-
-
def host_search(request):
keyword = request.GET.get('keyword')
login_types = {'L': 'LDAP', 'S': 'SSH_KEY', 'P': 'PASSWORD', 'M': 'MAP'}
diff --git a/jlog/views.py b/jlog/views.py
index 62a7071a0..eb5f636e6 100644
--- a/jlog/views.py
+++ b/jlog/views.py
@@ -18,6 +18,7 @@ CONF.read('%s/jumpserver.conf' % BASE_DIR)
def log_list_online(request):
header_title, path1, path2 = u'查看日志', u'查看日志', u'在线用户'
+ keyword = request.GET.get('keyword')
web_socket_host = CONF.get('websocket', 'web_socket_host')
posts = Log.objects.filter(is_finished=0).order_by('-start_time')
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
@@ -27,6 +28,7 @@ def log_list_online(request):
def log_list_offline(request):
header_title, path1, path2 = u'查看日志', u'查看日志', u'历史记录'
+ keyword = request.GET.get('keyword')
web_socket_host = CONF.get('websocket', 'web_socket_host')
posts = Log.objects.filter(is_finished=1).order_by('-start_time')
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
diff --git a/jumpserver/views.py b/jumpserver/views.py
index 991fc1c60..66a474d73 100644
--- a/jumpserver/views.py
+++ b/jumpserver/views.py
@@ -45,7 +45,7 @@ def getDaysByNum(num):
for i in range(0, num):
today = today-oneday
li_date.append(today)
- li_str.append(str(today)[0:10])
+ li_str.append(str(today)[5:10])
li_date.reverse()
li_str.reverse()
t = (li_date, li_str)
@@ -103,8 +103,6 @@ def index(request):
return render_to_response('index.html', locals(), context_instance=RequestContext(request))
-
-
def skin_config(request):
return render_to_response('skin_config.html')
diff --git a/templates/index.html b/templates/index.html
index 4bfd2e4e1..14e55a745 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -58,12 +58,13 @@
-
-
-
-
-
-
+
+
@@ -71,8 +72,11 @@
var cate = {{ li_str|safe }};
$(function () {
$('#top10').highcharts({
+ chart: {
+ type: 'column'
+ },
title: {
- text: '数据总览',
+ text: '一周数据总览',
x: -20 //center
},
subtitle: {
@@ -101,12 +105,6 @@ $(function () {
tooltip: {
valueSuffix: '次'
},
- legend: {
- layout: 'vertical',
- align: 'right',
- verticalAlign: 'middle',
- borderWidth: 0
- },
navigation: {
buttonOptions: {
align: 'right'
@@ -149,12 +147,6 @@ $(function () {
tooltip: {
valueSuffix: '次'
},
- legend: {
- layout: 'vertical',
- align: 'right',
- verticalAlign: 'middle',
- borderWidth: 0
- },
series: [
{% for k,v in user_dic.items %}
{
@@ -192,12 +184,6 @@ $(function () {
tooltip: {
valueSuffix: '次'
},
- legend: {
- layout: 'vertical',
- align: 'right',
- verticalAlign: 'middle',
- borderWidth: 0
- },
series: [
{% for k,v in host_dic.items %}
{
@@ -227,7 +213,7 @@ $(function () {
});
};
- setInterval(update, 1000); //5秒钟执行一次
+ setInterval(update, 5000); //5秒钟执行一次
update();
});
diff --git a/templates/jasset/group_detail.html b/templates/jasset/group_detail.html
index bcbf367b7..5e30a50f5 100644
--- a/templates/jasset/group_detail.html
+++ b/templates/jasset/group_detail.html
@@ -88,6 +88,9 @@
Previous
{% endif %}
+ {% ifequal show_first 1 %}
+ 1...
+ {% endifequal %}
{% for page in page_range %}
{% ifequal current_page page %}
{{ page }}
@@ -95,6 +98,9 @@
{{ page }}
{% endifequal %}
{% endfor %}
+ {% ifequal show_end 1 %}
+ ...{{ p.num_pages }}
+ {% endifequal %}
{% if contacts.has_next %}
Next
diff --git a/templates/jasset/host_search.html b/templates/jasset/host_search.html
index 11fe6ce14..1436b20cd 100644
--- a/templates/jasset/host_search.html
+++ b/templates/jasset/host_search.html
@@ -40,7 +40,45 @@
- {% include 'paginator.html' %}
+
+