mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-18 23:45:52 +08:00
ssl功能90%
This commit is contained in:
+34
-5
@@ -403,9 +403,9 @@ class site_api:
|
|||||||
'rm -rf /etc/letsencrypt/archive/' + siteName + '-00*')
|
'rm -rf /etc/letsencrypt/archive/' + siteName + '-00*')
|
||||||
public.execShell(
|
public.execShell(
|
||||||
'rm -f /etc/letsencrypt/renewal/' + siteName + '.conf')
|
'rm -f /etc/letsencrypt/renewal/' + siteName + '.conf')
|
||||||
public.execShell('rm -f /etc/letsencrypt/renewal/' +
|
public.execShell('rm -rf /etc/letsencrypt/renewal/' +
|
||||||
siteName + '-00*.conf')
|
siteName + '-00*.conf')
|
||||||
public.execShell('rm -f ' + path + '/README')
|
public.execShell('rm -rf ' + path + '/README')
|
||||||
public.execShell('mkdir -p ' + path)
|
public.execShell('mkdir -p ' + path)
|
||||||
|
|
||||||
public.writeFile(keypath, key)
|
public.writeFile(keypath, key)
|
||||||
@@ -424,9 +424,38 @@ class site_api:
|
|||||||
return public.returnJson(False, 'ERROR: <br><a style="color:red;">' + isError.replace("\n", '<br>') + '</a>')
|
return public.returnJson(False, 'ERROR: <br><a style="color:red;">' + isError.replace("\n", '<br>') + '</a>')
|
||||||
|
|
||||||
public.restartWeb()
|
public.restartWeb()
|
||||||
public.writeLog('TYPE_SITE', '证书已保存!')
|
public.writeLog('网站管理', '证书已保存!')
|
||||||
return public.returnJson(True, '证书已保存!')
|
return public.returnJson(True, '证书已保存!')
|
||||||
|
|
||||||
|
def setCertToSiteApi(self):
|
||||||
|
certName = request.form.get('certName', '').encode('utf-8')
|
||||||
|
siteName = request.form.get('siteName', '').encode('utf-8')
|
||||||
|
try:
|
||||||
|
path = self.sslDir + siteName
|
||||||
|
if not os.path.exists(path):
|
||||||
|
return public.returnJson(False, '证书不存在!')
|
||||||
|
|
||||||
|
result = self.setSslConf(siteName)
|
||||||
|
if not result['status']:
|
||||||
|
return public.getJson(result)
|
||||||
|
|
||||||
|
public.restartWeb()
|
||||||
|
public.writeLog('网站管理', '证书已部署!')
|
||||||
|
return public.returnJson(True, '证书已部署!')
|
||||||
|
except Exception as ex:
|
||||||
|
return public.returnJson(False, '设置错误,' + str(ex))
|
||||||
|
|
||||||
|
def removeCertApi(self):
|
||||||
|
certName = request.form.get('certName', '').encode('utf-8')
|
||||||
|
try:
|
||||||
|
path = self.sslDir + certName
|
||||||
|
if not os.path.exists(path):
|
||||||
|
return public.returnJson(False, '证书已不存在!')
|
||||||
|
os.system("rm -rf " + path)
|
||||||
|
return public.returnJson(True, '证书已删除!')
|
||||||
|
except:
|
||||||
|
return public.returnJson(False, '删除失败!')
|
||||||
|
|
||||||
def closeSslConfApi(self):
|
def closeSslConfApi(self):
|
||||||
siteName = request.form.get('siteName', '').encode('utf-8')
|
siteName = request.form.get('siteName', '').encode('utf-8')
|
||||||
|
|
||||||
@@ -633,11 +662,11 @@ class site_api:
|
|||||||
if conf.find('ssl_certificate') == -1:
|
if conf.find('ssl_certificate') == -1:
|
||||||
return public.returnJson(False, '当前未开启SSL')
|
return public.returnJson(False, '当前未开启SSL')
|
||||||
to = """#error_page 404/404.html;
|
to = """#error_page 404/404.html;
|
||||||
#HTTP_TO_HTTPS_START
|
# HTTP_TO_HTTPS_START
|
||||||
if ($server_port !~ 443){
|
if ($server_port !~ 443){
|
||||||
rewrite ^(/.*)$ https://$host$1 permanent;
|
rewrite ^(/.*)$ https://$host$1 permanent;
|
||||||
}
|
}
|
||||||
#HTTP_TO_HTTPS_END"""
|
# HTTP_TO_HTTPS_END"""
|
||||||
conf = conf.replace('#error_page 404/404.html;', to)
|
conf = conf.replace('#error_page 404/404.html;', to)
|
||||||
public.writeFile(file, conf)
|
public.writeFile(file, conf)
|
||||||
|
|
||||||
|
|||||||
@@ -1497,21 +1497,21 @@ function sslAdmin(siteName){
|
|||||||
function removeSsl(certName){
|
function removeSsl(certName){
|
||||||
safeMessage('删除证书','您真的要从证书夹删除证书吗?',function(){
|
safeMessage('删除证书','您真的要从证书夹删除证书吗?',function(){
|
||||||
var loadT = layer.msg(lan.site.the_msg,{icon:16,time:0,shade: [0.3, '#000']});
|
var loadT = layer.msg(lan.site.the_msg,{icon:16,time:0,shade: [0.3, '#000']});
|
||||||
$.post('/ssl?action=RemoveCert',{certName:certName},function(rdata){
|
$.post('/site/remove_cert',{certName:certName},function(rdata){
|
||||||
layer.close(loadT);
|
layer.close(loadT);
|
||||||
layer.msg(rdata.msg,{icon:rdata.status?1:2});
|
layer.msg(rdata.msg,{icon:rdata.status?1:2});
|
||||||
$("#ssl_admin").click();
|
$("#ssl_admin").click();
|
||||||
});
|
},'json');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//从证书夹部署
|
//从证书夹部署
|
||||||
function setCertSsl(certName,siteName){
|
function setCertSsl(certName,siteName){
|
||||||
var loadT = layer.msg('正在部署证书...',{icon:16,time:0,shade: [0.3, '#000']});
|
var loadT = layer.msg('正在部署证书...',{icon:16,time:0,shade: [0.3, '#000']});
|
||||||
$.post('/ssl?action=SetCertToSite',{certName:certName,siteName:siteName},function(rdata){
|
$.post('/site/set_cert_to_site',{certName:certName,siteName:siteName},function(rdata){
|
||||||
layer.close(loadT);
|
layer.close(loadT);
|
||||||
layer.msg(rdata.msg,{icon:rdata.status?1:2});
|
layer.msg(rdata.msg,{icon:rdata.status?1:2});
|
||||||
});
|
},'json');
|
||||||
}
|
}
|
||||||
|
|
||||||
//ssl
|
//ssl
|
||||||
|
|||||||
Reference in New Issue
Block a user