Skip to content

Commit

Permalink
6.9.9
Browse files Browse the repository at this point in the history
  • Loading branch information
showpy committed Sep 4, 2019
1 parent f1b5935 commit 8372ff2
Show file tree
Hide file tree
Showing 15 changed files with 321 additions and 167 deletions.
25 changes: 15 additions & 10 deletions BTPanel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def service_status():

@app.before_request
def request_check():

if not request.path in ['/safe','/hook','/public']:
ip_check = public.check_ip_panel()
if ip_check: return ip_check
Expand Down Expand Up @@ -168,6 +169,7 @@ def login():

if hasattr(get,'dologin'):
login_path = '/login'
if not 'login' in session: return redirect(login_path)
if os.path.exists(admin_path_file): login_path = route_path
if session['login'] != False:
session['login'] = False;
Expand Down Expand Up @@ -573,6 +575,7 @@ def panel_public():
get = get_input();
get.client_ip = public.GetClientIp();
if not hasattr(get,'name'): get.name = ''
if not hasattr(get,'fun'): return abort(404)
if not public.path_safe_check("%s/%s" % (get.name,get.fun)): return abort(404)
if get.fun in ['scan_login', 'login_qrcode', 'set_login', 'is_scan_ok', 'blind','static']:
if get.fun == 'static':
Expand Down Expand Up @@ -722,7 +725,9 @@ def panel_other(name=None,fun = None,stype=None):
if r_type == dict: return public.returnJson(False,'错误的返回类型[%s]' % r_type),json_header
return data
except:
return public.get_error_info().replace('\n','<br>\n')
error_info = public.get_error_info()
public.submit_error(error_info)
return error_info.replace('\n','<br>\n')


@app.route('/wxapp',methods=method_all)
Expand Down Expand Up @@ -877,7 +882,8 @@ def panel_cloud():
@socketio.on('connect')
def socket_connect(msg=None):
if not check_login():
raise emit('server_response',{'data':public.getMsg('INIT_WEBSSH_LOGOUT')})
emit('server_response',{'data':public.getMsg('111')})
return False

@socketio.on('webssh')
def webssh(msg):
Expand Down Expand Up @@ -1080,6 +1086,7 @@ def notfound(e):
@app.errorhandler(500)
def internalerror(e):
#if str(e).find('Permanent Redirect') != -1: return e
public.submit_error()
errorStr = public.ReadFile('./BTPanel/templates/' + public.GetConfigValue('template') + '/error.html')
try:
if not app.config['DEBUG']:
Expand All @@ -1093,14 +1100,12 @@ def internalerror(e):
#获取输入数据
def get_input():
data = common.dict_obj()
post = request.form.to_dict()
get = request.args.to_dict()
data.args = get
for key in get.keys():
data[key] = str(get[key])
for key in post.keys():
data[key] = str(post[key])

exludes = ['blob']
for key in request.args.keys():
data[key] = str(request.args.get(key,''))
for key in request.form.keys():
if key in exludes: continue
data[key] = str(request.form.get(key,''))
if not hasattr(data,'data'): data.data = []
return data

Expand Down
138 changes: 76 additions & 62 deletions BTPanel/templates/default/license.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions class/ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ def setPHPMyAdmin(self,get):
#try:
filename = self.__get_webserver_conffile()
conf = public.readFile(filename);
if not conf: return public.returnMsg(False,'ERROR');
if hasattr(get,'port'):
mainPort = public.readFile('data/port.pl').strip();
rulePort = ['80','443','21','20','8080','8081','8089','11211','6379']
Expand Down
2 changes: 1 addition & 1 deletion class/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def init(self):
if ua:
ua = ua.lower();
if ua.find('spider') != -1 or ua.find('bot') != -1: return redirect('https://www.baidu.com');
g.version = '6.9.33'
g.version = '6.9.8'
g.title = public.GetConfigValue('title')
g.uri = request.path
session['version'] = g.version;
Expand Down
8 changes: 6 additions & 2 deletions class/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,12 @@ def GetDbStatus(self,get):
gets = ['table_open_cache','thread_cache_size','query_cache_type','key_buffer_size','query_cache_size','tmp_table_size','max_heap_table_size','innodb_buffer_pool_size','innodb_additional_mem_pool_size','innodb_log_buffer_size','max_connections','sort_buffer_size','read_buffer_size','read_rnd_buffer_size','join_buffer_size','thread_stack','binlog_cache_size'];
result['mem'] = {}
for d in data:
for g in gets:
if d[0] == g: result['mem'][g] = d[1];
try:
for g in gets:
if d[0] == g: result['mem'][g] = d[1];
except:
continue

