panel ssl https 功能添加
This commit is contained in:
parent
a56d53c672
commit
6f884fe60a
|
|
@ -387,6 +387,50 @@ class config_api:
|
|||
mw.writeFile('ssl/input.pl', 'True')
|
||||
return mw.returnJson(True, '证书已保存!')
|
||||
|
||||
# 设置面板SSL证书设置
|
||||
def setPanelHttpToHttps(self):
|
||||
|
||||
bind_domain = 'data/bind_domain.pl'
|
||||
if not os.path.exists(bind_domain):
|
||||
return mw.returnJson(False, '先要绑定域名!')
|
||||
|
||||
keyPath = 'ssl/private.pem'
|
||||
if not os.path.exists(keyPath):
|
||||
return mw.returnJson(False, '未申请SSL证书!')
|
||||
|
||||
is_https = request.form.get('https', '').strip()
|
||||
|
||||
panel_ssl = mw.getServerDir() + "/web_conf/nginx/vhost/panel.conf"
|
||||
|
||||
if is_https == 'true':
|
||||
conf = mw.readFile(panel_ssl)
|
||||
if conf:
|
||||
if conf.find('ssl_certificate') == -1:
|
||||
return mw.returnJson(False, '当前未开启SSL')
|
||||
to = "#error_page 404/404.html;\n\
|
||||
# HTTP_TO_HTTPS_START\n\
|
||||
if ($server_port !~ 443){\n\
|
||||
rewrite ^(/.*)$ https://$host$1 permanent;\n\
|
||||
}\n\
|
||||
# HTTP_TO_HTTPS_END"
|
||||
conf = conf.replace('#error_page 404/404.html;', to)
|
||||
mw.writeFile(panel_ssl, conf)
|
||||
else:
|
||||
conf = mw.readFile(file)
|
||||
if conf:
|
||||
rep = "\n\s*#HTTP_TO_HTTPS_START(.|\n){1,300}#HTTP_TO_HTTPS_END"
|
||||
conf = re.sub(rep, '', conf)
|
||||
rep = "\s+if.+server_port.+\n.+\n\s+\s*}"
|
||||
conf = re.sub(rep, '', conf)
|
||||
mw.writeFile(file, conf)
|
||||
|
||||
mw.restartWeb()
|
||||
|
||||
action = '开启'
|
||||
if is_https == 'false':
|
||||
action = '关闭'
|
||||
return mw.returnJson(True, action + 'HTTPS跳转成功!')
|
||||
|
||||
# 删除面板证书
|
||||
def delPanelSslApi(self):
|
||||
bind_domain = 'data/bind_domain.pl'
|
||||
|
|
|
|||
|
|
@ -446,9 +446,9 @@ function getPanelSSL(){
|
|||
<span class='ellipsis_text ssl_subject'>"+cert['info']['subject']+"</span></div>\
|
||||
<div class='state_item'>\
|
||||
<span>强制HTTPS:</span>\
|
||||
<span class='ellipsis_text switch'>\
|
||||
<span class='switch'>\
|
||||
<input class='btswitch btswitch-ios' id='toHttps' type='checkbox'>\
|
||||
<label class='btswitch-btn' for='toHttps' onclick=\"panelHttpToHttps()\"></label>\
|
||||
<label class='btswitch-btn set_panel_http_to_https' for='toHttps'></label>\
|
||||
</span>\
|
||||
</div>\
|
||||
</div></div>";
|
||||
|
|
@ -485,7 +485,7 @@ function getPanelSSL(){
|
|||
shadeClose: false,
|
||||
content:certBody,
|
||||
success:function(layero, layer_id){
|
||||
|
||||
|
||||
//保存SSL
|
||||
$('.save-panel-ssl').click(function(){
|
||||
var data = {
|
||||
|
|
@ -514,6 +514,18 @@ function getPanelSSL(){
|
|||
},'json');
|
||||
});
|
||||
|
||||
// 设置面板SSL的Http
|
||||
$('.set_panel_http_to_https').click(function(){
|
||||
var https = $('#toHttps').prop('checked');
|
||||
$.post('/config/del_panel_ssl',{'https':https},function(rdata){
|
||||
layer.close(loadT);
|
||||
if(rdata.status){
|
||||
layer.closeAll();
|
||||
}
|
||||
layer.msg(rdata.msg,{icon:rdata.status?1:2});
|
||||
},'json');
|
||||
});
|
||||
|
||||
//申请Lets证书
|
||||
$('.apply-lets-ssl').click(function(){
|
||||
showSpeedWindow('正在申请...', 'site.get_let_logs', function(layers,index){
|
||||
|
|
|
|||
Loading…
Reference in New Issue