Skip to content

Commit

Permalink
7.1.16
Browse files Browse the repository at this point in the history
  • Loading branch information
showpy committed Jan 2, 2020
1 parent 8659709 commit e99554b
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 204 deletions.
20 changes: 17 additions & 3 deletions BT-Panel
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,27 @@ if __name__ == '__main__':

keyfile = 'ssl/privateKey.pem'
certfile = 'ssl/certificate.pem'
is_ssl = False
if os.path.exists('data/ssl.pl') and os.path.exists(keyfile) and os.path.exists(certfile):
is_ssl = True
if os.path.exists('data/debug.pl'):
ssl_context = None
if os.path.exists('data/ssl.pl'): ssl_context=(certfile,keyfile)
if is_ssl: ssl_context=(certfile,keyfile)
app.run(host=HOST,port=PORT,threaded=True,debug=True,ssl_context=ssl_context)
else:
if os.path.exists('data/ssl.pl'):
http_server = WSGIServer((HOST, PORT), app,handler_class=WebSocketHandler,keyfile=keyfile,certfile=certfile,log=None,error_log = None)
if is_ssl:
my_ssl = {
'certfile': certfile,
'keyfile': keyfile,
'ciphers': 'ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE',
'ssl_version':ssl.OP_NO_SSLv3,
'suppress_ragged_eofs':False
}
ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ssl_context.load_cert_chain(certfile=certfile,keyfile=keyfile)
ssl_context.options &= ~ssl.OP_NO_SSLv3

http_server = WSGIServer((HOST, PORT), app,handler_class=WebSocketHandler,ssl_context = ssl_context)
else:
http_server = WSGIServer((HOST, PORT), app,handler_class=WebSocketHandler)
http_server.serve_forever()
23 changes: 14 additions & 9 deletions BTPanel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,15 +634,19 @@ def config(pdata = None):
if public.is_local(): data['is_local'] = 'checked'
return render_template( 'config.html',data=data)
import config
defs = (
'get_panel_error_logs', 'clean_panel_error_logs', 'get_basic_auth_stat', 'set_basic_auth', 'get_cli_php_version',
'get_tmp_token', 'set_cli_php_version', 'DelOldSession', 'GetSessionCount', 'SetSessionConf', 'GetSessionConf',
'get_ipv6_listen', 'set_ipv6_status', 'GetApacheValue', 'SetApacheValue', 'GetNginxValue', 'SetNginxValue',
'get_token', 'set_token', 'set_admin_path', 'is_pro', 'get_php_config', 'get_config', 'SavePanelSSL', 'GetPanelSSL',
'GetPHPConf', 'SetPHPConf', 'GetPanelList', 'AddPanelInfo', 'SetPanelInfo', 'DelPanelInfo', 'ClickPanelInfo',
'SetPanelSSL', 'SetTemplates', 'Set502', 'setPassword', 'setUsername', 'setPanel', 'setPathInfo', 'setPHPMaxSize',
'getFpmConfig', 'setFpmConfig', 'setPHPMaxTime', 'syncDate', 'setPHPDisable', 'SetControl', 'ClosePanel',
'AutoUpdatePanel', 'SetPanelLock','return_mail_list','del_mail_list','add_mail_address','user_mail_send','get_user_mail','set_dingding','get_dingding','get_settings','user_stmp_mail_send','user_dingding_send')
defs = ('set_coll_open','get_qrcode_data','check_two_step','set_two_step_auth',
'get_key','get_php_session_path','set_php_session_path','get_cert_source',
'set_local','set_debug','get_panel_error_logs','clean_panel_error_logs',
'get_basic_auth_stat','set_basic_auth','get_cli_php_version','get_tmp_token',
'set_cli_php_version','DelOldSession', 'GetSessionCount', 'SetSessionConf',
'GetSessionConf','get_ipv6_listen','set_ipv6_status','GetApacheValue','SetApacheValue',
'GetNginxValue','SetNginxValue','get_token','set_token','set_admin_path','is_pro',
'get_php_config','get_config','SavePanelSSL','GetPanelSSL','GetPHPConf','SetPHPConf',
'GetPanelList','AddPanelInfo','SetPanelInfo','DelPanelInfo','ClickPanelInfo','SetPanelSSL',
'SetTemplates','Set502','setPassword','setUsername','setPanel','setPathInfo','setPHPMaxSize',
'getFpmConfig','setFpmConfig','setPHPMaxTime','syncDate','setPHPDisable','SetControl',
'ClosePanel','AutoUpdatePanel','SetPanelLock'
)
return publicObject(config.config(),defs,None,pdata)

