diff --git a/class/core/db.py b/class/core/db.py index 104ff5ab5..3ae39f8d4 100755 --- a/class/core/db.py +++ b/class/core/db.py @@ -61,8 +61,8 @@ class Sql(): self.__DB_FILE = 'data/' + name + '.db' return self - def dbPos(self, path, name): - self.__DB_FILE = path + '/' + name + '.db' + def dbPos(self, path, name, suffix_name = 'db'): + self.__DB_FILE = path + '/' + name + '.' + suffix_name return self def table(self, table): diff --git a/class/plugin/orm.py b/class/plugin/orm.py index a1852451d..89ba623e9 100755 --- a/class/plugin/orm.py +++ b/class/plugin/orm.py @@ -23,7 +23,7 @@ class ORM: __DB_CHARSET = "utf8" def __Conn(self): - # print(self.__DB_HOST, self.__DB_USER) + # print(self.__DB_HOST, self.__DB_USER, self.__DB_PASS, self.__DB_SOCKET) '''连接数据库''' try: diff --git a/plugins/dynamic-tracking/versions/ubuntu.sh b/plugins/dynamic-tracking/versions/ubuntu.sh index e2ba2d38e..b9dcff40b 100644 --- a/plugins/dynamic-tracking/versions/ubuntu.sh +++ b/plugins/dynamic-tracking/versions/ubuntu.sh @@ -9,3 +9,14 @@ serverPath=$(dirname "$rootPath") install_tmp=${rootPath}/tmp/mw_install.pl SYS_ARCH=`arch` + +# export GOPROXY=https://goproxy.io +# export GO111MODULE=on + + +apt -y install build-essential git make libelf-dev strace tar bpfcc-tools libbpf-dev + +# clang -v +apt -y install clang llvm + +apt -y install golang diff --git a/plugins/mariadb/conf/mariadb.sql b/plugins/mariadb/conf/mariadb.sql index dc0089bfb..e091e3b21 100755 --- a/plugins/mariadb/conf/mariadb.sql +++ b/plugins/mariadb/conf/mariadb.sql @@ -50,6 +50,7 @@ CREATE TABLE IF NOT EXISTS `slave_sync_user` ( `pass` TEXT, `mode` TEXT, `cmd` TEXT, + `db` TEXT, `addtime` TEXT ); diff --git a/plugins/mariadb/index.py b/plugins/mariadb/index.py index 2e0c7cbb9..b30be6fdf 100755 --- a/plugins/mariadb/index.py +++ b/plugins/mariadb/index.py @@ -867,6 +867,81 @@ def importDbExternal(): return mw.returnJson(True, 'ok') +def importDbExternalProgress(): + args = getArgs() + data = checkArgs(args, ['file', 'name']) + if not data[0]: + return data[1] + + file = args['file'] + name = args['name'] + + cmd = 'cd '+mw.getServerDir()+'/mdserver-web && source bin/activate && ' + cmd += 'python3 '+mw.getServerDir()+'/mdserver-web/plugins/mariadb/index.py import_db_external_progress_bar {"file":"'+file+'","name":"'+name+'"}' + return mw.returnJson(True, 'ok',cmd) + +def importDbExternalProgressBar(): + args = getArgs() + data = checkArgs(args, ['file', 'name']) + if not data[0]: + return data[1] + + file = args['file'] + name = args['name'] + + import_dir = mw.getRootDir() + '/backup/import/' + + file_path = import_dir + file + if not os.path.exists(file_path): + return mw.returnJson(False, '文件突然消失?') + + exts = ['sql', 'gz', 'zip'] + ext = mw.getFileSuffix(file) + if ext not in exts: + return mw.returnJson(False, '导入数据库格式不对!') + + tmp = file.split('/') + tmpFile = tmp[len(tmp) - 1] + tmpFile = tmpFile.replace('.sql.' + ext, '.sql') + tmpFile = tmpFile.replace('.' + ext, '.sql') + tmpFile = tmpFile.replace('tar.', '') + + # print(tmpFile) + import_sql = "" + if file.find("sql.gz") > -1: + cmd = 'cd ' + import_dir + ' && gzip -dc ' + \ + file + " > " + import_dir + tmpFile + info = mw.execShell(cmd) + if info[1] == "": + import_sql = import_dir + tmpFile + + if file.find(".zip") > -1: + cmd = 'cd ' + import_dir + ' && unzip -o ' + file + mw.execShell(cmd) + import_sql = import_dir + tmpFile + + if file.find("tar.gz") > -1: + cmd = 'cd ' + import_dir + ' && tar -zxvf ' + file + mw.execShell(cmd) + import_sql = import_dir + tmpFile + + if file.find(".sql") > -1 and file.find(".sql.gz") == -1: + import_sql = import_dir + file + + if import_sql == "": + return mw.returnJson(False, '未找SQL文件') + + pwd = pSqliteDb('config').where('id=?', (1,)).getField('mysql_root') + sock = getSocketFile() + + my_cnf = getConf() + mysql_cmd = getServerDir() + '/bin/mariadb --defaults-file=' + my_cnf + \ + ' -uroot -p"' + pwd + '" -f ' + name + mysql_cmd_progress_bar = "pv -t -p " + import_sql + '|'+ mysql_cmd + print(mysql_cmd_progress_bar) + rdata = os.system(mysql_cmd_progress_bar) + return "" + def deleteDbBackup(): args = getArgs() @@ -1958,6 +2033,64 @@ def addMasterRepSlaveUser(version=''): return mw.returnJson(True, '添加成功!') +def getMasterRepSlaveUserCmdSsh(version): + + args = getArgs() + data = checkArgs(args, ['username', 'db']) + if not data[0]: + return data[1] + + psdb = pSqliteDb('master_replication_user') + f = 'username,password' + username = args['username'] + if username == '': + count = psdb.count() + if count == 0: + return mw.returnJson(False, '请添加同步账户!') + + clist = psdb.field(f).limit('1').order('id desc').select() + else: + clist = psdb.field(f).where("username=?", (username,)).limit( + '1').order('id desc').select() + + if len(clist) == 0: + return mw.returnJson(False, '错误同步账户!') + + ip = mw.getLocalIp() + port = getMyPort() + db = pMysqlDb() + + mstatus = db.query('show master status') + if len(mstatus) == 0: + return mw.returnJson(False, '未开启!') + + mode = recognizeDbMode() + + # 查找同步点 + # SELECT BINLOG_GTID_POS('master1-bin.000002', 561866201); + + sid = getDbServerId() + connection_name = "" + if sid != '': + connection_name = "'r{}' ".format(sid) + + # MASTER_USE_GTID={current_pos|slave_pos|no} + # current_pos 依赖-> select @@global.gtid_current_pos; + # slave_pos 依赖-> select @@global.gtid_slave_pos; + # no -> 啥都不依赖,保证多主同步成功。同步出现问题,根据日志查找问题。 + + base_sql = "CHANGE MASTER " + connection_name + "TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ + clist[0]['username'] + "', MASTER_PASSWORD='" + \ + clist[0]['password']; + sql = '' + sql += base_sql + "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ + "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + data = {} + data['cmd'] = sql + data["info"] = clist[0] + data['mode'] = mode + return mw.returnJson(True, 'ok!', data) + def getMasterRepSlaveUserCmd(version): args = getArgs() @@ -2004,16 +2137,15 @@ def getMasterRepSlaveUserCmd(version): # slave_pos 依赖-> select @@global.gtid_slave_pos; # no -> 啥都不依赖,保证多主同步成功。同步出现问题,根据日志查找问题。 - if mode == "gtid": - sql = "CHANGE MASTER " + connection_name + "TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ - clist[0]['username'] + "', MASTER_PASSWORD='" + \ - clist[0]['password'] + "',MASTER_USE_GTID=no,MASTER_CONNECT_RETRY=10;" - else: - sql = "CHANGE MASTER " + connection_name + "TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ + base_sql = "CHANGE MASTER " + connection_name + "TO MASTER_HOST='" + ip + "', MASTER_PORT=" + port + ", MASTER_USER='" + \ clist[0]['username'] + "', MASTER_PASSWORD='" + \ - clist[0]['password'] + \ - "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ + clist[0]['password']; + sql = '' + sql += base_sql + "', MASTER_LOG_FILE='" + mstatus[0]["File"] + \ "',MASTER_LOG_POS=" + str(mstatus[0]["Position"]) + sql += "