if 'query_cache_type' in result['mem']:
if result['mem']['query_cache_type'] != 'ON': result['mem']['query_cache_size'] = '0';
return result;
Expand Down
38 changes: 35 additions & 3 deletions class/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# +-------------------------------------------------------------------

import sqlite3
import os,re,public
import os,re,public,time

class Sql():
#------------------------------
Expand All @@ -22,6 +22,7 @@ class Sql():
__OPT_ORDER = "" # order条件
__OPT_FIELD = "*" # field条件
__OPT_PARAM = () # where值
__LOCK = '/dev/shm/sqlite_lock.pl'

def __init__(self):
self.__DB_FILE = 'data/default.db'
Expand Down Expand Up @@ -174,6 +175,7 @@ def count(self):

def add(self,keys,param):
#插入数据
self.write_lock()
self.__GetConn()
self.__DB_CONN.text_factory = str
try:
Expand All @@ -186,6 +188,7 @@ def add(self,keys,param):
id = result.lastrowid
self.__close()
self.__DB_CONN.commit()
self.rm_lock()
return id
except Exception as ex:
return "error: " + str(ex)
Expand All @@ -212,6 +215,7 @@ def __format_pdata(self,pdata):

def addAll(self,keys,param):
#插入数据
self.write_lock()
self.__GetConn()
self.__DB_CONN.text_factory = str
try:
Expand All @@ -221,6 +225,7 @@ def addAll(self,keys,param):
values = values[0:len(values)-1]
sql = "INSERT INTO "+self.__DB_TABLE+"("+keys+") "+"VALUES("+values+")"
result = self.__DB_CONN.execute(sql,self.__to_tuple(param))
self.rm_lock()
return True
except Exception as ex:
return "error: " + str(ex)
Expand All @@ -232,6 +237,7 @@ def commit(self):

def save(self,keys,param):
#更新数据
self.write_lock()
self.__GetConn()
self.__DB_CONN.text_factory = str
try:
Expand All @@ -249,12 +255,14 @@ def save(self,keys,param):
result = self.__DB_CONN.execute(sql,self.__OPT_PARAM)
self.__close()
self.__DB_CONN.commit()
self.rm_lock()
return result.rowcount
except Exception as ex:
return "error: " + str(ex)

def delete(self,id=None):
#删除数据
self.write_lock()
self.__GetConn()
try:
if id:
Expand All @@ -264,22 +272,41 @@ def delete(self,id=None):
result = self.__DB_CONN.execute(sql,self.__OPT_PARAM)
self.__close()
self.__DB_CONN.commit()
self.rm_lock()
return result.rowcount
except Exception as ex:
return "error: " + str(ex)


def execute(self,sql,param = ()):
#执行SQL语句返回受影响行
self.write_lock()
self.__GetConn()
try:

result = self.__DB_CONN.execute(sql,self.__to_tuple(param))
self.__DB_CONN.commit()
self.rm_lock()
return result.rowcount
except Exception as ex:
return "error: " + str(ex)


#是否有锁
def is_lock(self):
n = 0
while os.path.exists(self.__LOCK):
n+=1
if n > 100:
self.rm_lock()
break
time.sleep(0.01)
#写锁
def write_lock(self):
self.is_lock()
public.writeFile(self.__LOCK,"True")
#解锁
def rm_lock(self):
if os.path.exists(self.__LOCK):
os.remove(self.__LOCK)

def query(self,sql,param = ()):
#执行SQL语句返回数据集
Expand All @@ -294,20 +321,24 @@ def query(self,sql,param = ()):

def create(self,name):
#创建数据表
self.write_lock()
self.__GetConn()
import public
script = public.readFile('data/' + name + '.sql')
result = self.__DB_CONN.executescript(script)
self.__DB_CONN.commit()
self.rm_lock()
return result.rowcount

def fofile(self,filename):
#执行脚本
self.write_lock()
self.__GetConn()
import public
script = public.readFile(filename)
result = self.__DB_CONN.executescript(script)
self.__DB_CONN.commit()
self.rm_lock()
return result.rowcount

def __close(self):
Expand All @@ -317,6 +348,7 @@ def __close(self):
self.__OPT_ORDER = ""
self.__OPT_LIMIT = ""
self.__OPT_PARAM = ()


def close(self):
#释放资源
Expand Down
Loading

0 comments on commit 8372ff2

Please sign in to comment.