mirror of https://github.com/flucont/btcloud.git
19 changed files with 641 additions and 72 deletions
-
25app/command/CleanViteJs.php
-
4app/script/convert.sh
-
4app/view/admin/plugins.html
-
3public/install/install_btmonitor.sh
-
59public/install/install_panel.sh
-
BINpublic/install/src/bt-monitor-2.3.3.zip
-
BINpublic/install/src/panel6.zip
-
BINpublic/install/update/LinuxPanel-11.2.0.zip
-
148public/install/update/update_prep_script.sh
-
1public/install/update6.sh
-
7public/install/update_btmonitor.sh
-
147public/install/update_panel.sh
-
1route/app.php
-
2wiki/btmonitor.md
-
69wiki/files/btmonitor/PluginLoader.py
-
217wiki/files/linux/PluginLoader.py.old
-
8wiki/update.md
@ -0,0 +1,148 @@ |
|||
#!/bin/bash |
|||
#=============================================================================== |
|||
# 宝塔面板更新预准备脚本 |
|||
# 功能:在面板更新时,提前准备,避免面板更新失败 |
|||
# 说明:接收两个参数:1.更新的面板版本号 2.更新的版本是否为稳定版 3.执行时机(prepare, after) |
|||
# prepare: 在下载面板文件之前就运行的内容 |
|||
# after: 在替换文件之后,运行重启之前执行的内容 |
|||
# 支持:CentOS/RHEL、Ubuntu、Debian系统 |
|||
#=============================================================================== |
|||
|
|||
UPDATE_VERSION="" # 版本号, 形如: 11.2.3 |
|||
UPDATE_VER_MAJOR="" # 主版本号 -> 11 |
|||
UPDATE_VER_MINOR="" # 次版本号 -> 2 |
|||
UPDATE_VER_MICRO="" # 小版本号 -> 3 |
|||
IS_STABLE=false # 默认不是稳定版而是正式版本 |
|||
OPPORTUNITY="prepare" |
|||
|
|||
PANEL_PATH="/www/server/panel" |
|||
|
|||
# 输出成功信息, 必须输出 "BT-Panel Update Ready" 才证明预处理成功 |
|||
function success() { |
|||
local message=$1 |
|||
if [ -n "$message" ]; then |
|||
echo "$message" |
|||
fi |
|||
echo "BT-Panel Update Ready" |
|||
} |
|||
|
|||
# 获取当前版本号 |
|||
function get_now_version() { |
|||
local common_file="$PANEL_PATH/class/common.py" |
|||
if [ ! -f "$common_file" ]; then |
|||
echo "" # 文件不存在时返回空字符串 |
|||
return 1 |
|||
fi |
|||
# 形如:g.version = '11.2.0' |
|||
local version_str=$(grep -E '^\s+g.version\s*=\s*.*$' "$PANEL_PATH/class/common.py" | cut -d "=" -f2 ) |
|||
# 形如:'11.2.0' |
|||
local version=$(echo "$version_str" | sed -n "s/.*['\"]\(.*\)['\"].*/\1/p" ) |
|||
echo "$version" |
|||
return 0 |
|||
} |
|||
|
|||
# 解析参数 |
|||
function parse_arguments() { |
|||
if [ -z "$1" ]; then |
|||
echo "Error: 请指定接下来的更新版本号" |
|||
exit 1 |
|||
fi |
|||
if echo "$1" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then |
|||
: |
|||
else |
|||
echo "Error: 请指定正确的版本号" |
|||
exit 1 |
|||
fi |
|||
UPDATE_VERSION=$1 |
|||
UPDATE_VER_MAJOR=$(echo $UPDATE_VERSION | cut -d. -f1) |
|||
UPDATE_VER_MINOR=$(echo $UPDATE_VERSION | cut -d. -f2) |
|||
UPDATE_VER_MICRO=$(echo $UPDATE_VERSION | cut -d. -f3) |
|||
case "$2" in |
|||
1|True|true) # 稳定版 |
|||
IS_STABLE=true |
|||
;; |
|||
0|False|false) # 非稳定版 |
|||
IS_STABLE=false |
|||
;; |
|||
*) |
|||
IS_STABLE=false |
|||
;; |
|||
esac |
|||
case "$3" in |
|||
prepare) |
|||
OPPORTUNITY="prepare" |
|||
;; |
|||
after) |
|||
OPPORTUNITY="after" |
|||
;; |
|||
*) |
|||
OPPORTUNITY="prepare" |
|||
;; |
|||
esac |
|||
} |
|||
|
|||
# 默认处理,什么都不做 |
|||
function nothing_do() { |
|||
local version=$1 |
|||
# 输出成功信息 |
|||
success "已完成[BT-Panel-$version]处理" |
|||
} |
|||
|
|||
function replace_bt_command() { |
|||
local init_path="${PANEL_PATH}/init.sh" |
|||
if [ -f "$init_path" ]; then |
|||
\cp -a "$init_path" /etc/init.d/bt |
|||
chmod +x /etc/init.d/bt |
|||
else |
|||
echo "Error: $init_path 文件不存在" |
|||
exit 1 |
|||
fi |
|||
} |
|||
|
|||
function prepare_main() { |
|||
echo "开始处理预更新..." |
|||
local now_version=$(get_now_version) |
|||
if [ $? -eq 0 ]; then |
|||
echo "当前版本:$now_version, 目标版本:$UPDATE_VERSION" |
|||
else |
|||
echo "获取当前版本失败" |
|||
exit 1 |
|||
fi |
|||
|
|||
case "$UPDATE_VER_MAJOR.$UPDATE_VER_MINOR.$UPDATE_VER_MICRO" in |
|||
11.3.*) |
|||
nothing_do $UPDATE_VERSION |
|||
;; |
|||
* ) |
|||
nothing_do $UPDATE_VERSION |
|||
;; |
|||
esac |
|||
} |
|||
|
|||
function after_main() { |
|||
echo "启动预检测..." |
|||
case "$UPDATE_VER_MAJOR.$UPDATE_VER_MINOR.$UPDATE_VER_MICRO" in |
|||
11.3.*) |
|||
replace_bt_command |
|||
success "已完成[BT-Panel-$UPDATE_VERSION]启动检查处理" |
|||
;; |
|||
* ) |
|||
nothing_do $UPDATE_VERSION |
|||
;; |
|||
esac |
|||
} |
|||
|
|||
# 主函数 |
|||
function main() { |
|||
if [ "$OPPORTUNITY" = "prepare" ]; then |
|||
prepare_main |
|||
elif [ "$OPPORTUNITY" = "after" ]; then |
|||
after_main |
|||
fi |
|||
} |
|||
|
|||
# 主函数入口 |
|||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then |
|||
parse_arguments $@ |
|||
main |
|||
fi |
|||
@ -0,0 +1,217 @@ |
|||
#coding: utf-8 |
|||
import public,os,sys,json |
|||
|
|||
#获取插件列表(0/1) |
|||
def get_plugin_list(force = 0): |
|||
api_root_url = 'https://api.bt.cn' |
|||
api_url = api_root_url+ '/panel/get_plugin_list' |
|||
cache_file = 'data/plugin_list.json' |
|||
|
|||
if force==0 and os.path.exists(cache_file): |
|||
jsonData = public.readFile(cache_file) |
|||
softList = json.loads(jsonData) |
|||
else: |
|||
try: |
|||
jsonData = public.HttpGet(api_url) |
|||
except Exception as ex: |
|||
raise public.error_conn_cloud(str(ex)) |
|||
softList = json.loads(jsonData) |
|||
if type(softList)!=dict or 'list' not in softList: |
|||
if type(softList)==str: |
|||
raise Exception(softList) |
|||
else: |
|||
raise Exception('云端插件列表获取失败') |
|||
public.writeFile(cache_file, jsonData) |
|||
return softList |
|||
|
|||
#获取授权状态() 返回:0.免费版 1.专业版 2.企业版 -1.获取失败 |
|||
def get_auth_state(): |
|||
try: |
|||
softList = get_plugin_list() |
|||
if softList['ltd'] > -1: |
|||
return 2 |
|||
elif softList['pro'] > -1: |
|||
return 1 |
|||
else: |
|||
return 0 |
|||
except: |
|||
return -1 |
|||
|
|||
#执行插件方法(插件名,方法名,参数) |
|||
def plugin_run(plugin_name, def_name, args): |
|||
if not plugin_name or not def_name: return public.returnMsg(False,'插件名称和插件方法名称不能为空!') |
|||
if not path_check(plugin_name) or not path_check(def_name): return public.returnMsg(False,'插件名或方法名不能包含特殊符号!') |
|||
p_path = public.get_plugin_path(plugin_name) |
|||
if not os.path.exists(p_path + '/index.php') and not os.path.exists(p_path + '/%s_main.py' % plugin_name): return public.returnMsg(False,'插件不存在!') |
|||
|
|||
is_php = os.path.exists(p_path + '/index.php') |
|||
if not is_php: |
|||
public.package_path_append(p_path) |
|||
plugin_main = __import__(plugin_name + '_main') |
|||
try: |
|||
if sys.version_info[0] == 2: |
|||
reload(plugin_main) |
|||
else: |
|||
from imp import reload |
|||
reload(plugin_main) |
|||
except: |
|||
pass |
|||
plu = eval('plugin_main.' + plugin_name + '_main()') |
|||
if not hasattr(plu, def_name): |
|||
return public.returnMsg(False,'在[%s]插件中找不到[%s]方法' % (plugin_name,def_name)) |
|||
|
|||
if 'plugin_get_object' in args and args.plugin_get_object == 1: |
|||
if not is_php: |
|||
return getattr(plu, def_name) |
|||
else: |
|||
return None |
|||
else: |
|||
if not is_php: |
|||
data = eval('plu.' + def_name + '(args)') |
|||
else: |
|||
import panelPHP |
|||
args.s = def_name |
|||
args.name = plugin_name |
|||
data = panelPHP.panelPHP(plugin_name).exec_php_script(args) |
|||
return data |
|||
|
|||
#执行模块方法(模块名,方法名,参数) |
|||
def module_run(mod_name, def_name, args): |
|||
if not mod_name or not def_name: return public.returnMsg(False,'模块名称和模块方法名称不能为空!') |
|||
if not path_check(mod_name) or not path_check(def_name): return public.returnMsg(False,'模块名或方法名不能包含特殊符号!') |
|||
|
|||
if 'model_index' in args: |
|||
if args.model_index: |
|||
mod_file = "{}/{}Model/{}Model.py".format(public.get_class_path(),args.model_index,mod_name) |
|||
else: |
|||
mod_file = "{}/projectModel/{}Model.py".format(public.get_class_path(),mod_name) |
|||
else: |
|||
module_list = get_module_list() |
|||
for module_dir in module_list: |
|||
mod_file = "{}/{}/{}Model.py".format(public.get_class_path(),module_dir,mod_name) |
|||
if os.path.exists(mod_file): break |
|||
|
|||
if not os.path.exists(mod_file): |
|||
return public.returnMsg(False,'模块[%s]不存在' % mod_name) |
|||
|
|||
def_object = public.get_script_object(mod_file) |
|||
if not def_object: return public.returnMsg(False,'模块[%s]不存在!' % mod_name) |
|||
try: |
|||
run_object = getattr(def_object.main(),def_name,None) |
|||
except: |
|||
return public.returnMsg(False,'模块入口实例化失败' % mod_name) |
|||
if not run_object: return public.returnMsg(False,'在[%s]模块中找不到[%s]方法' % (mod_name,def_name)) |
|||
if 'module_get_object' in args and args.module_get_object == 1: |
|||
return run_object |
|||
result = run_object(args) |
|||
return result |
|||
|
|||
#获取模块文件夹列表 |
|||
def get_module_list(): |
|||
list = [] |
|||
class_path = public.get_class_path() |
|||
f_list = os.listdir(class_path) |
|||
for fname in f_list: |
|||
f_path = class_path+'/'+fname |
|||
if os.path.isdir(f_path) and len(fname) > 6 and fname.find('.') == -1 and fname.find('Model') != -1: |
|||
list.append(fname) |
|||
return list |
|||
|
|||
#检查路径是否合法 |
|||
def path_check(path): |
|||
list = ["./","..",",",";",":","?","'","\"","<",">","|","\\","\n","\r","\t","\b","\a","\f","\v","*","%","&","$","#","@","!","~","`","^","(",")","+","=","{","}","[","]"] |
|||
for i in path: |
|||
if i in list: |
|||
return False |
|||
return True |
|||
|
|||
#数据加密 |
|||
def db_encrypt(data): |
|||
try: |
|||
key = __get_db_sgin() |
|||
iv = __get_db_iv() |
|||
str_arr = data.split('\n') |
|||
res_str = '' |
|||
for data in str_arr: |
|||
if not data: continue |
|||
res_str += __aes_encrypt(data, key, iv) |
|||
except: |
|||
res_str = data |
|||
result = { |
|||
'status' : True, |
|||
'msg' : res_str |
|||
} |
|||
return result |
|||
|
|||
#数据解密 |
|||
def db_decrypt(data): |
|||
try: |
|||
key = __get_db_sgin() |
|||
iv = __get_db_iv() |
|||
str_arr = data.split('\n') |
|||
res_str = '' |
|||
for data in str_arr: |
|||
if not data: continue |
|||
res_str += __aes_decrypt(data, key, iv) |
|||
except: |
|||
res_str = data |
|||
result = { |
|||
'status' : True, |
|||
'msg' : res_str |
|||
} |
|||
return result |
|||
|
|||
def __get_db_sgin(): |
|||
keystr = '3gP7+k_7lSNg3$+Fj!PKW+6$KYgHtw#R' |
|||
key = '' |
|||
for i in range(31): |
|||
if i & 1 == 0: |
|||
key += keystr[i] |
|||
return key |
|||
|
|||
def __get_db_iv(): |
|||
div_file = "{}/data/div.pl".format(public.get_panel_path()) |
|||
if not os.path.exists(div_file): |
|||
str = public.GetRandomString(16) |
|||
str = __aes_encrypt_module(str) |
|||
div = public.get_div(str) |
|||
public.WriteFile(div_file, div) |
|||
if os.path.exists(div_file): |
|||
div = public.ReadFile(div_file) |
|||
div = __aes_decrypt_module(div) |
|||
else: |
|||
keystr = '4jHCpBOFzL4*piTn^-4IHBhj-OL!fGlB' |
|||
div = '' |
|||
for i in range(31): |
|||
if i & 1 == 0: |
|||
div += keystr[i] |
|||
return div |
|||
|
|||
def __aes_encrypt_module(data): |
|||
key = 'Z2B87NEAS2BkxTrh' |
|||
iv = 'WwadH66EGWpeeTT6' |
|||
return __aes_encrypt(data, key, iv) |
|||
|
|||
def __aes_decrypt_module(data): |
|||
key = 'Z2B87NEAS2BkxTrh' |
|||
iv = 'WwadH66EGWpeeTT6' |
|||
return __aes_decrypt(data, key, iv) |
|||
|
|||
def __aes_decrypt(data, key, iv): |
|||
from Crypto.Cipher import AES |
|||
import base64 |
|||
encodebytes = base64.decodebytes(data.encode('utf-8')) |
|||
aes = AES.new(key.encode('utf-8'), AES.MODE_CBC, iv.encode('utf-8')) |
|||
de_text = aes.decrypt(encodebytes) |
|||
unpad = lambda s: s[0:-s[-1]] |
|||
de_text = unpad(de_text) |
|||
return de_text.decode('utf-8') |
|||
|
|||
def __aes_encrypt(data, key, iv): |
|||
from Crypto.Cipher import AES |
|||
import base64 |
|||
data = (lambda s: s + (16 - len(s) % 16) * chr(16 - len(s) % 16).encode('utf-8'))(data.encode('utf-8')) |
|||
aes = AES.new(key.encode('utf8'), AES.MODE_CBC, iv.encode('utf8')) |
|||
encryptedbytes = aes.encrypt(data) |
|||
en_text = base64.b64encode(encryptedbytes) |
|||
return en_text.decode('utf-8') |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue