From 3bee29338ce2ddffde2c2af8384018a505669170 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 6 Nov 2014 23:20:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B2=A1=E7=94=A8=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webroot/AutoSa/AutoSa/views.py | 40 ++++++++-------- webroot/AutoSa/templates/addVPN.html | 3 -- webroot/AutoSa/templates/assets_edit.html | 34 ------------- webroot/AutoSa/templates/assets_view.html | 58 ----------------------- webroot/AutoSa/templates/chgPass.html | 2 +- webroot/AutoSa/templates/index.html | 2 + webroot/AutoSa/templates/runCommand.html | 43 ----------------- webroot/AutoSa/templates/showAssets.html | 2 + webroot/AutoSa/templates/showServer.html | 33 ------------- 9 files changed, 25 insertions(+), 192 deletions(-) delete mode 100644 webroot/AutoSa/templates/addVPN.html delete mode 100644 webroot/AutoSa/templates/assets_edit.html delete mode 100644 webroot/AutoSa/templates/assets_view.html delete mode 100644 webroot/AutoSa/templates/runCommand.html delete mode 100644 webroot/AutoSa/templates/showServer.html diff --git a/webroot/AutoSa/AutoSa/views.py b/webroot/AutoSa/AutoSa/views.py index 95f847518..ca765bbd2 100644 --- a/webroot/AutoSa/AutoSa/views.py +++ b/webroot/AutoSa/AutoSa/views.py @@ -795,9 +795,6 @@ def addPerm(request): context_instance=RequestContext(request)) - - - @login_required def chgPass(request): """修改登录密码""" @@ -911,21 +908,24 @@ def upFile(request): port = asset.port jm = PyCrypt(key) user = User.objects.get(username=username) - t = paramiko.Transport((host, port)) - t.connect(username=username, password=jm.decrypt(user.ldap_password)) - sftp = paramiko.SFTPClient.from_transport(t) - sftp.put(filename, '%s/%s' % (path, upload_file.name)) - msg = u'上传成功,位于 %s主机,位置 %s.' % (host, path) - uplog_dir = os.path.join(log_dir, 'upload') - if not os.path.isdir(uplog_dir): - os.mkdir(uplog_dir) - filename = os.path.join(uplog_dir, time.strftime('%Y%m%d')) - f = open(filename, 'a') - f.write('DateTime: %s User: %s Host: %s File: %s' % - (time.strftime('%Y/%m/%d %H:%M:%S'), username, host, path)) - f.close() - - return render_to_response('info.html', {'msg': msg}) + try: + t = paramiko.Transport((host, port)) + t.connect(username=username, password=jm.decrypt(user.ldap_password)) + sftp = paramiko.SFTPClient.from_transport(t) + sftp.put(filename, '%s/%s' % (path, upload_file.name)) + msg = u'上传成功,位于 %s主机,位置 %s.' % (host, path) + uplog_dir = os.path.join(log_dir, 'upload') + if not os.path.isdir(uplog_dir): + os.mkdir(uplog_dir) + filename = os.path.join(uplog_dir, '%s.log' % time.strftime('%Y%m%d')) + f = open(filename, 'a') + f.write('DateTime: %s User: %s Host: %s File: %s\n' % + (time.strftime('%Y/%m/%d %H:%M:%S'), username, host, path)) + f.close() + except paramiko.AuthenticationException: + error = u'密码不对 或者 你用的admin用户' + + return render_to_response('info.html', {'msg': msg, 'error': error}) else: return render_to_response('info.html', {'error': u"上传失败"}) @@ -956,9 +956,9 @@ def downFile(request): downlog_dir = os.path.join(log_dir, 'download') if not os.path.isdir(downlog_dir): os.mkdir(downlog_dir) - filename = os.path.join(downlog_dir, time.strftime('%Y%m%d')) + filename = os.path.join(downlog_dir, '%s.log' % time.strftime('%Y%m%d')) f = open(filename, 'a') - f.write('DateTime: %s User: %s Host: %s File: %s' % + f.write('DateTime: %s User: %s Host: %s File: %s\n' % (time.strftime('%Y/%m/%d %H:%M:%S'), username, host, path)) f.close() wrapper = FileWrapper(open(download_file)) diff --git a/webroot/AutoSa/templates/addVPN.html b/webroot/AutoSa/templates/addVPN.html deleted file mode 100644 index 07c7501c0..000000000 --- a/webroot/AutoSa/templates/addVPN.html +++ /dev/null @@ -1,3 +0,0 @@ -{% extends 'base.html' %} -{% block content %} -{% endblock %} \ No newline at end of file diff --git a/webroot/AutoSa/templates/assets_edit.html b/webroot/AutoSa/templates/assets_edit.html deleted file mode 100644 index f57a076a8..000000000 --- a/webroot/AutoSa/templates/assets_edit.html +++ /dev/null @@ -1,34 +0,0 @@ -{% extends "base.html" %} -{% block content %} -

修改主机信息

-
-
- - - - - - - - - - - - - - - - - - - - - -
- - -
- -
-
-{% endblock %} diff --git a/webroot/AutoSa/templates/assets_view.html b/webroot/AutoSa/templates/assets_view.html deleted file mode 100644 index eeb324fe3..000000000 --- a/webroot/AutoSa/templates/assets_view.html +++ /dev/null @@ -1,58 +0,0 @@ -{% extends "base.html" %} -{% block content %} -
-

主机列表

-
添加 
-
- - - - - - - - - - - - - - - - - - {% for post in contacts.object_list %} - - - - - - - - - - - - - {% endfor %} - - -
编号IP主机名cpu内存硬盘操作系统详情编辑删除
{{ post.s_num }}{{ post.s_ip }}{{ post.s_hostname }}{{ post.s_cpu }}{{ post.s_mem }}{{ post.s_disk }}{{ post.s_system }}详情编辑删除
- - -{% endblock %} diff --git a/webroot/AutoSa/templates/chgPass.html b/webroot/AutoSa/templates/chgPass.html index 4ddfbfadf..3aee92594 100644 --- a/webroot/AutoSa/templates/chgPass.html +++ b/webroot/AutoSa/templates/chgPass.html @@ -41,7 +41,7 @@
- +
diff --git a/webroot/AutoSa/templates/index.html b/webroot/AutoSa/templates/index.html index 07ba7f21a..56ced86e4 100644 --- a/webroot/AutoSa/templates/index.html +++ b/webroot/AutoSa/templates/index.html @@ -15,6 +15,7 @@ ID IP Port + IDC 备注 @@ -25,6 +26,7 @@ {{ asset.id }} {{ asset.ip }} {{ asset.port }} + {{ asset.idc }} {{ asset.comment }} {% endfor %} diff --git a/webroot/AutoSa/templates/runCommand.html b/webroot/AutoSa/templates/runCommand.html deleted file mode 100644 index ab3d911ae..000000000 --- a/webroot/AutoSa/templates/runCommand.html +++ /dev/null @@ -1,43 +0,0 @@ -{% extends 'base.html' %} -{% block content %} -
-
-
-
-
- - - - - -
- 输入一个IP,或者多个IP逗号隔开。 -
-
- -
-
-
- - - - -
- 输入在执行的命令,多个命令分号隔开. -
-
-
- -
- -
-
- -
- {% if stdout %} -
{{ stdout }}
- {% endif %} - {% if stderr %} -
{{ stderr }}
- {% endif %} -{% endblock %} \ No newline at end of file diff --git a/webroot/AutoSa/templates/showAssets.html b/webroot/AutoSa/templates/showAssets.html index 198fe915f..92c120438 100644 --- a/webroot/AutoSa/templates/showAssets.html +++ b/webroot/AutoSa/templates/showAssets.html @@ -13,6 +13,7 @@ ID IP Port + IDC 备注 @@ -24,6 +25,7 @@ {{ asset.id }} {{ asset.ip }} {{ asset.port }} + {{ asset.idc }} {{ asset.comment }} {% endfor %} diff --git a/webroot/AutoSa/templates/showServer.html b/webroot/AutoSa/templates/showServer.html deleted file mode 100644 index 280c0e830..000000000 --- a/webroot/AutoSa/templates/showServer.html +++ /dev/null @@ -1,33 +0,0 @@ -{% extends 'base.html' %} -{% block content %} -
- {% if info %} -

- {{ info }} -

- {% endif %} - - - - - - - - - - - - {% for server in servers %} - - - - - - - - {% endfor %} - -
ip用户名端口sudo
{{ server.ip }}{{ server.username }}{{ server.port }}{{ server.sudo }}
- -
-{% endblock %} \ No newline at end of file