diff --git a/BT-Panel b/BT-Panel index 3659648f..2188b694 100644 --- a/BT-Panel +++ b/BT-Panel @@ -1,7 +1,7 @@ #!/www/server/panel/pyenv/bin/python #coding: utf-8 # +------------------------------------------------------------------- -# | 宝塔Linux面板 +# | 宝塔Linux面板 # +------------------------------------------------------------------- # | Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved. # +------------------------------------------------------------------- @@ -18,6 +18,14 @@ upgrade_file = 'script/upgrade_flask.sh' if os.path.exists(upgrade_file): os.system("nohup bash {} &>/dev/null &".format(upgrade_file)) +upgrade_file = 'script/upgrade_gevent.sh' +if os.path.exists(upgrade_file): + os.system("nohup bash {} &>/dev/null &".format(upgrade_file)) + +upgrade_file = 'script/upgrade_telegram.sh' +if os.path.exists(upgrade_file): + os.system("nohup bash {} &>/dev/null &".format(upgrade_file)) + if os.path.exists('class/flask'): os.system('rm -rf class/flask') @@ -28,23 +36,23 @@ from BTPanel import app,sys,public is_debug = os.path.exists('data/debug.pl') -# # 检查加载器 -# def check_plugin_loader(): -# plugin_loader_file = 'class/PluginLoader.so' -# machine = 'x86_64' -# try: -# machine = os.uname().machine -# except: -# pass -# plugin_loader_src_file = "class/PluginLoader.{}.Python3.7.so".format(machine) -# if machine == 'x86_64': -# glibc_version = public.get_glibc_version() -# if glibc_version in ['2.14','2.13','2.12','2.11','2.10']: -# plugin_loader_src_file = "class/PluginLoader.{}.glibc214.Python3.7.so".format(machine) -# if os.path.exists(plugin_loader_src_file): -# os.system("\cp -f {} {}".format(plugin_loader_src_file, plugin_loader_file)) +# 检查加载器 +def check_plugin_loader(): + plugin_loader_file = 'class/PluginLoader.so' + machine = 'x86_64' + try: + machine = os.uname().machine + except: + pass + plugin_loader_src_file = "class/PluginLoader.{}.Python3.7.so".format(machine) + if machine == 'x86_64': + glibc_version = public.get_glibc_version() + if glibc_version in ['2.14','2.13','2.12','2.11','2.10']: + plugin_loader_src_file = "class/PluginLoader.{}.glibc214.Python3.7.so".format(machine) + if os.path.exists(plugin_loader_src_file): + os.system("\cp -f {} {}".format(plugin_loader_src_file, plugin_loader_file)) -# check_plugin_loader() +check_plugin_loader() if is_debug: @@ -103,8 +111,7 @@ if is_debug: def process_IN_MOVED_TO(self,event): if not self.is_ext(event.pathname): return - self.panel_reload(event.pathname,'[覆盖]') - + self.panel_reload(event.pathname,'[Cover]') def debug_event(): logger.debug('Launch the panel in debug mode') logger.debug('Listening port:0.0.0.0:{}'.format(public.readFile('data/port.pl'))) @@ -248,7 +255,11 @@ if __name__ == '__main__': is_process = os.path.exists('data/is_process.pl') if not is_process: - http_server.serve_forever() + try: + http_server.serve_forever() + except: + pass + app.run(host=HOST, port=PORT, threaded=True) else: http_server.start() from multiprocessing import Process diff --git a/BTPanel/__init__.py b/BTPanel/__init__.py old mode 100644 new mode 100755 index 3c8e4947..527deba4 --- a/BTPanel/__init__.py +++ b/BTPanel/__init__.py @@ -1,6 +1,6 @@ -#coding: utf-8 +# coding: utf-8 # +------------------------------------------------------------------- -# | 宝塔Linux面板 +# | 宝塔Linux面板 # +------------------------------------------------------------------- # | Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved. # +------------------------------------------------------------------- @@ -15,20 +15,20 @@ import time import re import uuid import psutil + panel_path = '/www/server/panel' if not os.name in ['nt']: os.chdir(panel_path) if not 'class/' in sys.path: - sys.path.insert(0,'class/') + sys.path.insert(0, 'class/') from flask import Flask, session, render_template, send_file, request, redirect, g, make_response, \ - render_template_string, abort,stream_with_context, Response as Resp -from cachelib import SimpleCache + render_template_string, abort, stream_with_context, Response as Resp +from cachelib import SimpleCache, SimpleCacheSession from werkzeug.wrappers import Response from flask_session import Session from flask_compress import Compress - cache = SimpleCache(5000) import public @@ -62,10 +62,10 @@ if os.path.exists(basic_auth_conf): pass # 初始化SESSION服务 -app.secret_key = public.md5(str(os.uname()) + str(psutil.boot_time())) # uuid.UUID(int=uuid.getnode()).hex[-12:] +app.secret_key = public.md5(str(os.uname()) + str(psutil.boot_time())) # uuid.UUID(int=uuid.getnode()).hex[-12:] local_ip = None my_terms = {} -app.config['SESSION_MEMCACHED'] = SimpleCache(1000,86400) +app.config['SESSION_MEMCACHED'] = SimpleCacheSession(1000, 86400) app.config['SESSION_TYPE'] = 'memcached' app.config['SESSION_PERMANENT'] = True app.config['SESSION_USE_SIGNER'] = True @@ -82,9 +82,9 @@ Session(app) import common -#初始化路由 +# 初始化路由 comm = common.panelAdmin() -method_all = ['GET','POST'] +method_all = ['GET', 'POST'] method_get = ['GET'] method_post = ['POST'] json_header = {'Content-Type': 'application/json; charset=utf-8'} @@ -138,18 +138,23 @@ admin_path_checks = [ '/api', '/tips', '/message', - '/warning' + '/warning', + '/userRegister', + ] if admin_path in admin_path_checks: admin_path = '/bt' -uri_match = re.compile(r"(^/static/[\w_\./\-]+\.(js|css|png|jpg|gif|ico|svg|woff|woff2|ttf|otf|eot|map)$|^/[\w_\./\-]*$)") +if admin_path[-1] == '/': admin_path = admin_path[:-1] +uri_match = re.compile( + r"(^/static/[\w_\./\-]+\.(js|css|png|jpg|gif|ico|svg|woff|woff2|ttf|otf|eot|map)$|^/[\w_\./\-]*$)") session_id_match = re.compile(r"^[\w\.\-]+$") + # ===================================Flask HOOK========================# # Flask请求勾子 @app.before_request def request_check(): - if request.method not in ['GET','POST']:return abort(404) + if request.method not in ['GET', 'POST']: return abort(404) g.request_time = time.time() # 路由和URI长度过滤 if len(request.path) > 256: return abort(403) @@ -157,14 +162,22 @@ def request_check(): # URI过滤 if not uri_match.match(request.path): return abort(403) # POST参数过滤 - if request.path in ['/login', '/safe', '/hook', '/public', '/down', '/get_app_bind_status', '/check_bind']: + if request.path in ['/login', + '/safe', + '/hook', + '/public', + '/down', + '/get_app_bind_status', + '/check_bind', + '/userRegister', + + ]: pdata = request.form.to_dict() for k in pdata.keys(): if len(k) > 48: return abort(403) if len(pdata[k]) > 256: return abort(403) - # SESSIONID过滤 - session_id = request.cookies.get(app.config['SESSION_COOKIE_NAME'],'') + session_id = request.cookies.get(app.config['SESSION_COOKIE_NAME'], '') if session_id and not session_id_match.match(session_id): return abort(403) # 请求头过滤 @@ -174,7 +187,6 @@ def request_check(): if session.get('debug') == 1: return g.get_csrf_html_token_key = public.get_csrf_html_token_key() - if app.config['BASIC_AUTH_OPEN']: if request.path in ['/public', '/download', '/mail_sys', '/hook', '/down', '/check_bind', '/get_app_bind_status']: return @@ -190,28 +202,28 @@ def request_check(): ip_check = public.check_ip_panel() if ip_check: return ip_check - if request.path.find('/static/') != -1 or request.path == '/code': + if request.path.startswith('/static/') or request.path == '/code': if not 'login' in session and not 'admin_auth' in session and not 'down' in session: return abort(401) domain_check = public.check_domain_panel() if domain_check: return domain_check if public.is_local(): - not_networks = ['uninstall_plugin','install_plugin','UpdatePanel'] + not_networks = ['uninstall_plugin', 'install_plugin', 'UpdatePanel'] if request.args.get('action') in not_networks: - return public.returnJson(False,'This feature cannot be used in offline mode!'),json_header + return public.returnJson(False, 'This feature cannot be used in offline mode!'), json_header - if request.path in ['/site','/ftp','/database','/soft','/control','/firewall','/files','/xterm','/crontab','/config']: + if request.path in ['/site', '/ftp', '/database', '/soft', '/control', '/firewall', '/files', '/xterm', '/crontab', + '/config']: if public.is_error_path(): - return redirect('/error',302) + return redirect('/error', 302) if not request.path in ['/config']: - if session.get('password_expire',False): - return redirect('/modify_password',302) - + if session.get('password_expire', False): + return redirect('/modify_password', 302) # Flask 请求结束勾子 @app.teardown_request def request_end(reques=None): - if request.method not in ['GET','POST']:return + if request.method not in ['GET', 'POST']: return if not request.path.startswith('/static/'): public.write_request_log(reques) if 'api_request' in g: @@ -222,8 +234,8 @@ def request_end(reques=None): # Flask 404页面勾子 @app.errorhandler(404) def error_404(e): - if request.method not in ['GET','POST']:return - if not session.get('login',None): + if request.method not in ['GET', 'POST']: return + if not session.get('login', None): g.auth_error = True return public.error_not_login() errorStr = ''' @@ -233,17 +245,17 @@ def error_404(e):