Skip to content

Commit 382daa3

Browse files
committed
update 6.5.1
1 parent 5217c1f commit 382daa3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+5733
-2661
lines changed

BT-Panel

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/python
2+
#coding: utf-8
3+
# +-------------------------------------------------------------------
4+
# | 宝塔Linux面板
5+
# +-------------------------------------------------------------------
6+
# | Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved.
7+
# +-------------------------------------------------------------------
8+
# | Author: 黄文良 <[email protected]>
9+
# +-------------------------------------------------------------------
10+
from gevent import monkey
11+
monkey.patch_all()
12+
import os,ssl
13+
os.chdir('/www/server/panel')
14+
from BTPanel import app,sys
15+
16+
if __name__ == '__main__':
17+
f = open('data/port.pl')
18+
PORT = int(f.read())
19+
HOST = '0.0.0.0'
20+
if os.path.exists('data/ipv6.pl'):
21+
HOST = "0:0:0:0:0:0:0:0"
22+
f.close()
23+
24+
#app.threaded=True
25+
#app.jinja_env.auto_reload = True
26+
27+
from gevent.pywsgi import WSGIServer
28+
from geventwebsocket.handler import WebSocketHandler
29+
30+
keyfile = 'ssl/privateKey.pem'
31+
certfile = 'ssl/certificate.pem'
32+
if os.path.exists('data/debug.pl'):
33+
ssl_context = None
34+
if os.path.exists('data/ssl.pl'): ssl_context=(certfile,keyfile)
35+
app.run(host=HOST,port=PORT,threaded=True,debug=True,ssl_context=ssl_context)
36+
else:
37+
if os.path.exists('data/ssl.pl'):
38+
http_server = WSGIServer((HOST, PORT), app,handler_class=WebSocketHandler,keyfile=keyfile,certfile=certfile,log=None,error_log = None)
39+
else:
40+
http_server = WSGIServer((HOST, PORT), app,handler_class=WebSocketHandler)
41+
http_server.serve_forever()

BTPanel/__init__.py

+63-60
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
if sys.version_info[0] != 2:
1111
from imp import reload
1212
sys.path.insert(0,'/www/server/panel/class/')
13+
sys.setrecursionlimit(1000000)
1314
import public
1415
from flask import Flask
1516
app = Flask(__name__,template_folder="templates/" + public.GetConfigValue('template'))
@@ -18,8 +19,10 @@
1819
from flask_session import Session
1920
from werkzeug.contrib.cache import SimpleCache
2021
from werkzeug.wrappers import Response
21-
from flask_socketio import SocketIO,emit,send
2222
from threading import Lock
23+
from flask_sockets import Sockets
24+
sockets = Sockets(app)
25+
2326
dns_client = None
2427
app.config['DEBUG'] = os.path.exists('data/debug.pl')
2528

@@ -35,11 +38,12 @@
3538
except: pass
3639

3740
cache = SimpleCache()
38-
socketio = SocketIO()
39-
socketio.init_app(app)
4041

41-
import common,db,jobs,uuid,ssh_terminal
42-
jobs.control_init()
42+
import common,db,jobs,uuid,threading
43+
job = threading.Thread(target=jobs.control_init)
44+
job.setDaemon(True)
45+
job.start()
46+
4347
app.secret_key = uuid.UUID(int=uuid.getnode()).hex[-12:]
4448
local_ip = None
4549
my_terms = {}
@@ -92,23 +96,26 @@
9296
def service_status():
9397
return 'True'
9498

95-
96-
97-
@socketio.on('connect')
98-
def socket_connect(msg=None):
99-
if not check_login():
100-
emit('server_response',{'data':public.getMsg('111')})
101-
return False
102-
103-
@socketio.on('webssh')
104-
def webssh(msg):
99+
@sockets.route('/webssh')
100+
def webssh(ws):
105101
if not check_login():
106102
session.clear()
107103
emit('server_response',"Panel session is lost, please re-login panel!")
108104
return None
109105
if not 'ssh_obj' in session:
106+
import ssh_terminal
110107
session['ssh_obj'] = ssh_terminal.ssh_terminal()
111-
session['ssh_obj'].send(msg)
108+
if not 'ssh_info' in session:
109+
s_file = '/www/server/panel/config/t_info.json'
110+
if os.path.exists(s_file):
111+
try:
112+
session['ssh_info'] = json.loads(public.en_hexb(public.readFile(s_file)))
113+
except:
114+
session['ssh_info'] = {"host":"127.0.0.1","port":22}
115+
else:
116+
session['ssh_info'] = {"host":"127.0.0.1","port":22}
117+
118+
session['ssh_obj'].run(ws,session['ssh_info'])
112119

