You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jumpserver/jlog/views.py

82 lines
3.2 KiB

# coding:utf-8
import os
import ConfigParser
from datetime import datetime
10 years ago
from django.db.models import Q
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
10 years ago
from connect import BASE_DIR
from jlog.models import Log
10 years ago
from jumpserver.views import pages
CONF = ConfigParser.ConfigParser()
CONF.read('%s/jumpserver.conf' % BASE_DIR)
10 years ago
def log_list_online(request):
10 years ago
header_title, path1, path2 = u'查看日志', u'查看日志', u'在线用户'
10 years ago
keyword = request.GET.get('keyword')
10 years ago
web_socket_host = CONF.get('websocket', 'web_socket_host')
10 years ago
if keyword:
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, page_range, current_page, show_first, show_end = pages(posts, request)
else:
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)
10 years ago
return render_to_response('jlog/log_online.html', locals())
def log_list_offline(request):
10 years ago
header_title, path1, path2 = u'查看日志', u'查看日志', u'历史记录'
10 years ago
keyword = request.GET.get('keyword')
web_socket_host = CONF.get('websocket', 'web_socket_host')
10 years ago
if keyword:
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, page_range, current_page, show_first, show_end = pages(posts, request)
else:
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)
10 years ago
return render_to_response('jlog/log_offline.html', locals())
10 years ago
def log_kill(request, offset):
pid = offset
if pid:
os.kill(int(pid), 9)
Log.objects.filter(pid=pid).update(is_finished=1, end_time=datetime.now())
10 years ago
return HttpResponseRedirect('jlog/log_offline.html', locals())
def log_history(request):
if request.method == 'GET':
id = request.GET.get('id', 0)
log = Log.objects.get(id=int(id))
if log:
log_his = "%s.his" % log.log_path
if os.path.isfile(log_his):
f = open(log_his)
content = f.read()
return HttpResponse(content)
def log_search(request):
keyword = request.GET.get('keyword')
env = request.GET.get('env')
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')
10 years ago
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
10 years ago
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')
10 years ago
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
10 years ago
return render_to_response('jlog/log_search.html', locals())