mirror of
https://github.com/aaPanel/aaPanel.git
synced 2026-09-13 21:17:40 +02:00
update 6.1.5
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ class panelSetup:
|
||||
if ua:
|
||||
ua = ua.lower();
|
||||
if ua.find('spider') != -1 or ua.find('bot') != -1: return redirect('https://www.baidu.com');
|
||||
g.version = '6.1.4'
|
||||
g.version = '6.1.5'
|
||||
g.title = public.GetConfigValue('title')
|
||||
g.uri = request.path
|
||||
session['version'] = g.version;
|
||||
|
||||
+45
-16
@@ -416,20 +416,29 @@ class config:
|
||||
|
||||
#设置面板SSL
|
||||
def SetPanelSSL(self,get):
|
||||
sslConf = '/www/server/panel/data/ssl.pl';
|
||||
if os.path.exists(sslConf):
|
||||
os.system('rm -f ' + sslConf);
|
||||
return public.returnMsg(True,'PANEL_SSL_CLOSE');
|
||||
if hasattr(get,"email"):
|
||||
rep_mail = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$"
|
||||
if not re.search(rep_mail,get.email):
|
||||
return public.returnMsg(False,'The E-Mail format is illegal')
|
||||
import setPanelLets
|
||||
sp = setPanelLets.setPanelLets()
|
||||
sps = sp.set_lets(get)
|
||||
return sps
|
||||
else:
|
||||
os.system('pip install cffi');
|
||||
os.system('pip install cryptography');
|
||||
os.system('pip install pyOpenSSL');
|
||||
try:
|
||||
if not self.CreateSSL(): return public.returnMsg(False,'PANEL_SSL_ERR');
|
||||
public.writeFile(sslConf,'True')
|
||||
except Exception as ex:
|
||||
return public.returnMsg(False,'PANEL_SSL_ERR');
|
||||
return public.returnMsg(True,'PANEL_SSL_OPEN');
|
||||
sslConf = '/www/server/panel/data/ssl.pl';
|
||||
if os.path.exists(sslConf):
|
||||
os.system('rm -f ' + sslConf);
|
||||
return public.returnMsg(True,'PANEL_SSL_CLOSE');
|
||||
else:
|
||||
os.system('pip install cffi');
|
||||
os.system('pip install cryptography');
|
||||
os.system('pip install pyOpenSSL');
|
||||
try:
|
||||
if not self.CreateSSL(): return public.returnMsg(False,'PANEL_SSL_ERR');
|
||||
public.writeFile(sslConf,'True')
|
||||
except Exception as ex:
|
||||
return public.returnMsg(False,'PANEL_SSL_ERR');
|
||||
return public.returnMsg(True,'PANEL_SSL_OPEN');
|
||||
#自签证书
|
||||
def CreateSSL(self):
|
||||
if os.path.exists('ssl/input.pl'): return True;
|
||||
@@ -447,8 +456,8 @@ class config:
|
||||
cert_ca = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)
|
||||
private_key = OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, key)
|
||||
if len(cert_ca) > 100 and len(private_key) > 100:
|
||||
public.writeFile('ssl/certificate.pem',cert_ca)
|
||||
public.writeFile('ssl/privateKey.pem',private_key)
|
||||
public.writeFile('ssl/certificate.pem',cert_ca,'wb+')
|
||||
public.writeFile('ssl/privateKey.pem',private_key,'wb+')
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -912,4 +921,24 @@ class config:
|
||||
filename = 'logs/error.log'
|
||||
public.writeFile(filename,'')
|
||||
public.WriteLog('P_CONF','CLEARING_LOG')
|
||||
return public.returnMsg(True,'CLEARED')
|
||||
return public.returnMsg(True,'CLEARED')
|
||||
|
||||
# 获取lets证书
|
||||
def get_cert_source(self,get):
|
||||
import setPanelLets
|
||||
sp = setPanelLets.setPanelLets()
|
||||
spg = sp.get_cert_source()
|
||||
return spg
|
||||
|
||||
#设置debug模式
|
||||
def set_debug(self,get):
|
||||
debug_path = 'data/debug.pl'
|
||||
if os.path.exists(debug_path):
|
||||
t_str = 'Close'
|
||||
os.remove(debug_path)
|
||||
else:
|
||||
t_str = 'Open'
|
||||
public.writeFile(debug_path,'True')
|
||||
public.WriteLog('TYPE_PANEL','%sDeveloper mode(debug)' % t_str)
|
||||
public.restart_panel()
|
||||
return public.returnMsg(True,'Successful setup!')
|
||||
+6
-4
@@ -135,9 +135,11 @@ class files:
|
||||
s_path = os.path.dirname(path)
|
||||
p_stat = os.stat(s_path)
|
||||
os.chown(path,p_stat.st_uid,p_stat.st_gid)
|
||||
os.chmod(path,p_stat.st_mode)
|
||||
if os.path.isfile(path):
|
||||
os.chmod(path,0644)
|
||||
else:
|
||||
os.chmod(path,p_stat.st_mode)
|
||||
|
||||
|
||||
#取文件/目录列表
|
||||
def GetDir(self,get):
|
||||
if not hasattr(get,'path'):
|
||||
@@ -796,7 +798,7 @@ class files:
|
||||
data['chmod'] = str(oct(stat.st_mode)[-3:])
|
||||
data['chown'] = pwd.getpwuid(stat.st_uid).pw_name
|
||||
except:
|
||||
data['chmod'] = 755
|
||||
data['chmod'] = 644
|
||||
data['chown'] = 'www'
|
||||
return data
|
||||
|
||||
@@ -819,7 +821,7 @@ class files:
|
||||
|
||||
def SetFileAccept(self,filename):
|
||||
os.system('chown -R www:www ' + filename)
|
||||
os.system('chmod -R 755 ' + filename)
|
||||
os.system('chmod -R 644 ' + filename)
|
||||
|
||||
|
||||
|
||||
|
||||
+16
-6
@@ -151,7 +151,7 @@ class panelSite(panelRedirect):
|
||||
|
||||
htaccess = self.sitePath+'/.htaccess'
|
||||
if not os.path.exists(htaccess): public.writeFile(htaccess, ' ');
|
||||
public.ExecShell('chmod -R 755 ' + htaccess);
|
||||
public.ExecShell('chmod -R 644 ' + htaccess);
|
||||
public.ExecShell('chown -R www:www ' + htaccess);
|
||||
|
||||
filename = self.setupPath+'/panel/vhost/apache/'+self.siteName+'.conf'
|
||||
@@ -298,21 +298,21 @@ class panelSite(panelRedirect):
|
||||
if not os.path.exists(userIni):
|
||||
public.writeFile(userIni, 'open_basedir='+self.sitePath+'/:/tmp/:/proc/');
|
||||
public.ExecShell('chmod 644 ' + userIni);
|
||||
public.ExecShell('chown root:root ' + userIni);
|
||||
public.ExecShell('chown www:www ' + userIni);
|
||||
public.ExecShell('chattr +i '+userIni);
|
||||
|
||||
#创建默认文档
|
||||
index = self.sitePath+'/index.html'
|
||||
if not os.path.exists(index):
|
||||
public.writeFile(index, public.readFile('data/defaultDoc.html'))
|
||||
public.ExecShell('chmod -R 755 ' + index);
|
||||
public.ExecShell('chmod -R 644 ' + index);
|
||||
public.ExecShell('chown -R www:www ' + index);
|
||||
|
||||
#创建自定义404页
|
||||
doc404 = self.sitePath+'/404.html'
|
||||
if not os.path.exists(doc404):
|
||||
public.writeFile(doc404, public.readFile('data/404.html'));
|
||||
public.ExecShell('chmod -R 755 ' + doc404);
|
||||
public.ExecShell('chmod -R 644 ' + doc404);
|
||||
public.ExecShell('chown -R www:www ' + doc404);
|
||||
|
||||
#写入配置
|
||||
@@ -864,7 +864,15 @@ class panelSite(panelRedirect):
|
||||
if self.GetRedirectList(get): return public.returnMsg(False, 'SITE_SSL_ERR_301');
|
||||
if self.GetProxyList(get): return public.returnMsg(False,'Sites that have reverse proxy turned on cannot request SSL!');
|
||||
data = self.get_site_info(get.siteName)
|
||||
get.site_dir = data['path']
|
||||
get.id = data['id']
|
||||
runPath = self.GetRunPath(get)
|
||||
if runPath != '/':
|
||||
if runPath[:1] != '/': runPath = '/' + runPath
|
||||
else:
|
||||
runPath = ''
|
||||
get.site_dir = data['path'] + runPath
|
||||
print(get.site_dir)
|
||||
|
||||
else:
|
||||
dns_api_list = self.GetDnsApi(get)
|
||||
get.dns_param = None
|
||||
@@ -2084,7 +2092,9 @@ server
|
||||
n = 0
|
||||
for w in ["nginx", "apache"]:
|
||||
conf_path = "%s/panel/vhost/%s/%s.conf" % (self.setupPath, w, get.sitename)
|
||||
old_conf = public.readFile(conf_path)
|
||||
old_conf = ""
|
||||
if os.path.exists(conf_path):
|
||||
old_conf = public.readFile(conf_path)
|
||||
rep = "(#PROXY-START(\n|.)+#PROXY-END)"
|
||||
url_rep = "proxy_pass (.*);|ProxyPass\s/\s(.*)|Host\s(.*);"
|
||||
host_rep = "Host\s(.*);"
|
||||
|
||||
+404
-282
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,165 @@
|
||||
#coding: utf-8
|
||||
# +-------------------------------------------------------------------
|
||||
# | 宝塔Linux面板
|
||||
# +-------------------------------------------------------------------
|
||||
# | Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved.
|
||||
# +-------------------------------------------------------------------
|
||||
# | Author: 邹浩文 <627622230@qq.com>
|
||||
# +-------------------------------------------------------------------
|
||||
import os
|
||||
os.chdir("/www/server/panel")
|
||||
import public,db,panelSSL,json
|
||||
|
||||
|
||||
class setPanelLets:
|
||||
__vhost_cert_path = "/www/server/panel/vhost/ssl/"
|
||||
__panel_cert_path = "/www/server/panel/ssl/"
|
||||
__tmp_key = ""
|
||||
__tmp_cert = ""
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
# 保存面板证书
|
||||
def __save_panel_cert(self,cert,key):
|
||||
keyPath = 'ssl/privateKey.pem'
|
||||
certPath = 'ssl/certificate.pem'
|
||||
checkCert = '/tmp/cert.pl'
|
||||
public.writeFile(checkCert,cert)
|
||||
if key:
|
||||
public.writeFile(keyPath,key)
|
||||
if cert:
|
||||
public.writeFile(certPath,cert)
|
||||
if not public.CheckCert(checkCert): return public.returnMsg(False,'Certificate error, please check!')
|
||||
public.writeFile('ssl/input.pl','True')
|
||||
return public.returnMsg(True,'The certificate has been saved!')
|
||||
|
||||
# 检查是否存在站点aapanel主机名站点
|
||||
def __check_host_name(self, domain):
|
||||
sql = db.Sql()
|
||||
path = sql.table('sites').where('name=?', (domain,)).getField('path')
|
||||
return path
|
||||
|
||||
# 创建证书使用的站点
|
||||
def __create_site_of_panel_lets(self,get):
|
||||
import panelSite
|
||||
ps = panelSite.panelSite()
|
||||
get.webname = json.dumps({"domain":get.domain,"domainlist":[],"count":0})
|
||||
get.ps = "For panel Let's Encrypt certificate request and renewal, please do not delete"
|
||||
get.path = "/www/wwwroot/panel_ssl_site"
|
||||
get.ftp = "false"
|
||||
get.sql = "false"
|
||||
get.codeing = "utf8"
|
||||
get.type = "PHP"
|
||||
get.version = "00"
|
||||
get.type_id = "0"
|
||||
get.port = "80"
|
||||
psa = ps.AddSite(get)
|
||||
if "status" in psa.keys():
|
||||
return psa
|
||||
|
||||
# 申请面板域名证书
|
||||
def __create_lets(self,get):
|
||||
import panelSite
|
||||
ps = panelSite.panelSite()
|
||||
get.siteName = get.domain
|
||||
get.updateOf = "1"
|
||||
get.domains = json.dumps([get.domain])
|
||||
get.force = "true"
|
||||
psc = ps.CreateLet(get)
|
||||
if "False" in psc.values():
|
||||
return psc
|
||||
|
||||
# 检查证书夹是否存在可用证书
|
||||
def __check_cert_dir(self,get):
|
||||
pssl = panelSSL.panelSSL()
|
||||
gcl = pssl.GetCertList(get)
|
||||
for i in gcl:
|
||||
if get.domain in i.values():
|
||||
return i
|
||||
|
||||
# 读取可用站点证书
|
||||
def __read_site_cert(self,domain_cert):
|
||||
self.__tmp_key = public.readFile("{path}{domain}/{key}".format(path=self.__vhost_cert_path,domain=domain_cert["subject"],key="privkey.pem"))
|
||||
self.__tmp_cert = public.readFile(
|
||||
"{path}{domain}/{cert}".format(path=self.__vhost_cert_path, domain=domain_cert["subject"],
|
||||
cert="fullchain.pem"))
|
||||
public.writeFile("/tmp/2",str(self.__tmp_cert))
|
||||
|
||||
# 检查面板证书是否存在
|
||||
def __check_panel_cert(self):
|
||||
key = public.readFile(self.__panel_cert_path+"privateKey.pem")
|
||||
cert = public.readFile(self.__panel_cert_path+"certificate.pem")
|
||||
if key and cert:
|
||||
return {"key":key,"cert":cert}
|
||||
|
||||
# 写面板证书
|
||||
def __write_panel_cert(self):
|
||||
public.writeFile(self.__panel_cert_path + "privateKey.pem", self.__tmp_key)
|
||||
public.writeFile(self.__panel_cert_path + "certificate.pem", self.__tmp_cert)
|
||||
|
||||
# 记录证书源
|
||||
def __save_cert_source(self,domain,email):
|
||||
public.writeFile(self.__panel_cert_path+"lets.info",json.dumps({"domain":domain,"cert_type":"2","email":email}))
|
||||
|
||||
# 获取证书源
|
||||
def get_cert_source(self):
|
||||
data = public.readFile(self.__panel_cert_path+"lets.info")
|
||||
if not data:
|
||||
return {"cert_type":"","email":"","domain":""}
|
||||
return json.loads(data)
|
||||
|
||||
# 检查面板是否绑定域名
|
||||
def __check_panel_domain(self):
|
||||
domain = public.readFile("/www/server/panel/data/domain.conf")
|
||||
if not domain:
|
||||
return False
|
||||
return domain
|
||||
|
||||
# 复制证书
|
||||
def copy_cert(self,domain_cert):
|
||||
self.__read_site_cert(domain_cert)
|
||||
panel_cert_data = self.__check_panel_cert()
|
||||
if not panel_cert_data:
|
||||
self.__write_panel_cert()
|
||||
return True
|
||||
else:
|
||||
if panel_cert_data["key"] == self.__tmp_key and panel_cert_data["cert"] == self.__tmp_cert:
|
||||
pass
|
||||
else:
|
||||
self.__write_panel_cert()
|
||||
return True
|
||||
|
||||
# 设置lets证书
|
||||
def set_lets(self,get):
|
||||
"""
|
||||
传入参数
|
||||
get.domain 面板域名
|
||||
get.email 管理员email
|
||||
"""
|
||||
create_site = ""
|
||||
domain = self.__check_panel_domain()
|
||||
get.domain = domain
|
||||
if not domain:
|
||||
return public.returnMsg(False, "You need to bind the domain name to the panel before you can apply for the Let\'s Encrypt certificate.")
|
||||
if not self.__check_host_name(domain):
|
||||
create_site = self.__create_site_of_panel_lets(get)
|
||||
domain_cert = self.__check_cert_dir(get)
|
||||
if domain_cert:
|
||||
self.copy_cert(domain_cert)
|
||||
public.writeFile("/www/server/panel/data/ssl.pl", "True")
|
||||
public.writeFile("/www/server/panel/data/reload.pl","1")
|
||||
self.__save_cert_source(domain,get.email)
|
||||
return public.returnMsg(True, 'Panel lets set successfully')
|
||||
if not create_site:
|
||||
create_lets = self.__create_lets(get)
|
||||
if not create_lets:
|
||||
domain_cert = self.__check_cert_dir(get)
|
||||
self.copy_cert(domain_cert)
|
||||
public.writeFile("/www/server/panel/data/ssl.pl", "True")
|
||||
public.writeFile("/www/server/panel/data/reload.pl", "1")
|
||||
self.__save_cert_source(domain, get.email)
|
||||
return public.returnMsg(True, 'Panel lets set successfully')
|
||||
else:
|
||||
return create_lets
|
||||
else:
|
||||
return create_site
|
||||
@@ -13,7 +13,9 @@ import cryptography
|
||||
|
||||
from . import __version__ as sewer_version
|
||||
from .config import ACME_DIRECTORY_URL_PRODUCTION
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
try:
|
||||
requests.packages.urllib3.disable_warnings()
|
||||
except:pass
|
||||
|
||||
|
||||
class Client(object):
|
||||
@@ -585,6 +587,7 @@ class Client(object):
|
||||
"""
|
||||
self.logger.debug("get_acme_header")
|
||||
header = {"alg": "RS256", "nonce": self.get_nonce(), "url": url}
|
||||
|
||||
if url in [self.ACME_NEW_ACCOUNT_URL, self.ACME_REVOKE_CERT_URL, "GET_THUMBPRINT"]:
|
||||
private_key = cryptography.hazmat.primitives.serialization.load_pem_private_key(
|
||||
self.account_key.encode(),
|
||||
@@ -605,6 +608,7 @@ class Client(object):
|
||||
header["jwk"] = jwk
|
||||
else:
|
||||
header["kid"] = self.kid
|
||||
print('h:',url,header)
|
||||
return header
|
||||
|
||||
def make_signed_acme_request(self, url, payload):
|
||||
|
||||
Reference in New Issue
Block a user