113120

114121
@app.route('/term_open',methods=method_all)
@@ -126,10 +133,11 @@ def term_open():
126133
session[key] = session['ssh_info']
127134
s_file = '/www/server/panel/config/t_info.json'
128135
if 'is_save' in session['ssh_info']:
129-
public.writeFile(s_file,public.de_hexb(json.dumps(session['ssh_info'])))
136+
public.writeFile(s_file,public.de_hexb(json.dumps(session['ssh_info'])),'wb+')
130137
public.set_mode(s_file,600)
131138
else:
132139
if os.path.exists(s_file): os.remove(s_file)
140+
if 'ssh_obj' in session: session['ssh_obj']._ssh_info = session['ssh_info']
133141
return public.returnJson(True,'Successful setup!');
134142

135143
@app.route('/reload_mod',methods=method_all)
@@ -146,7 +154,9 @@ def reload_mod():
146154

147155
@app.before_request
148156
def request_check():
149-
if not request.path in ['/safe','/hook','/public']:
157+
if request.path in ['/service_status']: return
158+
159+
if not request.path in ['/safe','/hook','/public','/mail_sys']:
150160
ip_check = public.check_ip_panel()
151161
if ip_check: return ip_check
152162

@@ -162,7 +172,7 @@ def request_check():
162172
return public.returnJson(False,'This feature is not available in offline mode!'),json_header
163173

164174
if app.config['BASIC_AUTH_OPEN']:
165-
if request.path in ['/public','/download']: return;
175+
if request.path in ['/public','/download','/mail_sys','/hook']: return;
166176
auth = request.authorization
167177
if not comm.get_sk(): return;
168178
if not auth: return send_authenticated()
@@ -570,7 +580,7 @@ def code():
570580
try:
571581
import vilidate,time
572582
except:
573-
os.system("pip install Pillow==5.4.1 -I")
583+
public.ExecShell("pip install Pillow==5.4.1 -I")
574584
return "Pillow not install!"
575585
code_time = cache.get('codeOut')
576586
if code_time: return u'Error: Don\'t request validation codes frequently';
@@ -618,7 +628,7 @@ def plugin(pdata = None):
618628
if comReturn: return comReturn
619629
import panelPlugin
620630
pluginObject = panelPlugin.panelPlugin()
621-
defs = ('update_zip','input_zip','export_zip','add_index','remove_index','sort_index','install_plugin','uninstall_plugin','get_soft_find','get_index_list','get_soft_list','get_cloud_list','check_deps','flush_cache','GetCloudWarning','install','unInstall','getPluginList','getPluginInfo','getPluginStatus','setPluginStatus','a','getCloudPlugin','getConfigHtml','savePluginSort')
631+
defs = ('set_score','get_score','update_zip','input_zip','export_zip','add_index','remove_index','sort_index','install_plugin','uninstall_plugin','get_soft_find','get_index_list','get_soft_list','get_cloud_list','check_deps','flush_cache','GetCloudWarning','install','unInstall','getPluginList','getPluginInfo','getPluginStatus','setPluginStatus','a','getCloudPlugin','getConfigHtml','savePluginSort')
622632
return publicObject(pluginObject,defs,None,pdata);
623633

624634

@@ -650,6 +660,7 @@ def panel_public():
650660
data = public.getJson(eval('pluwx.'+get.fun+'(get)'))
651661
return data,json_header
652662

