From 533ba65a4d09012c8ef4f0a4feae3b1595c99bd5 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Thu, 10 Jan 2019 13:13:18 +0800 Subject: [PATCH] update --- plugins/redis/index.py | 2 +- plugins/simdht/conf/simdht.sql | 52 +++++ plugins/simdht/index.py | 243 +++++++----------------- plugins/simdht/init.d/simdht.tpl | 73 +++++++ plugins/simdht/workers/db.cfg | 6 + plugins/simdht/workers/simdht_worker.py | 16 +- 6 files changed, 208 insertions(+), 184 deletions(-) create mode 100644 plugins/simdht/conf/simdht.sql create mode 100644 plugins/simdht/init.d/simdht.tpl create mode 100755 plugins/simdht/workers/db.cfg diff --git a/plugins/redis/index.py b/plugins/redis/index.py index 2656938c9..e9923904f 100755 --- a/plugins/redis/index.py +++ b/plugins/redis/index.py @@ -37,7 +37,7 @@ def getConf(): def getInitDTpl(): - path = getPluginDir() + "/init.d/redis.tpl" + path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" return path diff --git a/plugins/simdht/conf/simdht.sql b/plugins/simdht/conf/simdht.sql new file mode 100644 index 000000000..739330ae1 --- /dev/null +++ b/plugins/simdht/conf/simdht.sql @@ -0,0 +1,52 @@ +CREATE TABLE `search_hash` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `info_hash` varchar(40) NOT NULL, + `category` varchar(20) NOT NULL, + `data_hash` varchar(32) NOT NULL, + `name` varchar(255) NOT NULL, + `extension` varchar(20) NOT NULL, + `classified` tinyint(1) NOT NULL, + `source_ip` varchar(20) DEFAULT NULL, + `tagged` tinyint(1) NOT NULL, + `length` bigint(20) NOT NULL, + `create_time` datetime NOT NULL, + `last_seen` datetime NOT NULL, + `requests` int(10) unsigned NOT NULL, + `comment` varchar(255) DEFAULT NULL, + `creator` varchar(20) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `info_hash` (`info_hash`), + KEY `search_hash_tagged_50480647a28d03e1_uniq` (`tagged`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE `search_filelist` ( + `info_hash` varchar(40) NOT NULL, + `file_list` longtext NOT NULL, + PRIMARY KEY (`info_hash`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE `search_extra` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `hash_id` int(11) NOT NULL, + `update_time` datetime NOT NULL, + `status` varchar(20) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `hash_id` (`hash_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE `search_statusreport` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `date` date NOT NULL, + `new_hashes` int(11) NOT NULL, + `total_requests` int(11) NOT NULL, + `valid_requests` int(11) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `search_statusreport_date_625dc87b8a52c947_uniq` (`date`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE `search_reckeywords` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `keyword` varchar(20) NOT NULL, + `order` int(10) unsigned NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/plugins/simdht/index.py b/plugins/simdht/index.py index ebb3e6c2f..570c3a289 100755 --- a/plugins/simdht/index.py +++ b/plugins/simdht/index.py @@ -46,195 +46,82 @@ def getArgs(): return tmp +def getInitDTpl(): + path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" + return path + + +def initDreplace(): + + ddir = getServerDir() + '/workers' + if not os.path.exists(ddir): + sdir = getPluginDir() + '/workers' + print public.execShell('cp -rf ' + sdir + ' ' + getServerDir()) + + 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(): - return 'start' - - -def getAllProjectList(search): - path = public.getWwwDir() - dlist = [] - if os.path.exists(path): - for filename in os.listdir(path): - tmp = {} - filePath = path + '/' + filename - if os.path.isdir(filePath): - if search == '': - tmp['name'] = filename - tmp['dir'] = filePath - dlist.append(tmp) - else: - if filename.find(search) != -1: - tmp['name'] = filename - tmp['dir'] = filePath - dlist.append(tmp) - return dlist - - -def checkProjectListIsSet(data): - dlen = len(data) - for x in range(dlen): - path = getServerDir() + '/' + data[x]['name'] + '.json' - if os.path.exists(path): - if os.path.getsize(path) == 0: - data[x]['isset'] = False - else: - data[x]['isset'] = True - else: - data[x]['isset'] = False - - return data - - -def projectListEdit(): - args = getArgs() - if not 'name' in args: - return 'missing name!' - - file = getServerDir() + '/' + args['name'] + '.json' - if not os.path.exists(file): - public.execShell('touch ' + file) - return file - - -def projectListDel(): - args = getArgs() - if not 'name' in args: - return 'missing name!' - - file = getServerDir() + '/' + args['name'] + '.json' - if os.path.exists(file): - content = public.readFile(file) - contentObj = json.loads(content) - asyncUser = contentObj['client_email'] - cmd = getServerDir() + '/google-cloud-sdk/bin/' - public.execShell(cmd + 'gcloud auth revoke ' + asyncUser) - public.execShell('rm -rf ' + file) - return 'ok' - - -def checkUserExist(cmd, user): - data = public.execShell(cmd + 'gcloud auth list | grep ' + user) - if data[0] == '': - return False - return True - - -def projectListAsync(): - import subprocess - args = getArgs() - if not 'name' in args: - return 'missing name!' - - file = getServerDir() + '/' + args['name'] + '.json' - if not os.path.exists(file): - return 'not configured file!' - - content = public.readFile(file) - contentObj = json.loads(content) - asyncUser = contentObj['client_email'] - cmd = getServerDir() + '/google-cloud-sdk/bin/' - projectDir = public.getWwwDir() + '/' + args['name'] - - if not checkUserExist(cmd, asyncUser): - public.execShell( - cmd + 'gcloud auth activate-service-account --key-file ' + file) - - pName = contentObj['project_id'] - setUserCmd = cmd + 'gcloud config set account ' + asyncUser - setUserCmd += ' && ' + cmd + 'gcloud config set project ' + pName - asyncCmd = setUserCmd + ' && cd ' + projectDir + \ - ' && ' + cmd + 'gcloud app deploy << y' - - taskAdd = (None, 'gae[async]', - 'execshell', '0', time.strftime('%Y-%m-%d %H:%M:%S'), asyncCmd) - public.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd) - return 'ok' - - -def projectListCmd(): - args = getArgs() - if not 'name' in args: - return 'missing name!' - - file = getServerDir() + '/' + args['name'] + '.json' - if not os.path.exists(file): - return 'not configured file!' - - content = public.readFile(file) - contentObj = json.loads(content) - asyncUser = contentObj['client_email'] - cmd = getServerDir() + '/google-cloud-sdk/bin/' - pName = contentObj['project_id'] - projectDir = public.getWwwDir() + '/' + args['name'] - - setUserCmd = 'sudo ' + cmd + 'gcloud config set account ' + asyncUser - setUserCmd += ' && sudo ' + cmd + 'gcloud config set project ' + pName - asyncCmd = setUserCmd + ' && sudo cd ' + projectDir + \ - ' && sudo ' + cmd + 'gcloud app deploy <> {$SERVER_PATH}/redis/logs.pl 2>&1 & + fi +} +redis_stop(){ + if [ ! -f $PIDFILE ] + then + echo "$PIDFILE does not exist, process is not running" + else + PID=$(cat $PIDFILE) + echo "Stopping ..." + $CLIEXEC shutdown + while [ -x /proc/${PID} ] + do + echo "Waiting for Redis to shutdown ..." + sleep 1 + done + echo "Redis stopped" + fi +} + + +case "$1" in + start) + redis_start + ;; + stop) + redis_stop + ;; + restart|reload) + redis_stop + sleep 0.3 + redis_start + ;; + *) + echo "Please use start or stop as first argument" + ;; +esac + diff --git a/plugins/simdht/workers/db.cfg b/plugins/simdht/workers/db.cfg new file mode 100755 index 000000000..790d8432c --- /dev/null +++ b/plugins/simdht/workers/db.cfg @@ -0,0 +1,6 @@ +[db] +DB_HOST = 127.0.0.1 +DB_USER = ssbc +DB_PORT = 33061 +DB_PASS = ssbc +DB_NAME = ssbc \ No newline at end of file diff --git a/plugins/simdht/workers/simdht_worker.py b/plugins/simdht/workers/simdht_worker.py index 17019769d..c888ea3da 100755 --- a/plugins/simdht/workers/simdht_worker.py +++ b/plugins/simdht/workers/simdht_worker.py @@ -25,6 +25,7 @@ from threading import Timer, Thread from time import sleep from collections import deque from Queue import Queue +from configparser import ConfigParser import pygeoip import MySQLdb as mdb @@ -41,11 +42,16 @@ import simMetadata from bencode import bencode, bdecode from metadata import save_metadata -DB_HOST = '127.0.0.1' -DB_USER = 'root' -DB_PORT = 3306 -DB_PASS = 'root' -DB_NAME = 'ssbc' + +from configparser import ConfigParser +cp = ConfigParser() +cp.read("db.cfg") +section = cp.sections()[0] +DB_HOST = cp.get(section, "DB_HOST") +DB_USER = cp.get(section, "DB_USER") +DB_PORT = cp.getint(section, "DB_PORT") +DB_PASS = cp.get(section, "DB_PASS") +DB_NAME = cp.get(section, "DB_NAME") BLACK_FILE = 'black_list.txt' BOOTSTRAP_NODES = (