pull/26/head
ibuler@qq.com 2015-10-27 20:25:18 +08:00
parent 9366003f7b
commit ffab7ae697
6 changed files with 114 additions and 83 deletions

View File

@ -49,7 +49,7 @@ def scriptToJSON(scriptf, timing=None):
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 open(time_file_path) as timef:
timing = getTiming(timef)

View File

@ -6,6 +6,7 @@ urlpatterns = patterns('',
url(r'^$', log_list),
url(r'^log_list/(\w+)/$', log_list),
# 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),
)

View File

@ -9,6 +9,7 @@ from django.http import HttpResponseNotFound
CONF = ConfigParser()
CONF.read('%s/jumpserver.conf' % BASE_DIR)
from jlog.models import Log
from jlog.log_api import renderTemplate
# 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))
# else:
# return HttpResponseNotFound(u'没有此进程!')
#
#
# def log_history(request):
# """ 命令历史记录 """
# log_id = request.GET.get('id', 0)
# log = Log.objects.filter(id=int(log_id))
# if log:
# log = log[0]
# dept_name = log.dept_name
# deptname = get_session_user_info(request)[4]
# if is_group_admin(request) and dept_name != deptname:
# return httperror(request, '查看失败, 您无权查看!')
#
# elif is_common_user(request):
# return httperror(request, '查看失败, 您无权查看!')
#
# log_his = "%s.his" % log.log_path
# if os.path.isfile(log_his):
# f = open(log_his)
# content = f.read()
# return HttpResponse(content)
# else:
# return httperror(request, '无日志记录, 请查看日志处理脚本是否开启!')
#
#
def log_history(request):
""" 命令历史记录 """
log_id = request.GET.get('id', 0)
log = Log.objects.filter(id=int(log_id))
if log:
log = log[0]
log_his = "%s.his" % log.log_path
print log_his
if os.path.isfile(log_his):
f = open(log_his)
content = f.read()
return HttpResponse(content)
else:
return HttpResponse('无日志记录, 请查看日志处理脚本是否开启!')
def log_record(request):
log_id = request.GET.get('id', 0)
log = Log.objects.filter(id=int(log_id))
if log:
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):
# """ 日志搜索 """
# offset = request.GET.get('env', '')

View File

@ -202,7 +202,7 @@ class Jtty(object):
try:
log_file_f = open(log_file_path + '.log', '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:
raise ServerError('Create logfile failed, Please modify %s permission.' % today_connect_log_dir)

View File

@ -1,6 +1,7 @@
{% extends 'base.html' %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<style>
.bootstrap-dialog-body {
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 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">
<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>
<form class="form-inline">
<div class="form-group" id="data_5">
<div class="input-daterange input-group" id="datepicker">
<input type="text" class="input-sm form-control" style="width: 100px;" name="start" value="05/14/2014">
<span class="input-group-addon">to</span>
<input type="text" class="input-sm form-control" style="width: 100px;" name="end" value="05/22/2014">
</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>
</li>
</ul>
</div>
@ -89,9 +96,9 @@
<td class="text-center" id="ip"> {{ post.host }} </td>
<td class="text-center" id="remote_ip"> {{ post.remote_ip }} </td>
{% 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 %}
<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="end_time"> {{ post.end_time|date:"Y-m-d H:i:s" }} </td>
</tr>
@ -110,10 +117,14 @@
</div>
</div>
{#<script src="http://{{ web_socket_host }}/socket.io/socket.io.js"></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 username = $('#username')[0].innerText;
var ip = $('#ip')[0].innerText;
@ -121,17 +132,15 @@
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 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]});
$.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;
});
globalConfig = {
SOCKET_HOST: "{{ web_socket_host }}"
};
function log_search(){
$.ajax({
@ -148,7 +157,16 @@
if(e.keyCode==13){
log_search()
}
})
});
$('#data_5 .input-daterange').datepicker({
keyboardNavigation: false,
forceParse: false,
autoclose: true
});
</script>
{% endblock %}
{% block self_footer_js %}
{% endblock %}

View File

@ -50,19 +50,6 @@
<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><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>
</div>
<br/>
@ -74,6 +61,7 @@
<th class="text-center"> 登录主机 </th>
<th class="text-center"> 来源IP </th>
{% ifnotequal session_role_id 0 %}
<th class="text-center"> 统计命令 </th>
<th class="text-center"> 实时监控 </th>
<th class="text-center"> 阻断 </th>
{% endifnotequal %}
@ -88,6 +76,7 @@
<td id="ip" class="text-center"> {{ post.host }} </td>
<td id="remote_ip" class="text-center"> {{ post.remote_ip }} </td>
{% 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"><input type="button" id="cut" class="btn btn-danger btn-xs" name="cut" value="阻断" onclick='cut("{{ post.pid }}")' /></td>
{% endifnotequal %}
@ -146,7 +135,7 @@
seed = info[1];
}
}
})
});
//告诉服务器端有用户登录
socket.emit('login', {userid:message.id, filename:message.filename,username:username,seed:seed});
@ -168,30 +157,23 @@
});
tag[0].style.color = "#00FF00";
return tag[0];
} ,
title:'Jumpserver实时监控 '+' 登录用户名: '+'<span class="text-info">'+username+'</span>'+' 登录主机: '+'<span class="text-info">'+ip,
onhide:function(){
socket.emit('disconnect');
}});
}
$this.on("click",function(e){
init(e);
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;
})
};
$this.on("click",function(e){
init(e);
return false;
});
};
globalConfig = {
SOCKET_HOST: "{{ web_socket_host }}"
}
$(".monitor").webSocket()
};
$(".monitor").webSocket();
function log_search(){
$.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){
log_search()
}
})
});
});
function cut(num){
var g_url = "/jlog/log_kill/?id="+num;