diff --git a/connect.py b/connect.py index 0ba04d99d..171e07dba 100644 --- a/connect.py +++ b/connect.py @@ -698,6 +698,11 @@ class Nav(object): file_path = raw_input("\033[1;32mPath>:\033[0m ").strip() if file_path == 'q': break + + if not file_path: + print "文件路径为空" + continue + runner.run('fetch', module_args='src=%s dest=%s' % (file_path, tmp_dir), pattern=pattern) ret = runner.results FileLog(user=self.user.name, host=asset_name_str, filename=file_path, type='download', diff --git a/jumpserver/views.py b/jumpserver/views.py index 2c207e157..6fa41a0f6 100644 --- a/jumpserver/views.py +++ b/jumpserver/views.py @@ -357,46 +357,76 @@ def web_terminal(request): def install(request): + if request.method == 'POST': + username = request.GET.get('username') + password = request.GET.get('password') + email = request.GET.get('email') + db_host = request.GET.get('db_host') + db_port = int(request.GET.get('db_port')) if request.GET.get('db_port') else 1 + db_user = request.GET.get('db_user') + db_pass = request.GET.get('db_pass') + db = request.GET.get('db') + smtp_host = request.GET.get('smtp_host') if request.GET.get('smtp_host') else 'jumpserver' + smtp_port = int(request.GET.get('smtp_port')) if request.GET.get('smtp_port') else 25 + mail_addr = request.GET.get('mail_addr') + mail_pass = request.GET.get('mail_pass') + + config = ConfigParser.ConfigParser() + config.read(os.path.join(BASE_DIR, 'jumpserver.conf')) + config.set('db', 'host', db_host) + config.set('db', 'port', db_port) + config.set('db', 'user', db_user) + config.set('db', 'password', db_pass) + config.set('db', 'database', db) + config.set('mail', 'email_host', smtp_host) + config.set('mail', 'email_port', smtp_port) + config.set('mail', 'email_host_user', mail_addr) + config.set('mail', 'email_host_passoword', mail_pass) + f = open(os.path.join(BASE_DIR, 'jumpserver.conf'), 'w') + config.write(f) + return render_to_response('install.html', locals()) def install_test(request, offset): - if request.method == 'post': + if request.method == 'GET': if offset == 'db': import MySQLdb db_host = request.GET.get('db_host') - db_port = int(request.GET.get('db_port')) + db_port = int(request.GET.get('db_port')) if request.GET.get('db_port') else 1 db_user = request.GET.get('db_user') db_pass = request.GET.get('db_pass') db = request.GET.get('db') try: conn = MySQLdb.connect(host=db_host, port=db_port, user=db_user, passwd=db_pass, db=db) - except Exception: - return HttpResponse('链接失败', status=500) + except Exception, e: + logger.debug(u'测试连接数据库失败: %s %s % s %s' % (db_host, db_port, db_user, db_pass)) + return HttpResponse(u'链接失败 %s' % e, status=500) else: return HttpResponse('连接成功') elif offset == 'mail': from smtplib import SMTP - smtp_host = request.GET.get('smtp_host') - smtp_port = request.GET.get('smtp_port') + smtp_host = request.GET.get('smtp_host') if request.GET.get('smtp_host') else 'jumpserver' + smtp_port = int(request.GET.get('smtp_port')) if request.GET.get('smtp_port') else 25 mail_addr = request.GET.get('mail_addr') mail_pass = request.GET.get('mail_pass') try: - smtp = SMTP(smtp_host, port=smtp_port) + smtp = SMTP(smtp_host, port=smtp_port, timeout=2) smtp.login(mail_addr, mail_pass) smtp.sendmail(mail_addr, (mail_addr), - '''From:%s\r\nTo:%s\r\nSubject:Jumpserver Mail Test!\r\n\r\n Mail test passed!\r\n''') + '''From:%s\r\nTo:%s\r\nSubject:Jumpserver Mail Test!\r\n\r\n Mail test passed!\r\n''' % + (mail_addr, mail_addr)) smtp.quit() - except Exception: - return HttpResponse('测试失败', status=500) + except Exception, e: + logger.debug(u'邮件测试失败: %s' % e) + return HttpResponse('测试失败 %s' % e) else: return HttpResponse(u'登陆 %s邮箱查看邮件' % mail_addr) else: - print request.method - return HttpResponse('请求方法错误', status=500) + return HttpResponse('请求方法错误') diff --git a/templates/install.html b/templates/install.html index 09965e14b..844c33ab3 100644 --- a/templates/install.html +++ b/templates/install.html @@ -46,40 +46,40 @@ 请输入相关信息完成安装

-
-{#

管理员账户

#} -{#
#} -{#

管理员账号是首次登陆的账号

#} -{#
#} -{#
#} -{#
#} -{# #} -{# #} -{#
#} -{#
#} -{# #} -{# #} -{#
#} -{#
#} -{#
#} -{#
#} -{# #} -{# #} -{#
#} -{#
#} -{# #} -{# #} -{#
#} -{#
#} -{#
#} -{#
#} -{#
#} -{# #} -{#
#} -{#
#} -{#
#} -{#
#} -{#
#} + +

管理员账户

+
+

管理员账号是首次登陆的账号

+
+
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+
+
+
+ +
+
+
+
+

数据库

数据库连接信息

@@ -87,29 +87,29 @@
- +
- +
- +
- +
- +
@@ -122,25 +122,25 @@
- +
- +
- +
- +
@@ -148,8 +148,8 @@

完成

-

Terms and Conditions

- +

确认信息

+

@@ -159,8 +159,6 @@ - - @@ -181,30 +179,76 @@