"; + sql += base_sql + "',MASTER_USE_GTID=slave_pos,MASTER_CONNECT_RETRY=10;"; + sql += "
"; data = {} data['cmd'] = sql @@ -2469,7 +2601,7 @@ def initSlaveStatusSSH(version=''): username='root', pkey=key) db_user = data['db_user'] - cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 plugins/mariadb/index.py get_master_rep_slave_user_cmd {"username":"' + db_user + '","db":""}' + cmd = 'cd /www/server/mdserver-web && source bin/activate && python3 plugins/mariadb/index.py get_master_rep_slave_user_cmd_ssh {"username":"' + db_user + '","db":""}' stdin, stdout, stderr = ssh.exec_command(cmd) result = stdout.read() result = result.decode('utf-8') @@ -2920,6 +3052,19 @@ def fullSync(version=''): return json.dumps({'code': 0, 'msg': '点击开始,开始同步!', 'progress': 0}) +def fullSyncCmd(): + time_all_s = time.time() + args = getArgs() + data = checkArgs(args, ['db', 'sign']) + if not data[0]: + return data[1] + + db = args['db'] + sign = args['sign'] + + cmd = 'cd '+mw.getServerDir()+'/mdserver-web && source bin/activate && python3 plugins/mariadb/index.py do_full_sync {"db":"'+db+'","sign":"'+sign+'"}' + return mw.returnJson(True,'ok',cmd) + # python3 plugins/mariadb/index.py do_full_sync {"db":"demo1","sign":"","beigin":"1"} def doFullSync(version=''): mode_file = getSyncModeFile() @@ -3258,6 +3403,10 @@ if __name__ == "__main__": print(importDbBackup()) elif func == 'import_db_external': print(importDbExternal()) + elif func == 'import_db_external_progress': + print(importDbExternalProgress()) + elif func == 'import_db_external_progress_bar': + print(importDbExternalProgressBar()) elif func == 'delete_db_backup': print(deleteDbBackup()) elif func == 'get_db_backup_list': @@ -3322,6 +3471,8 @@ if __name__ == "__main__": print(delMasterRepSlaveUser(version)) elif func == 'update_master_rep_slave_user': print(updateMasterRepSlaveUser(version)) + elif func == 'get_master_rep_slave_user_cmd_ssh': + print(getMasterRepSlaveUserCmdSsh(version)) elif func == 'get_master_rep_slave_user_cmd': print(getMasterRepSlaveUserCmd(version)) elif func == 'get_slave_list': @@ -3362,6 +3513,8 @@ if __name__ == "__main__": print(fullSync(version)) elif func == 'do_full_sync': print(doFullSync(version)) + elif func == 'full_sync_cmd': + print(fullSyncCmd()) elif func == 'dump_mysql_data': print(dumpMysqlData(version)) elif func == 'sync_database_repair': diff --git a/plugins/mariadb/js/mariadb.js b/plugins/mariadb/js/mariadb.js index 7ab192009..01bdc1fe5 100755 --- a/plugins/mariadb/js/mariadb.js +++ b/plugins/mariadb/js/mariadb.js @@ -938,6 +938,31 @@ function importDbExternal(file,name){ }); } +function importDbExternalProgress(file,name){ + myPost('import_db_external_progress',{file:file,name:name}, function(data){ + var rdata = $.parseJSON(data.data); + layer.open({ + title: "手动导入命令CMD【显示进度】", + area: ['600px', '180px'], + type:1, + closeBtn: 1, + shadeClose: false, + btn:["复制","取消"], + content: '
\ +
\ +
'+rdata.data+'
\ +
\ +
', + success:function(){ + copyText(rdata.data); + }, + yes:function(){ + copyText(rdata.data); + } + }); + }); +} + function setLocalImport(db_name){ //上传文件 @@ -993,6 +1018,7 @@ function setLocalImport(db_name){ ' + file_list[i]['time'] + '\ \ 导入 | \ + 导入进度 | \ 删除\ \ '; @@ -1016,7 +1042,7 @@ function setLocalImport(db_name){ var layerIndex = layer.open({ type: 1, title: "从文件导入数据", - area: ['600px', '380px'], + area: ['700px', '380px'], closeBtn: 1, shadeClose: false, content: '
\ @@ -1710,17 +1736,12 @@ function getMasterRepSlaveUserCmd(username, db=''){ area: '500px', content:"
\
"+cmd+"
\ -
\ - \ +
\ + \
\ ", }); - - copyPass(cmd); - $('.class-copy-cmd').click(function(){ - copyPass(cmd); - }); }); } @@ -1936,6 +1957,7 @@ function getFullSyncStatus(db){
\
\ 开始\ + 手动命令\
\
", cancel: function(){ @@ -1958,6 +1980,31 @@ function getFullSyncStatus(db){ layer.msg("正在同步中..",{icon:0}); } }); + + $('#full_sync_cmd').click(function(){ + myPostN('full_sync_cmd', {'db':db,'sign':''}, function(rdata){ + var rdata = $.parseJSON(rdata.data); + layer.open({ + title: "手动执行命令CMD", + area: ['600px', '180px'], + type:1, + closeBtn: 1, + shadeClose: false, + btn:["复制","取消"], + content: '
\ +
\ +
'+rdata.data+'
\ +
\ +
', + success:function(){ + copyText(rdata.data); + }, + yes:function(){ + copyText(rdata.data); + } + }); + }); + }); } }); }); @@ -2211,7 +2258,7 @@ function addSlaveSyncUser(ip=''){ var index = layer.open({ type: 1, - area: ['500px','470px'], + area: ['500px','510px'], title: '同步账户', closeBtn: 1, shift: 5, @@ -2222,6 +2269,15 @@ function addSlaveSyncUser(ip=''){
端口
\
同步账户
\
同步密码
\ +
\ + 同步模式\ +
\ + \ +
\ +
\
\ CMD[必填]\
\ diff --git a/plugins/mysql/index.py b/plugins/mysql/index.py index 6ee09f530..d77cb9cd2 100755 --- a/plugins/mysql/index.py +++ b/plugins/mysql/index.py @@ -183,7 +183,7 @@ def pMysqlDb(): db = mw.getMyORM() # MySQLdb | # db = mw.getMyORMDb() - + # print(getDbPort()) db.setPort(getDbPort()) db.setSocket(getSocketFile()) # db.setCharset("utf8") @@ -665,6 +665,8 @@ def my8cmd(version, method): def appCMD(version, action): makeInitRsaKey(version) mdb8 = getMdb8Ver() + mdb8.append('5.7') + # print(mdb8) if mw.inArray(mdb8, version): status = my8cmd(version, action) else: @@ -777,8 +779,7 @@ def setMyDbPos(version): mw.writeFile(myfile, mycnf) start(version) - result = mw.execShell( - 'ps aux|grep mysqld| grep -v grep|grep -v python') + result = mw.execShell('ps aux|grep mysqld| grep -v grep|grep -v python') if len(result[0]) > 10: mw.writeFile('data/datadir.pl', t_datadir) return mw.returnJson(True, '存储目录迁移成功!') diff --git a/plugins/simpleping/ico.png b/plugins/simpleping/ico.png new file mode 100644 index 000000000..348efe3f4 Binary files /dev/null and b/plugins/simpleping/ico.png differ diff --git a/plugins/simpleping/index.html b/plugins/simpleping/index.html new file mode 100755 index 000000000..83d25d8f9 --- /dev/null +++ b/plugins/simpleping/index.html @@ -0,0 +1,25 @@ +
+
+
+
+

服务

+

自启动

+

配置修改

+

连通性

+

MySQL

+

相关说明

+ +
+
+
+
+
+
+ + \ No newline at end of file diff --git a/plugins/simpleping/index.py b/plugins/simpleping/index.py new file mode 100755 index 000000000..89a8b16fb --- /dev/null +++ b/plugins/simpleping/index.py @@ -0,0 +1,302 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import re + +sys.path.append(os.getcwd() + "/class/core") +import mw + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + + +def getHomeDir(): + if mw.isAppleSystem(): + user = mw.execShell( + "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() + return '/Users/' + user + else: + return '/root' + + +def getRunUser(): + if mw.isAppleSystem(): + user = mw.execShell( + "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() + return user + else: + return 'root' + +__SR = '''#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH +export USER=%s +export HOME=%s && ''' % ( getRunUser(), getHomeDir()) + +def getPluginName(): + return 'simpleping' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getInitDFile(): + current_os = mw.getOs() + if current_os == 'darwin': + return '/tmp/' + getPluginName() + + if current_os.startswith('freebsd'): + return '/etc/rc.d/' + getPluginName() + return '/etc/init.d/' + getPluginName() + + +def getConf(): + path = getServerDir() + "/conf/app.conf" + return path + + +def getInitDTpl(): + path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" + return path + + +def getArgs(): + args = sys.argv[3:] + 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 configTpl(): + path = getPluginDir() + '/tpl' + pathFile = os.listdir(path) + tmp = [] + for one in pathFile: + file = path + '/' + one + tmp.append(file) + return mw.getJson(tmp) + + +def readConfigTpl(): + args = getArgs() + data = checkArgs(args, ['file']) + if not data[0]: + return data[1] + + content = mw.readFile(args['file']) + content = contentReplace(content) + return mw.returnJson(True, 'ok', content) + +def getPidFile(): + file = getConf() + content = mw.readFile(file) + rep = 'pidfile\s*(.*)' + tmp = re.search(rep, content) + return tmp.groups()[0].strip() + +def status(): + data = mw.execShell( + "ps aux|grep simpleping |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'") + + if data[0] == '': + return 'stop' + return 'start' + +def contentReplace(content): + service_path = mw.getServerDir() + content = content.replace('{$ROOT_PATH}', mw.getRootDir()) + content = content.replace('{$SERVER_PATH}', service_path) + content = content.replace('{$SERVER_APP}', service_path + '/simpleping') + return content + + + +def initDreplace(): + + file_tpl = getInitDTpl() + service_path = os.path.dirname(os.getcwd()) + + initD_path = getServerDir() + '/init.d' + if not os.path.exists(initD_path): + os.mkdir(initD_path) + file_bin = initD_path + '/' + getPluginName() + + # print(file_bin) + # initd replace + if not os.path.exists(file_bin): + content = mw.readFile(file_tpl) + content = content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(file_bin, content) + mw.execShell('chmod +x ' + file_bin) + + # systemd + # systemctl start simpleping.service + systemDir = mw.systemdCfgDir() + systemService = systemDir + '/' + getPluginName() + '.service' + if os.path.exists(systemDir) and not os.path.exists(systemService): + systemServiceTpl = getPluginDir() + '/init.d/' + getPluginName() + '.service.tpl' + service_path = mw.getServerDir() + content = mw.readFile(systemServiceTpl) + content = content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(systemService, content) + mw.execShell('systemctl daemon-reload') + + return file_bin + + +def appOp(method): + file = initDreplace() + + current_os = mw.getOs() + if current_os == "darwin": + data = mw.execShell(__SR + file + ' ' + method) + # print(data) + return 'ok' + + if current_os.startswith("freebsd"): + data = mw.execShell('service ' + getPluginName() + ' ' + method) + if data[1] == '': + return 'ok' + return data[1] + + data = mw.execShell('systemctl ' + method + ' ' + getPluginName()) + if data[1] == '': + return 'ok' + return data[1] + + +def start(): + return appOp('start') + + +def stop(): + return appOp('stop') + + +def restart(): + status = appOp('restart') + return status + + +def reload(): + return redisOp('reload') + + +def initdStatus(): + current_os = mw.getOs() + if current_os == 'darwin': + return "Apple Computer does not support" + + if current_os.startswith('freebsd'): + initd_bin = getInitDFile() + if os.path.exists(initd_bin): + return 'ok' + + shell_cmd = 'systemctl status ' + \ + getPluginName() + ' | grep loaded | grep "enabled;"' + data = mw.execShell(shell_cmd) + if data[0] == '': + return 'fail' + return 'ok' + + +def initdInstall(): + current_os = mw.getOs() + if current_os == 'darwin': + return "Apple Computer does not support" + + # freebsd initd install + if current_os.startswith('freebsd'): + import shutil + source_bin = initDreplace() + initd_bin = getInitDFile() + shutil.copyfile(source_bin, initd_bin) + mw.execShell('chmod +x ' + initd_bin) + mw.execShell('sysrc ' + getPluginName() + '_enable="YES"') + return 'ok' + + mw.execShell('systemctl enable ' + getPluginName()) + return 'ok' + + +def initdUinstall(): + current_os = mw.getOs() + if current_os == 'darwin': + return "Apple Computer does not support" + + if current_os.startswith('freebsd'): + initd_bin = getInitDFile() + os.remove(initd_bin) + mw.execShell('sysrc ' + getPluginName() + '_enable="NO"') + return 'ok' + + mw.execShell('systemctl disable ' + getPluginName()) + return 'ok' + + +def runLog(): + return getServerDir() + '/data/log.pl' + + +def ipList(): + config = getServerDir() + '/conf/app.conf' + content = mw.readFile(config) + rep = 'ip\s*=\s*(.*)' + tmp = re.search(rep, content) + if not tmp: + return '' + ip = tmp.groups()[0] + ips = ip.split(",") + return mw.returnJson(True, 'OK', ips) + +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 == 'conf': + print(getConf()) + elif func == 'ip_list': + print(ipList()) + else: + print('error') diff --git a/plugins/simpleping/info.json b/plugins/simpleping/info.json new file mode 100755 index 000000000..ae3d31e55 --- /dev/null +++ b/plugins/simpleping/info.json @@ -0,0 +1,17 @@ +{ + "sort": 999, + "ps": "简单Ping服务,检查连通性", + "name": "simpleping", + "title": "SimplePing", + "shell": "install.sh", + "versions":["1.0"], + "tip": "soft", + "checks": "server/simpleping", + "path": "server/simpleping", + "display": 1, + "author": "midoks", + "date": "2024-07-10", + "home": "https://github.com/midoks/simpleping", + "type": 0, + "pid": "5" +} diff --git a/plugins/simpleping/init.d/simpleping.service.tpl b/plugins/simpleping/init.d/simpleping.service.tpl new file mode 100644 index 000000000..f7d3d3411 --- /dev/null +++ b/plugins/simpleping/init.d/simpleping.service.tpl @@ -0,0 +1,21 @@ +[Unit] +Description=SimplePing Server +After=network.service +After=syslog.target + +[Service] +User=root +Group=root +Type=simple +WorkingDirectory={$SERVER_PATH}/simpleping +ExecStart={$SERVER_PATH}/simpleping/simpleping service +ExecReload=/bin/kill -USR2 $MAINPID +PermissionsStartOnly=true +LimitNOFILE=5000 +Restart=on-failure +RestartSec=10 +RestartPreventExitStatus=1 +PrivateTmp=false + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/plugins/simpleping/init.d/simpleping.tpl b/plugins/simpleping/init.d/simpleping.tpl new file mode 100644 index 000000000..682ae56bc --- /dev/null +++ b/plugins/simpleping/init.d/simpleping.tpl @@ -0,0 +1,46 @@ +#!/bin/sh +# chkconfig: 2345 55 25 +# description: SimplePing Service + +### BEGIN INIT INFO +# Provides: SimplePing +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts SimplePing +# Description: starts the MDW-Web +### END INIT INFO + +# Simple SimplePing init.d script conceived to work on Linux systems +# as it does use of the /proc filesystem. + +app_start(){ + echo "Starting SimplePing server..." + cd {$SERVER_PATH}/simpleping + ./simpleping service >> {$SERVER_PATH}/simpleping/logs.pl 2>&1 & +} + +app_stop(){ + echo "SimplePing stopped" + ps -ef| grep simpleping | grep -v grep | grep -v python | grep -v sh | awk '{print $2}'| xargs kill +} + + +case "$1" in + start) + app_start + ;; + stop) + app_stop + ;; + restart|reload) + app_stop + sleep 0.3 + app_start + ;; + *) + echo "Please use start or stop as first argument" + ;; +esac + diff --git a/plugins/simpleping/install.sh b/plugins/simpleping/install.sh new file mode 100755 index 000000000..647106bbd --- /dev/null +++ b/plugins/simpleping/install.sh @@ -0,0 +1,87 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/homebrew/bin +export PATH + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") + +ARCH=`uname -m` +sysName=`uname` +VERSION=$2 + +# 开启可以PING +# sysctl -w net.ipv4.ping_group_range="0 2147483647" + +install_tmp=${rootPath}/tmp/mw_install.pl + +Install_App() +{ + echo '正在安装脚本文件...' > $install_tmp + mkdir -p $serverPath/source + mkdir -p $serverPath/source/simpleping + + name=linux + if [ "$sysName" == "Darwin" ];then + name="darwin" + else + sysctl -w net.ipv4.ping_group_range="0 2147483647" + fi + + if [ "$ARCH" == "x86_64" ];then + ARCH="amd64" + fi + + FILE_TGZ=simpleping_${name}_${ARCH}.tar.gz + APP_DIR=$serverPath/source/simpleping + + # https://github.com/midoks/simpleping/releases/download/1.0/simpleping_linux_amd64.tar.gz + if [ ! -f $APP_DIR/${FILE_TGZ} ];then + wget -O $APP_DIR/${FILE_TGZ} https://github.com/midoks/simpleping/releases/download/2.0/${FILE_TGZ} + fi + + mkdir -p $serverPath/simpleping + cd $APP_DIR && tar -zxvf ${FILE_TGZ} -C $serverPath/simpleping + echo "${VERSION}" > $serverPath/simpleping/version.pl + + cd ${rootPath} && python3 ${rootPath}/plugins/simpleping/index.py start + cd ${rootPath} && python3 ${rootPath}/plugins/simpleping/index.py initd_install + + echo '安装SimplePing成功!' + +} + +Uninstall_App() +{ + if [ -f /usr/lib/systemd/system/simpleping.service ];then + systemctl stop simpleping + systemctl disable simpleping + rm -rf /usr/lib/systemd/system/simpleping.service + systemctl daemon-reload + fi + + if [ -f /lib/systemd/system/simpleping.service ];then + systemctl stop simpleping + systemctl disable simpleping + rm -rf /lib/systemd/system/simpleping.service + systemctl daemon-reload + fi + + if [ -f $serverPath/simpleping/initd/simpleping ];then + $serverPath/simpleping/initd/simpleping stop + fi + + if [ -d $serverPath/simpleping ];then + rm -rf $serverPath/simpleping + fi + + echo "卸载SimplePing成功" +} + +action=$1 +if [ "${1}" == 'install' ];then + Install_App +else + Uninstall_App +fi diff --git a/plugins/simpleping/js/simpleping.js b/plugins/simpleping/js/simpleping.js new file mode 100755 index 000000000..9c89ec66a --- /dev/null +++ b/plugins/simpleping/js/simpleping.js @@ -0,0 +1,531 @@ + +function pingPost(method, args, callback){ + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + + var req_data = {}; + req_data['name'] = 'simpleping'; + 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 (!data.status){ + //错误展示10S + layer.msg(data.msg,{icon:0,time:2000,shade: [10, '#000']}); + return; + } + + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + +function pingPostCallbak(method, args, callback){ + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + + var req_data = {}; + req_data['name'] = 'simpleping'; + req_data['script'] = 'simpleping_index'; + 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 pingPostCallbakN(method, args, callback){ + var req_data = {}; + req_data['name'] = 'simpleping'; + req_data['script'] = 'simpleping_index'; + 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) { + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + + +function appReadme(){ + + var readme = ''; + $('.soft-man-con').html(readme); +} + +var chartPing; +var chartPingData = []; +var posTimer; + +// 把Unix时间戳转化成普通日期 +function toCommonTime(unix_time){ + var unixTimestamp = new Date(unix_time*1000); + var commonTime = unixTimestamp.toLocaleString(); + return commonTime; +} + +function getToday(){ + var mydate = new Date(); + var str = "" + mydate.getFullYear() + "/"; + str += (mydate.getMonth()+1) + "/"; + str += mydate.getDate(); + return str; +} + +//定义周期时间 +function getBeforeDate(n){ + var n = n; + var d = new Date(); + var year = d.getFullYear(); + var mon=d.getMonth()+1; + var day=d.getDate(); + if(day <= n){ + if(mon>1) { + mon = mon-1; + } else { + year = year-1; + mon = 12; + } + } + d.setDate(d.getDate()-n); + year = d.getFullYear(); + mon=d.getMonth()+1; + day=d.getDate(); + s = year+"/"+(mon<10?('0'+mon):mon)+"/"+(day<10?('0'+day):day); + return s; +} + + +function pingDataGraphPosData(){ + + var isOk = document.getElementById('pingview'); + if (!isOk){ + clearInterval(posTimer); + } + + if (chartPingData.length>0){ + var dlen = chartPingData.length; + last_pos = chartPingData[dlen-1]; + // console.log(start,end); + var cur_ip = $('select[name="ip_list"]').val(); + pingPostCallbakN('pingData', {'type':'pos', 'pos':last_pos['created_unix'],"ip":cur_ip}, function(data){ + var tmp_data = data.data; + for (x in tmp_data){ + chartPingData.push(tmp_data[x]); + } + pingDataGraphRender(); + }); + + } +} + + +function pingDataGraphData(day){ + + var now = (new Date().getTime())/1000; + if(day==0){ + var start = (new Date(getToday() + " 00:00:01").getTime())/1000; + start = Math.round(start); + var end = Math.round(now); + } + if(day==1){ + var start = (new Date(getBeforeDate(day) + " 00:00:01").getTime())/1000; + var end = (new Date(getBeforeDate(day) + " 23:59:59").getTime())/1000; + start = Math.round(start); + end = Math.round(end); + } else { + var start = (new Date(getBeforeDate(day) + " 00:00:01").getTime())/1000; + start = Math.round(start); + var end = Math.round(now); + } + + var cur_ip = $('select[name="ip_list"]').val(); + // console.log(start,end); + pingPostCallbak('pingData', {'type':'range', 'start':start, 'end':end, 'ip':cur_ip}, function(data){ + chartPingData = data.data; + pingDataGraphRender(); + + if (day!=1){ + clearInterval(posTimer); + posTimer = setInterval(function() { + pingDataGraphPosData(); + }, 3000); + } + }); +} + +function pingDataGraphRender(){ + var xData = []; + var yData = []; + var rdata = chartPingData; + for(var i = 0; i < rdata.length; i++){ + xData.push(toCommonTime(rdata[i].created_unix)); + yData.push(rdata[i].speed/1000000); + } + var option = { + tooltip: { + trigger: 'axis', + axisPointer: { type: 'cross' }, + formatter: '{b}
{a}: {c}' + }, + xAxis: { + type: 'category', + boundaryGap: false, + data: xData, + axisLine:{ lineStyle:{ color:"#666"} } + }, + yAxis: { + type: 'value', + name: "PING延迟(ms)", + // boundaryGap: [0, '100%'], + // min:0, + // max: 100, + splitLine:{ lineStyle:{ color:"#ddd" } }, + axisLine:{ lineStyle:{ color:"#666" } } + }, + series: [ + { + name:'PING', + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { normal: { color: 'rgb(0, 153, 238)' } }, + data: yData + } + ] + }; + chartPing.setOption(option); +} + +function pingIpList(){ + pingPost('ip_list', {}, function(data){ + var rdata = $.parseJSON(data.data); + var ips = rdata.data; + + var option = ''; + option += ''; + + for (var i = 0; i < ips.length; i++) { + option += ''; + } + $('select[name="ip_list"]').html(option); + + + $('select[name="ip_list"]').change(function(){ + chartPingData = []; + pingDataGraphData(0); + }); + + pingDataGraphData(0); + }); + +} + +// console.log('pingDataGraph'); +function pingDataGraph(){ + var tpl = '\ +
\ +
\ +
\ +
\ +

连通性

\ +
\ + \ + 昨天\ + 今天\ + 最近7天\ +
\ +
\ +
\ +
\ +
\ +
'; + $('.soft-man-con').html(tpl); + + $('.searcTime span').click(function(e){ + $('.searcTime span').removeClass('on'); + $(this).addClass('on'); + }); + + chartPing = echarts.init(document.getElementById('pingview')); + + var option = { + tooltip: { + trigger: 'axis', + axisPointer: { type: 'cross' }, + formatter: '{b}
{a}: {c}' + }, + xAxis: { + type: 'category', + boundaryGap: false, + data: [], + axisLine:{ lineStyle:{ color:"#666"} } + }, + yAxis: { + type: 'value', + name: "PING延迟(ms)", + splitLine:{ lineStyle:{ color:"#ddd" } }, + axisLine:{ lineStyle:{ color:"#666" } } + }, + dataZoom: [{ + type: 'inside', + start: 0, + end: 100, + zoomLock:true + }, { + start: 0, + end: 100, + handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', + handleSize: '80%', + handleStyle: { + color: '#fff', + shadowBlur: 3, + shadowColor: 'rgba(0, 0, 0, 0.6)', + shadowOffsetX: 2, + shadowOffsetY: 2 + } + }], + series: [ + { + name:'PING', + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { normal: { color: 'rgb(0, 153, 238)' } }, + data: [] + } + ] + }; + chartPing.setOption(option); + window.addEventListener("resize",function(){ + chartPing.resize(); + }); + + pingIpList(); +} + + + + + +// -------------------------------------------------------------------------------------------------------------- +// MYSQL PING +// -------------------------------------------------------------------------------------------------------------- + +var chartMySQLPingData = []; +var chartMySQLPing; +var posMySQLTimer; + +function pingMySQLDataGraphPosData(){ + + var isOk = document.getElementById('mysqlview'); + if (!isOk){ + clearInterval(posMySQLTimer); + } + + if (chartMySQLPingData.length>0){ + var dlen = chartMySQLPingData.length; + last_pos = chartMySQLPingData[dlen-1]; + // console.log(start,end); + pingPostCallbakN('pingMySQLData', {'type':'pos', 'pos':last_pos['created_unix']}, function(data){ + var tmp_data = data.data; + for (x in tmp_data){ + chartMySQLPingData.push(tmp_data[x]); + } + pingDataMySQLGraphRender(); + }); + + } +} + +function pingDataMySQLGraphRender(){ + var xData = []; + var yData = []; + var rdata = chartMySQLPingData; + for(var i = 0; i < rdata.length; i++){ + xData.push(toCommonTime(rdata[i].created_unix)); + yData.push(rdata[i].value); + } + var option = { + tooltip: { + trigger: 'axis', + axisPointer: { type: 'cross' }, + formatter: '{b}
{a}: {c}' + }, + xAxis: { + type: 'category', + boundaryGap: false, + data: xData, + axisLine:{ lineStyle:{ color:"#666"} } + }, + yAxis: { + type: 'value', + name: "MySQL同步延迟", + splitLine:{ lineStyle:{ color:"#ddd" } }, + axisLine:{ lineStyle:{ color:"#666" } } + }, + series: [ + { + name:'同步延迟', + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { normal: { color: 'rgb(0, 153, 238)' } }, + data: yData + } + ] + }; + chartMySQLPing.setOption(option); +} + +function pingMySQLDataGraphData(day){ + + var now = (new Date().getTime())/1000; + if(day==0){ + var start = (new Date(getToday() + " 00:00:01").getTime())/1000; + start = Math.round(start); + var end = Math.round(now); + } + if(day==1){ + var start = (new Date(getBeforeDate(day) + " 00:00:01").getTime())/1000; + var end = (new Date(getBeforeDate(day) + " 23:59:59").getTime())/1000; + start = Math.round(start); + end = Math.round(end); + } else { + var start = (new Date(getBeforeDate(day) + " 00:00:01").getTime())/1000; + start = Math.round(start); + var end = Math.round(now); + } + + var cur_ip = $('select[name="ip_list"]').val(); + // console.log(start,end); + pingPostCallbak('pingMySQLData', {'type':'range', 'start':start, 'end':end, 'ip':cur_ip}, function(data){ + chartMySQLPingData = data.data; + pingDataMySQLGraphRender(); + if (day!=1){ + clearInterval(posMySQLTimer); + posMySQLTimer = setInterval(function() { + pingMySQLDataGraphPosData(); + }, 3000); + } + }); +} + + +function pingMySQLDataGraph(){ + var tpl = '\ +
\ +
\ +
\ +
\ +

MySQL检查

\ +
\ + 昨天\ + 今天\ + 最近7天\ +
\ +
\ +
\ +
\ +
\ +
'; + $('.soft-man-con').html(tpl); + + $('.searcTime span').click(function(e){ + $('.searcTime span').removeClass('on'); + $(this).addClass('on'); + }); + + chartMySQLPing = echarts.init(document.getElementById('mysqlview')); + + var option = { + tooltip: { + trigger: 'axis', + axisPointer: { type: 'cross' }, + formatter: '{b}
{a}: {c}' + }, + xAxis: { + type: 'category', + boundaryGap: false, + data: [], + axisLine:{ lineStyle:{ color:"#666"} } + }, + yAxis: { + type: 'value', + name: "MySQL延迟", + splitLine:{ lineStyle:{ color:"#ddd" } }, + axisLine:{ lineStyle:{ color:"#666" } } + }, + dataZoom: [{ + type: 'inside', + start: 0, + end: 100, + zoomLock:true + }, { + start: 0, + end: 100, + handleIcon: 'M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z', + handleSize: '80%', + handleStyle: { + color: '#fff', + shadowBlur: 3, + shadowColor: 'rgba(0, 0, 0, 0.6)', + shadowOffsetX: 2, + shadowOffsetY: 2 + } + }], + series: [ + { + name:'延迟', + type:'line', + smooth:true, + symbol: 'none', + sampling: 'average', + itemStyle: { normal: { color: 'rgb(0, 153, 238)' } }, + data: [] + } + ] + }; + chartMySQLPing.setOption(option); + window.addEventListener("resize",function(){ + chartMySQLPing.resize(); + }); + + pingMySQLDataGraphData(0); +} + + diff --git a/plugins/simpleping/simpleping_index.py b/plugins/simpleping/simpleping_index.py new file mode 100755 index 000000000..a0f4f7cef --- /dev/null +++ b/plugins/simpleping/simpleping_index.py @@ -0,0 +1,66 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import re +import json +import shutil + +sys.path.append(os.getcwd() + "/class/core") +import mw + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + +def getPluginName(): + return 'simpleping' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + +def pingData(args = ()): + conn = mw.M('sp_ping').dbPos(getServerDir()+'/data', 'simpleping', 'db3') + field = 'id,speed,created_unix' + conn = conn.field(field) + data = [] + atype = args['type'] + + if not 'ip' in args: + ip = 'all' + else: + ip = args['ip'] + if ip != 'all': + conn = conn.where('ip=?',(ip,)) + + if atype == 'pos': + pos = args['pos'] + data = conn.where('created_unix>?',(pos,)).limit("3000").select() + elif atype == 'range': + start = args['start'] + end = args['end'] + data = conn.where('created_unix>=? and created_unix<=?',(start,end)).limit("1000").select() + return data + + +def pingMySQLData(args = ()): + conn = mw.M('sp_mysql_ping').dbPos(getServerDir()+'/data', 'simpleping', 'db3') + field = 'id,value,created_unix' + conn = conn.field(field) + data = [] + atype = args['type'] + if atype == 'pos': + pos = args['pos'] + data = conn.where('created_unix>?',(pos,)).limit("3000").select() + elif atype == 'range': + start = args['start'] + end = args['end'] + data = conn.where('created_unix>=? and created_unix<=?',(start,end)).limit("1000").select() + return data + diff --git a/plugins/tgbot/startup/extend/push_ad.py b/plugins/tgbot/startup/extend/push_ad.py index 269f2df53..833a45f53 100644 --- a/plugins/tgbot/startup/extend/push_ad.py +++ b/plugins/tgbot/startup/extend/push_ad.py @@ -42,11 +42,15 @@ def send_msg(bot, tag='ad', trigger_time=300): # 信号只在一个周期内执行一次|end # https://t.me/gjgzs2022 | 22/m | @GJ_gzs - # https://zhaoziyuan1.cc | web | 15/m | 2m | next,7/15 | @baleite + # https://zhaoziyuan1.cc | web | 15/m | 2m | next,9/15 | @baleite # 综合包网/NG接口开户 | 28/m | 6m | next,10/28 | @aabbcx888 - # 实名认证/过人脸🕵️‍♀️各种账号处理✅ | 30/m| next,6/30 | @nngzs - # 海外服务器 高防CDN 解决移动屏蔽 | 群内置顶AD| 16/m | @YYCDNFW + # 实名认证/过人脸🕵️‍♀️各种账号处理✅ | 30/m| next,12/30 | @nngzs + # 桃花资源采集| 13/m| next,1/13 | @xiaolizi1122 keyboard = [ + [ + types.InlineKeyboardButton( + text="桃花资源采集🚀 ", url='https://thzy.me') + ], [ types.InlineKeyboardButton( text="👑 综合包网/NG接口开户", url='https://t.me/NG_Tony') diff --git a/plugins/tgbot/startup/extend/push_notice_msg.py b/plugins/tgbot/startup/extend/push_notice_msg.py index 317dc3783..b88c14b5a 100644 --- a/plugins/tgbot/startup/extend/push_notice_msg.py +++ b/plugins/tgbot/startup/extend/push_notice_msg.py @@ -51,10 +51,15 @@ def send_msg(bot, tag='ad', trigger_time=300): # 信号只在一个周期内执行一次|end # https://t.me/gjgzs2022 | 22/m | @GJ_gzs - # https://zhaoziyuan1.cc | web | 15/m | 2m | next,7/15 | @baleite + # https://zhaoziyuan1.cc | web | 15/m | 2m | next,9/15 | @baleite # 综合包网/NG接口开户 | 28/m | 6m | next,10/28 | @aabbcx888 - # 实名认证/过人脸🕵️‍♀️各种账号处理✅ | 30/m| next,6/30 | @nngzs + # 实名认证/过人脸🕵️‍♀️各种账号处理✅ | 30/m| next,12/30 | @nngzs + # 桃花资源采集| 13/m| next,1/13 | @xiaolizi1122 keyboard = [ + [ + types.InlineKeyboardButton( + text="桃花资源采集🚀 ", url='https://thzy.me') + ], [ types.InlineKeyboardButton( text="🚀 综合包网/NG接口开户", url='https://t.me/NG_Tony') diff --git a/scripts/init.d/mw.tpl b/scripts/init.d/mw.tpl index aed7ba960..6dc67551c 100755 --- a/scripts/init.d/mw.tpl +++ b/scripts/init.d/mw.tpl @@ -245,6 +245,22 @@ mw_update() } mw_update_dev() +{ + LOCAL_ADDR=common + cn=$(curl -fsSL -m 10 -s http://ipinfo.io/json | grep "\"country\": \"CN\"") + if [ ! -z "$cn" ] || [ "$?" == "0" ] ;then + LOCAL_ADDR=cn + fi + + if [ "$LOCAL_ADDR" == "common" ];then + curl --insecure -fsSL https://raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh | bash + else + curl --insecure -fsSL https://code.midoks.icu/midoks/mdserver-web/raw/branch/dev/scripts/update_dev.sh | bash + fi + cd /www/server/mdserver-web +} + +mw_update_venv() { rm -rf /www/server/mdserver-web/bin rm -rf /www/server/mdserver-web/lib64 @@ -469,7 +485,7 @@ case "$1" in 'mirror') mw_mirror;; 'db') mw_connect_mysql;; 'redis') mw_redis;; - 'venv') mw_venv;; + 'venv') mw_update_venv;; 'clean_lib') mw_clean_lib;; 'default') cd $mw_path