Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jumpserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
jumpserver
Commits
60729c49
Commit
60729c49
authored
Mar 07, 2015
by
halcyon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug
parent
d0600662
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
76 additions
and
39 deletions
+76
-39
views.py
jlog/views.py
+4
-4
views.py
jumpserver/views.py
+34
-24
highstock.js
static/js/highcharts/highstock.js
+0
-0
foot_script.html
templates/foot_script.html
+0
-1
index.html
templates/index.html
+5
-0
log_online.html
templates/jlog/log_online.html
+14
-1
index.js
websocket/index.js
+19
-9
No files found.
jlog/views.py
View file @
60729c49
...
...
@@ -20,7 +20,7 @@ def log_list_online(request):
header_title
,
path1
,
path2
=
u'查看日志'
,
u'查看日志'
,
u'在线用户'
web_socket_host
=
CONF
.
get
(
'websocket'
,
'web_socket_host'
)
posts
=
Log
.
objects
.
filter
(
is_finished
=
0
)
.
order_by
(
'-start_time'
)
contact_list
,
p
,
contacts
=
pages
(
posts
,
request
)
contact_list
,
p
,
contacts
,
page_range
,
current_page
=
pages
(
posts
,
request
)
return
render_to_response
(
'jlog/log_online.html'
,
locals
())
...
...
@@ -29,7 +29,7 @@ def log_list_offline(request):
header_title
,
path1
,
path2
=
u'查看日志'
,
u'查看日志'
,
u'历史记录'
web_socket_host
=
CONF
.
get
(
'websocket'
,
'web_socket_host'
)
posts
=
Log
.
objects
.
filter
(
is_finished
=
1
)
.
order_by
(
'-start_time'
)
contact_list
,
p
,
contacts
=
pages
(
posts
,
request
)
contact_list
,
p
,
contacts
,
page_range
,
current_page
=
pages
(
posts
,
request
)
return
render_to_response
(
'jlog/log_offline.html'
,
locals
())
...
...
@@ -60,10 +60,10 @@ def log_search(request):
if
env
==
'online'
:
posts
=
contact_list
=
Log
.
objects
.
filter
(
Q
(
user__contains
=
keyword
)
|
Q
(
host__contains
=
keyword
))
\
.
filter
(
is_finished
=
0
)
.
order_by
(
'-start_time'
)
contact_list
,
p
,
contacts
=
pages
(
posts
,
request
)
contact_list
,
p
,
contacts
,
page_range
,
current_page
=
pages
(
posts
,
request
)
elif
env
==
'offline'
:
posts
=
contact_list
=
Log
.
objects
.
filter
(
Q
(
user__contains
=
keyword
)
|
Q
(
host__contains
=
keyword
))
\
.
filter
(
is_finished
=
1
)
.
order_by
(
'-start_time'
)
contact_list
,
p
,
contacts
=
pages
(
posts
,
request
)
contact_list
,
p
,
contacts
,
page_range
,
current_page
=
pages
(
posts
,
request
)
return
render_to_response
(
'jlog/log_search.html'
,
locals
())
jumpserver/views.py
View file @
60729c49
...
...
@@ -56,40 +56,50 @@ def base(request):
return
render_to_response
(
'base.html'
,
context_instance
=
RequestContext
(
request
))
def
get_data
(
data
,
items
,
option
):
dic
=
{}
li_date
,
li_str
=
getDaysByNum
(
7
)
for
item
in
items
:
li
=
[]
name
=
item
[
option
]
if
option
==
'user'
:
option_data
=
data
.
filter
(
user
=
name
)
elif
option
==
'host'
:
option_data
=
data
.
filter
(
host
=
name
)
for
t
in
li_date
:
year
,
month
,
day
=
t
.
year
,
t
.
month
,
t
.
day
times
=
option_data
.
filter
(
start_time__year
=
year
,
start_time__month
=
month
,
start_time__day
=
day
)
.
count
()
li
.
append
(
times
)
dic
[
name
]
=
li
return
dic
def
index
(
request
):
path1
,
path2
=
u'仪表盘'
,
'Dashboard'
user_dic
,
host_dic
=
{},
{}
users
=
User
.
objects
.
all
()
hosts
=
Asset
.
objects
.
all
()
online_host
=
Log
.
objects
.
filter
(
is_finished
=
0
)
online_user
=
online_host
.
distinct
()
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
]
for
user
in
user_top_ten
:
username
=
user
[
'user'
]
li_user
=
[]
user_data
=
week_data
.
filter
(
user
=
username
)
for
t
in
li_date
:
year
,
month
,
day
=
t
.
year
,
t
.
month
,
t
.
day
times
=
user_data
.
filter
(
start_time__year
=
year
,
start_time__month
=
month
,
start_time__day
=
day
)
.
count
()
li_user
.
append
(
times
)
user_dic
[
username
]
=
li_user
for
host
in
host_top_ten
:
ip
=
host
[
'host'
]
li_host
=
[]
host_data
=
week_data
.
filter
(
host
=
ip
)
user_dic
,
host_dic
=
get_data
(
week_data
,
user_top_ten
,
'user'
),
get_data
(
week_data
,
host_top_ten
,
'host'
)
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
times
=
host_data
.
filter
(
start_time__year
=
year
,
start_time__month
=
month
,
start_time__day
=
day
)
.
count
()
li_host
.
append
(
times
)
host_dic
[
ip
]
=
li_host
users
=
User
.
objects
.
all
()
hosts
=
Asset
.
objects
.
all
()
online_host
=
Log
.
objects
.
filter
(
is_finished
=
0
)
online_user
=
online_host
.
distinct
()
top_dic
=
{
'活跃用户数'
:
[
8
,
10
,
5
,
9
,
8
,
12
,
3
],
'活跃主机数'
:
[
10
,
16
,
20
,
8
,
9
,
5
,
9
],
'登录次数'
:
[
20
,
30
,
35
,
18
,
40
,
38
,
65
]}
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
))
...
...
static/js/highcharts/highstock.js
deleted
100644 → 0
View file @
d0600662
This source diff could not be displayed because it is too large. You can
view the blob
instead.
templates/foot_script.html
View file @
60729c49
...
...
@@ -21,7 +21,6 @@
<!-- highcharts -->
<script
src=
"/static/js/highcharts/highcharts.js"
></script>
<script
src=
"/static/js/highcharts/highstock.js"
></script>
<!-- active menu -->
<script>
...
...
templates/index.html
View file @
60729c49
...
...
@@ -107,6 +107,11 @@ $(function () {
verticalAlign
:
'middle'
,
borderWidth
:
0
},
navigation
:
{
buttonOptions
:
{
align
:
'right'
}
},
series
:
[
{
%
for
k
,
v
in
top_dic
.
items
%
}
{
...
...
templates/jlog/log_online.html
View file @
60729c49
...
...
@@ -8,6 +8,9 @@
.bootstrap-dialog-message
{
background-color
:
rgba
(
0
,
0
,
0
,
0
);
}
.pre-class
{
background-color
:
rgba
(
0
,
0
,
0
,
1
);
}
.modal-content
{
background-color
:
rgba
(
0
,
0
,
0
,
0.6
);
}
...
...
@@ -142,6 +145,7 @@
var
username
=
$
(
'#username'
)[
0
].
innerText
;
var
ip
=
$
(
'#ip'
)[
0
].
innerText
;
BootstrapDialog
.
show
({
message
:
function
(){
var
option
,
exsit_message
;
var
escapeString
=
function
(
html
){
var
elem
=
document
.
createElement
(
'div'
)
var
txt
=
document
.
createTextNode
(
html
)
...
...
@@ -152,14 +156,23 @@
//告诉服务器端有用户登录
socket
.
emit
(
'login'
,
{
userid
:
message
.
id
,
filename
:
message
.
filename
});
socket
.
on
(
'message'
,
function
(
obj
){
option
=
obj
.
option
;
console
.
log
(
option
+
'so'
)
exsit_message
=
obj
.
content
;
console
.
log
(
obj
.
content
)
//去除log中的颜色控制字符
var
regx
=
/
\x
1B
\[([
0-9
]{1,3}((
;
[
0-9
]{1,3})
*
)?)?[
m|K
]
/g
;
// tag.append('
<
p
>
'+escapeString(obj.content.replace(regx,''))+'
<
/p>'
)
;
tag
.
append
(
'<p>'
+
escapeString
(
obj
.
content
)
+
'</p>'
);
if
(
option
==
'new'
)
{
tag
.
append
(
'<p>'
+
escapeString
(
obj
.
content
)
+
'</p>'
);
}
else
if
(
option
==
'exist'
)
{
tag
.
append
(
'<p>'
+
exsit_message
+
'</p>'
);
}
tag
.
animate
({
scrollTop
:
tag
[
0
].
scrollHeight
},
1
);
});
tag
[
0
].
style
.
color
=
"#00FF00"
;
return
tag
[
0
];
}
,
title
:
'Jumpserver实时监控 '
+
' 登录用户名: '
+
'<span class="text-info">'
+
username
+
'</span>'
+
' 登录主机: '
+
'<span class="text-info">'
+
ip
,
onhide
:
function
(){
...
...
websocket/index.js
View file @
60729c49
...
...
@@ -26,19 +26,29 @@ io.on('connection', function(socket){
socket
.
name
=
obj
.
userid
;
socket
.
fileName
=
obj
.
filename
;
var
tail
=
new
Tail
(
obj
.
filename
);
//console.log(obj.filename);
//2015-03-06 当用户打开监控窗口时,会把已存在的文件内容打印出来
var
fs
=
require
(
'fs'
);
fs
.
readFile
(
obj
.
filename
,
'utf8'
,
function
(
err
,
data
)
{
if
(
err
)
{
return
console
.
log
(
err
);
}
var
existData
=
{
userid
:
obj
.
userid
,
username
:
obj
.
username
,
content
:
data
,
option
:
'exist'
};
socket
.
emit
(
'message'
,
existData
);
});
tail
.
on
(
'line'
,
function
(
data
)
{
//console.log(data);
var
newData
=
{
userid
:
obj
.
userid
,
username
:
obj
.
username
,
content
:
data
};
var
newData
=
{
userid
:
obj
.
userid
,
username
:
obj
.
username
,
content
:
data
,
option
:
'new'
};
socket
.
emit
(
'message'
,
newData
);
});
//
var tail = spawn("tail", ['-f', obj.filename]);
//
tail.stdout.on('data',function(data){
//
var content = data.toString();
//
//console.log(content);
//
var newData = {userid:obj.userid,username:obj.username,content:content};
//
socket.emit('message',newData);
//
});
//
var tail = spawn("tail", ['-f', obj.filename]);
//
tail.stdout.on('data',function(data){
//
var content = data.toString();
//
//console.log(content);
//
var newData = {userid:obj.userid,username:obj.username,content:content};
//
socket.emit('message',newData);
//
});
socket
.
tail
=
tail
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment