From 3dc695508f7035b37f69f8886802cded70390fa3 Mon Sep 17 00:00:00 2001 From: midoks Date: Fri, 21 Oct 2022 19:09:34 +0800 Subject: [PATCH] up --- plugins/op_waf/t/index.py | 4 ++-- plugins/op_waf/waf/lua/common.lua | 21 ++++++++------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/plugins/op_waf/t/index.py b/plugins/op_waf/t/index.py index 4e9e1eb16..66108dbf5 100644 --- a/plugins/op_waf/t/index.py +++ b/plugins/op_waf/t/index.py @@ -221,6 +221,6 @@ def test_start(): if __name__ == "__main__": - # os.system('cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/op_waf && sh install.sh uninstall 0.2.2 && sh install.sh install 0.2.2') - # os.system('cd /Users/midoks/Desktop/mwdev/server/mdserver-web/ && python3 plugins/openresty/index.py stop && python3 plugins/openresty/index.py start') + os.system('cd /Users/midoks/Desktop/mwdev/server/mdserver-web/plugins/op_waf && sh install.sh uninstall 0.2.2 && sh install.sh install 0.2.2') + os.system('cd /Users/midoks/Desktop/mwdev/server/mdserver-web/ && python3 plugins/openresty/index.py stop && python3 plugins/openresty/index.py start') test_start() diff --git a/plugins/op_waf/waf/lua/common.lua b/plugins/op_waf/waf/lua/common.lua index fdeafcaec..f044d3a47 100644 --- a/plugins/op_waf/waf/lua/common.lua +++ b/plugins/op_waf/waf/lua/common.lua @@ -26,7 +26,6 @@ function _M.new(self) server_name = '', global_tatal = nil, params = nil, - db = nil, } return setmetatable(self, mt) end @@ -41,10 +40,6 @@ function _M.getInstance(self) end function _M.initDB(self) - if self.db then - return self.db - end - local path = log_dir .. "/waf.db" db, err = sqlite3.open(path) @@ -58,17 +53,16 @@ function _M.initDB(self) db:exec([[PRAGMA page_size = 32768]]) db:exec([[PRAGMA journal_mode = wal]]) db:exec([[PRAGMA journal_size_limit = 1073741824]]) - - self.db = db return db end function _M.log(self, args, rule_name, reason) - local local_db = self:initDB() - local stmt2 = local_db:prepare[[INSERT INTO logs(time, ip, domain, server_name, method, status_code, uri, user_agent, rule_name, reason) + local db = self:initDB() + + local stmt2 = db:prepare[[INSERT INTO logs(time, ip, domain, server_name, method, status_code, uri, user_agent, rule_name, reason) VALUES(:time, :ip, :domain, :server_name, :method, :status_code, :uri, :user_agent, :rule_name, :reason)]] - local_db:exec([[BEGIN TRANSACTION]]) + db:exec([[BEGIN TRANSACTION]]) stmt2:bind_names{ time=args["time"], @@ -91,10 +85,11 @@ function _M.log(self, args, rule_name, reason) return false end stmt2:reset() - local res, err = local_db:execute([[COMMIT]]) + + local res, err = db:execute([[COMMIT]]) -- self:D("LOG[2]:"..tostring(res)..":"..tostring(err)) - if local_db and local_db:isopen() then - local_db:close() + if db and db:isopen() then + db:close() end return true end