663+
if get.name != 'app': return abort(404)
653664
import panelPlugin
654665
plu = panelPlugin.panelPlugin()
655666
get.s = '_check';
@@ -676,14 +687,26 @@ def send_favicon():
676687
@app.route('/<name>/<fun>',methods=method_all)
677688
@app.route('/<name>/<fun>/<path:stype>',methods=method_all)
678689
def panel_other(name=None,fun = None,stype=None):
690+
is_accept = False
691+
if not fun: fun = 'index.html'
692+
if not stype:
693+
tmp = fun.split('.')
694+
fun = tmp[0]
695+
if len(tmp) == 1: tmp.append('')
696+
stype = tmp[1]
697+
698+
if not name in ['mail_sys'] or not fun in ['send_mail_http']:
699+
comReturn = comm.local()
700+
if comReturn: return comReturn
701+
else:
702+
is_accept = True
679703
if not name: name = 'coll'
680704
if not public.path_safe_check("%s/%s/%s" % (name,fun,stype)): return abort(404)
681705
if name.find('./') != -1 or not re.match("^[\w-]+$",name): return abort(404)
682706
if not name: return public.returnJson(False,public.GetMsg("PLUGIN_INPUT_A")),json_header
683707
p_path = '/www/server/panel/plugin/' + name
684708
if not os.path.exists(p_path): return abort(404)
685709

686-
687710
#是否响插件应静态文件
688711
if fun == 'static':
689712
if stype.find('./') != -1 or not os.path.exists(p_path + '/static'): return abort(404)
@@ -697,12 +720,6 @@ def panel_other(name=None,fun = None,stype=None):
697720
#准备参数
698721
args = get_input();
699722
args.client_ip = public.GetClientIp();
700-
if not fun: fun = 'index.html'
701-
if not stype:
702-
tmp = fun.split('.')
703-
fun = tmp[0]
704-
if len(tmp) == 1: tmp.append('')
705-
stype = tmp[1]
706723
args.fun = fun
707724

708725
#初始化插件对象
@@ -721,32 +738,12 @@ def panel_other(name=None,fun = None,stype=None):
721738
plu = eval('plugin_main.' + name + '_main()')
722739
if not hasattr(plu,fun): return public.returnJson(False,'SPECIFY_METHOD'),json_header
723740

724-
#检查访问权限
725-
comReturn = comm.local()
726-
if comReturn:
727-
if not is_php:
728-
if not hasattr(plu,'_check'):
729-
session.clear()
730-
return public.returnJson(False,'SPECIFY_PLUG_ERR'),json_header
731-
checks = plu._check(args)
732-
r_type = type(checks)
733-
if r_type == Response: return checks
734-
if r_type != bool or not checks: return public.getJson(checks),json_header
735-
736-
#初始化面板数据
737-
comm.setSession()
738-
comm.init()
739-
comm.checkWebType()
740-
comm.GetOS()
741-
742-
import panelPlugin
743-
plugins = panelPlugin.panelPlugin()
744-
args.name = name
745-
if not plugins.check_accept(args):
746-
return public.returnMsg(False,public.to_string([24744, 26410, 36141, 20080, 91, 37, 115, 93, 25110, 25480, 26435, 24050, 21040, 26399, 33]) % (plugins.get_title_byname(args),))
747741

748742
#执行插件方法
749743
if not is_php:
744+
if is_accept:
745+
checks = plu._check(args)
746+
if type(checks) != bool or not checks: return public.getJson(checks),json_header
750747
data = eval('plu.'+fun+'(args)')
751748
else:
752749
import panelPHP
@@ -964,15 +961,7 @@ def publicObject(toObject,defs,action=None,get = None):
964961
if hasattr(toObject,'site_path_check'):
965962
if not toObject.site_path_check(get): return public.ReturnJson(False,'Excessive operation!'),json_header
966963

967-
for key in defs:
968-
if key == get.action:
969-
fun = 'toObject.'+key+'(get)'
970-
if hasattr(get,'html') or hasattr(get,'s_module'):
971-
return eval(fun)
972-
else:
973-
return public.GetJson(eval(fun)),json_header
974-
975-
return public.ReturnJson(False,'ARGS_ERR'),json_header
964+
return run_exec().run(toObject,defs,get)
976965

977966

978967
def check_login(http_token=None):
@@ -1077,3 +1066,17 @@ def get_input_data(data):
10771066
for key in data.keys():
10781067
pdata[key] = str(data[key])
10791068
return pdata
1069+
1070+
1071+
class run_exec:
1072+
1073+
def run(self,toObject,defs,get):
1074+
for key in defs:
1075+
if key == get.action:
1076+
fun = 'toObject.'+key+'(get)'
1077+
if hasattr(get,'html') or hasattr(get,'s_module'):
1078+
return eval(fun)
1079+
else:
1080+
return public.GetJson(eval(fun)),json_header
1081+
1082+
return public.ReturnJson(False,'ARGS_ERR'),json_header

0 commit comments

Comments
 (0)