Browse Source

bugs

pull/6/head
halcyon 10 years ago
parent
commit
da4d6b85fc
  1. 2
      jlog/urls.py
  2. 82
      jlog/views.py
  3. 0
      nohup.out
  4. 0
      websocket/nohup.out

2
jlog/urls.py

@ -5,7 +5,7 @@ from jlog.views import *
urlpatterns = patterns('',
url(r'^$', log_list),
url(r'^log_list/(\w+)/$', log_list),
url(r'^log_kill/(\d+)', log_kill),
url(r'^log_kill/', log_kill),
url(r'^history/$', log_history),
url(r'^search/$', log_search),
)

82
jlog/views.py

@ -13,13 +13,27 @@ from connect import BASE_DIR
from jlog.models import Log
from jumpserver.views import pages
from juser.models import User, DEPT
from jumpserver.api import get_user_dept, is_super_user, is_group_admin, is_common_user, require_admin, require_login
from jumpserver.api import *
from jasset.views import httperror
CONF = ConfigParser.ConfigParser()
CONF = ConfigParser()
CONF.read('%s/jumpserver.conf' % BASE_DIR)
def get_user_log(request, keyword, env, username, dept_name):
def get_user_info(request, offset):
env_dic = {'online': 0, 'offline': 1}
env = env_dic[offset]
keyword = request.GET.get('keyword', '')
user_info = get_session_user_info(request)
user_id, username = user_info[0:2]
dept_id, dept_name = user_info[3:5]
ret = [request, keyword, env, username, dept_name]
return ret
def get_user_log(ret_list):
request, keyword, env, username, dept_name = ret_list
if is_super_user(request):
if keyword:
posts = Log.objects.filter(Q(user__contains=keyword) | Q(host__contains=keyword)) \
@ -47,23 +61,23 @@ def get_user_log(request, keyword, env, username, dept_name):
def log_list(request, offset):
header_title, path1, path2 = u'查看日志', u'查看日志', u'在线用户'
web_socket_host = CONF.get('websocket', 'web_socket_host')
env_dic = {'online': 0, 'offline': 1}
env = env_dic[offset]
keyword = request.GET.get('keyword')
dept_id = get_user_dept(request)
dept_name = DEPT.objects.get(id=dept_id).name
user_id = request.session.get('user_id')
username = User.objects.get(id=user_id).username
posts = get_user_log(request, keyword, env, username, dept_name)
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_%s.html' % offset, locals(), context_instance=RequestContext(request))
@require_admin
def log_kill(request, offset):
pid = offset
if pid:
def log_kill(request):
pid = request.GET.get('id', '')
log = Log.objects.filter(pid=pid)
if log:
pid = log.pid
dept_name = log.dept_name
deptname = get_session_user_info(request)[4]
if is_group_admin(request) and dept_name != deptname:
return httperror(request, 'Kill失败, 您无权操作!')
os.kill(int(pid), 9)
Log.objects.filter(pid=pid).update(is_finished=1, end_time=datetime.now())
return HttpResponseRedirect('jlog/log_offline.html', locals(), context_instance=RequestContext(request))
@ -71,28 +85,30 @@ def log_kill(request, offset):
@require_login
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)
log_id = request.GET.get('id', 0)
log = Log.objects.filter(id=int(log_id))
if log:
log = log.first()
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, '无日志记录, 请查看日志处理脚本是否开启!')
@require_login
def log_search(request):
keyword = request.GET.get('keyword')
offset = request.GET.get('env')
dept_id = get_user_dept(request)
dept_name = DEPT.objects.get(id=dept_id).name
user_id = request.session.get('user_id')
username = User.objects.get(id=user_id).username
env_dic = {'online': 0, 'offline': 1}
env = env_dic[offset]
posts = get_user_log(request, keyword, env, username, dept_name)
offset = request.GET.get('env', '')
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))

0
websocket/nohup.out

Loading…
Cancel
Save