diff --git a/connect.py b/connect.py index ae4527a62..80d0c4c9e 100755 --- a/connect.py +++ b/connect.py @@ -126,6 +126,7 @@ def log_record(username, host): 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_file.write('Starttime is %s\n' % datetime.now()) log.save() return log_file, log @@ -168,6 +169,7 @@ def posix_shell(chan, username, host): finally: timestamp_end = time.time() termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty) + log_file.write('Endtime is %s' % datetime.now()) log_file.close() log.is_finished = True log.log_finished = False diff --git a/jasset/views.py b/jasset/views.py index 804dfe91b..3d16b588c 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -22,7 +22,8 @@ def index(request): def f_add_host(ip, port, idc, jtype, group, active, comment, username='', password=''): groups = [] idc = IDC.objects.get(name=idc) - if type == 'M': + if jtype == 'M': + print username, password a = Asset(ip=ip, port=port, login_type=jtype, idc=idc, is_active=int(active), @@ -135,7 +136,15 @@ def batch_host_edit(request): j_active = request.POST.get(j_active).strip() j_comment = request.POST.get(j_comment).strip() - jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment) + if j_type == 'M': + j_user = "editable[" + str(i) + "][j_user]" + j_password = "editable[" + str(i) + "][j_password]" + j_user = request.POST.get(j_user).strip() + password = request.POST.get(j_password).strip() + j_password = cryptor.encrypt(password) + jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment, j_user, j_password) + else: + jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment) return render_to_response('jasset/host_list.html') @@ -199,8 +208,11 @@ def host_edit(request): a = Asset.objects.get(id=int(offset)) if j_type == 'M': + if post.password == request.POST.get('j_password'): + j_password = post.password + else: + j_password = cryptor.encrypt(request.POST.get('j_password')) j_user = request.POST.get('j_user') - j_password = cryptor.encrypt(request.POST.get('j_password')) a.ip = j_ip a.port = j_port a.login_type = j_type diff --git a/jumpserver.conf b/jumpserver.conf index 9540fa014..be7b190a4 100644 --- a/jumpserver.conf +++ b/jumpserver.conf @@ -9,10 +9,10 @@ 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 +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/jumpserver/views.py b/jumpserver/views.py index 66a474d73..32d04aead 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -126,7 +126,7 @@ def page_list_return(total, current=1): return range(min_page, max_page+1) -def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment): +def jasset_host_edit(j_id, j_ip, j_idc, j_port, j_type, j_group, j_active, j_comment, j_user='', j_password=''): groups = [] is_active = {u'是': '1', u'否': '2'} login_types = {'LDAP': 'L', 'SSH_KEY': 'S', 'PASSWORD': 'P', 'MAP': 'M'} diff --git a/log_handler.py b/log_handler.py index 16fbf49ed..f64445cd4 100755 --- a/log_handler.py +++ b/log_handler.py @@ -2,6 +2,7 @@ #coding: utf-8 import os +import re import time import psutil from datetime import datetime @@ -15,14 +16,21 @@ from jlog.models import Log def log_hanler(id): log = Log.objects.get(id=id) + pattern = re.compile(r'\[.*@.*\][\$#].*') if log: filename = log.log_path if os.path.isfile(filename): - ret1 = os.system('cat %s | grep "DateTime" > %s.his' % (filename, filename)) - ret2 = os.system('cat %s | grep "\[.*@.*\][\$\#]" >> %s.his' % (filename, filename)) - ret3 = os.system('cat %s | grep "EndTime" >> %s.his' % (filename, filename)) - if (ret1 + ret2 + ret3) == 0: - print 'Handler %s ok.' % filename + f_his = filename + '.his' + f1 = open(filename) + f2 = open(f_his, 'a') + lines = f1.readlines() + for line in lines[7:]: + match = pattern.match(line) + if match: + newline = re.sub('\[[A-Z]', '', line) + f2.write(newline) + f1.close() + f2.close() log.log_finished = True log.save() diff --git a/templates/jasset/group_detail.html b/templates/jasset/group_detail.html index 5e30a50f5..0d8cd85b9 100644 --- a/templates/jasset/group_detail.html +++ b/templates/jasset/group_detail.html @@ -57,7 +57,7 @@ {{ post.port }} {{ login_types|get_item:post.login_type }} {{ post.idc.name }} - {% for group in post.bis_group.all|filter_private %} {{ group }} {% endfor %} + {{ post.bis_group.all | group_str2 }} {{ post.is_active|bool2str }} {{ post.date_added|date:"Y-m-d H:i:s" }} {{ post.comment }} diff --git a/templates/jasset/host_edit.html b/templates/jasset/host_edit.html index 00e8483f5..441ed3e7b 100644 --- a/templates/jasset/host_edit.html +++ b/templates/jasset/host_edit.html @@ -56,15 +56,25 @@ {% endfor %} - + {% else %} + + {% endifequal %}
@@ -177,19 +187,7 @@ $('#assetForm').validator({ msg: {required: "请填写用户名"} }, "j_password": { - rule: "required(type_m);length[6~16]", - tip: "密码6-16位", - ok: "", - msg: {required: "6-16位"} - }, - "j_root": { - rule: "required(type_m)", - tip: "超管用户名", - ok: "", - msg: {required: "请填写用户名"} - }, - "j_passwd": { - rule: "required(type_m);length[6~16]", + rule: "required(type_m);length[6~100]", tip: "密码6-16位", ok: "", msg: {required: "6-16位"} diff --git a/templates/jasset/host_list.html b/templates/jasset/host_list.html index 5638342d8..04f716c34 100644 --- a/templates/jasset/host_list.html +++ b/templates/jasset/host_list.html @@ -68,7 +68,7 @@ {{ post.port }} {{ login_types|get_item:post.login_type }} {{ post.idc.name }} - {% for group in post.bis_group.all|filter_private %} {{ group }} {% endfor %} + {{ post.bis_group.all | group_str2 }} {{ post.is_active|bool2str }} {{ post.date_added|date:"Y-m-d H:i:s" }} {{ post.comment }} diff --git a/templates/jasset/host_search.html b/templates/jasset/host_search.html index 1436b20cd..a160a1160 100644 --- a/templates/jasset/host_search.html +++ b/templates/jasset/host_search.html @@ -22,7 +22,7 @@ {{ post.port }} {{ login_types|get_item:post.login_type }} {{ post.idc.name }} - {% for group in post.bis_group.all|filter_private %} {{ group }} {% endfor %} + {{ post.bis_group.all | group_str2 }} {{ post.is_active|bool2str }} {{ post.date_added|date:"Y-m-d H:i:s" }} {{ post.comment }} diff --git a/templates/jasset/idc_detail.html b/templates/jasset/idc_detail.html index fd318bb20..b305e9694 100644 --- a/templates/jasset/idc_detail.html +++ b/templates/jasset/idc_detail.html @@ -57,7 +57,7 @@ {{ post.port }} {{ login_types|get_item:post.login_type }} {{ post.idc.name }} - {% for group in post.bis_group.all|filter_private %} {{ group }} {% endfor %} + {{ post.bis_group.all | group_str2 }} {{ post.is_active|bool2str }} {{ post.date_added|date:"Y-m-d H:i:s" }} {{ post.comment }}