From acfa0171cad29e6d49fe0c4ea8ed3f679ff1ab14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E6=9E=AB?= Date: Mon, 15 Jun 2015 16:06:12 +0800 Subject: [PATCH 01/19] Update log_offline.html a small bug --- templates/jlog/log_offline.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/jlog/log_offline.html b/templates/jlog/log_offline.html index 12bfb5af5..8e560d62f 100644 --- a/templates/jlog/log_offline.html +++ b/templates/jlog/log_offline.html @@ -127,7 +127,7 @@ var end_time = $('#end_time')[0].innerText; var div_username = ' 用户名: '+''+username+'' + ''; var div_ip = ' 主机: '+'' + ip + ''; - var div_time = ' 开始时间: ' + ''+start_time +'' + ' 结束时间: ' +'' + end_time + ''+start_time +'' + ' 结束时间: ' +'' + end_time + '' var title = 'JumpServer命令统计 '+ div_username + div_ip + div_time; $.ajax({url:url,success:function(data){ var tag = $('
').html(data.replace(/\n/g,"
")); @@ -157,4 +157,4 @@ }) -{% endblock %} \ No newline at end of file +{% endblock %} From 915adb2fd3b101db11498a48101d1161ad64de61 Mon Sep 17 00:00:00 2001 From: Jiajun Liu Date: Fri, 3 Jul 2015 23:06:58 +0800 Subject: [PATCH 02/19] fix user can not get permission applies bug --- jperm/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jperm/views.py b/jperm/views.py index 4f38f09b9..ec7f58d56 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -268,7 +268,7 @@ def sudo_ldap_add(user_group, user_runas, asset_groups_select, ldap_conn = LDAPMgmt(LDAP_HOST_URL, LDAP_BASE_DN, LDAP_ROOT_DN, LDAP_ROOT_PW) else: return - + assets = [] cmds = [] user_runas = user_runas.split(',') @@ -751,7 +751,7 @@ def perm_apply_log(request, offset): header_title, path1, path2 = u'权限申请记录', u'权限管理', u'申请记录' keyword = request.GET.get('keyword', '') user_id = get_session_user_info(request)[0] - username = User.objects.get(id=user_id).name + username = User.objects.get(id=user_id).username dept_name = get_session_user_info(request)[4] status_dic = {'online': 0, 'offline': 1} status = status_dic[offset] From 19343540b93454abcae9f841c70e3b5523dfb9f8 Mon Sep 17 00:00:00 2001 From: Jiajun Liu Date: Fri, 3 Jul 2015 23:09:40 +0800 Subject: [PATCH 03/19] fix line break bug some system user '\n\r' as line break, if we split commands by '\n', then '\r' will be considered as part of commands which will break sudo authentication. we can use splitlines function to avoid the problem. --- jperm/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jperm/views.py b/jperm/views.py index ec7f58d56..ebb12c7ea 100644 --- a/jperm/views.py +++ b/jperm/views.py @@ -484,7 +484,7 @@ def cmd_add(request): if request.method == 'POST': name = request.POST.get('name') dept_id = request.POST.get('dept_id') - cmd = ','.join(request.POST.get('cmd').split('\n')) + cmd = ','.join(request.POST.get('cmd').splitlines()) comment = request.POST.get('comment') dept = DEPT.objects.filter(id=dept_id) @@ -514,7 +514,7 @@ def cmd_add_adm(request): if request.method == 'POST': name = request.POST.get('name') - cmd = ','.join(request.POST.get('cmd').split('\n')) + cmd = ','.join(request.POST.get('cmd').splitlines()) comment = request.POST.get('comment') try: @@ -552,7 +552,7 @@ def cmd_edit(request): cmd_group_id = request.POST.get('cmd_group_id') name = request.POST.get('name') dept_id = request.POST.get('dept_id') - cmd = ','.join(request.POST.get('cmd').split('\n')) + cmd = ','.join(request.POST.get('cmd').splitlines()) comment = request.POST.get('comment') cmd_group = CmdGroup.objects.filter(id=cmd_group_id) From 627d6279955c325192cf671f11e0634f2bac474a Mon Sep 17 00:00:00 2001 From: Jiajun Liu Date: Tue, 7 Jul 2015 16:51:54 +0800 Subject: [PATCH 04/19] fix user can not get login logs bug --- juser/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/juser/views.py b/juser/views.py index 22a08499b..76e92cdfb 100644 --- a/juser/views.py +++ b/juser/views.py @@ -812,8 +812,8 @@ def user_detail(request): if user: user = user[0] asset_group_permed = user_perm_group_api(user) - logs_last = Log.objects.filter(user=user.name).order_by('-start_time')[0:10] - logs_all = Log.objects.filter(user=user.name).order_by('-start_time') + logs_last = Log.objects.filter(user=user.username).order_by('-start_time')[0:10] + logs_all = Log.objects.filter(user=user.username).order_by('-start_time') logs_num = len(logs_all) return render_to_response('juser/user_detail.html', locals(), context_instance=RequestContext(request)) @@ -1053,4 +1053,4 @@ def down_key(request): response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(private_key_file) return response - return HttpResponse('No Key File. Contact Admin.') \ No newline at end of file + return HttpResponse('No Key File. Contact Admin.') From b8dfb26a3a92db71538074025a4220b781b75e09 Mon Sep 17 00:00:00 2001 From: Jiajun Liu Date: Tue, 7 Jul 2015 17:44:12 +0800 Subject: [PATCH 05/19] fix error url in host search page --- templates/jasset/host_search.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/jasset/host_search.html b/templates/jasset/host_search.html index 38ed8c1ad..2fe6e0449 100644 --- a/templates/jasset/host_search.html +++ b/templates/jasset/host_search.html @@ -35,7 +35,7 @@ {{ post.date_added|date:"Y-m-d H:i:s" }} {{ post.comment }} - 详情 + 详情 {% ifnotequal session_role_id 0 %} 编辑 删除 From f5e57da106a356ecb22c1af6ba575488d4674b10 Mon Sep 17 00:00:00 2001 From: Jiajun Liu Date: Tue, 7 Jul 2015 18:12:25 +0800 Subject: [PATCH 06/19] fix line break bug on add multiple hosts --- jasset/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jasset/views.py b/jasset/views.py index 22c72f8e5..fc2a1225c 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -232,7 +232,7 @@ def host_add_batch(request): active_types = {'激活': 1, '禁用': 0} dept_id = get_user_dept(request) if request.method == 'POST': - multi_hosts = request.POST.get('j_multi').split('\n') + multi_hosts = request.POST.get('j_multi').splitlines() for host in multi_hosts: if host == '': break @@ -927,4 +927,4 @@ def host_search(request): posts = list(set(post_all) & set(post_perm)) contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request) - return my_render('jasset/host_search.html', locals(), request) \ No newline at end of file + return my_render('jasset/host_search.html', locals(), request) From a040b1c181290440b9f42a2be7112d170eb2c568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E6=9E=AB?= Date: Tue, 21 Jul 2015 10:26:49 +0800 Subject: [PATCH 07/19] Update connect.py fix cpu used 100% --- connect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect.py b/connect.py index dc74a6701..83a23a5c7 100644 --- a/connect.py +++ b/connect.py @@ -131,7 +131,7 @@ def posix_shell(chan, username, host): if chan in r: try: - x = chan.recv(1024) + x = chan.recv(10240) if len(x) == 0: break sys.stdout.write(x) From e9c69245308194bf21397da0f5858039735b8401 Mon Sep 17 00:00:00 2001 From: pengyao Date: Wed, 26 Aug 2015 16:06:22 +0800 Subject: [PATCH 08/19] exact match --- connect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connect.py b/connect.py index 83a23a5c7..3fa72c719 100644 --- a/connect.py +++ b/connect.py @@ -90,8 +90,8 @@ def log_record(username, host): log_file_path = os.path.join(today_connect_log_dir, log_filename) dept_name = User.objects.get(username=username).dept.name pid = os.getpid() - pts = os.popen("ps axu | grep %s | grep -v grep | awk '{ print $7 }'" % pid).read().strip() - ip_list = os.popen("who | grep %s | awk '{ print $5 }'" % pts).read().strip('()\n') + pts = os.popen("ps axu | awk '$2==%s{ print $7 }'" % pid).read().strip() + ip_list = os.popen("who | awk '$2==%s{ print $5 }'" % pts).read().strip('()\n') if not os.path.isdir(today_connect_log_dir): try: From f47cddbd5c94d9a22309102bf3ee3cd763d8ab27 Mon Sep 17 00:00:00 2001 From: ibuler Date: Fri, 28 Aug 2015 10:04:07 +0800 Subject: [PATCH 09/19] =?UTF-8?q?=E4=BF=AE=E6=94=B9cpu=E5=8D=A0=E7=94=A8?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log_handler.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/log_handler.py b/log_handler.py index 199afe1cb..5e5e4f698 100644 --- a/log_handler.py +++ b/log_handler.py @@ -69,7 +69,7 @@ def run(): try: file_time = int(os.stat(log_path).st_ctime) now_time = int(time.time()) - if now_time - file_time > 18000: + if now_time - file_time > 10800: if psutil.pid_exists(pid): kill_pid(pid) set_finish(pid_id) @@ -77,7 +77,29 @@ def run(): except OSError: pass +#function erorcheck is added by Lin to resolve CPU filled issue 2015.08.24 + +def errorcheck(): + f=os.popen("ps auxr | grep -v auxr|sed -n 2p") + a=f.read().strip() + f.close() + pid=0 + try: + if a is not None: + b=a.split(" ") + if b[-1]=='/opt/jumpserver/connect.py' and b[-2]=='python' and b[-8]=='R' and int(b[-3].split(':')[0])>100: + for i,j in enumerate(b): + if i==0 or j=='': + continue + else: + pid=int(j) + break + kill_pid(pid) + except : + pass + if __name__ == '__main__': while True: run() time.sleep(5) + errorcheck() From 073e7b36fad310a2e2b8fe00f3e318303f41da24 Mon Sep 17 00:00:00 2001 From: Peng Xiao Date: Mon, 31 Aug 2015 10:28:54 +0800 Subject: [PATCH 10/19] Delete .DS_Store file .DS_Store is the name of a file in the Apple OS X operating system for storing custom attributes of a folder such as the position of icons or the choice of a background image. --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 228971d07180d06cd79ed2aa5688f4d23b0bfcb3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK&1%~~5S~rkL~$-ENlGA>y#{=614YeEanfVKppsCM;!2gMHz<;kWSd|Ny0(we zzw|Xq^AdfMUOTh9DRG@#gDEp&=9}HwSxKLyT@3(;&M=Bz)0J<;oQLtFarz50DZenIENuzzyNN2ztOlHL}?yj{C6}+Rav#$zr@mV z3QCC>V9yXo!w^#FJBL)A3uHm^7Y%*_a8saqY$`sY1y!N1J~%>NzEuI zvNX@$W1MnVkhTg!R0Z#tHll5Yl7HyJFv~(PU|)P^eIc%fFM=6h1{R3{S|21Tp>MG^ zsFw~jx&%O^-v}+}Q!PO`(xPv%Hi!`vVNwxIs<0)7FzMJY?Kt0JZP28Hu*HY4XBM_X z5&G;nztqD)_y*ZB1I)lI1IwoA(*FPA{`!A5iCfG7Gw@$AAR0%(Q3r3y?yYk-M|-VA seTzy$<7$IC1&!T~wL@F+HmVkkNpcWTd;6WMq1LBIkxBvhE From 2f5cf429ed17f90925b5ef446f845d7b911faa1b Mon Sep 17 00:00:00 2001 From: IYism Date: Fri, 25 Sep 2015 16:30:15 +0800 Subject: [PATCH 11/19] bugfix ip_list bugfix ip_list --- connect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect.py b/connect.py index 3fa72c719..e5d372bf0 100644 --- a/connect.py +++ b/connect.py @@ -91,7 +91,7 @@ def log_record(username, host): dept_name = User.objects.get(username=username).dept.name pid = os.getpid() pts = os.popen("ps axu | awk '$2==%s{ print $7 }'" % pid).read().strip() - ip_list = os.popen("who | awk '$2==%s{ print $5 }'" % pts).read().strip('()\n') + ip_list = os.popen("who | awk '$2==\"%s\"{ print $5 }'" % pts).read().strip('()\n') if not os.path.isdir(today_connect_log_dir): try: From 667862223c8a816d9810e91f0d9d78c6f4b60bff Mon Sep 17 00:00:00 2001 From: IYism Date: Fri, 25 Sep 2015 16:33:11 +0800 Subject: [PATCH 12/19] bugfix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复chrome浏览器有时候不能阻断的bug --- templates/jlog/log_online.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/jlog/log_online.html b/templates/jlog/log_online.html index 7e2858e57..1af12a9aa 100644 --- a/templates/jlog/log_online.html +++ b/templates/jlog/log_online.html @@ -223,10 +223,12 @@ $.ajax({ type: "GET", url: g_url, - success: window.open("/jlog/log_list/online/", "_self") + success: function(){ + document.location.reload(); + } // error: window.open(g_url, "_self") }); } -{% endblock %} \ No newline at end of file +{% endblock %} From 949065be2cd3d13f9c2473259e52812ada2b51db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=93=9D=E6=9E=AB?= Date: Thu, 1 Oct 2015 16:25:17 +0800 Subject: [PATCH 13/19] Update connect.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正vim颜色 --- connect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect.py b/connect.py index e5d372bf0..98c66aa95 100644 --- a/connect.py +++ b/connect.py @@ -258,7 +258,7 @@ def connect(username, password, host, port, login_name): """ Connect server. """ - ps1 = "PS1='[\u@%s \W]\$ '\n" % host + ps1 = "PS1='[\u@%s \W]\$ ' && TERM=xterm && export TERM\n" % host login_msg = "clear;echo -e '\\033[32mLogin %s done. Enjoy it.\\033[0m'\n" % host # Make a ssh connection From 0667067c0c4a77930ac5ac93b8521899ed82c33d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B3=BD?= Date: Tue, 13 Oct 2015 16:36:16 +0800 Subject: [PATCH 14/19] =?UTF-8?q?=E6=8D=95=E8=8E=B7=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E9=82=AE=E7=AE=B1=E5=A1=AB=E5=86=99=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=97=B6=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- juser/views.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/juser/views.py b/juser/views.py index 76e92cdfb..29f86caaa 100644 --- a/juser/views.py +++ b/juser/views.py @@ -663,8 +663,11 @@ def user_add(request): except Exception: pass else: - send_mail(mail_title, mail_msg, MAIL_FROM, [email], fail_silently=False) - msg = u'添加用户 %s 成功! 用户密码已发送到 %s 邮箱!' % (username, email) + try: + send_mail(mail_title, mail_msg, MAIL_FROM, [email], fail_silently=False) + msg = u'添加用户 %s 成功! 用户密码已发送到 %s 邮箱!' % (username, email) + except: + msg = u'添加用户 %s 成功! 用户密码发送失败,请检查邮箱是否正确!' % username return render_to_response('juser/user_add.html', locals(), context_instance=RequestContext(request)) From 64973e43deebdef790ec7a8aaa1b150a8a55618d Mon Sep 17 00:00:00 2001 From: shadowzey Date: Tue, 13 Oct 2015 17:19:47 +0800 Subject: [PATCH 15/19] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=8E=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E9=83=A8=E9=97=A8=E9=A1=B5=E9=9D=A2=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E4=B8=BB=E6=9C=BA=E5=88=97=E8=A1=A8=E7=82=B9=E5=87=BB=E8=AF=A6?= =?UTF-8?q?=E6=83=85404=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/jasset/host_list_nop.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/jasset/host_list_nop.html b/templates/jasset/host_list_nop.html index eb1e3dd34..9f61bfbd5 100644 --- a/templates/jasset/host_list_nop.html +++ b/templates/jasset/host_list_nop.html @@ -73,7 +73,7 @@ {{ post.is_active|bool2str }} {{ post.comment }} - 详情 + 详情 {% ifnotequal session_role_id 0 %} 编辑 删除 @@ -174,4 +174,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} From ec8ef4d1d76aab30aacb7d9e7c733e5bea3f2a86 Mon Sep 17 00:00:00 2001 From: zyan Date: Mon, 26 Oct 2015 10:35:50 +0800 Subject: [PATCH 16/19] Update idc_detail.html MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复IDC详情页面显示错误 --- templates/jasset/idc_detail.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/jasset/idc_detail.html b/templates/jasset/idc_detail.html index acc072590..643491c16 100644 --- a/templates/jasset/idc_detail.html +++ b/templates/jasset/idc_detail.html @@ -48,7 +48,7 @@ 端口号 登录方式 所属IDC - 所属业务组 + 所属部门 是否激活 添加时间 备注 @@ -64,8 +64,8 @@ {{ post.login_type|get_login_type }} {{ post.idc.name }} {{ post.dept.all | group_str2 }} - {{ post.bis_group.all | group_str2_all }} {{ post.is_active|bool2str }} + {{ post.date_added }} {{ post.comment }} 详情 @@ -208,4 +208,4 @@ } -{% endblock %} \ No newline at end of file +{% endblock %} From c00a55619cb3a316a1a52fbd41b79fa28d189a64 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 17 Nov 2015 16:43:33 +0800 Subject: [PATCH 17/19] Update connect.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去掉compress --- connect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connect.py b/connect.py index 98c66aa95..e2f17ec10 100644 --- a/connect.py +++ b/connect.py @@ -266,7 +266,7 @@ def connect(username, password, host, port, login_name): ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: - ssh.connect(host, port=port, username=username, password=password, compress=True) + ssh.connect(host, port=port, username=username, password=password) except paramiko.ssh_exception.AuthenticationException, paramiko.ssh_exception.SSHException: raise ServerError('Authentication Error.') except socket.error: From 3f451158f0635e179153ed24634626413940492e Mon Sep 17 00:00:00 2001 From: Alex Wang Date: Mon, 30 Nov 2015 15:15:05 +0800 Subject: [PATCH 18/19] add choose group to execute commands. --- connect.py | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/connect.py b/connect.py index e2f17ec10..11f3cefe1 100644 --- a/connect.py +++ b/connect.py @@ -216,7 +216,8 @@ def print_prompt(): 3) Type \033[32mG/g\033[0m To Print The Server Groups You Available. 4) Type \033[32mG/g(1-N)\033[0m To Print The Server Group Hosts You Available. 5) Type \033[32mE/e\033[0m To Execute Command On Several Servers. - 6) Type \033[32mQ/q\033[0m To Quit. + 6) Type \033[32mE/e(1-N)\033[0m To Execute Command On select server group hosts. + 7) Type \033[32mQ/q\033[0m To Quit. """ print textwrap.dedent(msg) @@ -314,14 +315,42 @@ def remote_exec_cmd(ip, port, username, password, cmd): def multi_remote_exec_cmd(hosts, username, cmd): - pool = Pool(processes=5) + pool = Pool(processes=10) for host in hosts: - username, password, ip, port = get_connect_item(username, host) - pool.apply_async(remote_exec_cmd, (ip, port, username, password, cmd)) + remote_username, password, ip, port = get_connect_item(username, host) + pool.apply_async(remote_exec_cmd, (ip, port, remote_username, password, cmd)) pool.close() pool.join() +def exec_cmd_group_servers(username, gid): + group_attr = get_user_hostgroup(username) + groups = group_attr.keys() + hosts=[] + for g in groups: + if long(gid)==long(group_attr[g][0]): + hosts_attr = get_user_hostgroup_host(username, gid) + hosts = hosts_attr.keys() + color_print("You choosed server group: %s, include ips: %s" % (g, hosts), 'green') + color_print("Input the Command, The command will be Execute on servers, q/Q to quit.", 'green') + break + + if hosts: + while True: + cmd = raw_input('\033[1;32mCmd(s): \033[0m') + if cmd in ['q', 'Q']: + break + exec_log_dir = os.path.join(LOG_DIR, 'exec_cmds') + if not os.path.isdir(exec_log_dir): + os.mkdir(exec_log_dir) + os.chmod(exec_log_dir, 0777) + filename = "%s/%s.log" % (exec_log_dir, time.strftime('%Y%m%d')) + f = open(filename, 'a') + f.write("DateTime: %s User: %s Host: %s Cmds: %s\n" % + (time.strftime('%Y/%m/%d %H:%M:%S'), username, hosts, cmd)) + multi_remote_exec_cmd(hosts, username, cmd) + + def exec_cmd_servers(username): color_print("You can choose in the following IP(s), Use glob or ips split by comma. q/Q to PreLayer.", 'green') print_user_host(LOGIN_NAME) @@ -366,6 +395,7 @@ def exec_cmd_servers(username): if __name__ == '__main__': print_prompt() gid_pattern = re.compile(r'^g\d+$') + e_gid_pattern = re.compile(r'^e\d+$') try: while True: try: @@ -387,6 +417,10 @@ if __name__ == '__main__': continue elif option in ['E', 'e']: exec_cmd_servers(LOGIN_NAME) + elif e_gid_pattern.match(option): + gid = option[1:].strip() + exec_cmd_group_servers(LOGIN_NAME, gid) + continue elif option in ['Q', 'q', 'exit']: sys.exit() else: From e24003df9744e85388724da3f9b66835f7aa01f9 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 17 Dec 2015 17:12:26 +0800 Subject: [PATCH 19/19] Update connect.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复 remote ip抓取问题 --- connect.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/connect.py b/connect.py index 11f3cefe1..ca5f76566 100644 --- a/connect.py +++ b/connect.py @@ -90,8 +90,7 @@ def log_record(username, host): log_file_path = os.path.join(today_connect_log_dir, log_filename) dept_name = User.objects.get(username=username).dept.name pid = os.getpid() - pts = os.popen("ps axu | awk '$2==%s{ print $7 }'" % pid).read().strip() - ip_list = os.popen("who | awk '$2==\"%s\"{ print $5 }'" % pts).read().strip('()\n') + ip_list = os.popen("who -m | awk '{ print $5 }'").read().strip('()\n') if not os.path.isdir(today_connect_log_dir): try: