From 2e1c7d2fb80a7a9652c3517ea3c6ea6d56aa13ad Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 30 Oct 2014 21:39:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=20=E4=BF=AE=E6=94=B9jumpserver.py=20=20=201.2=201.21?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E4=B8=8B=E8=BD=BD=E5=A4=A7=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/jumpserver.iml | 2 +- jumpserver.py | 30 +++++++++++++++----------- webroot/AutoSa/AutoSa/views.py | 7 +++--- webroot/AutoSa/templates/info.html | 2 +- webroot/AutoSa/templates/showUser.html | 4 ++-- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/.idea/jumpserver.iml b/.idea/jumpserver.iml index 68c3f23cd..94e54876c 100644 --- a/.idea/jumpserver.iml +++ b/.idea/jumpserver.iml @@ -2,7 +2,7 @@ - + diff --git a/jumpserver.py b/jumpserver.py index 4f19f2c7c..da3bdefae 100755 --- a/jumpserver.py +++ b/jumpserver.py @@ -132,7 +132,6 @@ def connect(host, port, user, password): signal.signal(signal.SIGWINCH, sigwinch_passthrough) size = getwinsize() foo.setwinsize(size[0], size[1]) - print "\033[32;1mLogin %s success!\033[0m" % host foo.interact() break elif index == 0: @@ -259,19 +258,26 @@ def exec_cmd_servers(username): def connect_one(username, option): - ip = option.strip() + ip_input = option.strip() ip_all, ip_all_dict = ip_all_select(username) - ip_matched = match_ip(ip_all, ip) + ip_matched = match_ip(ip_all, ip_input) ip_len = len(ip_matched) - if ip_len == 1: - ip = ip_matched[0] - password = jm.decrypt(sth_select(username=username)) - port = sth_select(ip=ip) - print "Connecting %s ..." % ip - connect(ip, port, username, password) - elif ip_len > 1: - for ip in ip_matched: - print ip + ip = '' + if ip_len >= 1: + if ip_len == 1: + ip = ip_matched[0] + else: + for one_ip in ip_matched: + if one_ip.endswith(ip_input): + ip = one_ip + break + else: + print one_ip + if ip: + password = jm.decrypt(sth_select(username=username)) + port = sth_select(ip=ip_input) + print "Connecting %s ..." % ip + connect(ip, port, username, password) else: print '\033[31mNo permision .\033[0m' diff --git a/webroot/AutoSa/AutoSa/views.py b/webroot/AutoSa/AutoSa/views.py index cacc3952a..03face8a0 100644 --- a/webroot/AutoSa/AutoSa/views.py +++ b/webroot/AutoSa/AutoSa/views.py @@ -18,6 +18,7 @@ import crypt import hashlib from UserManage.forms import UserAddForm, GroupAddForm import paramiko +from django.core.servers.basehttp import FileWrapper base_dir = "/opt/jumpserver/" @@ -940,11 +941,9 @@ def downFile(request): sftp = paramiko.SFTPClient.from_transport(t) sftp.get(path, download_file) if os.path.isfile(download_file): - f = open(download_file) - data = f.read() - f.close() + wrapper = FileWrapper(open(download_file)) - response = HttpResponse(data, mimetype='application/octet-stream') + response = HttpResponse(wrapper, mimetype='application/octet-stream') response['Content-Disposition'] = 'attachment; filename=%s' % os.path.basename(path) return response diff --git a/webroot/AutoSa/templates/info.html b/webroot/AutoSa/templates/info.html index ec1393336..8d94df003 100644 --- a/webroot/AutoSa/templates/info.html +++ b/webroot/AutoSa/templates/info.html @@ -38,7 +38,7 @@ {% if msg %} -
成功:{{ msg }}
+
成功:{{ msg }}
{% endif %} {% if error %} diff --git a/webroot/AutoSa/templates/showUser.html b/webroot/AutoSa/templates/showUser.html index 6e14b9d42..b27df1c75 100644 --- a/webroot/AutoSa/templates/showUser.html +++ b/webroot/AutoSa/templates/showUser.html @@ -17,8 +17,8 @@ is_admin is_superuser Email - Key - 修改 + 密钥 + 用户信息 sudo sudo