From bb7f1b6a7dd409fc99aab78c31b92af95903407f Mon Sep 17 00:00:00 2001 From: midoks Date: Mon, 13 Feb 2023 14:16:06 +0800 Subject: [PATCH] up --- plugins/op_waf/index.py | 97 +++++++++++++------------ plugins/op_waf/waf/lua/init.lua | 11 --- plugins/op_waf/waf/lua/init_preload.lua | 11 +++ plugins/op_waf/waf/lua/init_worker.lua | 16 ++-- 4 files changed, 68 insertions(+), 67 deletions(-) create mode 100644 plugins/op_waf/waf/lua/init_preload.lua diff --git a/plugins/op_waf/index.py b/plugins/op_waf/index.py index 00dc1a669..de99dd7d4 100755 --- a/plugins/op_waf/index.py +++ b/plugins/op_waf/index.py @@ -325,9 +325,43 @@ def restartWeb(): mw.opWeb('start') -def initDreplace(): +def makeDstLua(): + root_init_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_by_lua_file' root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file' root_access_dir = mw.getServerDir() + '/web_conf/nginx/lua/access_by_lua_file' + path = getServerDir() + path_tpl = getPluginDir() + + waf_common_tpl = path_tpl + "/waf/lua/waf_common.lua" + waf_common_dst = path + "/waf/lua/waf_common.lua" + content = mw.readFile(waf_common_tpl) + content = contentReplace(content) + mw.writeFile(waf_common_dst, content) + + waf_init_tpl = path_tpl + "/waf/lua/init_preload.lua" + waf_init_dst = root_init_dir + "/waf_init_preload.lua" + content = mw.readFile(waf_init_tpl) + content = contentReplace(content) + mw.writeFile(waf_init_dst, content) + + init_worker_tpl = path_tpl + "/waf/lua/init_worker.lua" + init_worker_dst = root_worker_dir + '/opwaf_init_worker.lua' + content = mw.readFile(init_worker_tpl) + content = contentReplace(content) + mw.writeFile(init_worker_dst, content) + + access_file_tpl = path_tpl + "/waf/lua/init.lua" + access_file_dst = root_access_dir + '/opwaf_init.lua' + content = mw.readFile(access_file_tpl) + content = contentReplace(content) + mw.writeFile(access_file_dst, content) + + mw.opLuaInitFile() + mw.opLuaInitWorkerFile() + mw.opLuaInitAccessFile() + + +def initDreplace(): path = getServerDir() if not os.path.exists(path + '/waf/lua'): sdir = getPluginDir() + '/waf' @@ -350,24 +384,7 @@ def initDreplace(): content['reqfile_path'] = wfDir mw.writeFile(config, mw.getJson(content)) - waf_common = path + "/waf/lua/waf_common.lua" - content = mw.readFile(waf_common) - content = contentReplace(content) - mw.writeFile(waf_common, content) - - dst_init_worker = root_worker_dir + '/opwaf_init_worker.lua' - init_worker = path + "/waf/lua/init_worker.lua" - content = mw.readFile(init_worker) - content = contentReplace(content) - mw.writeFile(dst_init_worker, content) - mw.writeFile(init_worker, content) - - access_file = root_access_dir + '/opwaf_init.lua' - config = path + "/waf/lua/init.lua" - content = mw.readFile(config) - content = contentReplace(content) - mw.writeFile(access_file, content) - mw.writeFile(config, content) + makeDstLua() waf_conf = dstWafConf() if not os.path.exists(waf_conf): @@ -402,9 +419,6 @@ def status(): def start(): initDreplace() - mw.opLuaInitWorkerFile() - mw.opLuaInitAccessFile() - import tool_task tool_task.createBgTask() @@ -413,16 +427,21 @@ def start(): def stop(): + root_init_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_by_lua_file' root_worker_dir = mw.getServerDir() + '/web_conf/nginx/lua/init_worker_by_lua_file' root_access_dir = mw.getServerDir() + '/web_conf/nginx/lua/access_by_lua_file' - dst_init_worker = root_worker_dir + '/opwaf_init_worker.lua' - if os.path.exists(dst_init_worker): - os.remove(dst_init_worker) + waf_init_dst = root_init_dir + "/waf_init_preload.lua" + if os.path.exists(waf_init_dst): + os.remove(waf_init_dst) - access_file = root_access_dir + '/opwaf_init.lua' - if os.path.exists(access_file): - os.remove(access_file) + init_worker_dst = root_worker_dir + '/opwaf_init_worker.lua' + if os.path.exists(init_worker_dst): + os.remove(init_worker_dst) + + access_file_dst = root_access_dir + '/opwaf_init.lua' + if os.path.exists(access_file_dst): + os.remove(access_file_dst) wafconf = dstWafConf() if os.path.exists(wafconf): @@ -431,6 +450,7 @@ def stop(): import tool_task tool_task.removeBgTask() + mw.opLuaInitFile() mw.opLuaInitWorkerFile() mw.opLuaInitAccessFile() @@ -446,26 +466,7 @@ def restart(): def reload(): stop() - path = getServerDir() - path_tpl = getPluginDir() - - config = path + "/waf/lua/common.lua" - config_tpl = path_tpl + "/waf/lua/common.lua" - content = mw.readFile(config_tpl) - content = contentReplace(content) - mw.writeFile(config, content) - - config = path + "/waf/lua/init_worker.lua" - config_tpl = path_tpl + "/waf/lua/init_worker.lua" - content = mw.readFile(config_tpl) - content = contentReplace(content) - mw.writeFile(config, content) - - config = path + "/waf/lua/init.lua" - config_tpl = path_tpl + "/waf/lua/init.lua" - content = mw.readFile(config_tpl) - content = contentReplace(content) - mw.writeFile(config, content) + makeDstLua() errlog = mw.getServerDir() + "/openresty/nginx/logs/error.log" mw.execShell('rm -rf ' + errlog) diff --git a/plugins/op_waf/waf/lua/init.lua b/plugins/op_waf/waf/lua/init.lua index f7465c576..33ded01ad 100644 --- a/plugins/op_waf/waf/lua/init.lua +++ b/plugins/op_waf/waf/lua/init.lua @@ -1,14 +1,3 @@ -local waf_root = "{$WAF_ROOT}" -local waf_cpath = waf_root.."/waf/lua/?.lua;"..waf_root.."/waf/conf/?.lua;"..waf_root.."/waf/html/?.lua;" -local waf_sopath = waf_root.."/waf/conf/?.so;" - -if not package.path:find(waf_cpath) then - package.path = waf_cpath .. package.path -end - -if not package.cpath:find(waf_sopath) then - package.cpath = waf_sopath .. package.cpath -end local json = require "cjson" local ngx_match = ngx.re.find diff --git a/plugins/op_waf/waf/lua/init_preload.lua b/plugins/op_waf/waf/lua/init_preload.lua new file mode 100644 index 000000000..8087b0065 --- /dev/null +++ b/plugins/op_waf/waf/lua/init_preload.lua @@ -0,0 +1,11 @@ +local waf_root = "{$WAF_ROOT}" +local waf_cpath = waf_root.."/waf/lua/?.lua;"..waf_root.."/waf/conf/?.lua;"..waf_root.."/waf/html/?.lua;" +local waf_sopath = waf_root.."/waf/conf/?.so;" + +if not package.path:find(waf_cpath) then + package.path = waf_cpath .. package.path +end + +if not package.cpath:find(waf_sopath) then + package.cpath = waf_sopath .. package.cpath +end \ No newline at end of file diff --git a/plugins/op_waf/waf/lua/init_worker.lua b/plugins/op_waf/waf/lua/init_worker.lua index 26c15bb80..757576371 100644 --- a/plugins/op_waf/waf/lua/init_worker.lua +++ b/plugins/op_waf/waf/lua/init_worker.lua @@ -1,14 +1,14 @@ local waf_root = "{$WAF_ROOT}" -local waf_cpath = waf_root.."/waf/lua/?.lua;"..waf_root.."/waf/conf/?.lua;"..waf_root.."/waf/html/?.lua;" -local waf_sopath = waf_root.."/waf/conf/?.so;" -if not package.path:find(waf_cpath) then - package.path = waf_cpath .. package.path -end +-- local waf_cpath = waf_root.."/waf/lua/?.lua;"..waf_root.."/waf/conf/?.lua;"..waf_root.."/waf/html/?.lua;" +-- local waf_sopath = waf_root.."/waf/conf/?.so;" +-- if not package.path:find(waf_cpath) then +-- package.path = waf_cpath .. package.path +-- end -if not package.cpath:find(waf_sopath) then - package.cpath = waf_sopath .. package.cpath -end +-- if not package.cpath:find(waf_sopath) then +-- package.cpath = waf_sopath .. package.cpath +-- end local json = require "cjson"