Skip to content

Commit

Permalink
重构了Let'sEncrypt一键部署模块
Browse files Browse the repository at this point in the history
  • Loading branch information
showpy committed Jul 10, 2019
1 parent c00f83f commit 274502b
Show file tree
Hide file tree
Showing 27 changed files with 3,316 additions and 491 deletions.
3 changes: 2 additions & 1 deletion BTPanel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def home():
data['ftpCount'] = public.M('ftps').count()
data['databaseCount'] = public.M('databases').count()
data['lan'] = public.GetLan('index')
data['724'] = public.format_date("%m%d") == '0724'
return render_template( 'index.html',data = data)

@app.route('/close',methods=method_get)
Expand Down Expand Up @@ -483,7 +484,7 @@ def ssl(pdata = None):
if comReturn: return comReturn
import panelSSL
toObject = panelSSL.panelSSL()
defs = ('RemoveCert','SetCertToSite','GetCertList','SaveCert','GetCert','GetCertName','DelToken','GetToken','GetUserInfo','GetOrderList','GetDVSSL','Completed','SyncOrder','GetSSLInfo','downloadCRT','GetSSLProduct','Renew_SSL','Get_Renew_SSL')
defs = ('RemoveCert','renew_lets_ssl','SetCertToSite','GetCertList','SaveCert','GetCert','GetCertName','DelToken','GetToken','GetUserInfo','GetOrderList','GetDVSSL','Completed','SyncOrder','GetSSLInfo','downloadCRT','GetSSLProduct','Renew_SSL','Get_Renew_SSL')
result = publicObject(toObject,defs,None,pdata);
return result;

Expand Down
7 changes: 7 additions & 0 deletions BTPanel/static/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -4397,6 +4397,13 @@ html .menu .menu_exit:hover {
padding-left:13px;
margin-right:20px;
}

