10
10
if sys .version_info [0 ] != 2 :
11
11
from imp import reload
12
12
sys .path .insert (0 ,'/www/server/panel/class/' )
13
+ sys .setrecursionlimit (1000000 )
13
14
import public
14
15
from flask import Flask
15
16
app = Flask (__name__ ,template_folder = "templates/" + public .GetConfigValue ('template' ))
18
19
from flask_session import Session
19
20
from werkzeug .contrib .cache import SimpleCache
20
21
from werkzeug .wrappers import Response
21
- from flask_socketio import SocketIO ,emit ,send
22
22
from threading import Lock
23
+ from flask_sockets import Sockets
24
+ sockets = Sockets (app )
25
+
23
26
dns_client = None
24
27
app .config ['DEBUG' ] = os .path .exists ('data/debug.pl' )
25
28
35
38
except : pass
36
39
37
40
cache = SimpleCache ()
38
- socketio = SocketIO ()
39
- socketio .init_app (app )
40
41
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
+
43
47
app .secret_key = uuid .UUID (int = uuid .getnode ()).hex [- 12 :]
44
48
local_ip = None
45
49
my_terms = {}
92
96
def service_status ():
93
97
return 'True'
94
98
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 ):
105
101
if not check_login ():
106
102
session .clear ()
107
103
emit ('server_response' ,"Panel session is lost, please re-login panel!" )
108
104
return None
109
105
if not 'ssh_obj' in session :
106
+ import ssh_terminal
110
107
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' ])
112
119
113
120
114
121
@app .route ('/term_open' ,methods = method_all )
@@ -126,10 +133,11 @@ def term_open():
126
133
session [key ] = session ['ssh_info' ]
127
134
s_file = '/www/server/panel/config/t_info.json'
128
135
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+' )
130
137
public .set_mode (s_file ,600 )
131
138
else :
132
139
if os .path .exists (s_file ): os .remove (s_file )
140
+ if 'ssh_obj' in session : session ['ssh_obj' ]._ssh_info = session ['ssh_info' ]
133
141
return public .returnJson (True ,'Successful setup!' );
134
142
135
143
@app .route ('/reload_mod' ,methods = method_all )
@@ -146,7 +154,9 @@ def reload_mod():
146
154
147
155
@app .before_request
148
156
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' ]:
150
160
ip_check = public .check_ip_panel ()
151
161
if ip_check : return ip_check
152
162
@@ -162,7 +172,7 @@ def request_check():
162
172
return public .returnJson (False ,'This feature is not available in offline mode!' ),json_header
163
173
164
174
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 ;
166
176
auth = request .authorization
167
177
if not comm .get_sk (): return ;
168
178
if not auth : return send_authenticated ()
@@ -570,7 +580,7 @@ def code():
570
580
try :
571
581
import vilidate ,time
572
582
except :
573
- os . system ("pip install Pillow==5.4.1 -I" )
583
+ public . ExecShell ("pip install Pillow==5.4.1 -I" )
574
584
return "Pillow not install!"
575
585
code_time = cache .get ('codeOut' )
576
586
if code_time : return u'Error: Don\' t request validation codes frequently' ;
@@ -618,7 +628,7 @@ def plugin(pdata = None):
618
628
if comReturn : return comReturn
619
629
import panelPlugin
620
630
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' )
622
632
return publicObject (pluginObject ,defs ,None ,pdata );
623
633
624
634
@@ -650,6 +660,7 @@ def panel_public():
650
660
data = public .getJson (eval ('pluwx.' + get .fun + '(get)' ))
651
661
return data ,json_header
652
662
663
+ if get .name != 'app' : return abort (404 )
653
664
import panelPlugin
654
665
plu = panelPlugin .panelPlugin ()
655
666
get .s = '_check' ;
@@ -676,14 +687,26 @@ def send_favicon():
676
687
@app .route ('/<name>/<fun>' ,methods = method_all )
677
688
@app .route ('/<name>/<fun>/<path:stype>' ,methods = method_all )
678
689
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
679
703
if not name : name = 'coll'
680
704
if not public .path_safe_check ("%s/%s/%s" % (name ,fun ,stype )): return abort (404 )
681
705
if name .find ('./' ) != - 1 or not re .match ("^[\w-]+$" ,name ): return abort (404 )
682
706
if not name : return public .returnJson (False ,public .GetMsg ("PLUGIN_INPUT_A" )),json_header
683
707
p_path = '/www/server/panel/plugin/' + name
684
708
if not os .path .exists (p_path ): return abort (404 )
685
709
686
-
687
710
#是否响插件应静态文件
688
711
if fun == 'static' :
689
712
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):
697
720
#准备参数
698
721
args = get_input ();
699
722
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 ]
706
723
args .fun = fun
707
724
708
725
#初始化插件对象
@@ -721,32 +738,12 @@ def panel_other(name=None,fun = None,stype=None):
721
738
plu = eval ('plugin_main.' + name + '_main()' )
722
739
if not hasattr (plu ,fun ): return public .returnJson (False ,'SPECIFY_METHOD' ),json_header
723
740
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 ),))
747
741
748
742
#执行插件方法
749
743
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
750
747
data = eval ('plu.' + fun + '(args)' )
751
748
else :
752
749
import panelPHP
@@ -964,15 +961,7 @@ def publicObject(toObject,defs,action=None,get = None):
964
961
if hasattr (toObject ,'site_path_check' ):
965
962
if not toObject .site_path_check (get ): return public .ReturnJson (False ,'Excessive operation!' ),json_header
966
963
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 )
976
965
977
966
978
967
def check_login (http_token = None ):
@@ -1077,3 +1066,17 @@ def get_input_data(data):
1077
1066
for key in data .keys ():
1078
1067
pdata [key ] = str (data [key ])
1079
1068
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