pull/216/head
midoks 3 years ago
parent 0c769b02e5
commit 3dc695508f
  1. 4
      plugins/op_waf/t/index.py
  2. 21
      plugins/op_waf/waf/lua/common.lua

@ -221,6 +221,6 @@ def test_start():
if __name__ == "__main__": 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/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/ && python3 plugins/openresty/index.py stop && python3 plugins/openresty/index.py start')
test_start() test_start()

@ -26,7 +26,6 @@ function _M.new(self)
server_name = '', server_name = '',
global_tatal = nil, global_tatal = nil,
params = nil, params = nil,
db = nil,
} }
return setmetatable(self, mt) return setmetatable(self, mt)
end end
@ -41,10 +40,6 @@ function _M.getInstance(self)
end end
function _M.initDB(self) function _M.initDB(self)
if self.db then
return self.db
end
local path = log_dir .. "/waf.db" local path = log_dir .. "/waf.db"
db, err = sqlite3.open(path) db, err = sqlite3.open(path)
@ -58,17 +53,16 @@ function _M.initDB(self)
db:exec([[PRAGMA page_size = 32768]]) db:exec([[PRAGMA page_size = 32768]])
db:exec([[PRAGMA journal_mode = wal]]) db:exec([[PRAGMA journal_mode = wal]])
db:exec([[PRAGMA journal_size_limit = 1073741824]]) db:exec([[PRAGMA journal_size_limit = 1073741824]])
self.db = db
return db return db
end end
function _M.log(self, args, rule_name, reason) function _M.log(self, args, rule_name, reason)
local local_db = self:initDB() 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 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)]] 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{ stmt2:bind_names{
time=args["time"], time=args["time"],
@ -91,10 +85,11 @@ function _M.log(self, args, rule_name, reason)
return false return false
end end
stmt2:reset() stmt2:reset()
local res, err = local_db:execute([[COMMIT]])
local res, err = db:execute([[COMMIT]])
-- self:D("LOG[2]:"..tostring(res)..":"..tostring(err)) -- self:D("LOG[2]:"..tostring(res)..":"..tostring(err))
if local_db and local_db:isopen() then if db and db:isopen() then
local_db:close() db:close()
end end
return true return true
end end

Loading…
Cancel
Save