.bt-724 {
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAQCAMAAACvHOZVAAAAA3NCSVQICAjb4U/gAAAAOVBMVEXeQRTxrJnkZUD76OLqiWzzuKfgTSP53NT////30MXvoIriWTHmcU/99PHslHvofV71xLbjXznpgGGbp65eAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAFnRFWHRDcmVhdGlvbiBUaW1lADA3LzEwLzE5ht15uwAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTNui8sowAAACrSURBVCiRrZBLAsMgCETJRxwUTdP7H7b4SUnW7SxU4gMnQ/QP5TSlrVqDyGufV4usbVNMJSv2cVw6UIHexdoUUdjOBVHXAPBs1e9TB9AGctqybf3G6OKEVcmd7R2PCOJEwuaAFoi5RGQnbMRln3iB3dmcksmJ2m0OINpPMeWCTcR8y/hsTzpQ9B4BRmbAQWd6dzbyPYKqVzJEZ1vqo9N9VAk9BPMnU4/Uf9cHAxAHhkB15V0AAAAASUVORK5CYII=");
background-repeat: no-repeat;
padding-left: 35px;
margin-right: 20px;
}
/*系统图标*/
.ico-linux{
background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABEAAAATBAMAAACEi/vCAAAAA3NCSVQICAjb4U/gAAAAMFBMVEX///9mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmambAcKAAAAEHRSTlMAESIzRFVmd4iZqrvM3e7/dpUBFQAAAAlwSFlzAAAOwwAADsMBx2+oZAAAABZ0RVh0Q3JlYXRpb24gVGltZQAwOC8xNi8xOCL5ZhgAAAAcdEVYdFNvZnR3YXJlAEFkb2JlIEZpcmV3b3JrcyBDUzbovLKMAAAAmUlEQVQImWNgYGCQ/GvAAAHz/1+CMBjPvvoOYTFVLXkNZZ2u+isAZjE/4vyvAGaxlgbnJ4BZHAoM3A/BLA8GBpafYNYiIL4PMpt1A5DYPwFIcDWArDkAJPgWAInzF4BE9jMGBvb/QM2SBfEGDFy7UhkY3Bk4CxisGdgCGMwYGI97vGKwSmAQC1G8e+aN2WagDuP0IEGbawIMAPDJKG706GgtAAAAAElFTkSuQmCC");
Expand Down
Binary file added BTPanel/static/img/724.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
106 changes: 86 additions & 20 deletions BTPanel/static/js/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var site = {
get_list: function (page, search, type) {
if (page == undefined) page = 1;
if (type == '-1' || type == undefined) {
//console.log($('.site_type select').val())
type = $('.site_type select').val();
}
bt.site.get_list(page, search, type, function (rdata) {
Expand Down Expand Up @@ -346,7 +345,6 @@ var site = {
}
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
});
console.log(php_version)
},
del_site: function (wid, wname) {
var thtml = "<div class='options'><label><input type='checkbox' id='delftp' name='ftp'><span>FTP</span></label><label><input type='checkbox' id='deldata' name='data'><span>" + lan.site.database + "</span></label><label><input type='checkbox' id='delpath' name='path'><span>" + lan.site.root_dir + "</span></label></div>";
Expand Down Expand Up @@ -527,13 +525,60 @@ var site = {
},
ssl: {
my_ssl_msg : null,
renew_ssl: function () {
$.post('/ssl?action=Renew_SSL', {}, function (rdata) {
layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 });
renew_ssl: function (siteName) {
data = {}
if (siteName != undefined) data = { siteName: siteName }
var loadT = bt.load("正在一键续订证书.")
bt.send("renew_lets_ssl", 'ssl/renew_lets_ssl', data, function (rdata) {
loadT.close();
if (rdata.status) {
setTimeout(function () { site.ssl.get_renew_stat(); }, 500);
if (siteName != undefined) {
if (rdata.err_list.length > 0) {
bt.msg({ status: false, msg: rdata.err_list[0].msg })
}
else {
site.reload();
bt.msg({ status: true, time: 6, msg: '网站【' + siteName + '】续订证书成功.' })
}
}
else {
var ehtml = '', shtml = ''

if (rdata.sucess_list.length > 0) {
var sucess = {};
sucess.title = "成功续签 " + rdata.sucess_list.length + " 张证书";
sucess.list = [{ title: "域名列表", val: rdata.sucess_list.join() }];
shtml = bt.render_ps(sucess);
}

if (rdata.err_list.length > 0) {
var error = {};
error.title = "续签失败 " + rdata.err_list.length + " 张证书";
error.list = []
for (var i = 0; i < rdata.err_list.length; i++) {
error.list.push({ title: rdata.err_list[i]['siteName'], val: rdata.err_list[i]['msg'] })
}
ehtml = bt.render_ps(error);
}

bt.open({
type: 1,
area: '600px',
title: "续签证书成功",
closeBtn: 2,
shadeClose: false,
content: "<div class='success-msg'><div class='pic'><img src='/static/img/success-pic.png'></div><div class='suc-con'>" + shtml + ehtml + "</div></div>",
});

if ($(".success-msg").height() < 150) {
$(".success-msg").find("img").css({ "width": "150px", "margin-top": "30px" });
}
}
}
});
else {
bt.msg(rdata)
}
})
},
get_renew_stat: function () {
$.post('/ssl?action=Get_Renew_SSL', {}, function (task_list) {
Expand Down Expand Up @@ -1309,7 +1354,7 @@ var site = {
arrs_list.push({ title: api[x].title, value: api[x].name });
arr_obj[api[x].name] = api[x];
}
var data = {
var data = [{
title: '选择DNS接口', class: 'checks_line', items: [
{
name: 'dns_select', width: '120px', type: 'select', items: arrs_list, callback: function (obj) {
Expand Down Expand Up @@ -1365,16 +1410,26 @@ var site = {
}
]
}
var _form_data = bt.render_form_line(data);
$(obj).parents('.line').append(_form_data.html);
bt.render_clicks(_form_data.clicks);
, {
title: ' ', class: 'checks_line label-input-group', items:
[
{ css: 'label-input-group ptb10', text: '申请泛域名', name: 'app_root', type: 'checkbox' }
]
}
]
for (var i = 0; i < data.length; i++) {
var _form_data = bt.render_form_line(data[i]);
$(obj).parents('.line').append(_form_data.html)
bt.render_clicks(_form_data.clicks);
}
})
}
},
]
},
{ title: '管理员邮箱', name: 'admin_email', value: rdata.email, width: '260px' }
]

for (var i = 0; i < datas.length; i++) {
var _form_data = bt.render_form_line(datas[i]);
robj.append(_form_data.html);
Expand Down Expand Up @@ -1415,17 +1470,28 @@ var site = {
updateOf: 1,
domains: JSON.stringify(ldata['domains'])
}
if (ddata.email.indexOf('@') === -1) {
layer.msg('管理员邮箱不能为空!', {icon:2});
return;
}

if (ldata.check_file) {
ddata['force'] = ldata.force;
site.create_let(ddata);
site.create_let(ddata, function (res) {
if (res.status === true) {
site.reload();
}

});
}
else {
ddata['dnsapi'] = ldata.dns_select;
ddata['dnssleep'] = ldata.dnssleep;
ddata['app_root'] = ldata.app_root ? 1 : 0;
site.create_let(ddata, function (ret) {
if (ldata.dns_select == 'dns') {
if (ret.key) {
site.ssl.reload(1);
site.reload();
bt.msg(ret);
return;
}
Expand All @@ -1440,7 +1506,7 @@ var site = {
});
setTimeout(function () {
var data = [];
for (var j = 0; j < ret.fullDomain.length; j++) data.push({ name: ret.fullDomain[j], txt: ret.txtValue[j] });
for (var j = 0; j < ret.dns_names.length; j++) data.push({ name: ret.dns_names[j].acme_name, txt: ret.dns_names[j].domain_dns_value });
bt.render({
table: '#dns_txt_jx',
columns: [
Expand All @@ -1449,16 +1515,17 @@ var site = {
],
data: data
})
if (ret.fullDomain.length == 0) ret.fullDomain.append('_acme-challenge.bt.cn')
$('.div_txt_jx').append(bt.render_help(['解析域名需要一定时间来生效,完成所以上所有解析操作后,请等待1分钟后再点击验证按钮', '可通过CMD命令来手动验证域名解析是否生效: nslookup -q=txt ' + ret.fullDomain[0], '若您使用的是宝塔云解析插件,阿里云DNS,DnsPod作为DNS,可使用DNS接口自动解析']));
if (ret.dns_names.length == 0) ret.dns_names.append('_acme-challenge.bt.cn')
$('.div_txt_jx').append(bt.render_help(['解析域名需要一定时间来生效,完成所以上所有解析操作后,请等待1分钟后再点击验证按钮', '可通过CMD命令来手动验证域名解析是否生效: nslookup -q=txt ' + ret.dns_names[0].acme_name, '若您使用的是宝塔云解析插件,阿里云DNS,DnsPod作为DNS,可使用DNS接口自动解析']));

$('.btn_check_txt').click(function () {
var new_data = {
siteName: web.name,
domains: ddata.domains,
updateOf: 1,
email: ldata.email,
renew: 'True'
renew: 'True',
dnsapi:'dns'
}
site.create_let(new_data, function (ldata) {
if (ldata.status) {
Expand All @@ -1470,7 +1537,7 @@ var site = {
}, 100)
}
else {
site.ssl.reload(1);
site.reload();
bt.msg(ret);
}
})
Expand Down Expand Up @@ -1561,7 +1628,7 @@ var site = {
},
{
title: "证书夹", callback: function (robj) {
robj.html("<div class='divtable'><table id='cer_list_table' class='table table-hover'></table></div>");
robj.html("<div class='divtable' style='height:510px;'><table id='cer_list_table' class='table table-hover'></table></div>");
bt.site.get_cer_list(function (rdata) {
bt.render({
table: '#cer_list_table',
Expand Down Expand Up @@ -2165,7 +2232,6 @@ var site = {
},
{
field: 'dname', title: '操作', align: 'right', templet: function (item) {
console.log(item)
var proxyname = item.proxyname;
var sitename = item.sitename;
item = JSON.stringify(item).myReplace('"', '\'');
Expand Down
30 changes: 18 additions & 12 deletions BTPanel/templates/default/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@
<div class="main-content">
<div class="container-fluid" style="padding-bottom: 66px;">
<div class="index-pos-box bgw mtb15">
<div class="position f12 c6 pull-left" style="background:none;padding-left:15px">
<span class="bind-user c4">
<a href="javascript:bt.pub.bind_btname();" class="btlink">宝塔账户</a>
</span>
{% if data['pd'].find('免费版') != -1 %}
<span class="bt-dashi">
<a class="btlink" href="https://www.bt.cn/invite" target="_blank" style="margin-left:5px">邀请奖励</a>
</span>
{% endif %}
<span class="bind-weixin c4"><a href="javascript:bt.weixin.open_wxapp();" class="btlink">微信</a></span>
<span class="ico-system">系统:</span><span id="info" style="margin-left:10px;"> {{data['lan']['S2']}}</span>&#12288;&#12288;{{data['lan']['S3']}} <span id="running">{{data['lan']['S4']}}</span>
</div>
<div class="position f12 c6 pull-left" style="background:none;padding-left:15px">
<span class="bind-user c4">
<a href="javascript:bt.pub.bind_btname();" class="btlink">宝塔账户</a>
</span>
{% if data['pd'].find('免费版') != -1 %}
{% if not data['724'] %}
<span id="bt-fuli" class="bt-dashi">
<a class="btlink" href="https://www.bt.cn/invite" target="_blank" style="margin-left:5px">邀请奖励</a>
</span>
{% else %}
<span id="bt-fuli" class="bt-724">
<a class="btlink" href="https://www.bt.cn/724.html" target="_blank" style="margin-left:5px">运维节</a>
</span>
{% endif %}
{% endif %}
<span class="bind-weixin c4"><a href="javascript:bt.weixin.open_wxapp();" class="btlink">微信</a></span>
<span class="ico-system">系统:</span><span id="info" style="margin-left:10px;"> {{data['lan']['S2']}}</span>&#12288;&#12288;{{data['lan']['S3']}} <span id="running">{{data['lan']['S4']}}</span>
</div>
<span class="pull-right f12 c6" style="line-height:52px; margin-right:15px">
{{data['pd']|safe}} <span id="btversion" style="margin-right:10px"><a onclick="index.open_log()">{{session['version']}}</a></span>
<span id="toUpdate"><a class="btlink" href="javascript:index.check_update();">更新</a></span>
Expand Down
2 changes: 1 addition & 1 deletion class/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def init(self):
if ua:
ua = ua.lower();
if ua.find('spider') != -1 or ua.find('bot') != -1: return redirect('https://www.baidu.com');
g.version = '6.9.6'
g.version = '6.9.25'
g.title = public.GetConfigValue('title')
g.uri = request.path
session['version'] = g.version;
Expand Down
5 changes: 1 addition & 4 deletions class/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,6 @@ def SetPanelSSL(self,get):
os.system('rm -f ' + sslConf);
return public.returnMsg(True,'PANEL_SSL_CLOSE');
else:
os.system('pip insatll cffi==1.10');
os.system('pip install cryptography==2.1');
os.system('pip install pyOpenSSL==16.2');
try:
if not self.CreateSSL(): return public.returnMsg(False,'PANEL_SSL_ERR');
public.writeFile(sslConf,'True')
Expand All @@ -438,7 +435,7 @@ def CreateSSL(self):
key.generate_key(OpenSSL.crypto.TYPE_RSA, 2048)
cert = OpenSSL.crypto.X509()
cert.set_serial_number(0)
cert.get_subject().CN = '120.27.27.98';
cert.get_subject().CN = public.GetLocalIp()
cert.set_issuer(cert.get_subject())
cert.gmtime_adj_notBefore( 0 )
cert.gmtime_adj_notAfter(86400 * 3650)
Expand Down
Loading

0 comments on commit 274502b

Please sign in to comment.