@app.route('/ajax',methods=method_all)
Expand All @@ -659,6 +663,7 @@ def ajax(pdata = None):
'UninstallLib','InstallLib','SetQiniuAS','GetQiniuAS','GetLibList','GetProcessList','GetNetWorkList',
'GetNginxStatus','GetPHPStatus','GetTaskCount','GetSoftList','GetNetWorkIo','GetDiskIo','GetCpuIo',
'CheckInstalled','UpdatePanel','GetInstalled','GetPHPConfig','SetPHPConfig')

return publicObject(ajaxObject,defs,None,pdata)

@app.route('/system',methods=method_all)
Expand Down
79 changes: 41 additions & 38 deletions class/acme_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
os.chdir('/www/server/panel')
sys.path.append('class/')
import http_requests as requests
requests.DEFAULT_TYPE = 'curl'
import public

#import requests
Expand Down Expand Up @@ -748,44 +749,46 @@ def get_cert_init_api(self, args):
def get_cert_init(self, pem_file):
if not os.path.exists(pem_file):
return None
result = {}
x509 = OpenSSL.crypto.load_certificate(
OpenSSL.crypto.FILETYPE_PEM, public.readFile(pem_file))
# 取产品名称
issuer = x509.get_issuer()
result['issuer'] = ''
if hasattr(issuer, 'CN'):
result['issuer'] = issuer.CN
if not result['issuer']:
is_key = [b'0', '0']
issue_comp = issuer.get_components()
if len(issue_comp) == 1:
is_key = [b'CN', 'CN']
for iss in issue_comp:
if iss[0] in is_key:
result['issuer'] = iss[1].decode()
break
# 取到期时间
result['notAfter'] = self.strf_date(
bytes.decode(x509.get_notAfter())[:-1])
# 取申请时间
result['notBefore'] = self.strf_date(
bytes.decode(x509.get_notBefore())[:-1])
# 取可选名称
result['dns'] = []
for i in range(x509.get_extension_count()):
s_name = x509.get_extension(i)
if s_name.get_short_name() in [b'subjectAltName', 'subjectAltName']:
s_dns = str(s_name).split(',')
for d in s_dns:
result['dns'].append(d.split(':')[1])
subject = x509.get_subject().get_components()
# 取主要认证名称
if len(subject) == 1:
result['subject'] = subject[0][1].decode()
else:
result['subject'] = result['dns'][0]
return result
try:
result = {}
x509 = OpenSSL.crypto.load_certificate(
OpenSSL.crypto.FILETYPE_PEM, public.readFile(pem_file))
# 取产品名称
issuer = x509.get_issuer()
result['issuer'] = ''
if hasattr(issuer, 'CN'):
result['issuer'] = issuer.CN
if not result['issuer']:
is_key = [b'0', '0']
issue_comp = issuer.get_components()
if len(issue_comp) == 1:
is_key = [b'CN', 'CN']
for iss in issue_comp:
if iss[0] in is_key:
result['issuer'] = iss[1].decode()
break
# 取到期时间
result['notAfter'] = self.strf_date(
bytes.decode(x509.get_notAfter())[:-1])
# 取申请时间
result['notBefore'] = self.strf_date(
bytes.decode(x509.get_notBefore())[:-1])
# 取可选名称
result['dns'] = []
for i in range(x509.get_extension_count()):
s_name = x509.get_extension(i)
if s_name.get_short_name() in [b'subjectAltName', 'subjectAltName']:
s_dns = str(s_name).split(',')
for d in s_dns:
result['dns'].append(d.split(':')[1])
subject = x509.get_subject().get_components()
# 取主要认证名称
if len(subject) == 1:
result['subject'] = subject[0][1].decode()
else:
result['subject'] = result['dns'][0]
return result
except: return None

