From 9e1dd270aea73fad064e4dd8fbe2dde3ca58bfa5 Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Tue, 17 Mar 2015 13:56:43 +0800 Subject: [PATCH] bugs --- connect.py | 9 ++++++++- jasset/views.py | 7 ++----- jlog/models.py | 1 + jlog/views.py | 9 +++++---- jumpserver.conf | 10 +++++----- templates/jlog/log_online.html | 4 ++-- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/connect.py b/connect.py index 0c6e8134d..9eab35dc5 100755 --- a/connect.py +++ b/connect.py @@ -3,6 +3,7 @@ import socket import sys import os +import ast import select import time from datetime import datetime @@ -103,6 +104,12 @@ def log_record(username, host): log_filename = '%s_%s_%s.log' % (username, host, time_now) log_file_path = os.path.join(today_connect_log_dir, log_filename) pid = os.getpid() + ip_list = [] + remote_ip = os.popen("who |grep `ps aux |gawk '{if ($2==%s) print $1}'` |gawk '{print $5}'|tr -d '()'" % pid).readlines() + for ip in remote_ip: + ip_list.append(ip.strip('\n')) + print ip_list + ip_list = list(set(ip_list)) if not os.path.isdir(today_connect_log_dir): try: @@ -116,7 +123,7 @@ def log_record(username, host): except IOError: raise ServerError('Create logfile failed, Please modify %s permission.' % today_connect_log_dir) - log = Log(user=username, host=host, log_path=log_file_path, start_time=datetime.now(), pid=pid) + log = Log(user=username, host=host, remote_ip=ip_list, log_path=log_file_path, start_time=datetime.now(), pid=pid) log_file.write('Starttime is %s\n' % datetime.now()) log.save() return log_file, log diff --git a/jasset/views.py b/jasset/views.py index e399d8067..74fbfe023 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -37,7 +37,6 @@ def f_add_host(ip, port, idc, jtype, group, dept, active, comment, username='', comment=comment) a.save() - jasset_group_add(ip, ip, 'P') all_group = BisGroup.objects.get(name='ALL') private_group = BisGroup.objects.get(name=ip.strip()) for g in group: @@ -45,9 +44,7 @@ def f_add_host(ip, port, idc, jtype, group, dept, active, comment, username='', groups.append(c) groups.extend([all_group, private_group]) - print dept for d in dept: - print d p = DEPT.objects.get(name=d) depts.append(p) @@ -61,7 +58,7 @@ def add_host(request): header_title, path1, path2 = u'添加主机', u'资产管理', u'添加主机' eidc = IDC.objects.all() edept = DEPT.objects.all() - egroup = BisGroup.objects.filter(type='A') + egroup = BisGroup.objects.all() eusergroup = UserGroup.objects.all() if request.method == 'POST': @@ -197,7 +194,7 @@ def host_edit(request): header_title, path1, path2 = u'修改主机', u'资产管理', u'修改主机' groups, e_group, e_dept, depts = [], [], [], [] eidc = IDC.objects.all() - egroup = BisGroup.objects.filter(type='A') + egroup = BisGroup.objects.all() edept = DEPT.objects.all() offset = request.GET.get('id') for g in Asset.objects.get(id=int(offset)).bis_group.all(): diff --git a/jlog/models.py b/jlog/models.py index 3bb861569..a716765c3 100644 --- a/jlog/models.py +++ b/jlog/models.py @@ -4,6 +4,7 @@ from django.db import models class Log(models.Model): user = models.CharField(max_length=20, null=True) host = models.CharField(max_length=20, null=True) + remote_ip = models.CharField(max_length=100) log_path = models.CharField(max_length=100) start_time = models.DateTimeField(null=True) pid = models.IntegerField(max_length=10) diff --git a/jlog/views.py b/jlog/views.py index f6b3744aa..c423334ac 100644 --- a/jlog/views.py +++ b/jlog/views.py @@ -5,6 +5,7 @@ from datetime import datetime from django.db.models import Q from django.http import HttpResponse +from django.template import RequestContext from django.http import HttpResponseRedirect from django.shortcuts import render_to_response @@ -28,7 +29,7 @@ def log_list_online(request): 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) - return render_to_response('jlog/log_online.html', locals()) + return render_to_response('jlog/log_online.html', locals(), context_instance=RequestContext(request)) def log_list_offline(request): @@ -43,7 +44,7 @@ def log_list_offline(request): 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) - return render_to_response('jlog/log_offline.html', locals()) + return render_to_response('jlog/log_offline.html', locals(), context_instance=RequestContext(request)) def log_kill(request, offset): @@ -51,7 +52,7 @@ def log_kill(request, offset): if pid: 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()) + return HttpResponseRedirect('jlog/log_offline.html', locals(), context_instance=RequestContext(request)) def log_history(request): @@ -78,4 +79,4 @@ def log_search(request): .filter(is_finished=1).order_by('-start_time') contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) - return render_to_response('jlog/log_search.html', locals()) + return render_to_response('jlog/log_search.html', locals(), context_instance=RequestContext(request)) diff --git a/jumpserver.conf b/jumpserver.conf index 9540fa014..8de09fc8b 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -8,11 +8,11 @@ password = mysql234 database = jumpserver [ldap] -ldap_enable = 0 -host_url = ldap://127.0.0.1:389 -base_dn = dc=jumpserver, dc=org -root_dn = cn=admin,dc=jumpserver,dc=org -root_pw = secret234 +ldap_enable = 1 +host_url = ldap://192.168.8.230:389 +base_dn = dc=fengxing, dc=com +root_dn = cn=admin,dc=fengxing,dc=com +root_pw = 123456 [websocket] web_socket_host = 127.0.0.1:3000 diff --git a/templates/jlog/log_online.html b/templates/jlog/log_online.html index b7003a076..ed69c33d1 100644 --- a/templates/jlog/log_online.html +++ b/templates/jlog/log_online.html @@ -145,9 +145,9 @@ var regx = /\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]/g; // tag.append('

'+escapeString(obj.content.replace(regx,''))+'

'); if (option == 'new') { - tag.append('

' + escapeString(obj.content) + '

'); + tag.append('

' + escapeString(obj.content) + '

'); } else if (option == 'exist') { - tag.append('

' + exsit_message + '

'); + tag.append('

' + exsit_message + '

'); } tag.animate({ scrollTop: tag[0].scrollHeight}, 1); });