diff --git a/plugins/qbittorrent/ico.png b/plugins/qbittorrent/ico.png new file mode 100644 index 000000000..0c04d3b9e Binary files /dev/null and b/plugins/qbittorrent/ico.png differ diff --git a/plugins/qbittorrent/index.py b/plugins/qbittorrent/index.py new file mode 100755 index 000000000..969e8e9ff --- /dev/null +++ b/plugins/qbittorrent/index.py @@ -0,0 +1,299 @@ +# coding: utf-8 + +import time +import random +import os +import json +import re +import sys + +sys.path.append(os.getcwd() + "/class/core") +import public + + +app_debug = False +if public.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'simdht' + + +def getPluginDir(): + return public.getPluginDir() + '/' + getPluginName() + +sys.path.append(getPluginDir() + "/class") +import mysql + + +def getServerDir(): + return public.getServerDir() + '/' + getPluginName() + + +def getInitDFile(): + if app_debug: + return '/tmp/' + getPluginName() + return '/etc/init.d/' + getPluginName() + + +def getArgs(): + args = sys.argv[2:] + tmp = {} + args_len = len(args) + + if args_len == 1: + t = args[0].strip('{').strip('}') + t = t.split(':') + 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, public.returnJson(False, '参数:(' + ck[i] + ')没有!')) + return (True, public.returnJson(True, 'ok')) + + +def getInitDTpl(): + path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" + return path + + +def getSqlFile(): + file = getPluginDir() + "/conf/simdht.sql" + return file + + +def getDbConf(): + file = getServerDir() + "/db.cfg" + return file + + +def getRunLog(): + file = getServerDir() + "/logs.pl" + return file + + +def initDreplace(): + + ddir = getServerDir() + '/workers' + if not os.path.exists(ddir): + sdir = getPluginDir() + '/workers' + public.execShell('cp -rf ' + sdir + ' ' + getServerDir()) + + cfg = getServerDir() + '/db.cfg' + if not os.path.exists(cfg): + cfg_tpl = getPluginDir() + '/workers/db.cfg' + content = public.readFile(cfg_tpl) + public.writeFile(cfg, content) + + 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() + + # initd replace + content = public.readFile(file_tpl) + content = content.replace('{$SERVER_PATH}', service_path) + public.writeFile(file_bin, content) + public.execShell('chmod +x ' + file_bin) + + return file_bin + + +def status(): + data = public.execShell( + "ps -ef|grep \"python simdht_worker.py\" | grep -v grep | awk '{print $2}'") + if data[0] == '': + return 'stop' + return 'start' + + +def start(): + file = initDreplace() + + data = public.execShell(file + ' start') + if data[1] == '': + return 'ok' + return data[1] + + +def stop(): + file = initDreplace() + data = public.execShell(file + ' stop') + if data[1] == '': + public.execShell('rm -rf /tmp/mysql.sock') + return 'ok' + return 'fail' + + +def restart(): + file = initDreplace() + data = public.execShell(file + ' restart') + if data[1] == '': + return 'ok' + return 'fail' + + +def reload(): + file = initDreplace() + data = public.execShell(file + ' reload') + if data[1] == '': + return 'ok' + return 'fail' + + +def initdStatus(): + if not app_debug: + if public.isAppleSystem(): + return "Apple Computer does not support" + + initd_bin = getInitDFile() + if os.path.exists(initd_bin): + return 'ok' + return 'fail' + + +def initdInstall(): + import shutil + if not app_debug: + if public.isAppleSystem(): + return "Apple Computer does not support" + + mysql_bin = initDreplace() + initd_bin = getInitDFile() + shutil.copyfile(mysql_bin, initd_bin) + public.execShell('chmod +x ' + initd_bin) + return 'ok' + + +def initdUinstall(): + if not app_debug: + if public.isAppleSystem(): + return "Apple Computer does not support" + initd_bin = getInitDFile() + os.remove(initd_bin) + return 'ok' + + +def matchData(reg, content): + tmp = re.search(reg, content).groups() + return tmp[0] + + +def getDbConfInfo(): + cfg = getDbConf() + content = public.readFile(cfg) + data = {} + data['DB_HOST'] = matchData("DB_HOST\s*=\s(.*)", content) + data['DB_USER'] = matchData("DB_USER\s*=\s(.*)", content) + data['DB_PORT'] = matchData("DB_PORT\s*=\s(.*)", content) + data['DB_PASS'] = matchData("DB_PASS\s*=\s(.*)", content) + data['DB_NAME'] = matchData("DB_NAME\s*=\s(.*)", content) + return data + + +def pMysqlDb(): + data = getDbConfInfo() + conn = mysql.mysql() + conn.setHost(data['DB_HOST']) + conn.setUser(data['DB_USER']) + conn.setPwd(data['DB_PASS']) + conn.setPort(int(data['DB_PORT'])) + conn.setDb(data['DB_NAME']) + return conn + + +def isSqlError(mysqlMsg): + # 检测数据库执行错误 + mysqlMsg = str(mysqlMsg) + if "MySQLdb" in mysqlMsg: + return public.returnJson(False, 'MySQLdb组件缺失!
进入SSH命令行输入: pip install mysql-python') + if "2002," in mysqlMsg: + return public.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!') + if "using password:" in mysqlMsg: + return public.returnJson(False, '数据库管理密码错误!') + if "Connection refused" in mysqlMsg: + return public.returnJson(False, '数据库连接失败,请检查数据库服务是否启动!') + if "1133" in mysqlMsg: + return public.returnJson(False, '数据库用户不存在!') + if "1007" in mysqlMsg: + return public.returnJson(False, '数据库已经存在!') + return None + + +def getMinData(conn, sec): + time_diff = 0 + if public.isAppleSystem(): + time_diff = 3 * 60 + pre = time.strftime("%Y-%m-%d %H:%M:%S", + time.localtime(time.time() - sec - time_diff)) + sql = "select count(id) from search_hash where create_time > '" + pre + "'" + data = conn.query(sql) + return data[0][0] + + +def getTrendData(): + try: + args = getArgs() + data = checkArgs(args, ['interval']) + if not data[0]: + return data[1] + pdb = pMysqlDb() + # interval = int(args['interval']) + result = pdb.execute("show tables") + isError = isSqlError(result) + if isError: + return isError + one = getMinData(pdb, 1) + two = getMinData(pdb, 5) + three = getMinData(pdb, 10) + return public.getJson([one, two, three]) + except Exception as e: + print str(e) + return public.getJson([0, 0, 0]) + +def dhtCmd(): + file = initDreplace() + return file+' restart' + +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_sql': + print getSqlFile() + elif func == 'get_db_conf': + print getDbConf() + elif func == 'get_run_Log': + print getRunLog() + elif func == 'get_trend_data': + print getTrendData() + elif func == 'dht_cmd': + print dhtCmd(); + else: + print 'error' diff --git a/plugins/qbittorrent/info.json b/plugins/qbittorrent/info.json new file mode 100755 index 000000000..4aa33e725 --- /dev/null +++ b/plugins/qbittorrent/info.json @@ -0,0 +1,17 @@ +{ + "sort": 7, + "ps": "一个新的轻量级BitTorrent客户端", + "name": "qbittorrent", + "title": "qBittorrent", + "shell": "install.sh", + "versions":["4.1.5"], + "updates":["4.1.5"], + "tip": "soft", + "checks": "server/qbittorrent", + "display": 1, + "author": "Zend", + "date": "2017-04-01", + "home": "https://www.qbittorrent.org", + "type": 0, + "pid": "5" +} \ No newline at end of file diff --git a/plugins/qbittorrent/install.sh b/plugins/qbittorrent/install.sh new file mode 100755 index 000000000..60eebe776 --- /dev/null +++ b/plugins/qbittorrent/install.sh @@ -0,0 +1,67 @@ +#!/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") +sysName=`uname` + +install_tmp=${rootPath}/tmp/bt_install.pl + + +Install_qbittorrent() +{ + if [ $sysName == 'Darwin' ]; then + else + yum -y install qt-devel boost-devel openssl-devel qt5-qtbase-devel qt5-linguist + fi + + echo '正在安装脚本文件...' > $install_tmp + mkdir -p $serverPath/qbittorrent + + QB_DIR=${serverPath}/source/qbittorrent + mkdir -p $QB_DIR + + if [ ! -f ${QB_DIR}/libtorrent-rasterbar-1.1.9.tar.gz ];then + wget -O ${QB_DIR}/libtorrent-rasterbar-1.1.9.tar.gz https://github.com/arvidn/libtorrent/releases/download/libtorrent-1_1_9/libtorrent-rasterbar-1.1.9.tar.gz + fi + cd ${QB_DIR} tar -zxf libtorrent-rasterbar-1.1.9.tar.gz + cd ${QB_DIR} && cd libtorrent-rasterbar-1.1.9 + + #修改为固定端口号 + #sed -i "s/i2p ? 1 : tracker_req().listen_port/8999/" src/http_tracker_connection.cpp + ./configure --prefix=$serverPath/lib/libtorrent CXXFLAGS=-std=c++11 + make && make install + #echo "$serverPath/lib/libtorrent/lib" > /etc/ld.so.conf.d/libtorrent-x86_64.conf + #ldconfig + #export LD_LIBRARY_PATH=/usr/local/libtorrent/lib/ + #export CPLUS_INCLUDE_PATH=/usr/local/libtorrent/include/ + #export PKG_CONFIG_PATH=/usr/local/libtorrent/lib/pkgconfig/ + + + if [ ! -f ${QB_DIR}/qbittorrent-4.1.5.tar.gz ];then + wget -O ${QB_DIR}/qbittorrent-4.1.5.tar.gz https://github.com/qbittorrent/qBittorrent/archive/release-4.1.5.tar.gz + fi + + cd ${QB_DIR} && tar -zxvf qbittorrent-4.1.5.tar.gz + + #cp -rf ${SPHINX_DIR}/sphinx-3.1.1/ $serverPath/sphinx/bin + + echo '4.1.5' > $serverPath/qbittorrent/version.pl + echo '安装完成' > $install_tmp +} + +Uninstall_qbittorrent() +{ + rm -rf $serverPath/qbittorrent + echo "Uninstall_qbittorrent" > $install_tmp +} + +action=$1 +if [ "${1}" == 'install' ];then + Install_qbittorrent +else + Uninstall_qbittorrent +fi diff --git a/plugins/sphinx/install.sh b/plugins/sphinx/install.sh index 096f04643..c8971749b 100755 --- a/plugins/sphinx/install.sh +++ b/plugins/sphinx/install.sh @@ -6,7 +6,7 @@ curPath=`pwd` rootPath=$(dirname "$curPath") rootPath=$(dirname "$rootPath") serverPath=$(dirname "$rootPath") - +sysName=`uname` install_tmp=${rootPath}/tmp/bt_install.pl