# 转换时间
def strf_date(self, sdate):
Expand Down
2 changes: 1 addition & 1 deletion class/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def init(self):
ua = ua.lower()
if ua.find('spider') != -1 or ua.find('bot') != -1:
return redirect('https://www.baidu.com')
g.version = '7.1.15'
g.version = '7.1.16'
g.title = public.GetConfigValue('title')
g.uri = request.path
session['version'] = g.version
Expand Down
27 changes: 15 additions & 12 deletions class/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

from BTPanel import session,admin_path_checks
from flask import request
import send_mail
try:
import send_mail
except:pass
class config:
_setup_path = "/www/server/panel"
_key_file = _setup_path+"/data/two_step_auth.txt"
Expand All @@ -29,18 +31,19 @@ class config:
__weixin_user = []

def __init__(self):
self.mail = send_mail.send_mail()
if not os.path.exists(self.__mail_list_data):
ret = []
public.writeFile(self.__mail_list_data, json.dumps(ret))
else:
try:
mail_data = json.loads(public.ReadFile(self.__mail_list_data))
self.__mail_list = mail_data
except:
try:
self.mail = send_mail.send_mail()
if not os.path.exists(self.__mail_list_data):
ret = []
public.writeFile(self.__mail_list_data, json.dumps(ret))

else:
try:
mail_data = json.loads(public.ReadFile(self.__mail_list_data))
self.__mail_list = mail_data
except:
ret = []
public.writeFile(self.__mail_list_data, json.dumps(ret))
except:pass
# 返回配置邮件地址
def return_mail_list(self, get):
return public.returnMsg(True, self.__mail_list)
Expand Down Expand Up @@ -701,7 +704,7 @@ def GetPHPConf(self,get):

result = []
for g in gets:
rep = g['name'] + '\s*=\s*([0-9A-Za-z_& ~]+)(\s*;?|\r?\n)';
rep = g['name'] + '\s*=\s*([0-9A-Za-z_&/ ~]+)(\s*;?|\r?\n)';
tmp = re.search(rep,phpini)
if not tmp: continue;
g['value'] = tmp.groups()[0];
Expand Down
34 changes: 21 additions & 13 deletions class/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,22 +893,31 @@ def GetFileBody(self, get):
detector.close()
char = detector.result
data['encoding'] = char['encoding']
if char['encoding'] == 'GB2312' or not char['encoding'] or char['encoding'] == 'TIS-620' or char['encoding'] == 'ISO-8859-9':
data['encoding'] = 'GBK'
if char['encoding'] == 'ascii' or char['encoding'] == 'ISO-8859-1':
data['encoding'] = 'utf-8'
if char['encoding'] == 'Big5':
data['encoding'] = 'BIG5'
if not char['encoding'] in ['GBK', 'utf-8', 'BIG5']:
data['encoding'] = 'utf-8'
try:
if sys.version_info[0] == 2:
data['data'] = srcBody.decode(data['encoding']).encode('utf-8', errors='ignore')
else:
data['data'] = srcBody.decode(data['encoding'])
except:
data['encoding'] = char['encoding']
data['data'] = srcBody
try:
if sys.version_info[0] == 2:
data['data'] = srcBody.decode('GBK').encode('utf-8', errors='ignore')
else:
data['data'] = srcBody.decode("GBK")
except:
try:
if sys.version_info[0] == 2:
data['data'] = srcBody.decode('BIG5').encode('utf-8', errors='ignore')
else:
data['data'] = srcBody.decode("BIG5")
except:
try:
if sys.version_info[0] == 2:
data['data'] = srcBody.decode('utf-8').encode('utf-8', errors='ignore')
else:
data['data'] = srcBody.decode("utf-8")
except:
return public.returnMsg(False, u'文件编码不被兼容,无法正确读取文件!')
else:
return public.returnMsg(False, '打开文件失败,文件可能被其它进程占用!')
if hasattr(get, 'filename'):
Expand All @@ -917,7 +926,7 @@ def GetFileBody(self, get):
data['auto_save'] = self.get_auto_save(get.path)
return data
except Exception as ex:
return public.returnMsg(False, u'文件编码不被兼容,无法正确读取文件!' + public.get_error_info())
return public.returnMsg(False, u'文件编码不被兼容,无法正确读取文件!' + str(ex))

