Merge pull request #807 from midoks/dev

OP防火墙修复
pull/809/head
Mr Chen 3 weeks ago committed by GitHub
commit 23d817d1f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 10
      plugins/op_waf/conf/init.sql
  2. 37
      plugins/op_waf/install.sh
  3. 98
      plugins/op_waf/tool_task.py
  4. 2
      web/static/app/files.js

@ -15,3 +15,13 @@ CREATE TABLE IF NOT EXISTS `logs` (
`rule_name` TEXT,
`reason` TEXT
);
CREATE INDEX time_idx ON logs(`time`);
CREATE INDEX ip_idx ON logs (`ip`);
CREATE INDEX uri_idx ON logs (`uri`);
CREATE INDEX method_idx ON logs (`method`);
CREATE INDEX server_name_idx ON logs (`server_name`);
CREATE INDEX status_code_idx ON logs (`status_code`);
CREATE INDEX all_union_idx ON logs (`status_code`, `time`, `ip`, `domain`, `server_name`, `method`, `uri`);

@ -3,6 +3,9 @@ PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin:/opt/hom
export PATH
# cd /www/server/mdserver-web/plugins/op_waf && bash install.sh install 0.4.1
# cd /www/server/mdserver-web && python3 plugins/op_waf/index.py start
# cd /www/server/mdserver-web && python3 plugins/op_waf/index.py stop
# cd /www/server/mdserver-web && python3 plugins/op_waf/tool_task.py run
curPath=`pwd`
rootPath=$(dirname "$curPath")
@ -52,8 +55,12 @@ Install_App(){
fi
# if [ ! -f $serverPath/source/op_waf/lsqlite3_v096.zip ];then
# wget --no-check-certificate -O $serverPath/source/op_waf/lsqlite3_v096.zip http://lua.sqlite.org/home/zip/lsqlite3_v096.zip?uuid=v0.9.6
# fi
if [ ! -f $serverPath/source/op_waf/lsqlite3_v096.zip ];then
wget --no-check-certificate -O $serverPath/source/op_waf/lsqlite3_v096.zip http://lua.sqlite.org/home/zip/lsqlite3_v096.zip?uuid=v0.9.6
wget --no-check-certificate -O $serverPath/source/op_waf/lsqlite3_v096.zip https://github.com/midoks/mdserver-web/releases/download/0.18.4/lsqlite3_v096.zip
fi
if [ ! -d $serverPath/source/op_waf/lsqlite3_v096 ];then
@ -68,7 +75,7 @@ Install_App(){
cd $serverPath/source/op_waf/lsqlite3_v096
find_cfg=`cat Makefile | grep 'SQLITE_DIR'`
if [ "$find_cfg" == "" ];then
LIB_SQLITE_DIR=`brew info sqlite | grep /usr/local/Cellar/sqlite | cut -d \ -f 1 | awk 'END {print}'`
LIB_SQLITE_DIR=`brew info sqlite | grep /opt/homebrew/Cellar/sqlite | cut -d \ -f 1 | awk 'END {print}'`
echo $LIB_SQLITE_DIR
sed -i $BAK "s#\$(ROCKSPEC)#\$(ROCKSPEC) SQLITE_DIR=${LIB_SQLITE_DIR}#g" Makefile
fi
@ -88,20 +95,29 @@ Install_App(){
cn=$(curl -fsSL -m 10 http://ipinfo.io/json | grep "\"country\": \"CN\"")
HTTP_PREFIX="https://"
if [ ! -z "$cn" ];then
HTTP_PREFIX="https://mirror.ghproxy.com/"
HTTP_PREFIX="https://gh-proxy.com/"
fi
# download GeoLite Data
GeoLite2_TAG=`curl -sL "https://api.github.com/repos/P3TERX/GeoLite.mmdb/releases/latest" | grep '"tag_name":' | cut -d'"' -f4`
#if [ ! -f $serverPath/op_waf/GeoLite2-City.mmdb ];then
wget --no-check-certificate -O $serverPath/op_waf/GeoLite2-City.mmdb ${HTTP_PREFIX}github.com/P3TERX/GeoLite.mmdb/releases/download/${GeoLite2_TAG}/GeoLite2-City.mmdb
#fi
if [ ! -f $serverPath/source/op_waf/GeoLite2-City.mmdb ];then
wget --no-check-certificate -O $serverPath/source/op_waf/GeoLite2-City.mmdb ${HTTP_PREFIX}github.com/P3TERX/GeoLite.mmdb/releases/download/${GeoLite2_TAG}/GeoLite2-City.mmdb
fi
#if [ ! -f $serverPath/op_waf/GeoLite2-Country.mmdb ];then
wget --no-check-certificate -O $serverPath/op_waf/GeoLite2-Country.mmdb ${HTTP_PREFIX}github.com/P3TERX/GeoLite.mmdb/releases/download/${GeoLite2_TAG}/GeoLite2-Country.mmdb
#fi
if [ ! -f $serverPath/op_waf/GeoLite2-City.mmdb ];then
cp -rf $serverPath/source/op_waf/GeoLite2-City.mmdb $serverPath/op_waf/GeoLite2-City.mmdb
fi
if [ ! -f $serverPath/source/op_waf/GeoLite2-Country.mmdb ];then
wget --no-check-certificate -O $serverPath/source/op_waf/GeoLite2-Country.mmdb ${HTTP_PREFIX}github.com/P3TERX/GeoLite.mmdb/releases/download/${GeoLite2_TAG}/GeoLite2-Country.mmdb
fi
libmaxminddb_ver='1.7.1'
if [ ! -f $serverPath/op_waf/GeoLite2-Country.mmdb ];then
cp -rf $serverPath/source/op_waf/GeoLite2-Country.mmdb $serverPath/op_waf/GeoLite2-Country.mmdb
fi
libmaxminddb_ver='1.12.2'
if [ ! -f $serverPath/op_waf/waf/mmdb/lib/libmaxminddb.a ] && [ ! -f $serverPath/op_waf/waf/mmdb/lib/libmaxminddb.so ];then
libmaxminddb_local_path=$serverPath/source/op_waf/libmaxminddb-${libmaxminddb_ver}.tar.gz
libmaxminddb_url_path=${HTTP_PREFIX}github.com/maxmind/libmaxminddb/releases/download/${libmaxminddb_ver}/libmaxminddb-${libmaxminddb_ver}.tar.gz
@ -124,7 +140,6 @@ Install_App(){
}
Uninstall_App(){
cd ${rootPath} && python3 ${rootPath}/plugins/op_waf/index.py stop
if [ "$?" == "0" ];then
rm -rf $serverPath/op_waf

@ -41,31 +41,24 @@ def getConfigData():
conf = getTaskConf()
if os.path.exists(conf):
return json.loads(mw.readFile(getTaskConf()))
return []
def getConfigTpl():
tpl = {
"name": "",
return {
"task_id": -1,
"period": "day-n",
"where1": "7",
"hour": "0",
"minute": "15",
}
return tpl
def createBgTask():
removeBgTask()
args = {
"period": "minute-n",
"minute-n": "1",
}
createBgTaskByName(getPluginName())
if mw.isAppleSystem():
createBgTaskByName(getPluginName(), args)
def createBgTaskByName(name):
cfg = getConfigData()
def createBgTaskByName(name, args):
cfg = getConfigTpl()
_name = "[勿删]OP防火墙后台任务[" + name + "]"
_name = "[勿删]OP防火墙后台任务"
res = mw.M("crontab").field("id, name").where("name=?", (_name,)).find()
if res:
return True
@ -76,22 +69,6 @@ def createBgTaskByName(name, args):
if res and res["id"] == cfg["task_id"]:
print("计划任务已经存在!")
return True
import crontab_api
cron_api = crontab_api.crontab_api()
period = args['period']
_hour = ''
_minute = ''
_where1 = ''
_type_day = "day"
if period == 'day':
_type_day = 'day'
_hour = args['hour']
_minute = args['minute']
elif period == 'minute-n':
_type_day = 'minute-n'
_where1 = args['minute-n']
_minute = ''
mw_dir = mw.getPanelDir()
cmd = '''
@ -104,23 +81,20 @@ logs_file=$plugin_path/${rname}.log
cmd += 'echo "★【`date +"%Y-%m-%d %H:%M:%S"`】 STSRT★" >> $logs_file' + "\n"
cmd += 'echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" >> $logs_file' + "\n"
if mw.isAppleSystem():
cmd += 'echo "cd $mw_dir && source bin/activate && python3 $script_path/tool_task.py run >> $logs_file 2>&1"' + "\n"
cmd += 'cd $mw_dir && source bin/activate && python3 $script_path/tool_task.py run >> $logs_file 2>&1' + "\n"
else:
cmd += 'echo "cd $mw_dir && source bin/activate && bash $script_path/shell/cpu_usage_file.sh >> $logs_file 2>&1"' + "\n"
cmd += 'cd $mw_dir && source bin/activate && bash $script_path/shell/cpu_usage.sh >> $logs_file 2>&1' + "\n"
cmd += 'echo "cd $mw_dir && source bin/activate && python3 $script_path/tool_task.py run >> $logs_file 2>&1"' + "\n"
cmd += 'cd $mw_dir && source bin/activate && python3 $script_path/tool_task.py run >> $logs_file 2>&1' + "\n"
cmd += 'echo "【`date +"%Y-%m-%d %H:%M:%S"`】 END★" >> $logs_file' + "\n"
cmd += 'echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" >> $logs_file' + "\n"
params = {
'name': _name,
'type': _type_day,
'type': cfg['period'],
'week': "",
'where1': _where1,
'hour': _hour,
'minute': _minute,
'where1': cfg['where1'],
'hour': cfg['hour'],
'minute': cfg['minute'],
'save': "",
'backup_to': "",
'stype': "toShell",
@ -131,30 +105,21 @@ logs_file=$plugin_path/${rname}.log
task_id = MwCrontab.instance().add(params)
if task_id > 0:
cfg["task_id"] = task_id
cfg["name"] = name
_dd = getConfigData()
_dd.append(cfg)
mw.writeFile(getTaskConf(), json.dumps(_dd))
cfg["task_id"] = task_id
mw.writeFile(getTaskConf(), json.dumps(cfg))
def removeBgTask():
if not mw.isAppleSystem():
return False
cfg_list = getConfigData()
for x in range(len(cfg_list)):
cfg = cfg_list[x]
cfg = getConfigData()
for x in range(len(cfg)):
if "task_id" in cfg.keys() and cfg["task_id"] > 0:
res = mw.M("crontab").field("id, name").where(
"id=?", (cfg["task_id"],)).find()
if res and res["id"] == cfg["task_id"]:
data = MwCrontab.instance().delete(cfg["task_id"])
if data[0]:
if data['status']:
cfg["task_id"] = -1
cfg_list[x] = cfg
mw.writeFile(getTaskConf(), '[]')
mw.writeFile(getTaskConf(), json.dumps(cfg))
return True
return False
@ -171,8 +136,25 @@ def getCpuUsed():
mw.writeFile(path, str(int(data[0].strip())))
def pSqliteDb(dbname='logs'):
db_dir = getServerDir() + '/logs/'
conn = mw.M(dbname).dbPos(db_dir, "waf")
conn.execute("PRAGMA synchronous = 0")
conn.execute("PRAGMA cache_size = 8000")
conn.execute("PRAGMA page_size = 32768")
conn.execute("PRAGMA journal_mode = wal")
conn.execute("PRAGMA journal_size_limit = 1073741824")
return conn
def run():
getCpuUsed()
now_t = int(time.time())
logs_conn = pSqliteDb('logs')
del_hot_log = "delete from logs where time<{}".format(now_t)
print(del_hot_log)
r = logs_conn.execute(del_hot_log)
return 'ok'
if __name__ == "__main__":
if len(sys.argv) > 1:

@ -285,7 +285,7 @@ function openFilename(obj){
var ext = getSuffixName(path);
// console.log(path,ext);
if (inArray(ext,['html','htm','php','txt','md','js','css','scss','json','c','h','pl','py','java','log','conf','sh','json','ini', 'yml','yaml'])){
if (inArray(ext,['html','htm','php','lua','rs','py','txt','md','js','css','scss','json','c','h','pl','java','log','conf','sh','json','ini', 'yml','yaml'])){
onlineEditFile(0, path);
}

Loading…
Cancel
Save