pull/109/head
Mr Chen 6 years ago
parent bc510782d3
commit 533ba65a4d
  1. 2
      plugins/redis/index.py
  2. 52
      plugins/simdht/conf/simdht.sql
  3. 219
      plugins/simdht/index.py
  4. 73
      plugins/simdht/init.d/simdht.tpl
  5. 6
      plugins/simdht/workers/db.cfg
  6. 16
      plugins/simdht/workers/simdht_worker.py

@ -37,7 +37,7 @@ def getConf():
def getInitDTpl(): def getInitDTpl():
path = getPluginDir() + "/init.d/redis.tpl" path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
return path return path

@ -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;

@ -46,195 +46,82 @@ def getArgs():
return tmp return tmp
def status(): def getInitDTpl():
return 'start' path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl"
return path
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 initDreplace():
def projectListEdit(): ddir = getServerDir() + '/workers'
args = getArgs() if not os.path.exists(ddir):
if not 'name' in args: sdir = getPluginDir() + '/workers'
return 'missing name!' print public.execShell('cp -rf ' + sdir + ' ' + getServerDir())
file = getServerDir() + '/' + args['name'] + '.json' file_tpl = getInitDTpl()
if not os.path.exists(file): service_path = os.path.dirname(os.getcwd())
public.execShell('touch ' + file)
return file
initD_path = getServerDir() + '/init.d'
if not os.path.exists(initD_path):
os.mkdir(initD_path)
file_bin = initD_path + '/' + getPluginName()
def projectListDel(): # initd replace
args = getArgs() content = public.readFile(file_tpl)
if not 'name' in args: content = content.replace('{$SERVER_PATH}', service_path)
return 'missing name!' public.writeFile(file_bin, content)
public.execShell('chmod +x ' + file_bin)
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
return file_bin
def projectListAsync():
import subprocess
args = getArgs()
if not 'name' in args:
return 'missing name!'
file = getServerDir() + '/' + args['name'] + '.json' def status():
if not os.path.exists(file): return 'stop'
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]', def start():
'execshell', '0', time.strftime('%Y-%m-%d %H:%M:%S'), asyncCmd) file = initDreplace()
public.M('tasks').add('id,name,type,status,addtime, execstr', taskAdd) data = public.execShell(file + ' start')
if data[1] == '':
return 'ok' return 'ok'
return data[1]
def projectListCmd(): def stop():
args = getArgs() file = initDreplace()
if not 'name' in args: data = public.execShell(file + ' stop')
return 'missing name!' if data[1] == '':
return 'ok'
file = getServerDir() + '/' + args['name'] + '.json' return 'fail'
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 <<y'
return asyncCmd
def projectListUrl():
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']
plist = asyncUser.split('@')
url = 'https://' + plist[0] + '.appspot.com'
return url
def projectList():
args = getArgs()
page = 1
page_size = 10
search = ''
if 'page' in args:
page = int(args['page'])
if 'page_size' in args:
page_size = int(args['page_size'])
if 'search' in args: def restart():
search = args['search'] file = initDreplace()
data = public.execShell(file + ' restart')
if data[1] == '':
return 'ok'
return 'fail'
dlist = getAllProjectList(search)
dlist_sum = len(dlist)
start = (page - 1) * page_size def reload():
ret_data = dlist[start:start + page_size] file = initDreplace()
ret_data = checkProjectListIsSet(ret_data) data = public.execShell(file + ' reload')
if data[1] == '':
return 'ok'
return 'fail'
data = {}
data['data'] = ret_data
data['list'] = public.getPage(
{'count': dlist_sum, 'p': page, 'row': 10, 'tojs': 'projectList'})
return public.getJson(data)
if __name__ == "__main__": if __name__ == "__main__":
func = sys.argv[1] func = sys.argv[1]
if func == 'status': if func == 'status':
print status() print status()
elif func == 'project_list': elif func == 'start':
print projectList() print start()
elif func == 'project_list_edit': elif func == 'stop':
print projectListEdit() print stop()
elif func == 'project_list_del': elif func == 'restart':
print projectListDel() print restart()
elif func == 'project_list_async': elif func == 'reload':
print projectListAsync() print reload()
elif func == 'project_list_cmd':
print projectListCmd()
elif func == 'project_list_url':
print projectListUrl()
else: else:
print 'error' print 'error'

@ -0,0 +1,73 @@
#!/bin/sh
# chkconfig: 2345 55 25
# description: Redis Service
### BEGIN INIT INFO
# Provides: Redis
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts Redis
# Description: starts the MDW-Web
### END INIT INFO
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
CONF="{$SERVER_PATH}/redis/redis.conf"
REDISPORT=$(cat $CONF |grep port|grep -v '#'|awk '{print $2}')
REDISPASS=$(cat $CONF |grep requirepass|grep -v '#'|awk '{print $2}')
if [ "$REDISPASS" != "" ];then
REDISPASS=" -a $REDISPASS"
fi
EXEC={$SERVER_PATH}/redis/bin/redis-server
CLIEXEC="{$SERVER_PATH}/redis/bin/redis-cli -p $REDISPORT$REDISPASS"
PIDFILE={$SERVER_PATH}/redis/redis_6379.pid
mkdir -p {$SERVER_PATH}/redis/data
redis_start(){
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
nohup $EXEC $CONF >> {$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

@ -0,0 +1,6 @@
[db]
DB_HOST = 127.0.0.1
DB_USER = ssbc
DB_PORT = 33061
DB_PASS = ssbc
DB_NAME = ssbc

@ -25,6 +25,7 @@ from threading import Timer, Thread
from time import sleep from time import sleep
from collections import deque from collections import deque
from Queue import Queue from Queue import Queue
from configparser import ConfigParser
import pygeoip import pygeoip
import MySQLdb as mdb import MySQLdb as mdb
@ -41,11 +42,16 @@ import simMetadata
from bencode import bencode, bdecode from bencode import bencode, bdecode
from metadata import save_metadata from metadata import save_metadata
DB_HOST = '127.0.0.1'
DB_USER = 'root' from configparser import ConfigParser
DB_PORT = 3306 cp = ConfigParser()
DB_PASS = 'root' cp.read("db.cfg")
DB_NAME = 'ssbc' 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' BLACK_FILE = 'black_list.txt'
BOOTSTRAP_NODES = ( BOOTSTRAP_NODES = (

Loading…
Cancel
Save