mirror of https://github.com/jumpserver/jumpserver
add install wizzrd
parent
ef7f42cf6d
commit
5740dec7b4
|
@ -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',
|
||||
|
|
|
@ -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('请求方法错误')
|
||||
|
||||
|
||||
|
|
|
@ -46,40 +46,40 @@
|
|||
请输入相关信息完成安装
|
||||
</p>
|
||||
|
||||
<form id="form" action="#" class="wizard-big" >
|
||||
{# <h1>管理员账户</h1>#}
|
||||
{# <fieldset>#}
|
||||
{# <h2>管理员账号是首次登陆的账号</h2>#}
|
||||
{# <div class="row">#}
|
||||
{# <div class="col-sm-6">#}
|
||||
{# <div class="form-group">#}
|
||||
{# <label>用户名 *</label>#}
|
||||
{# <input id="username" name="username" type="text" class="form-control required" minlength="5" >#}
|
||||
{# </div>#}
|
||||
{# <div class="form-group">#}
|
||||
{# <label>密码 *</label>#}
|
||||
{# <input id="password" name="password" type="password" class="form-control required password" minlength="8">#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# <div class="col-sm-6">#}
|
||||
{# <div class="form-group">#}
|
||||
{# <label>邮件 *</label>#}
|
||||
{# <input id="email" name="email" type="email" class="form-control required">#}
|
||||
{# </div>#}
|
||||
{# <div class="form-group">#}
|
||||
{# <label>确认密码 *</label>#}
|
||||
{# <input id="pass_confirm" name="pass_confirm" type="password" equalto="#password" class="form-control required">#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# <div class="col-sm-4">#}
|
||||
{# <div class="text-center">#}
|
||||
{# <div style="margin-top: 20px">#}
|
||||
{# <i class="fa fa-sign-in" style="font-size: 180px;color: #e5e5e5 "></i>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </div>#}
|
||||
{# </fieldset>#}
|
||||
<form id="form" action="{% url 'install' %}" method="post" class="wizard-big" >
|
||||
<h1>管理员账户</h1>
|
||||
<fieldset>
|
||||
<h2>管理员账号是首次登陆的账号</h2>
|
||||
<div class="row">
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label>用户名 *</label>
|
||||
<input id="username" name="username" type="text" class="form-control required" minlength="5" >
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>密码 *</label>
|
||||
<input id="password" name="password" type="password" class="form-control required password" minlength="8">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label>邮件 *</label>
|
||||
<input id="email" name="email" type="email" class="form-control required">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>确认密码 *</label>
|
||||
<input id="pass_confirm" name="pass_confirm" type="password" equalto="#password" class="form-control required">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<div class="text-center">
|
||||
<div style="margin-top: 20px">
|
||||
<i class="fa fa-sign-in" style="font-size: 180px;color: #e5e5e5 "></i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
<h1>数据库</h1>
|
||||
<fieldset>
|
||||
<h2>数据库连接信息</h2>
|
||||
|
@ -87,29 +87,29 @@
|
|||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label>地址 *</label>
|
||||
<input id="db_host" name="db_host" type="text" class="form-control required">
|
||||
<input id="db_host" name="db_host" type="text" value="127.0.0.1" class="form-control required">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>端口 *</label>
|
||||
<input id="db_port" name="db_port" type="text" class="form-control required number">
|
||||
<input id="db_port" name="db_port" type="text" value="3306" class="form-control required number">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>数据库 *</label>
|
||||
<input id="db" name="db" type="text" class="form-control required">
|
||||
<input id="db" name="db" type="text" value="jumpserver" class="form-control required">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label>用户名 *</label>
|
||||
<input id="db_user" name="db_user" type="text" class="form-control required">
|
||||
<input id="db_user" name="db_user" type="text" value="jumpserver" class="form-control required">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>密码 *</label>
|
||||
<input id="db_pass" name="db_pass" type="password" class="form-control">
|
||||
<input id="db_pass" name="db_pass" type="password" class="form-control required">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div></div>
|
||||
<a id="db_btn" value="{% url 'install_test' 'db' %}" class="btn btn-sm btn-warning" style="float: right"> 测试连接 </a>
|
||||
<a id="db_btn" value="{% url 'install_test' 'db' %}" class="btn btn-sm btn-warning" style="float: right" onclick="db_test(this)"> 测试连接 </a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -122,25 +122,25 @@
|
|||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label>SMTP *</label>
|
||||
<input id="smtp_host" name="smtp_host" type="text" class="form-control required">
|
||||
<input id="smtp_host" name="smtp_host" placeholder="smtp.qq.com" type="text" class="form-control required">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>端口 *</label>
|
||||
<input id="smtp_port" name="smtp_port" type="text" class="form-control required">
|
||||
<input id="smtp_port" name="smtp_port" value="25" type="text" class="form-control required">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6">
|
||||
<div class="form-group">
|
||||
<label>邮件地址 *</label>
|
||||
<input id="mail_addr" name="mail_addr" type="text" class="form-control required">
|
||||
<input id="mail_addr" name="mail_addr" placeholder="xxxx@qq.com" type="text" class="form-control required">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>密码 *</label>
|
||||
<input id="mail_pass" name="mail_pass" type="password" class="form-control">
|
||||
<input id="mail_pass" name="mail_pass" type="password" class="form-control required">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div></div>
|
||||
<a id="mail_btn" href="{% url 'install_test' 'mail' %}" class="btn btn-sm btn-warning" style="float: right"> 测试邮件 </a>
|
||||
<a id="mail_btn" value="{% url 'install_test' 'mail' %}" class="btn btn-sm btn-warning" style="float: right" onclick="smtp_test(this)"> 测试邮件 </a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -148,8 +148,8 @@
|
|||
|
||||
<h1>完成</h1>
|
||||
<fieldset>
|
||||
<h2>Terms and Conditions</h2>
|
||||
<input id="acceptTerms" name="acceptTerms" type="checkbox" class="required"> <label for="acceptTerms">I agree with the Terms and Conditions.</label>
|
||||
<h2>确认信息</h2>
|
||||
<p id="confirm"></p>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -159,8 +159,6 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!-- Mainly scripts -->
|
||||
<!-- // <script src="js/jquery-2.1.1.js"></script> -->
|
||||
<script src="/static/js/jquery-2.1.1.js"></script>
|
||||
|
@ -181,30 +179,76 @@
|
|||
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
// $("#wizard").steps();
|
||||
var db_test_valid = false;
|
||||
var smtp_test_valid = false;
|
||||
|
||||
$('#db_btn').click(function(){
|
||||
console.log('hello');
|
||||
var db_host = $('#db_host').val();
|
||||
var db_port = $('#db_port').val();
|
||||
var db_user = $('#db_user').val();
|
||||
var db_pass = $('#db_pass').val();
|
||||
$.post(
|
||||
$(this).attr('value'),
|
||||
{'db_host': db_host,
|
||||
'db_port': db_port,
|
||||
'db_user': db_user,
|
||||
'db_pass': db_pass
|
||||
},
|
||||
function(data, status){
|
||||
alert(data)
|
||||
}
|
||||
function db_test(t, alert_){
|
||||
var valid = $(t).closest('form').valid();
|
||||
if (valid == false){
|
||||
console.log('Not valid');
|
||||
return
|
||||
}
|
||||
var db_host = $('#db_host').val();
|
||||
var db_port = $('#db_port').val();
|
||||
var db_user = $('#db_user').val();
|
||||
var db_pass = $('#db_pass').val();
|
||||
var db = $('#db').val();
|
||||
$.ajax({
|
||||
url: $(t).attr('value'),
|
||||
data: {'db_host': db_host,
|
||||
'db_port': db_port,
|
||||
'db_user': db_user,
|
||||
'db_pass': db_pass,
|
||||
'db': db },
|
||||
success: function(data, status){
|
||||
db_test_valid = true;
|
||||
$('#db_btn').removeClass('btn-danger');
|
||||
$('#db_btn').addClass('btn-primary');
|
||||
alert(data)
|
||||
},
|
||||
error: function(data){
|
||||
$('#db_btn').addClass('btn-danger');
|
||||
alert(data.responseText)
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
);
|
||||
return false;
|
||||
function smtp_test(t){
|
||||
var valid = $(t).closest('form').valid();
|
||||
if (valid == false){
|
||||
console.log('Not valid');
|
||||
return
|
||||
}
|
||||
var smtp_host = $('#smtp_host').val();
|
||||
var smtp_port = $('#smtp_port').val();
|
||||
var mail_addr = $('#mail_addr').val();
|
||||
var mail_pass = $('#mail_pass').val();
|
||||
$.ajax({
|
||||
url: $(t).attr('value'),
|
||||
data: {
|
||||
'smtp_host': smtp_host,
|
||||
'smtp_port': smtp_port,
|
||||
'mail_addr': mail_addr,
|
||||
'mail_pass': mail_pass
|
||||
},
|
||||
success: function(data, status){
|
||||
smtp_test_valid = false;
|
||||
$('#smtp_btn').removeClass('btn-danger');
|
||||
$('#smtp_btn').addClass('btn-primary');
|
||||
alert(data)
|
||||
},
|
||||
error: function(data) {
|
||||
$('#smtp_btn').addClass('btn-danger');
|
||||
alert(data.responseText)
|
||||
}
|
||||
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
// $("#wizard").steps();
|
||||
|
||||
$("#form").steps({
|
||||
bodyTag: "fieldset",
|
||||
|
@ -217,11 +261,23 @@
|
|||
}
|
||||
|
||||
// Forbid suppressing "Warning" step if the user is to young
|
||||
if (newIndex === 3 && Number($("#age").val()) < 18)
|
||||
{
|
||||
return false;
|
||||
if (newIndex === 2){
|
||||
if (db_test_valid == false) {
|
||||
$('#db_btn').removeClass('btn-warning');
|
||||
$('#db_btn').addClass('btn-danger');
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (newIndex === 3){
|
||||
//if (smtp_test_valid == false){
|
||||
// $('#smtp_btn').removeClass('btn-warning');
|
||||
// $('#smtp_btn').addClass('btn-danger');
|
||||
// return false;
|
||||
//}
|
||||
console.log('pass')
|
||||
}
|
||||
var form = $(this);
|
||||
|
||||
// Clean up if user went backward before
|
||||
|
@ -251,6 +307,20 @@
|
|||
{
|
||||
$(this).steps("previous");
|
||||
}
|
||||
console.log(currentIndex + ';' + priorIndex);
|
||||
if (currentIndex === 3 && priorIndex === 2)
|
||||
{
|
||||
$('#confirm').html(
|
||||
'<span>' + '管理账号: ' + $('#username').val() + '<br/ >' +
|
||||
'<span>' + '管理邮箱: ' + $('#email').val() + '<br/ >' +
|
||||
'<span>' + '数据库地址: ' + $('#db_host').val() + '<br/ >' +
|
||||
'<span>' + '数据库端口: ' + $('#db_port').val() + '<br/ >' +
|
||||
'<span>' + '数据库账号: ' + $('#db_user').val() + '<br/ >' +
|
||||
'<span>' + 'SMTP地址: ' + $('#smtp_host').val() + '<br/ >' +
|
||||
'<span>' + 'SMTP端口: ' + $('#smtp_port').val() + '<br/ >' +
|
||||
'<span>' + '邮件账号: ' + $('#mail_addr').val() + '<br/ >'
|
||||
)
|
||||
}
|
||||
},
|
||||
onFinishing: function (event, currentIndex)
|
||||
{
|
||||
|
|
|
@ -150,12 +150,6 @@ $('#userForm').validator({
|
|||
ok: "",
|
||||
msg: {required: "必须填写!"}
|
||||
},
|
||||
"password": {
|
||||
rule: "length[6~50];check_pass",
|
||||
tip: "输入密码",
|
||||
ok: "",
|
||||
msg: {required: "必须填写!"}
|
||||
},
|
||||
"name": {
|
||||
rule: "required",
|
||||
tip: "姓名",
|
||||
|
|
Loading…
Reference in New Issue