# 保存文件
def SaveFileBody(self, get):
Expand Down Expand Up @@ -965,8 +974,7 @@ def SaveFileBody(self, get):
fp = open(get.path, 'w+')
else:

data = data.encode(
get.encoding, errors='ignore').decode(get.encoding)
data = data.encode(get.encoding , errors='ignore').decode(get.encoding)
fp = open(get.path, 'w+', encoding=get.encoding)
except:
fp = open(get.path, 'w+')
Expand Down
26 changes: 21 additions & 5 deletions class/http_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self):
pass

def get(self,url,timeout = 60,headers = {},verify = False,type = 'python'):
url = self.quote(url)
if type == 'python':
if sys.version_info[0] == 2:
result = self._get_py2(url,timeout,headers,verify)
Expand All @@ -32,6 +33,7 @@ def get(self,url,timeout = 60,headers = {},verify = False,type = 'python'):
return result

def post(self,url,data,timeout = 60,headers = {},verify = False,type = 'python'):
url = self.quote(url)
if type == 'python':
if sys.version_info[0] == 2:
result = self._post_py2(url,data,timeout,headers,verify)
Expand All @@ -48,7 +50,7 @@ def _post_py2(self,url,data,timeout,headers,verify):
import urllib2
req = urllib2.Request(url, self._str_py_post(data,headers),headers = headers)
try:
if verify:
if not verify:
context = ssl._create_unverified_context()
r_response = urllib2.urlopen(req,timeout = timeout,context = context)
else:
Expand All @@ -64,7 +66,7 @@ def _post_py3(self,url,data,timeout,headers,verify):
import urllib.request
req = urllib.request.Request(url, self._str_py_post(data,headers),headers = headers)
try:
if verify:
if not verify:
context = ssl._create_unverified_context()
r_response = urllib.request.urlopen(req,timeout = timeout,context = context)
else:
Expand Down Expand Up @@ -140,7 +142,7 @@ def _get_py2(self,url,timeout,headers,verify):
import urllib2
req = urllib2.Request(url, headers = headers)
try:
if verify:
if not verify:
context = ssl._create_unverified_context()
r_response = urllib2.urlopen(req,timeout = timeout,context = context)
else:
Expand All @@ -151,12 +153,26 @@ def _get_py2(self,url,timeout,headers,verify):
return response(str(err),0,[])
return response(r_response.read(),r_response.getcode(),r_response.info().headers)

#URL转码
def quote(self,url):
url_tmp = url.split('?')
if len(url_tmp) == 1: return url
url_last = url_tmp[0]
url_args = '?'.join(url_tmp[1:])
if sys.version_info[0] == 2:
import urllib2
url_args = urllib2.quote(url_args)
else:
import urllib.parse
url_args = urllib.parse.quote(url_args)
return url_last + '?' + url_args

#GET请求 Python3
def _get_py3(self,url,timeout,headers,verify):
import urllib.request
import urllib.request
req = urllib.request.Request(url,headers = headers)
try:
if verify:
if not verify:
context = ssl._create_unverified_context()
r_response = urllib.request.urlopen(req,timeout = timeout,context = context)
else:
Expand Down
Loading

0 comments on commit e99554b

Please sign in to comment.