From 7301edbc5ade749d04f74af33b327acf89e238df Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 16:19:13 +0800 Subject: [PATCH 01/48] =?UTF-8?q?=E6=B7=BB=E5=8A=A0tgbot=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 现在只是为了获取chat_id --- plugins/redis/index.py | 7 +- plugins/redis/js/redis.js | 15 +- plugins/tgbot/ico.png | Bin 0 -> 974 bytes plugins/tgbot/index.html | 24 +++ plugins/tgbot/index.py | 239 +++++++++++++++++++++++++ plugins/tgbot/info.json | 17 ++ plugins/tgbot/init.d/tgbot.service.tpl | 15 ++ plugins/tgbot/init.d/tgbot.tpl | 85 +++++++++ plugins/tgbot/install.sh | 59 ++++++ plugins/tgbot/js/tgbot.js | 78 ++++++++ plugins/tgbot/startup/tgbot.py | 63 +++++++ route/static/app/public.js | 153 ++++++++++++++++ 12 files changed, 739 insertions(+), 16 deletions(-) create mode 100644 plugins/tgbot/ico.png create mode 100755 plugins/tgbot/index.html create mode 100755 plugins/tgbot/index.py create mode 100755 plugins/tgbot/info.json create mode 100644 plugins/tgbot/init.d/tgbot.service.tpl create mode 100644 plugins/tgbot/init.d/tgbot.tpl create mode 100755 plugins/tgbot/install.sh create mode 100755 plugins/tgbot/js/tgbot.js create mode 100644 plugins/tgbot/startup/tgbot.py diff --git a/plugins/redis/index.py b/plugins/redis/index.py index 62a8686c24..334ab4d195 100755 --- a/plugins/redis/index.py +++ b/plugins/redis/index.py @@ -214,7 +214,8 @@ def initdStatus(): if mw.isAppleSystem(): return "Apple Computer does not support" - shell_cmd = 'systemctl status redis | grep loaded | grep "enabled;"' + shell_cmd = 'systemctl status ' + \ + getPluginName() + ' | grep loaded | grep "enabled;"' data = mw.execShell(shell_cmd) if data[0] == '': return 'fail' @@ -225,7 +226,7 @@ def initdInstall(): if mw.isAppleSystem(): return "Apple Computer does not support" - mw.execShell('systemctl enable redis') + mw.execShell('systemctl enable ' + getPluginName()) return 'ok' @@ -233,7 +234,7 @@ def initdUinstall(): if mw.isAppleSystem(): return "Apple Computer does not support" - mw.execShell('systemctl disable redis') + mw.execShell('systemctl disable ' + getPluginName()) return 'ok' diff --git a/plugins/redis/js/redis.js b/plugins/redis/js/redis.js index 047328f153..01da0647c4 100755 --- a/plugins/redis/js/redis.js +++ b/plugins/redis/js/redis.js @@ -1,14 +1,3 @@ - -function str2Obj(str){ - var data = {}; - kv = str.split('&'); - for(i in kv){ - v = kv[i].split('='); - data[v[0]] = v[1]; - } - return data; -} - function redisPost(method, version, args,callback){ var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); @@ -18,7 +7,7 @@ function redisPost(method, version, args,callback){ req_data['version'] = version; if (typeof(args) == 'string'){ - req_data['args'] = JSON.stringify(str2Obj(args)); + req_data['args'] = JSON.stringify(toArrayObject(args)); } else { req_data['args'] = JSON.stringify(args); } @@ -46,7 +35,7 @@ function redisPostCallbak(method, version, args,callback){ args['version'] = version; if (typeof(args) == 'string'){ - req_data['args'] = JSON.stringify(str2Obj(args)); + req_data['args'] = JSON.stringify(toArrayObject(args)); } else { req_data['args'] = JSON.stringify(args); } diff --git a/plugins/tgbot/ico.png b/plugins/tgbot/ico.png new file mode 100644 index 0000000000000000000000000000000000000000..9416145b2c846c57f2b02e97cb9a32f1664f94c8 GIT binary patch literal 974 zcmV;<12O!GP)Px&h)G02RA@u(nY~imKoG}wg%iq1eu3Z_q&DybfhUM5Qzev0MNF3t^8_)4L>bbi z!AiubmSb^e>kiBe?riSk|J%LY+glKx_y?c3e$WbFe(9U> zVJ+5aBy9lZX@3LR=#mikV|TNy3ql`2a9uZm&be?#v>$uUnGOhT0M(#(27n*9Xd;N| zPo<{gIB5akXCGgV`iNkTtxj+}^z5c;FK7X%`e73gj;6&Dz(wTRJE{X)Ie_W+J{pK$ zXDv-cT?FXz--n*FugVij0gA-Wie(79@qyh@0ig_lr%i)KeHl>%(1~1oS7xkej4}Yr z58H_FF58fRt_ZPV5d54cf)Q=Uo|7D@G9Q%yQI>TG;1~U_Z1A*c1!0T;ul_qmitYww z0M#I*Ny@~Np|{!K-%Y=_g@~P52vwJxG5{+GxyZN4&6@@(7Z1jZ7}%|8AYM*;fnlW< zAJhhAjt`%!3}D*Q3~-OvKUM#_#gGQEYqzYR*G0fLiC~&|Xk`F$$A$2WA0f*R2LKdB zp0jQFVHzX!ZRk25%L>otEAv3MAirsi_1hL1Yu}NvA9n`F_dx73fzec5nMwnsdHxdt z)e&$*WI-YTOjqa8Ewd2;4G^%+uyP_BA2RELc^d8@gY#T*CLqWG5CLX1BJ!+yHDFKX zwiW`+tt=%(lpP{lf(rqr>-w^y7N0K;cp-r0_bw4}Yf>V>1raq=lmXK~X&P>2cS#cb zL|vZ2?gJMBEtf1G=(j!l2k?Yj>(yIbcq;CvRBvb^DvkVxAqKis2eo-Bz0eHE92(M*>PBi|( z0Yn~}jS12CXMoINS+-f$Vnx|#+4YL%m5u?Cpp`#Dxu68Pid<)WYtQq7X#9i6fEirZ z5m?eP1Zu8iDKSUiN)>an0@LfesNJDleybYm(g_0pj?!ZQE_Tb`z%5MJbtU6UIPBpR`rj-$v3_NvltJd&-R@f}5nRVyv~4wpHY| wf1FX$9(Wvi;$5Es#5U49;@Jaw?JHjWAFr8vPi;?b +
+
+
+

服务

+

自启动

+

Bot配置

+
+
+
+
+
+ + + \ No newline at end of file diff --git a/plugins/tgbot/index.py b/plugins/tgbot/index.py new file mode 100755 index 0000000000..3b76feef29 --- /dev/null +++ b/plugins/tgbot/index.py @@ -0,0 +1,239 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import re +import json +import base64 + +sys.path.append(os.getcwd() + "/class/core") +import mw + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'tgbot' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getInitDFile(): + if app_debug: + return '/tmp/' + getPluginName() + return '/etc/init.d/' + getPluginName() + + +def getConfigData(): + cfg_path = getServerDir() + "/data.cfg" + if not os.path.exists(cfg_path): + mw.writeFile(cfg_path, '{}') + t = mw.readFile(cfg_path) + return json.loads(t) + + +def writeConf(data): + cfg_path = getServerDir() + "/data.cfg" + mw.writeFile(cfg_path, json.dumps(data)) + return True + + +def getInitDTpl(): + path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" + return path + + +def getArgs(): + args = sys.argv[2:] + tmp = {} + args_len = len(args) + if args_len == 1: + t = args[0].strip('{').strip('}') + if t.strip() == '': + tmp = [] + else: + t = t.split(':') + tmp[t[0]] = t[1] + tmp[t[0]] = t[1] + elif args_len > 1: + for i in range(len(args)): + t = args[i].split(':') + tmp[t[0]] = t[1] + return tmp + + +def checkArgs(data, ck=[]): + for i in range(len(ck)): + if not ck[i] in data: + return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) + return (True, mw.returnJson(True, 'ok')) + + +def status(): + data = mw.execShell( + "ps -ef|grep tgbot |grep -v grep | grep -v mdserver-web | awk '{print $2}'") + if data[0] == '': + return 'stop' + return 'start' + + +def initDreplace(): + + file_tpl = getInitDTpl() + service_path = mw.getServerDir() + + initD_path = getServerDir() + '/init.d' + if not os.path.exists(initD_path): + os.mkdir(initD_path) + file_bin = initD_path + '/' + getPluginName() + + # initd replace + # if not os.path.exists(file_bin): + content = mw.readFile(file_tpl) + content = content.replace('{$SERVER_PATH}', service_path + '/mdserver-web') + content = content.replace( + '{$APP_PATH}', service_path + '/' + getPluginName()) + + mw.writeFile(file_bin, content) + mw.execShell('chmod +x ' + file_bin) + + # systemd + systemDir = mw.systemdCfgDir() + systemService = systemDir + '/tgbot.service' + systemServiceTpl = getPluginDir() + '/init.d/tgbot.service.tpl' + if os.path.exists(systemDir) and not os.path.exists(systemService): + service_path = mw.getServerDir() + se_content = mw.readFile(systemServiceTpl) + se_content = se_content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(systemService, se_content) + mw.execShell('systemctl daemon-reload') + + return file_bin + + +def tbOp(method): + file = initDreplace() + + if not mw.isAppleSystem(): + data = mw.execShell('systemctl ' + method + ' ' + getPluginName()) + if data[1] == '': + return 'ok' + return data[1] + + data = mw.execShell(file + ' ' + method) + print(data) + # if data[1] == '': + # return 'ok' + return 'ok' + + +def start(): + return tbOp('start') + + +def stop(): + return tbOp('stop') + + +def restart(): + status = tbOp('restart') + return status + + +def reload(): + + tgbot_tpl = getPluginDir() + '/startup/tgbot.py' + tgbot_dst = getServerDir() + '/tgbot.py' + + content = mw.readFile(tgbot_tpl) + mw.writeFile(tgbot_dst, content) + + return tbOp('reload') + + +def initdStatus(): + if mw.isAppleSystem(): + return "Apple Computer does not support" + + shell_cmd = 'systemctl status ' + \ + getPluginName() + ' | grep loaded | grep "enabled;"' + data = mw.execShell(shell_cmd) + if data[0] == '': + return 'fail' + return 'ok' + + +def initdInstall(): + if mw.isAppleSystem(): + return "Apple Computer does not support" + + mw.execShell('systemctl enable ' + getPluginName()) + return 'ok' + + +def initdUinstall(): + if mw.isAppleSystem(): + return "Apple Computer does not support" + + mw.execShell('systemctl disable ' + getPluginName()) + return 'ok' + + +def getBotConf(): + data = getConfigData() + if 'bot' in data: + + return mw.returnJson(True, 'ok', data['bot']) + return mw.returnJson(False, 'ok', {}) + + +def setBotConf(): + args = getArgs() + data_args = checkArgs(args, ['app_token']) + if not data_args[0]: + return data_args[1] + + data = getConfigData() + args['app_token'] = base64.b64decode(args['app_token']).decode('ascii') + data['bot'] = args + writeConf(data) + + return mw.returnJson(True, '保存成功!', []) + + +if __name__ == "__main__": + func = sys.argv[1] + if func == 'status': + print(status()) + elif func == 'start': + print(start()) + elif func == 'stop': + print(stop()) + elif func == 'restart': + print(restart()) + elif func == 'reload': + print(reload()) + elif func == 'initd_status': + print(initdStatus()) + elif func == 'initd_install': + print(initdInstall()) + elif func == 'initd_uninstall': + print(initdUinstall()) + elif func == 'get_bot_conf': + print(getBotConf()) + elif func == 'set_bot_conf': + print(setBotConf()) + elif func == 'conf': + print(getConf()) + else: + print('error') diff --git a/plugins/tgbot/info.json b/plugins/tgbot/info.json new file mode 100755 index 0000000000..266bbfb6be --- /dev/null +++ b/plugins/tgbot/info.json @@ -0,0 +1,17 @@ +{ + "sort": 7, + "ps": "[DEV]简单Telegram机器人", + "name": "tgbot", + "title": "tgbot", + "shell": "install.sh", + "versions":["0.1"], + "tip": "soft", + "checks": "server/tgbot", + "path": "server/tgbot", + "display": 1, + "author": "Zend", + "date": "2023-03-06", + "home": "https://core.telegram.org/bots/api", + "type": 0, + "pid": "5" +} \ No newline at end of file diff --git a/plugins/tgbot/init.d/tgbot.service.tpl b/plugins/tgbot/init.d/tgbot.service.tpl new file mode 100644 index 0000000000..77a48f06cc --- /dev/null +++ b/plugins/tgbot/init.d/tgbot.service.tpl @@ -0,0 +1,15 @@ +[Unit] +Description=Redis In-Memory Data Store +After=network.target + +[Service] +Type=forking +ExecStart={$APP_PATH}/init.d/tgbot start +ExecStop={$APP_PATH}/init.d/tgbot stop +ExecReload={$APP_PATH}/init.d/tgbot reload +ExecRestart={$APP_PATH}/init.d/tgbot restart +KillMode=process +Restart=on-failure + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/plugins/tgbot/init.d/tgbot.tpl b/plugins/tgbot/init.d/tgbot.tpl new file mode 100644 index 0000000000..a7c2aaea5d --- /dev/null +++ b/plugins/tgbot/init.d/tgbot.tpl @@ -0,0 +1,85 @@ +#!/bin/sh +# chkconfig: 2345 55 25 +# description: Tgbot Service + +### BEGIN INIT INFO +# Provides: Tgbot +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts Tgbot +# Description: starts the MDW-Web +### END INIT INFO + +# Simple Tgbot init.d script conceived to work on Linux systems +# as it does use of the /proc filesystem. + +PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export LANG=en_US.UTF-8 + + +mw_path={$SERVER_PATH} +PATH=$PATH:$mw_path/bin + +if [ -f $mw_path/bin/activate ];then + source $mw_path/bin/activate +fi + +tg_start(){ + + isStart=`ps -ef|grep 'tgbot.py' |grep -v grep | awk '{print $2}'` + if [ "$isStart" == '' ];then + echo -e "starting tgbot... \c" + cd $mw_path + python3 {$APP_PATH}/tgbot.py >> {$APP_PATH}/task.log & + isStart="" + while [[ "$isStart" == "" ]]; + do + echo -e ".\c" + sleep 0.5 + isStart=`ps -ef|grep 'tgbot.py' |grep -v grep | awk '{print $2}'` + let n+=1 + if [ $n -gt 20 ];then + break; + fi + done + if [ "$isStart" == '' ];then + echo -e "\033[31mfailed\033[0m" + echo -e "\033[31mError: tgbot service startup failed.\033[0m" + return; + fi + echo -e "\033[32mdone\033[0m" + else + echo "starting tgbot...(pid $(echo $isStart)) already running" + fi +} + + +tg_stop(){ + echo -e "stopping tgbot ... \c"; + arr=`ps aux|grep 'tgbot.py'|grep -v grep|awk '{print $2}'` + for p in ${arr[@]} + do + kill -9 $p > /dev/null 2>&1 + done + echo -e "\033[32mdone\033[0m" +} + +case "$1" in + start) + tg_start + ;; + stop) + tg_stop + ;; + restart|reload) + tg_stop + sleep 0.3 + tg_start + ;; + *) + echo "Please use start or stop as first argument" + ;; +esac + diff --git a/plugins/tgbot/install.sh b/plugins/tgbot/install.sh new file mode 100755 index 0000000000..cec3fab831 --- /dev/null +++ b/plugins/tgbot/install.sh @@ -0,0 +1,59 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") + + +install_tmp=${rootPath}/tmp/mw_install.pl + +VERSION=$2 + +# pip3 install ccxt +if [ -f ${rootPath}/bin/activate ];then + source ${rootPath}/bin/activate +fi + +pip3 install pyTelegramBotAPI +pip3 install telebot + +Install_App() +{ + echo '正在安装脚本文件...' > $install_tmp + mkdir -p $serverPath/source + mkdir -p $serverPath/tgbot + echo "${VERSION}" > $serverPath/tgbot/version.pl + + cp -rf ${rootPath}/plugins/tgbot/startup/* $serverPath/tgbot + + cd ${rootPath} && python3 ${rootPath}/plugins/tgbot/index.py start + cd ${rootPath} && python3 ${rootPath}/plugins/tgbot/index.py initd_install + echo '安装完成' > $install_tmp +} + +Uninstall_App() +{ + if [ -f /usr/lib/systemd/system/tgbot.service ];then + systemctl stop tgbot + systemctl disable tgbot + rm -rf /usr/lib/systemd/system/tgbot.service + systemctl daemon-reload + fi + + if [ -f $serverPath/tgbot/initd/tgbot ];then + $serverPath/tgbot/initd/tgbot stop + fi + + rm -rf $serverPath/tgbot + echo "Uninstall_redis" > $install_tmp +} + +action=$1 +if [ "${1}" == 'install' ];then + Install_App +else + Uninstall_App +fi diff --git a/plugins/tgbot/js/tgbot.js b/plugins/tgbot/js/tgbot.js new file mode 100755 index 0000000000..04c1643ed9 --- /dev/null +++ b/plugins/tgbot/js/tgbot.js @@ -0,0 +1,78 @@ +function appPost(method, args,callback){ + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + + var req_data = {}; + req_data['name'] = 'tgbot'; + req_data['func'] = method; + + if (typeof(args) == 'string'){ + req_data['args'] = JSON.stringify(toArrayObject(args)); + } else { + req_data['args'] = JSON.stringify(args); + } + + $.post('/plugins/run', req_data, function(data) { + layer.close(loadT); + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + +function appPostCallbak(method, args,callback){ + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + + var req_data = {}; + req_data['name'] = 'tgbot'; + req_data['func'] = method; + + if (typeof(args) == 'string'){ + req_data['args'] = JSON.stringify(toArrayObject(args)); + } else { + req_data['args'] = JSON.stringify(args); + } + + $.post('/plugins/callback', req_data, function(data) { + layer.close(loadT); + if (!data.status){ + layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + +function botConf(){ + appPost('get_bot_conf','',function(data){ + var rdata = $.parseJSON(data.data); + var app_token = 'app_token'; + if(rdata['status']){ + db_data = rdata['data']; + app_token = db_data['app_token']; + + } + + var mlist = ''; + mlist += '

app_token必填写

' + var option = '\ +
\ + ' + mlist + '\ +
\ + \ +
\ +
'; + $(".soft-man-con").html(option); + }); +} + +function submitBotConf(){ + var pull_data = {}; + pull_data['app_token'] = base64_encode($('input[name="app_token"]').val()); + appPost('set_bot_conf',pull_data,function(data){ + var rdata = $.parseJSON(data.data); + layer.msg(rdata['msg'],{icon:rdata['status']?1:2,time:2000,shade: [0.3, '#000']}); + }); +} diff --git a/plugins/tgbot/startup/tgbot.py b/plugins/tgbot/startup/tgbot.py new file mode 100644 index 0000000000..1851f22135 --- /dev/null +++ b/plugins/tgbot/startup/tgbot.py @@ -0,0 +1,63 @@ + +# coding:utf-8 + +import sys +import io +import os +import time +import re +import json +import base64 + +sys.path.append(os.getcwd() + "/class/core") +import mw + +import telebot + + +def getPluginName(): + return 'tgbot' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getConfigData(): + cfg_path = getServerDir() + "/data.cfg" + if not os.path.exists(cfg_path): + mw.writeFile(cfg_path, '{}') + t = mw.readFile(cfg_path) + return json.loads(t) + + +def writeConf(data): + cfg_path = getServerDir() + "/data.cfg" + mw.writeFile(cfg_path, json.dumps(data)) + return True + +# start tgbot +cfg = getConfigData() +bot = telebot.TeleBot(cfg['bot']['app_token']) + + +# from telebot.async_telebot import AsyncTeleBot +# import asyncio +# bot = AsyncTeleBot(cfg['bot']['app_token']) + + +@bot.message_handler(commands=['start', 'help']) +def hanle_start_help(message): + bot.reply_to(message, "hello world") + + +@bot.message_handler(commands=['chat_id']) +def hanle_get_chat_id(message): + bot.reply_to(message, message.chat.id) + +bot.polling() +# asyncio.run(bot.polling()) diff --git a/route/static/app/public.js b/route/static/app/public.js index 5f65bcce8c..1b83a07c11 100755 --- a/route/static/app/public.js +++ b/route/static/app/public.js @@ -1773,6 +1773,159 @@ function entitiesDecode(text) { return text; } +// base64.js +// base64加密 +function base64_encode(str) { + var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + var out, i, len; + var c1, c2, c3; + + len = str.length; + i = 0; + out = ""; + while(i < len) { + c1 = str.charCodeAt(i++) & 0xff; + if(i == len) + { + out += base64EncodeChars.charAt(c1 >> 2); + out += base64EncodeChars.charAt((c1 & 0x3) << 4); + out += "=="; + break; + } + c2 = str.charCodeAt(i++); + if(i == len) + { + out += base64EncodeChars.charAt(c1 >> 2); + out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)); + out += base64EncodeChars.charAt((c2 & 0xF) << 2); + out += "="; + break; + } + c3 = str.charCodeAt(i++); + out += base64EncodeChars.charAt(c1 >> 2); + out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4)); + out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6)); + out += base64EncodeChars.charAt(c3 & 0x3F); + } + return out; +} + + +// base64解密 +function base64_decode(str) { + var base64DecodeChars = new Array( + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1); + var c1, c2, c3, c4; + var i, len, out; + + len = str.length; + i = 0; + out = ""; + while(i < len) { + /* c1 */ + do { + c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff]; + } while(i < len && c1 == -1); + if(c1 == -1) + break; + + /* c2 */ + do { + c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff]; + } while(i < len && c2 == -1); + if(c2 == -1) + break; + + out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4)); + + /* c3 */ + do { + c3 = str.charCodeAt(i++) & 0xff; + if(c3 == 61) + return out; + c3 = base64DecodeChars[c3]; + } while(i < len && c3 == -1); + if(c3 == -1) + break; + + out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2)); + + /* c4 */ + do { + c4 = str.charCodeAt(i++) & 0xff; + if(c4 == 61) + return out; + c4 = base64DecodeChars[c4]; + } while(i < len && c4 == -1); + if(c4 == -1) + break; + out += String.fromCharCode(((c3 & 0x03) << 6) | c4); + } + return out; +} + +function utf16to8(str) { + var out, i, len, c; + + out = ""; + len = str.length; + for(i = 0; i < len; i++) { + c = str.charCodeAt(i); + if ((c >= 0x0001) && (c <= 0x007F)) { + out += str.charAt(i); + } else if (c > 0x07FF) { + out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F)); + out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F)); + out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); + } else { + out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F)); + out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); + } + } + return out; +} + +function utf8to16(str) { + var out, i, len, c; + var char2, char3; + + out = ""; + len = str.length; + i = 0; + while(i < len) { + c = str.charCodeAt(i++); + switch(c >> 4) + { + case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: + // 0xxxxxxx + out += str.charAt(i-1); + break; + case 12: case 13: + // 110x xxxx 10xx xxxx + char2 = str.charCodeAt(i++); + out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F)); + break; + case 14: + // 1110 xxxx 10xx xxxx 10xx xxxx + char2 = str.charCodeAt(i++); + char3 = str.charCodeAt(i++); + out += String.fromCharCode(((c & 0x0F) << 12) | + ((char2 & 0x3F) << 6) | + ((char3 & 0x3F) << 0)); + break; + } + } + + return out; +} + function pluginService(_name, version){ var data = {name:_name, func:'status'} From 3e695770d7374595b0e4b91ead284807f1ad2a35 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 16:26:49 +0800 Subject: [PATCH 02/48] Update config_api.py --- class/core/config_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index 737f53ecb9..185bc7ba1a 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -27,7 +27,7 @@ class config_api: - __version = '0.13.1' + __version = '0.13.1.1' __api_addr = 'data/api.json' def __init__(self): From e75abae4b935a14687b107aa969fa0cfbdc7b6cd Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 16:32:05 +0800 Subject: [PATCH 03/48] Update tgbot.service.tpl --- plugins/tgbot/init.d/tgbot.service.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tgbot/init.d/tgbot.service.tpl b/plugins/tgbot/init.d/tgbot.service.tpl index 77a48f06cc..64e9135891 100644 --- a/plugins/tgbot/init.d/tgbot.service.tpl +++ b/plugins/tgbot/init.d/tgbot.service.tpl @@ -1,5 +1,5 @@ [Unit] -Description=Redis In-Memory Data Store +Description=Tgbot Service After=network.target [Service] From d056c37be56d993cc3e8c01bfbdd4871cd96e22e Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 16:33:18 +0800 Subject: [PATCH 04/48] Update index.py --- plugins/tgbot/index.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/tgbot/index.py b/plugins/tgbot/index.py index 3b76feef29..6ea4e09267 100755 --- a/plugins/tgbot/index.py +++ b/plugins/tgbot/index.py @@ -91,6 +91,7 @@ def initDreplace(): file_tpl = getInitDTpl() service_path = mw.getServerDir() + app_path = service_path + '/' + getPluginName() initD_path = getServerDir() + '/init.d' if not os.path.exists(initD_path): @@ -101,8 +102,7 @@ def initDreplace(): # if not os.path.exists(file_bin): content = mw.readFile(file_tpl) content = content.replace('{$SERVER_PATH}', service_path + '/mdserver-web') - content = content.replace( - '{$APP_PATH}', service_path + '/' + getPluginName()) + content = content.replace('{$APP_PATH}', app_path) mw.writeFile(file_bin, content) mw.execShell('chmod +x ' + file_bin) @@ -114,7 +114,7 @@ def initDreplace(): if os.path.exists(systemDir) and not os.path.exists(systemService): service_path = mw.getServerDir() se_content = mw.readFile(systemServiceTpl) - se_content = se_content.replace('{$SERVER_PATH}', service_path) + se_content = se_content.replace('{$APP_PATH}', app_path) mw.writeFile(systemService, se_content) mw.execShell('systemctl daemon-reload') From 2ed70b4b9631815b839a28d9888ec65ae7ad3056 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 16:39:27 +0800 Subject: [PATCH 05/48] Update tgbot.py --- plugins/tgbot/startup/tgbot.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/tgbot/startup/tgbot.py b/plugins/tgbot/startup/tgbot.py index 1851f22135..907ea84ec6 100644 --- a/plugins/tgbot/startup/tgbot.py +++ b/plugins/tgbot/startup/tgbot.py @@ -42,6 +42,13 @@ def writeConf(data): # start tgbot cfg = getConfigData() +while True: + cfg = getConfigData() + if 'bot' in cfg and 'app_token' in cfg['bot']: + if cfg['bot']['app_token'] != '' and cfg['bot']['app_token'] != 'app_token': + break + time.sleep(3) + bot = telebot.TeleBot(cfg['bot']['app_token']) From b8f04043bca339687ed7fa175192b5ab04652530 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 16:41:25 +0800 Subject: [PATCH 06/48] Update tgbot.service.tpl --- plugins/tgbot/init.d/tgbot.service.tpl | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/tgbot/init.d/tgbot.service.tpl b/plugins/tgbot/init.d/tgbot.service.tpl index 64e9135891..04ee1b9526 100644 --- a/plugins/tgbot/init.d/tgbot.service.tpl +++ b/plugins/tgbot/init.d/tgbot.service.tpl @@ -7,7 +7,6 @@ Type=forking ExecStart={$APP_PATH}/init.d/tgbot start ExecStop={$APP_PATH}/init.d/tgbot stop ExecReload={$APP_PATH}/init.d/tgbot reload -ExecRestart={$APP_PATH}/init.d/tgbot restart KillMode=process Restart=on-failure From 197e2d80c6c698772c46bd3e5a6c5a76f8d060f6 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 16:42:29 +0800 Subject: [PATCH 07/48] Update tgbot.py --- plugins/tgbot/startup/tgbot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/tgbot/startup/tgbot.py b/plugins/tgbot/startup/tgbot.py index 907ea84ec6..cd4c530cc5 100644 --- a/plugins/tgbot/startup/tgbot.py +++ b/plugins/tgbot/startup/tgbot.py @@ -47,6 +47,7 @@ def writeConf(data): if 'bot' in cfg and 'app_token' in cfg['bot']: if cfg['bot']['app_token'] != '' and cfg['bot']['app_token'] != 'app_token': break + print('wait input config') time.sleep(3) bot = telebot.TeleBot(cfg['bot']['app_token']) From 29e3017e5108f35abdc8e087167dafdd3b8ac6dc Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 16:49:42 +0800 Subject: [PATCH 08/48] up --- plugins/tgbot/index.html | 1 + plugins/tgbot/index.py | 10 ++++++++-- plugins/tgbot/startup/tgbot.py | 12 +++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/plugins/tgbot/index.html b/plugins/tgbot/index.html index fa1873be62..f98fd5ded4 100755 --- a/plugins/tgbot/index.html +++ b/plugins/tgbot/index.html @@ -5,6 +5,7 @@

服务

自启动

Bot配置

+

日志

diff --git a/plugins/tgbot/index.py b/plugins/tgbot/index.py index 6ea4e09267..cd040d32f2 100755 --- a/plugins/tgbot/index.py +++ b/plugins/tgbot/index.py @@ -211,6 +211,11 @@ def setBotConf(): return mw.returnJson(True, '保存成功!', []) +def runLog(): + p = getServerDir() + '/task.log' + return p + + if __name__ == "__main__": func = sys.argv[1] if func == 'status': @@ -233,7 +238,8 @@ def setBotConf(): print(getBotConf()) elif func == 'set_bot_conf': print(setBotConf()) - elif func == 'conf': - print(getConf()) + elif func == 'run_log': + print(runLog()) + else: print('error') diff --git a/plugins/tgbot/startup/tgbot.py b/plugins/tgbot/startup/tgbot.py index cd4c530cc5..c763e8c1c1 100644 --- a/plugins/tgbot/startup/tgbot.py +++ b/plugins/tgbot/startup/tgbot.py @@ -40,6 +40,15 @@ def writeConf(data): mw.writeFile(cfg_path, json.dumps(data)) return True + +def writeLog(log_str): + if __name__ == "__main__": + print(log_str) + + log_file = getServerDir() + '/task.log' + mw.writeFileLog(log_str, log_file, limit_size=5 * 1024) + return True + # start tgbot cfg = getConfigData() while True: @@ -47,7 +56,7 @@ def writeConf(data): if 'bot' in cfg and 'app_token' in cfg['bot']: if cfg['bot']['app_token'] != '' and cfg['bot']['app_token'] != 'app_token': break - print('wait input config') + writeLog('等待输入配置,填写app_token') time.sleep(3) bot = telebot.TeleBot(cfg['bot']['app_token']) @@ -67,5 +76,6 @@ def hanle_start_help(message): def hanle_get_chat_id(message): bot.reply_to(message, message.chat.id) +writeLog('启动成功') bot.polling() # asyncio.run(bot.polling()) From 51ccbefb041e0bd26eb67ecb321c046b815618af Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 17:15:41 +0800 Subject: [PATCH 09/48] up --- route/static/app/public.js | 9 ++++++--- route/templates/default/config.html | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/route/static/app/public.js b/route/static/app/public.js index 1b83a07c11..dd153ff0f8 100755 --- a/route/static/app/public.js +++ b/route/static/app/public.js @@ -2277,6 +2277,8 @@ function pluginOpInitD(a, _version, b) { } function pluginLogs(_name, version, func, line){ + + var _this = this; if ( typeof(version) == 'undefined' ){ version = ''; } @@ -2317,9 +2319,10 @@ function pluginLogs(_name, version, func, line){ if(rdata.data == '') { rdata.data = '当前没有日志!'; } - var ebody = '
\ - \ -
'; + + + var h = parseInt($('.bt-w-menu').css('height')) - 40; + var ebody = ''; $(".soft-man-con").html(ebody); var ob = document.getElementById('info_log'); ob.scrollTop = ob.scrollHeight; diff --git a/route/templates/default/config.html b/route/templates/default/config.html index 7429ff58a8..a6c5f2f38d 100755 --- a/route/templates/default/config.html +++ b/route/templates/default/config.html @@ -102,7 +102,6 @@

安全

-

@@ -148,6 +147,21 @@ 为非管理员临时提供面板访问权限

+ + +

通知

+ +
+ +

+ TG机器人通知 + + + + Telegram Bot机器人通知 +

+ +
From 64d1387b0346c02b84ee6f4e2a8eb39c2618f573 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 19:32:36 +0800 Subject: [PATCH 10/48] =?UTF-8?q?Telegram=20Bot=E6=9C=BA=E5=99=A8=E4=BA=BA?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=20=E5=8A=A0=E5=85=A5=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/config_api.py | 58 +++++++++++++++++++++++ class/core/mw.py | 42 +++++++++++++++++ data/notify.json | 1 + route/static/app/config.js | 72 +++++++++++++++++++++++++++++ route/templates/default/config.html | 6 +-- 5 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 data/notify.json diff --git a/class/core/config_api.py b/class/core/config_api.py index 185bc7ba1a..a09f865ec5 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -661,6 +661,54 @@ def setStatusCodeApi(self): mw.writeLog('面板设置', '将未授权响应状态码设置为:{}'.format(status_code)) return mw.returnJson(True, '设置成功!') + def getNotifyApi(self): + # 获取 + data = mw.getNotifyData() + return mw.returnData(True, 'ok', data) + + def setNotifyApi(self): + tag = request.form.get('tag', '').strip() + tag_data = request.form.get('data', '').strip() + + data = mw.getNotifyData() + data[tag] = json.loads(tag_data) + + mw.writeNotify(data) + return mw.returnData(True, '设置成功') + + def setNotifyTestApi(self): + # 异步通知验证 + tag = request.form.get('tag', '').strip() + tag_data = request.form.get('data', '').strip() + + if tag == 'tgbot': + t = json.loads(tag_data) + test_bool = mw.tgbotNotifyTest(t['app_token'], t['chat_id']) + if test_bool: + return mw.returnData(True, '验证成功') + return mw.returnData(False, '验证失败') + + return mw.returnData(False, '暂时未支持该验证') + + def setNotifyEnableApi(self): + # 异步通知验证 + tag = request.form.get('tag', '').strip() + tag_enable = request.form.get('enable', '').strip() + + data = mw.getNotifyData() + op_enable = True + op_action = '开启' + if tag_enable != 'true': + op_enable = False + op_action = '关闭' + + if tag in data: + data[tag]['enable'] = op_enable + + mw.writeNotify(data) + + return mw.returnData(True, op_action + '成功') + def getPanelTokenApi(self): api_file = self.__api_addr tmp = mw.readFile(api_file) @@ -853,4 +901,14 @@ def get(self): else: data['hook_global_static'] = [] + # notiy config + notify_data = mw.getNotifyData() + notify_tag_list = ['tgbot', 'email'] + for tag in notify_tag_list: + new_tag = 'notify_' + tag + '_enable' + data[new_tag] = '' + if tag in notify_data and 'enable' in notify_data[tag]: + if notify_data[tag]['enable']: + data[new_tag] = 'checked' + return data diff --git a/class/core/mw.py b/class/core/mw.py index 8e4bb0e99b..1deae6be02 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -1662,6 +1662,48 @@ def getMyORMDb(): o = ormDb.ORM() return o +##################### notify start ######################################### + + +def initNotifyConfig(): + p = getNotifyPath() + if not os.path.exists(p): + writeFile(p, '{}') + return True + + +def getNotifyPath(): + path = 'data/notify.json' + return path + + +def getNotifyData(): + initNotifyConfig() + p = getNotifyPath() + t = readFile(p) + return json.loads(t) + + +def writeNotify(data): + p = getNotifyPath() + return writeFile(p, json.dumps(data)) + + +def tgbotNotifyTest(app_token, chat_id): + import telebot + bot = telebot.TeleBot(app_token) + + try: + data = bot.send_message(chat_id, "MW-通知验证测试OK") + # print(data) + return True + except Exception as e: + pass + return False + + +##################### notify end ######################################### + ##################### ssh start ######################################### def getSshDir(): diff --git a/data/notify.json b/data/notify.json new file mode 100644 index 0000000000..8de1fa9092 --- /dev/null +++ b/data/notify.json @@ -0,0 +1 @@ +{"tgbot": {"app_token": "5928900966:AAEqs-pIDfai-7rS_cr1R4igsInaXd1OANs", "chat_id": "5568699210", "enable": true}} \ No newline at end of file diff --git a/route/static/app/config.js b/route/static/app/config.js index 83a8a8c679..b4b9c899c0 100755 --- a/route/static/app/config.js +++ b/route/static/app/config.js @@ -354,6 +354,78 @@ function setPanelSSL(){ }); } +function setNotifyApi(tag, obj){ + var enable = $(obj).prop("checked"); + console.log(tag,obj,enable); + $.post('/config/set_notify_enable', {'tag':tag, 'enable':enable},function(rdata){ + showMsg(rdata.msg, function(){ + if (rdata.status){} + } ,{icon:rdata.status?1:2}, 1000); + },'json'); +} + +function getTgbot(){ + var loadT = layer.msg('正在获取TgBot信息...',{icon:16,time:0,shade: [0.3, '#000']}); + $.post('/config/get_notify',{},function(data){ + layer.close(loadT); + + var app_token = ''; + var chat_id = ''; + + if (data.status){ + if (typeof(data['data']['tgbot']) !='undefined'){ + app_token = data['data']['tgbot']['app_token']; + chat_id = data['data']['tgbot']['chat_id']; + } + } + + layer.open({ + type: 1, + area: "500px", + title: '配置TgBot配置', + closeBtn: 1, + shift: 5, + btn:["确定","关闭","验证"], + shadeClose: false, + content: "
\ +
\ + APP_TOKEN\ +
\ +
\ +
\ + CHAT_ID\ +
\ +
\ +
", + yes:function(index){ + var pdata = {}; + pdata['app_token'] = $('input[name="app_token"]').val(); + pdata['chat_id'] = $('input[name="chat_id"]').val(); + $.post('/config/set_notify',{'tag':'tgbot', 'data':JSON.stringify(pdata)},function(rdata){ + showMsg(rdata.msg, function(){ + if (rdata.status){ + layer.close(index); + } + },{icon:rdata.status?1:2},2000); + }); + }, + + btn3:function(index){ + var pdata = {}; + pdata['app_token'] = $('input[name="app_token"]').val(); + pdata['chat_id'] = $('input[name="chat_id"]').val(); + $.post('/config/set_notify_test',{'tag':'tgbot', 'data':JSON.stringify(pdata)},function(rdata){ + showMsg(rdata.msg, function(){ + if (rdata.status){ + layer.close(index); + } + },{icon:rdata.status?1:2},2000); + }); + return false; + } + }); + }); +} function getPanelSSL(){ var loadT = layer.msg('正在获取证书信息...',{icon:16,time:0,shade: [0.3, '#000']}); diff --git a/route/templates/default/config.html b/route/templates/default/config.html index a6c5f2f38d..34d10050f3 100755 --- a/route/templates/default/config.html +++ b/route/templates/default/config.html @@ -155,9 +155,9 @@

TG机器人通知 - - - + + + Telegram Bot机器人通知

From 44f891f7a32bd65cae947d25dfe404b885ece7a5 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 20:12:52 +0800 Subject: [PATCH 11/48] Update mw.py --- class/core/mw.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/class/core/mw.py b/class/core/mw.py index 1deae6be02..5df49936b5 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -1689,12 +1689,17 @@ def writeNotify(data): return writeFile(p, json.dumps(data)) -def tgbotNotifyTest(app_token, chat_id): +def tgbotNotify(app_token): import telebot bot = telebot.TeleBot(app_token) + return bot + + +def tgbotNotifyMessage(app_token, chat_id, msg): + bot = tgbotNotify(app_token) try: - data = bot.send_message(chat_id, "MW-通知验证测试OK") + data = bot.send_message(chat_id, msg) # print(data) return True except Exception as e: @@ -1702,6 +1707,22 @@ def tgbotNotifyTest(app_token, chat_id): return False +def tgbotNotifyTest(app_token, chat_id): + return tgbotNotifyApp(app_token, chat_id, 'MW-通知验证测试OK') + + +def notifyMessage(msg): + data = getNotifyData() + # tag_list = ['tgbot', 'email'] + # tagbot + do_notify = False + if 'tgbot' in data and 'enable' in data['tgbot']: + if data['tgbot']['enable']: + t = data['tgbot'] + do_notify = tgbotNotifyMessage(t['app_token'], t['chat_id'], msg) + return do_notify + + ##################### notify end ######################################### From de225fc8b9f0a1ff3b433a4938ad824d635752cd Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 20:28:29 +0800 Subject: [PATCH 12/48] 0.13.1.2 --- class/core/config_api.py | 2 +- requirements.txt | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/class/core/config_api.py b/class/core/config_api.py index a09f865ec5..bf8c741582 100755 --- a/class/core/config_api.py +++ b/class/core/config_api.py @@ -27,7 +27,7 @@ class config_api: - __version = '0.13.1.1' + __version = '0.13.1.2' __api_addr = 'data/api.json' def __init__(self): diff --git a/requirements.txt b/requirements.txt index deb9e8f357..211761a52f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -29,3 +29,5 @@ flask-caching>=1.10.1 bcrypt==3.1.3 PyMySQL==1.0.2 whitenoise==5.3.0 +pyTelegramBotAPI +telebot From 43bf755609e837d107e6487f419af46c80a37f64 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 20:35:06 +0800 Subject: [PATCH 13/48] Update mw.py --- class/core/mw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/class/core/mw.py b/class/core/mw.py index 5df49936b5..6049bf5e74 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -1708,7 +1708,7 @@ def tgbotNotifyMessage(app_token, chat_id, msg): def tgbotNotifyTest(app_token, chat_id): - return tgbotNotifyApp(app_token, chat_id, 'MW-通知验证测试OK') + return tgbotNotifyMessage(app_token, chat_id, 'MW-通知验证测试OK') def notifyMessage(msg): From 28437ccfb023f3cbcbac9f85774e82abc645228e Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 21:30:18 +0800 Subject: [PATCH 14/48] Update mw.py --- class/core/mw.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/class/core/mw.py b/class/core/mw.py index 6049bf5e74..5245d1815d 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -28,6 +28,8 @@ import db from random import Random +import telebot + def execShell(cmdstring, cwd=None, timeout=None, shell=True): @@ -1689,26 +1691,39 @@ def writeNotify(data): return writeFile(p, json.dumps(data)) -def tgbotNotify(app_token): - import telebot +def tgbotNotifyObject(app_token): bot = telebot.TeleBot(app_token) return bot def tgbotNotifyMessage(app_token, chat_id, msg): - bot = tgbotNotify(app_token) + bot = tgbotNotifyObject(app_token) try: data = bot.send_message(chat_id, msg) # print(data) return True except Exception as e: - pass + writeFileLog(str(e)) return False def tgbotNotifyTest(app_token, chat_id): - return tgbotNotifyMessage(app_token, chat_id, 'MW-通知验证测试OK') + # return tgbotNotifyMessage(app_token, chat_id, 'MW-通知验证测试OK') + msg = 'MW-通知验证测试OK' + try: + + url = 'https://api.telegram.org/bot' + app_token + '/sendMessage' + post_data = { + 'chat_id': chat_id, + 'text': msg, + } + rdata = httpPost(url, post_data) + json.loads(rdata) + return True + except Exception as e: + writeFileLog(str(e)) + return False def notifyMessage(msg): From cfd2d99e2434bb8d89d848864137397faf35e1c4 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 21:31:24 +0800 Subject: [PATCH 15/48] Update mw.py --- class/core/mw.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/class/core/mw.py b/class/core/mw.py index 5245d1815d..aa2a19c331 100755 --- a/class/core/mw.py +++ b/class/core/mw.py @@ -1709,10 +1709,8 @@ def tgbotNotifyMessage(app_token, chat_id, msg): def tgbotNotifyTest(app_token, chat_id): - # return tgbotNotifyMessage(app_token, chat_id, 'MW-通知验证测试OK') msg = 'MW-通知验证测试OK' try: - url = 'https://api.telegram.org/bot' + app_token + '/sendMessage' post_data = { 'chat_id': chat_id, From d4290cbdd2fa6b1e94f3ef9a0a34e8866e03c0b1 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 22:29:20 +0800 Subject: [PATCH 16/48] =?UTF-8?q?mariadb=E6=9B=B4=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/mariadb/versions/10.6/install.sh | 2 +- plugins/mariadb/versions/10.7/install.sh | 2 +- plugins/mariadb/versions/10.8/install.sh | 2 +- plugins/mariadb/versions/10.9/install.sh | 2 +- plugins/mariadb/versions/11.0/install.sh | 119 +++++++++++++++++++++++ 5 files changed, 123 insertions(+), 4 deletions(-) create mode 100755 plugins/mariadb/versions/11.0/install.sh diff --git a/plugins/mariadb/versions/10.6/install.sh b/plugins/mariadb/versions/10.6/install.sh index 9b7e522dcd..9772e8c0a7 100755 --- a/plugins/mariadb/versions/10.6/install.sh +++ b/plugins/mariadb/versions/10.6/install.sh @@ -13,7 +13,7 @@ sysName=`uname` install_tmp=${rootPath}/tmp/mw_install.pl mariadbDir=${serverPath}/source/mariadb -MY_VER=10.6.9 +MY_VER=10.6.12 Install_app() { diff --git a/plugins/mariadb/versions/10.7/install.sh b/plugins/mariadb/versions/10.7/install.sh index ea02e3c165..2a8112c3fe 100755 --- a/plugins/mariadb/versions/10.7/install.sh +++ b/plugins/mariadb/versions/10.7/install.sh @@ -14,7 +14,7 @@ sysName=`uname` install_tmp=${rootPath}/tmp/mw_install.pl mariadbDir=${serverPath}/source/mariadb -MY_VER=10.7.4 +MY_VER=10.7.8 Install_app() { diff --git a/plugins/mariadb/versions/10.8/install.sh b/plugins/mariadb/versions/10.8/install.sh index 7c3a880a3c..895a767d42 100755 --- a/plugins/mariadb/versions/10.8/install.sh +++ b/plugins/mariadb/versions/10.8/install.sh @@ -14,7 +14,7 @@ sysName=`uname` install_tmp=${rootPath}/tmp/mw_install.pl mariadbDir=${serverPath}/source/mariadb -MY_VER=10.8.5 +MY_VER=10.8.7 Install_app() { diff --git a/plugins/mariadb/versions/10.9/install.sh b/plugins/mariadb/versions/10.9/install.sh index 6cfe763ce7..61299f769e 100755 --- a/plugins/mariadb/versions/10.9/install.sh +++ b/plugins/mariadb/versions/10.9/install.sh @@ -14,7 +14,7 @@ sysName=`uname` install_tmp=${rootPath}/tmp/mw_install.pl mariadbDir=${serverPath}/source/mariadb -MY_VER=10.9.2 +MY_VER=10.9.5 Install_app() { diff --git a/plugins/mariadb/versions/11.0/install.sh b/plugins/mariadb/versions/11.0/install.sh new file mode 100755 index 0000000000..801e91ad91 --- /dev/null +++ b/plugins/mariadb/versions/11.0/install.sh @@ -0,0 +1,119 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +#https://dev.mysql.com/downloads/mysql/5.5.html#downloads +#https://dev.mysql.com/downloads/file/?id=480541 + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") +sysName=`uname` + +install_tmp=${rootPath}/tmp/mw_install.pl +mariadbDir=${serverPath}/source/mariadb + +MY_VER=11.0.1 + +Install_app() +{ + mkdir -p ${mariadbDir} + echo '正在安装脚本文件...' > $install_tmp + + if id mysql &> /dev/null ;then + echo "mysql uid is `id -u www`" + echo "mysql shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `" + else + groupadd mysql + useradd -g mysql mysql + fi + + if [ "$sysName" != "Darwin" ];then + mkdir -p /var/log/mariadb + touch /var/log/mariadb/mariadb.log + fi + + # ----- cpu start ------ + if [ -z "${cpuCore}" ]; then + cpuCore="1" + fi + + if [ -f /proc/cpuinfo ];then + cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l` + fi + + MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}') + if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then + if [ "${cpuCore}" -gt "${MEM_INFO}" ];then + cpuCore="${MEM_INFO}" + fi + else + cpuCore="1" + fi + + if [ "$cpuCore" -gt "2" ];then + cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'` + else + cpuCore="1" + fi + # ----- cpu end ------ + + # if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then + # wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://mirrors.aliyun.com/mariadb/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz + # fi + + # https://downloads.mariadb.org/interstitial/mariadb-10.9.1/source/mariadb-10.9.1.tar.gz + if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then + wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://archive.mariadb.org/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz + fi + + if [ ! -d ${mariadbDir}/mariadb-${MY_VER} ];then + cd ${mariadbDir} && tar -zxvf ${mariadbDir}/mariadb-${MY_VER}.tar.gz + fi + + + if [ ! -d $serverPath/mariadb ];then + cd ${mariadbDir}/mariadb-${MY_VER} && cmake \ + -DCMAKE_INSTALL_PREFIX=$serverPath/mariadb \ + -DMYSQL_DATADIR=$serverPath/mariadb/data/ \ + -DMYSQL_USER=mysql \ + -DMYSQL_UNIX_ADDR=$serverPath/mariadb/mysql.sock \ + -DWITH_MYISAM_STORAGE_ENGINE=1 \ + -DWITH_INNOBASE_STORAGE_ENGINE=1 \ + -DWITH_MEMORY_STORAGE_ENGINE=1 \ + -DENABLED_LOCAL_INFILE=1 \ + -DWITH_PARTITION_STORAGE_ENGINE=1 \ + -DEXTRA_CHARSETS=all \ + -DDEFAULT_CHARSET=utf8mb4 \ + -DDEFAULT_COLLATION=utf8mb4_general_ci \ + -DCMAKE_C_COMPILER=/usr/bin/gcc \ + -DCMAKE_CXX_COMPILER=/usr/bin/g++ + make -j${cpuCore} && make install && make clean + + if [ -d $serverPath/mariadb ];then + echo '10.9' > $serverPath/mariadb/version.pl + echo '安装完成' > $install_tmp + else + echo '安装失败' > $install_tmp + echo 'install fail'>&2 + exit 1 + fi + fi + + rm -rf ${mariadbDir}/mariadb-${MY_VER} + rm -rf ${mariadbDir}/mariadb-${MY_VER}.tar.gz +} + +Uninstall_app() +{ + rm -rf $serverPath/mariadb + echo '卸载完成' > $install_tmp +} + +action=$1 +if [ "${1}" == 'install' ];then + Install_app +else + Uninstall_app +fi From abac3456280d94e8da1d1afd7125b1bd6f3922a2 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 23:10:12 +0800 Subject: [PATCH 17/48] Update info.json --- plugins/mariadb/info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mariadb/info.json b/plugins/mariadb/info.json index aa6364b5c0..3dcc2af109 100755 --- a/plugins/mariadb/info.json +++ b/plugins/mariadb/info.json @@ -8,7 +8,7 @@ "uninstall_pre_inspection":true, "checks": "server/mariadb", "path": "server/mariadb", - "versions":["10.6","10.7","10.8","10.9"], + "versions":["10.6","10.7","10.8","10.9","11.0"], "shell":"install.sh", "checks":"server/mariadb", "path":"server/mariadb", From d786b2524a9547938f3112416421611738763ff7 Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 23:21:55 +0800 Subject: [PATCH 18/48] up --- plugins/mariadb/info.json | 2 +- plugins/mariadb/versions/10.11/install.sh | 119 ++++++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100755 plugins/mariadb/versions/10.11/install.sh diff --git a/plugins/mariadb/info.json b/plugins/mariadb/info.json index 3dcc2af109..a0767c8238 100755 --- a/plugins/mariadb/info.json +++ b/plugins/mariadb/info.json @@ -8,7 +8,7 @@ "uninstall_pre_inspection":true, "checks": "server/mariadb", "path": "server/mariadb", - "versions":["10.6","10.7","10.8","10.9","11.0"], + "versions":["10.6","10.7","10.8","10.9","10.11","11.0"], "shell":"install.sh", "checks":"server/mariadb", "path":"server/mariadb", diff --git a/plugins/mariadb/versions/10.11/install.sh b/plugins/mariadb/versions/10.11/install.sh new file mode 100755 index 0000000000..44ed9fe5f8 --- /dev/null +++ b/plugins/mariadb/versions/10.11/install.sh @@ -0,0 +1,119 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +#https://dev.mysql.com/downloads/mysql/5.5.html#downloads +#https://dev.mysql.com/downloads/file/?id=480541 + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") +sysName=`uname` + +install_tmp=${rootPath}/tmp/mw_install.pl +mariadbDir=${serverPath}/source/mariadb + +MY_VER=10.11.2 + +Install_app() +{ + mkdir -p ${mariadbDir} + echo '正在安装脚本文件...' > $install_tmp + + if id mysql &> /dev/null ;then + echo "mysql uid is `id -u www`" + echo "mysql shell is `grep "^www:" /etc/passwd |cut -d':' -f7 `" + else + groupadd mysql + useradd -g mysql mysql + fi + + if [ "$sysName" != "Darwin" ];then + mkdir -p /var/log/mariadb + touch /var/log/mariadb/mariadb.log + fi + + # ----- cpu start ------ + if [ -z "${cpuCore}" ]; then + cpuCore="1" + fi + + if [ -f /proc/cpuinfo ];then + cpuCore=`cat /proc/cpuinfo | grep "processor" | wc -l` + fi + + MEM_INFO=$(free -m|grep Mem|awk '{printf("%.f",($2)/1024)}') + if [ "${cpuCore}" != "1" ] && [ "${MEM_INFO}" != "0" ];then + if [ "${cpuCore}" -gt "${MEM_INFO}" ];then + cpuCore="${MEM_INFO}" + fi + else + cpuCore="1" + fi + + if [ "$cpuCore" -gt "2" ];then + cpuCore=`echo "$cpuCore" | awk '{printf("%.f",($1)*0.8)}'` + else + cpuCore="1" + fi + # ----- cpu end ------ + + # if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then + # wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://mirrors.aliyun.com/mariadb/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz + # fi + + # https://downloads.mariadb.org/interstitial/mariadb-10.9.1/source/mariadb-10.9.1.tar.gz + if [ ! -f ${mariadbDir}/mariadb-${MY_VER}.tar.gz ];then + wget --no-check-certificate -O ${mariadbDir}/mariadb-${MY_VER}.tar.gz --tries=3 https://archive.mariadb.org/mariadb-${MY_VER}/source/mariadb-${MY_VER}.tar.gz + fi + + if [ ! -d ${mariadbDir}/mariadb-${MY_VER} ];then + cd ${mariadbDir} && tar -zxvf ${mariadbDir}/mariadb-${MY_VER}.tar.gz + fi + + + if [ ! -d $serverPath/mariadb ];then + cd ${mariadbDir}/mariadb-${MY_VER} && cmake \ + -DCMAKE_INSTALL_PREFIX=$serverPath/mariadb \ + -DMYSQL_DATADIR=$serverPath/mariadb/data/ \ + -DMYSQL_USER=mysql \ + -DMYSQL_UNIX_ADDR=$serverPath/mariadb/mysql.sock \ + -DWITH_MYISAM_STORAGE_ENGINE=1 \ + -DWITH_INNOBASE_STORAGE_ENGINE=1 \ + -DWITH_MEMORY_STORAGE_ENGINE=1 \ + -DENABLED_LOCAL_INFILE=1 \ + -DWITH_PARTITION_STORAGE_ENGINE=1 \ + -DEXTRA_CHARSETS=all \ + -DDEFAULT_CHARSET=utf8mb4 \ + -DDEFAULT_COLLATION=utf8mb4_general_ci \ + -DCMAKE_C_COMPILER=/usr/bin/gcc \ + -DCMAKE_CXX_COMPILER=/usr/bin/g++ + make -j${cpuCore} && make install && make clean + + if [ -d $serverPath/mariadb ];then + echo '10.11' > $serverPath/mariadb/version.pl + echo '安装完成' > $install_tmp + else + echo '安装失败' > $install_tmp + echo 'install fail'>&2 + exit 1 + fi + fi + + rm -rf ${mariadbDir}/mariadb-${MY_VER} + rm -rf ${mariadbDir}/mariadb-${MY_VER}.tar.gz +} + +Uninstall_app() +{ + rm -rf $serverPath/mariadb + echo '卸载完成' > $install_tmp +} + +action=$1 +if [ "${1}" == 'install' ];then + Install_app +else + Uninstall_app +fi From 547027be0dbcf9c1b6fb2f3daf61990247a16b0a Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 6 Mar 2023 23:40:56 +0800 Subject: [PATCH 19/48] Update install.sh --- plugins/mariadb/versions/11.0/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mariadb/versions/11.0/install.sh b/plugins/mariadb/versions/11.0/install.sh index 801e91ad91..7335bb11ba 100755 --- a/plugins/mariadb/versions/11.0/install.sh +++ b/plugins/mariadb/versions/11.0/install.sh @@ -92,7 +92,7 @@ Install_app() make -j${cpuCore} && make install && make clean if [ -d $serverPath/mariadb ];then - echo '10.9' > $serverPath/mariadb/version.pl + echo '10.11' > $serverPath/mariadb/version.pl echo '安装完成' > $install_tmp else echo '安装失败' > $install_tmp From b541abad4257cb49fe8fc3f87d5c9a9eef7030ab Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 7 Mar 2023 13:44:28 +0800 Subject: [PATCH 20/48] Update index.py --- plugins/supervisor/index.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/supervisor/index.py b/plugins/supervisor/index.py index 00d20a90fb..046cf3caa2 100755 --- a/plugins/supervisor/index.py +++ b/plugins/supervisor/index.py @@ -462,8 +462,9 @@ def configTpl(): pathFile = os.listdir(path) tmp = [] for one in pathFile: - file = path + '/' + one - tmp.append(file) + if one.endswith(".ini"): + file = path + '/' + one + tmp.append(file) return mw.getJson(tmp) From 3cb63c6265771f1a3cd5bded72dc7676aa0ef400 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 7 Mar 2023 16:28:48 +0800 Subject: [PATCH 21/48] Update index.html --- plugins/supervisor/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/supervisor/index.html b/plugins/supervisor/index.html index 798116a54d..f58df6ecc6 100755 --- a/plugins/supervisor/index.html +++ b/plugins/supervisor/index.html @@ -23,7 +23,7 @@ .code span {display: block;margin-left: 15px;margin-bottom: 0;}