mirror of https://github.com/jumpserver/jumpserver
some
parent
9366003f7b
commit
ffab7ae697
|
@ -49,7 +49,7 @@ def scriptToJSON(scriptf, timing=None):
|
||||||
return dumps(ret)
|
return dumps(ret)
|
||||||
|
|
||||||
|
|
||||||
def renderTemplate(script_path, time_file_path, dimensions=(24, 60), templatename=DEFAULT_TEMPLATE):
|
def renderTemplate(script_path, time_file_path, dimensions=(24, 80), templatename=DEFAULT_TEMPLATE):
|
||||||
with copen(script_path, encoding='utf-8', errors='replace') as scriptf:
|
with copen(script_path, encoding='utf-8', errors='replace') as scriptf:
|
||||||
with open(time_file_path) as timef:
|
with open(time_file_path) as timef:
|
||||||
timing = getTiming(timef)
|
timing = getTiming(timef)
|
||||||
|
|
|
@ -6,6 +6,7 @@ urlpatterns = patterns('',
|
||||||
url(r'^$', log_list),
|
url(r'^$', log_list),
|
||||||
url(r'^log_list/(\w+)/$', log_list),
|
url(r'^log_list/(\w+)/$', log_list),
|
||||||
# url(r'^log_kill/', log_kill),
|
# url(r'^log_kill/', log_kill),
|
||||||
# url(r'^history/$', log_history),
|
url(r'^history/$', log_history),
|
||||||
|
url(r'^record/$', log_record),
|
||||||
# url(r'^search/$', log_search),
|
# url(r'^search/$', log_search),
|
||||||
)
|
)
|
|
@ -9,6 +9,7 @@ from django.http import HttpResponseNotFound
|
||||||
CONF = ConfigParser()
|
CONF = ConfigParser()
|
||||||
CONF.read('%s/jumpserver.conf' % BASE_DIR)
|
CONF.read('%s/jumpserver.conf' % BASE_DIR)
|
||||||
from jlog.models import Log
|
from jlog.models import Log
|
||||||
|
from jlog.log_api import renderTemplate
|
||||||
|
|
||||||
# def get_user_info(request, offset):
|
# def get_user_info(request, offset):
|
||||||
# """ 获取用户信息及环境 """
|
# """ 获取用户信息及环境 """
|
||||||
|
@ -72,31 +73,38 @@ def log_list(request, offset):
|
||||||
# return render_to_response('jlog/log_offline.html', locals(), context_instance=RequestContext(request))
|
# return render_to_response('jlog/log_offline.html', locals(), context_instance=RequestContext(request))
|
||||||
# else:
|
# else:
|
||||||
# return HttpResponseNotFound(u'没有此进程!')
|
# return HttpResponseNotFound(u'没有此进程!')
|
||||||
#
|
|
||||||
#
|
|
||||||
# def log_history(request):
|
def log_history(request):
|
||||||
# """ 命令历史记录 """
|
""" 命令历史记录 """
|
||||||
# log_id = request.GET.get('id', 0)
|
log_id = request.GET.get('id', 0)
|
||||||
# log = Log.objects.filter(id=int(log_id))
|
log = Log.objects.filter(id=int(log_id))
|
||||||
# if log:
|
if log:
|
||||||
# log = log[0]
|
log = log[0]
|
||||||
# dept_name = log.dept_name
|
log_his = "%s.his" % log.log_path
|
||||||
# deptname = get_session_user_info(request)[4]
|
print log_his
|
||||||
# if is_group_admin(request) and dept_name != deptname:
|
if os.path.isfile(log_his):
|
||||||
# return httperror(request, '查看失败, 您无权查看!')
|
f = open(log_his)
|
||||||
#
|
content = f.read()
|
||||||
# elif is_common_user(request):
|
return HttpResponse(content)
|
||||||
# return httperror(request, '查看失败, 您无权查看!')
|
else:
|
||||||
#
|
return HttpResponse('无日志记录, 请查看日志处理脚本是否开启!')
|
||||||
# log_his = "%s.his" % log.log_path
|
|
||||||
# if os.path.isfile(log_his):
|
|
||||||
# f = open(log_his)
|
def log_record(request):
|
||||||
# content = f.read()
|
log_id = request.GET.get('id', 0)
|
||||||
# return HttpResponse(content)
|
log = Log.objects.filter(id=int(log_id))
|
||||||
# else:
|
if log:
|
||||||
# return httperror(request, '无日志记录, 请查看日志处理脚本是否开启!')
|
log = log[0]
|
||||||
#
|
log_file = log.log_path + '.log'
|
||||||
#
|
log_time = log.log_path + '.time'
|
||||||
|
if os.path.isfile(log_file) and os.path.isfile(log_time):
|
||||||
|
content = renderTemplate(log_file, log_time)
|
||||||
|
return HttpResponse(content)
|
||||||
|
else:
|
||||||
|
return HttpResponse('无日志记录, 请查看日志处理脚本是否开启!')
|
||||||
|
|
||||||
|
|
||||||
# def log_search(request):
|
# def log_search(request):
|
||||||
# """ 日志搜索 """
|
# """ 日志搜索 """
|
||||||
# offset = request.GET.get('env', '')
|
# offset = request.GET.get('env', '')
|
||||||
|
|
|
@ -202,7 +202,7 @@ class Jtty(object):
|
||||||
try:
|
try:
|
||||||
log_file_f = open(log_file_path + '.log', 'a')
|
log_file_f = open(log_file_path + '.log', 'a')
|
||||||
log_time_f = open(log_file_path + '.time', 'a')
|
log_time_f = open(log_file_path + '.time', 'a')
|
||||||
log_res_f = open(log_file_path + '.res', 'a')
|
log_res_f = open(log_file_path + '.his', 'a')
|
||||||
except IOError:
|
except IOError:
|
||||||
raise ServerError('Create logfile failed, Please modify %s permission.' % today_connect_log_dir)
|
raise ServerError('Create logfile failed, Please modify %s permission.' % today_connect_log_dir)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% include 'nav_cat_bar.html' %}
|
{% include 'nav_cat_bar.html' %}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.bootstrap-dialog-body {
|
.bootstrap-dialog-body {
|
||||||
background-color: rgba(0, 0, 0, 0);
|
background-color: rgba(0, 0, 0, 0);
|
||||||
|
@ -51,17 +52,23 @@
|
||||||
<li><a href="/jlog/log_list/online/" class="text-center"><i class="fa fa-laptop"></i> 在线 </a></li>
|
<li><a href="/jlog/log_list/online/" class="text-center"><i class="fa fa-laptop"></i> 在线 </a></li>
|
||||||
<li class="active"><a href="/jlog/log_list/offline/" class="text-center"><i class="fa fa-bar-chart-o"></i> 历史记录 </a></li>
|
<li class="active"><a href="/jlog/log_list/offline/" class="text-center"><i class="fa fa-bar-chart-o"></i> 历史记录 </a></li>
|
||||||
<li style="float: right">
|
<li style="float: right">
|
||||||
<form id="search_form" method="get" action="" class="pull-right mail-search">
|
<form class="form-inline">
|
||||||
<div class="input-group">
|
<div class="form-group" id="data_5">
|
||||||
<input type="text" class="form-control input-sm" id="search_input" name="keyword" placeholder="Search">
|
<div class="input-daterange input-group" id="datepicker">
|
||||||
<input type="text" style="display: none">
|
<input type="text" class="input-sm form-control" style="width: 100px;" name="start" value="05/14/2014">
|
||||||
<div class="input-group-btn">
|
<span class="input-group-addon">to</span>
|
||||||
<button id='search_btn' type="button" class="btn btn-sm btn-primary" onclick="log_search()">
|
<input type="text" class="input-sm form-control" style="width: 100px;" name="end" value="05/22/2014">
|
||||||
Search
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="text" class="form-control input-sm" id="search_input" name="keyword" placeholder="Search">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button id='search_btn' type="button" class="btn btn-sm btn-primary" onclick="log_search()">
|
||||||
|
Search
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -89,9 +96,9 @@
|
||||||
<td class="text-center" id="ip"> {{ post.host }} </td>
|
<td class="text-center" id="ip"> {{ post.host }} </td>
|
||||||
<td class="text-center" id="remote_ip"> {{ post.remote_ip }} </td>
|
<td class="text-center" id="remote_ip"> {{ post.remote_ip }} </td>
|
||||||
{% ifnotequal session_role_id 0 %}
|
{% ifnotequal session_role_id 0 %}
|
||||||
<td class="text-center"><a href="/jlog/history/?id={{ post.id }}" class="log_command"> 命令统计 </td>
|
<td class="text-center"><a href="/jlog/history/?id={{ post.id }}" class="log_command"> 命令统计 </a></td>
|
||||||
{% endifnotequal %}
|
{% endifnotequal %}
|
||||||
<td class="text-center"><a href="/jlog/record/?id={{ post.id }}" class="log_command"> 回放 </td>
|
<td class="text-center"><a value="/jlog/record/?id={{ post.id }}" class="log_record"> 回放 </a></td>
|
||||||
<td class="text-center" id="start_time"> {{ post.start_time|date:"Y-m-d H:i:s"}} </td>
|
<td class="text-center" id="start_time"> {{ post.start_time|date:"Y-m-d H:i:s"}} </td>
|
||||||
<td class="text-center" id="end_time"> {{ post.end_time|date:"Y-m-d H:i:s" }} </td>
|
<td class="text-center" id="end_time"> {{ post.end_time|date:"Y-m-d H:i:s" }} </td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -110,10 +117,14 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{#<script src="http://{{ web_socket_host }}/socket.io/socket.io.js"></script>#}
|
|
||||||
<script>
|
<script>
|
||||||
$('.log_command').on('click',function(){
|
$('.log_record').click(function(){
|
||||||
|
var url = $(this).attr('value');
|
||||||
|
window.open(url, '播放', 'height=500, width=910, top=89px, left=99px,toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.log_command').on('click',function(){
|
||||||
var url = $(this).attr('href');
|
var url = $(this).attr('href');
|
||||||
var username = $('#username')[0].innerText;
|
var username = $('#username')[0].innerText;
|
||||||
var ip = $('#ip')[0].innerText;
|
var ip = $('#ip')[0].innerText;
|
||||||
|
@ -121,17 +132,15 @@
|
||||||
var end_time = $('#end_time')[0].innerText;
|
var end_time = $('#end_time')[0].innerText;
|
||||||
var div_username = ' 用户名: '+'<span class="text-info">'+username+'' + '</span>';
|
var div_username = ' 用户名: '+'<span class="text-info">'+username+'' + '</span>';
|
||||||
var div_ip = ' 主机: '+'<span class="text-info">' + ip + '</span>';
|
var div_ip = ' 主机: '+'<span class="text-info">' + ip + '</span>';
|
||||||
var div_time = ' 开始时间: ' + '<span class="text-info">'+start_time +'</span>' + ' 结束时间: ' +'<span class="text-info">' + end_time + '</span'
|
var div_time = ' 开始时间: ' + '<span class="text-info">'+start_time +'</span>' + ' 结束时间: ' +'<span class="text-info">' + end_time + '</span>';
|
||||||
var title = 'JumpServer命令统计 '+ div_username + div_ip + div_time;
|
var title = 'JumpServer命令统计 '+ div_username + div_ip + div_time;
|
||||||
$.ajax({url:url,success:function(data){
|
$.ajax({url:url,
|
||||||
var tag = $('<div style="height: 500px;overflow: auto;background-color: rgba(0, 0, 0, 0);"></div>').html(data.replace(/\n/g,"<br />"));
|
success:function(data){
|
||||||
BootstrapDialog.show({title: title, message:tag[0]});
|
var tag = $('<div style="height: 500px;overflow: auto;background-color: rgba(0, 0, 0, 0);"></div>').html(data.replace(/\n/g,"<br />"));
|
||||||
|
BootstrapDialog.show({title: title, message:tag[0]});
|
||||||
}});
|
}});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
globalConfig = {
|
|
||||||
SOCKET_HOST: "{{ web_socket_host }}"
|
|
||||||
};
|
|
||||||
|
|
||||||
function log_search(){
|
function log_search(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -148,7 +157,16 @@
|
||||||
if(e.keyCode==13){
|
if(e.keyCode==13){
|
||||||
log_search()
|
log_search()
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
|
$('#data_5 .input-daterange').datepicker({
|
||||||
|
keyboardNavigation: false,
|
||||||
|
forceParse: false,
|
||||||
|
autoclose: true
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
{% block self_footer_js %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -50,19 +50,6 @@
|
||||||
<ul class="nav nav-tabs">
|
<ul class="nav nav-tabs">
|
||||||
<li class="active"><a href="/jlog/log_list/online/" class="text-center"><i class="fa fa-laptop"></i> 在线 </a></li>
|
<li class="active"><a href="/jlog/log_list/online/" class="text-center"><i class="fa fa-laptop"></i> 在线 </a></li>
|
||||||
<li><a href="/jlog/log_list/offline/" class="text-center"><i class="fa fa-bar-chart-o"></i> 历史记录 </a></li>
|
<li><a href="/jlog/log_list/offline/" class="text-center"><i class="fa fa-bar-chart-o"></i> 历史记录 </a></li>
|
||||||
<li style="float: right">
|
|
||||||
<form id="search_form" method="get" action="" class="pull-right mail-search">
|
|
||||||
<div class="input-group">
|
|
||||||
<input type="text" class="form-control input-sm" id="search_input" name="keyword" placeholder="Search">
|
|
||||||
<input type="text" style="display: none">
|
|
||||||
<div class="input-group-btn">
|
|
||||||
<button id='search_btn' type="button" class="btn btn-sm btn-primary" onclick="log_search()">
|
|
||||||
Search
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
|
@ -74,6 +61,7 @@
|
||||||
<th class="text-center"> 登录主机 </th>
|
<th class="text-center"> 登录主机 </th>
|
||||||
<th class="text-center"> 来源IP </th>
|
<th class="text-center"> 来源IP </th>
|
||||||
{% ifnotequal session_role_id 0 %}
|
{% ifnotequal session_role_id 0 %}
|
||||||
|
<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>
|
||||||
{% endifnotequal %}
|
{% endifnotequal %}
|
||||||
|
@ -88,6 +76,7 @@
|
||||||
<td id="ip" class="text-center"> {{ post.host }} </td>
|
<td id="ip" class="text-center"> {{ post.host }} </td>
|
||||||
<td id="remote_ip" class="text-center"> {{ post.remote_ip }} </td>
|
<td id="remote_ip" class="text-center"> {{ post.remote_ip }} </td>
|
||||||
{% ifnotequal session_role_id 0 %}
|
{% ifnotequal session_role_id 0 %}
|
||||||
|
<td class="text-center"><a href="/jlog/history/?id={{ post.id }}" class="log_command"> 命令统计 </a></td>
|
||||||
<td class="text-center"><a class="monitor" filename="{{ post.log_path }}"> 监控 </a></td>
|
<td class="text-center"><a class="monitor" filename="{{ post.log_path }}"> 监控 </a></td>
|
||||||
<td class="text-center"><input type="button" id="cut" class="btn btn-danger btn-xs" name="cut" value="阻断" onclick='cut("{{ post.pid }}")' /></td>
|
<td class="text-center"><input type="button" id="cut" class="btn btn-danger btn-xs" name="cut" value="阻断" onclick='cut("{{ post.pid }}")' /></td>
|
||||||
{% endifnotequal %}
|
{% endifnotequal %}
|
||||||
|
@ -146,7 +135,7 @@
|
||||||
seed = info[1];
|
seed = info[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
//告诉服务器端有用户登录
|
//告诉服务器端有用户登录
|
||||||
socket.emit('login', {userid:message.id, filename:message.filename,username:username,seed:seed});
|
socket.emit('login', {userid:message.id, filename:message.filename,username:username,seed:seed});
|
||||||
|
@ -168,30 +157,23 @@
|
||||||
});
|
});
|
||||||
tag[0].style.color = "#00FF00";
|
tag[0].style.color = "#00FF00";
|
||||||
return tag[0];
|
return tag[0];
|
||||||
|
|
||||||
} ,
|
} ,
|
||||||
title:'Jumpserver实时监控 '+' 登录用户名: '+'<span class="text-info">'+username+'</span>'+' 登录主机: '+'<span class="text-info">'+ip,
|
title:'Jumpserver实时监控 '+' 登录用户名: '+'<span class="text-info">'+username+'</span>'+' 登录主机: '+'<span class="text-info">'+ip,
|
||||||
onhide:function(){
|
onhide:function(){
|
||||||
socket.emit('disconnect');
|
socket.emit('disconnect');
|
||||||
}});
|
}});
|
||||||
}
|
};
|
||||||
$this.on("click",function(e){
|
$this.on("click",function(e){
|
||||||
init(e);
|
init(e);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
$('.log_command').on('click',function(){
|
|
||||||
var url = $(this).attr('href');
|
|
||||||
$.ajax({url:url,success:function(data){
|
|
||||||
BootstrapDialog.show({title:'命令统计',message:data});
|
|
||||||
}});
|
|
||||||
return false;
|
|
||||||
})
|
|
||||||
globalConfig = {
|
globalConfig = {
|
||||||
SOCKET_HOST: "{{ web_socket_host }}"
|
SOCKET_HOST: "{{ web_socket_host }}"
|
||||||
}
|
};
|
||||||
$(".monitor").webSocket()
|
$(".monitor").webSocket();
|
||||||
|
|
||||||
|
|
||||||
function log_search(){
|
function log_search(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -204,11 +186,33 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#search_input").keydown(function(e){
|
$(document).ready(function(){
|
||||||
|
$('.log_command').on('click',function(){
|
||||||
|
var url = $(this).attr('href');
|
||||||
|
var username = $('#username')[0].innerText;
|
||||||
|
var ip = $('#ip')[0].innerText;
|
||||||
|
var start_time = $('#start_time')[0].innerText;
|
||||||
|
var end_time = $('#end_time')[0].innerText;
|
||||||
|
var div_username = ' 用户名: '+'<span class="text-info">'+username+'' + '</span>';
|
||||||
|
var div_ip = ' 主机: '+'<span class="text-info">' + ip + '</span>';
|
||||||
|
var div_time = ' 开始时间: ' + '<span class="text-info">'+start_time +'</span>' + ' 结束时间: ' +'<span class="text-info">' + end_time + '</span>';
|
||||||
|
var title = 'JumpServer命令统计 '+ div_username + div_ip + div_time;
|
||||||
|
$.ajax({url:url,
|
||||||
|
success:function(data){
|
||||||
|
var tag = $('<div style="height: 500px;overflow: auto;background-color: rgba(0, 0, 0, 0);"></div>').html(data.replace(/\n/g,"<br />"));
|
||||||
|
BootstrapDialog.show({title: title, message:tag[0]});
|
||||||
|
}});
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#search_input").keydown(function(e){
|
||||||
if(e.keyCode==13){
|
if(e.keyCode==13){
|
||||||
log_search()
|
log_search()
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function cut(num){
|
function cut(num){
|
||||||
var g_url = "/jlog/log_kill/?id="+num;
|
var g_url = "/jlog/log_kill/?id="+num;
|
||||||
|
|
Loading…
Reference in New Issue