mirror of https://github.com/jumpserver/jumpserver
修复log kill和在线查看命令统计
parent
e4ccb1c43f
commit
a0a7623743
|
@ -6,8 +6,6 @@ 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'^history/$', log_history),
|
url(r'^history/$', log_history),
|
||||||
# url(r'^log_kill/', log_kill),
|
url(r'^log_kill/', log_kill),
|
||||||
url(r'^record/$', log_record),
|
url(r'^record/$', log_record),
|
||||||
url(r'^search/$', log_search),
|
|
||||||
url(r'^monitor/$', log_monitor),
|
|
||||||
)
|
)
|
|
@ -11,10 +11,12 @@ from models import Log
|
||||||
from jumpserver.settings import web_socket_host
|
from jumpserver.settings import web_socket_host
|
||||||
|
|
||||||
|
|
||||||
|
web_socket_host = 'ws://j:8080/monitor'
|
||||||
|
|
||||||
|
|
||||||
def log_list(request, offset):
|
def log_list(request, offset):
|
||||||
""" 显示日志 """
|
""" 显示日志 """
|
||||||
header_title, path1, path2 = u'查看日志', u'查看日志', u'在线用户'
|
header_title, path1, path2 = u'查看日志', u'查看日志', u'在线用户'
|
||||||
# posts = get_user_log(get_user_info(request, offset))
|
|
||||||
date_seven_day = request.GET.get('start', '')
|
date_seven_day = request.GET.get('start', '')
|
||||||
date_now_str = request.GET.get('end', '')
|
date_now_str = request.GET.get('end', '')
|
||||||
username_list = request.GET.getlist('username', [])
|
username_list = request.GET.getlist('username', [])
|
||||||
|
@ -29,22 +31,18 @@ def log_list(request, offset):
|
||||||
ip_all = set([log.host for log in Log.objects.all()])
|
ip_all = set([log.host for log in Log.objects.all()])
|
||||||
|
|
||||||
if date_seven_day and date_now_str:
|
if date_seven_day and date_now_str:
|
||||||
datetime_start = datetime.datetime.strptime(date_seven_day, '%m/%d/%Y %H:%M:%S')
|
datetime_start = datetime.datetime.strptime(date_seven_day + ' 00:00:01', '%m/%d/%Y %H:%M:%S')
|
||||||
datetime_end = datetime.datetime.strptime(date_now_str, '%m/%d/%Y %H:%M:%S')
|
datetime_end = datetime.datetime.strptime(date_now_str + ' 23:59:59', '%m/%d/%Y %H:%M:%S')
|
||||||
posts = posts.filter(start_time__gte=datetime_start).filter(start_time__lte=datetime_end)
|
posts = posts.filter(start_time__gte=datetime_start).filter(start_time__lte=datetime_end)
|
||||||
|
|
||||||
if username_list:
|
if username_list:
|
||||||
print username_list
|
|
||||||
posts = posts.filter(user__in=username_list)
|
posts = posts.filter(user__in=username_list)
|
||||||
|
|
||||||
if host_list:
|
if host_list:
|
||||||
posts = posts.filter(host__in=host_list)
|
posts = posts.filter(host__in=host_list)
|
||||||
print posts
|
|
||||||
if cmd:
|
if cmd:
|
||||||
log_id_list = set([log.log_id for log in TtyLog.objects.filter(cmd__contains=cmd)])
|
log_id_list = set([log.log_id for log in TtyLog.objects.filter(cmd__contains=cmd)])
|
||||||
print [post.id for post in posts]
|
|
||||||
posts = posts.filter(id__in=log_id_list)
|
posts = posts.filter(id__in=log_id_list)
|
||||||
print posts
|
|
||||||
else:
|
else:
|
||||||
date_now = datetime.datetime.now()
|
date_now = datetime.datetime.now()
|
||||||
date_now_str = date_now.strftime('%m/%d/%Y')
|
date_now_str = date_now.strftime('%m/%d/%Y')
|
||||||
|
@ -52,27 +50,24 @@ def log_list(request, offset):
|
||||||
|
|
||||||
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
|
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
|
||||||
|
|
||||||
|
web_socket_uri = web_socket_host
|
||||||
return render_to_response('jlog/log_%s.html' % offset, locals(), context_instance=RequestContext(request))
|
return render_to_response('jlog/log_%s.html' % offset, locals(), context_instance=RequestContext(request))
|
||||||
|
|
||||||
#
|
|
||||||
# def log_kill(request):
|
def log_kill(request):
|
||||||
# """ 杀掉connect进程 """
|
""" 杀掉connect进程 """
|
||||||
# pid = request.GET.get('id', '')
|
pid = request.GET.get('id', '')
|
||||||
# log = Log.objects.filter(pid=pid)
|
log = Log.objects.filter(pid=pid)
|
||||||
# if log:
|
if log:
|
||||||
# log = log[0]
|
log = log[0]
|
||||||
# dept_name = log.dept_name
|
try:
|
||||||
# deptname = get_session_user_info(request)[4]
|
os.kill(int(pid), 9)
|
||||||
# if is_group_admin(request) and dept_name != deptname:
|
except OSError:
|
||||||
# return httperror(request, u'Kill失败, 您无权操作!')
|
pass
|
||||||
# try:
|
Log.objects.filter(pid=pid).update(is_finished=1, end_time=datetime.datetime.now())
|
||||||
# os.kill(int(pid), 9)
|
return render_to_response('jlog/log_offline.html', locals(), context_instance=RequestContext(request))
|
||||||
# except OSError:
|
else:
|
||||||
# pass
|
return HttpResponseNotFound(u'没有此进程!')
|
||||||
# Log.objects.filter(pid=pid).update(is_finished=1, end_time=datetime.datetime.now())
|
|
||||||
# return render_to_response('jlog/log_offline.html', locals(), context_instance=RequestContext(request))
|
|
||||||
# else:
|
|
||||||
# return HttpResponseNotFound(u'没有此进程!')
|
|
||||||
|
|
||||||
|
|
||||||
def log_history(request):
|
def log_history(request):
|
||||||
|
@ -106,19 +101,4 @@ def log_record(request):
|
||||||
return HttpResponse('无日志记录, 请查看日志处理脚本是否开启!')
|
return HttpResponse('无日志记录, 请查看日志处理脚本是否开启!')
|
||||||
|
|
||||||
|
|
||||||
def log_search(request):
|
|
||||||
print request.GET
|
|
||||||
return render_to_response('jlog/log_filter.html', locals())
|
|
||||||
|
|
||||||
|
|
||||||
def log_monitor(request):
|
|
||||||
return my_render('jlog/log_monitor.html', locals(), request)
|
|
||||||
|
|
||||||
|
|
||||||
# def log_search(request):
|
|
||||||
# """ 日志搜索 """
|
|
||||||
# offset = request.GET.get('env', '')
|
|
||||||
# keyword = request.GET.get('keyword', '')
|
|
||||||
# posts = get_user_log(get_user_info(request, offset))
|
|
||||||
# contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
|
|
||||||
# return render_to_response('jlog/log_search.html', locals(), context_instance=RequestContext(request))
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
background-color: rgba(0, 0, 0, 0);
|
background-color: rgba(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
.bootstrap-dialog-message {
|
.bootstrap-dialog-message {
|
||||||
background-color: rgba(0, 0, 0, 0);
|
color: #00FF00;
|
||||||
}
|
}
|
||||||
.modal-content {
|
.modal-content {
|
||||||
background-color: rgba(0, 0, 0, 0.6);
|
background-color: rgba(0, 0, 0, 0.6);
|
||||||
|
@ -27,9 +27,7 @@
|
||||||
.modal-header {
|
.modal-header {
|
||||||
background-color: #FFFFFF;
|
background-color: #FFFFFF;
|
||||||
}
|
}
|
||||||
.bootstrap-dialog-message {
|
|
||||||
color: #00FF00;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="wrapper wrapper-content animated fadeInRight">
|
<div class="wrapper wrapper-content animated fadeInRight">
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
background-color: rgba(0, 0, 0, 0);
|
background-color: rgba(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
.bootstrap-dialog-message {
|
.bootstrap-dialog-message {
|
||||||
background-color: rgba(0, 0, 0, 0);
|
color: #00FF00;
|
||||||
}
|
}
|
||||||
.pre-class {
|
.pre-class {
|
||||||
background-color: rgba(0, 0, 0, 1);
|
background-color: rgba(0, 0, 0, 1);
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
<td class="text-center"><a class="monitor" file_path="{{ post.log_path }}"> 监控 </a></td>
|
<td class="text-center"><a class="monitor" file_path="{{ 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 %}
|
||||||
<td class="text-center"> {{ 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>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -108,8 +108,8 @@
|
||||||
|
|
||||||
function init(obj){
|
function init(obj){
|
||||||
var file_path = obj.attr('file_path');
|
var file_path = obj.attr('file_path');
|
||||||
console.log(file_path);
|
var wsUri = '{{ web_socket_uri }}';
|
||||||
var socket = new WebSocket('ws://j:8080/monitor?file_path='+file_path);
|
var socket = new WebSocket(wsUri + '?file_path=' + file_path);
|
||||||
socket.onopen = function(evt){
|
socket.onopen = function(evt){
|
||||||
socket.send(file_path)
|
socket.send(file_path)
|
||||||
};
|
};
|
||||||
|
@ -159,30 +159,16 @@
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('.monitor').click(function(){
|
$('.monitor').click(function(){
|
||||||
init($(this))
|
init($(this))
|
||||||
})
|
|
||||||
});
|
|
||||||
|
|
||||||
function log_search(){
|
|
||||||
$.ajax({
|
|
||||||
type: "GET",
|
|
||||||
url: "/jlog/search/?env=online",
|
|
||||||
data: $("#search_form").serialize(),
|
|
||||||
success: function (data) {
|
|
||||||
$(".tab-content").html(data);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
$(document).ready(function(){
|
$('.log_command').on('click',function(){
|
||||||
$('.log_command').on('click',function(){
|
|
||||||
var url = $(this).attr('href');
|
var url = $(this).attr('href');
|
||||||
var username = $('#username')[0].innerText;
|
var username = $(this).closest('tr').find('#username').text();
|
||||||
var ip = $('#ip')[0].innerText;
|
var ip = $(this).closest('tr').find('#ip').text();
|
||||||
var start_time = $('#start_time')[0].innerText;
|
var start_time = $(this).closest('tr').find('#start_time').text();
|
||||||
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>';
|
||||||
var title = 'JumpServer命令统计 '+ div_username + div_ip + div_time;
|
var title = 'JumpServer命令统计 '+ div_username + div_ip + div_time;
|
||||||
$.ajax({url:url,
|
$.ajax({url:url,
|
||||||
success:function(data){
|
success:function(data){
|
||||||
|
@ -191,16 +177,18 @@
|
||||||
}});
|
}});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#search_input").keydown(function(e){
|
|
||||||
if(e.keyCode==13){
|
|
||||||
log_search()
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$('')
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
{# function log_search(){#}
|
||||||
|
{# $.ajax({#}
|
||||||
|
{# type: "GET",#}
|
||||||
|
{# url: "/jlog/search/?env=online",#}
|
||||||
|
{# data: $("#search_form").serialize(),#}
|
||||||
|
{# success: function (data) {#}
|
||||||
|
{# $(".tab-content").html(data);#}
|
||||||
|
{# }#}
|
||||||
|
{# });#}
|
||||||
|
{# }#}
|
||||||
|
|
||||||
|
|
||||||
function cut(num){
|
function cut(num){
|
||||||
|
@ -209,7 +197,6 @@
|
||||||
type: "GET",
|
type: "GET",
|
||||||
url: g_url,
|
url: g_url,
|
||||||
success: window.open("/jlog/log_list/online/", "_self")
|
success: window.open("/jlog/log_list/online/", "_self")
|
||||||
// error: window.open(g_url, "_self")
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue