mirror of
https://github.com/potats0/lua-resty-coraza.git
synced 2025-11-16 09:21:56 +03:00
修改api
This commit is contained in:
@@ -52,10 +52,9 @@ function _M.check_schema(conf)
|
||||
if conf.rules ~= nil then
|
||||
for i, rule in ipairs(conf.rules) do
|
||||
local ok, msg = coraza.rules_add(rule)
|
||||
ngx.log(ngx.ERR, ok)
|
||||
if not ok then
|
||||
return false, rule..msg
|
||||
end
|
||||
if not ok then
|
||||
return false, rule.."\t"..msg
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
@@ -64,12 +63,13 @@ end
|
||||
function _M.init()
|
||||
-- call this function when plugin is loaded
|
||||
core_log.info("coraza init")
|
||||
coraza.do_init()
|
||||
_M.waf = coraza.create_waf()
|
||||
end
|
||||
|
||||
function _M.access(conf, ctx)
|
||||
core.log.info("plugin access phase, conf: ", core.json.delay_encode(conf))
|
||||
-- each connection will be created a transaction
|
||||
coraza.do_create_transaction(_M.waf)
|
||||
coraza.do_access_filter()
|
||||
return coraza.do_handle()
|
||||
end
|
||||
@@ -83,12 +83,13 @@ end
|
||||
|
||||
function _M.destroy()
|
||||
core.log.info("coraza destroy")
|
||||
coraza.free_waf(_M.waf)
|
||||
end
|
||||
|
||||
|
||||
function _M.log(conf, ctx)
|
||||
coraza.do_log()
|
||||
coraza.do_free()
|
||||
coraza.do_free_transaction()
|
||||
end
|
||||
|
||||
return _M
|
||||
|
||||
@@ -17,11 +17,11 @@ local _M = {
|
||||
_VERSION = '1.0.0'
|
||||
}
|
||||
|
||||
function _M.do_init()
|
||||
function _M.create_waf()
|
||||
return coraza.new_waf()
|
||||
end
|
||||
|
||||
function _M.do_free_waf(waf)
|
||||
function _M.free_waf(waf)
|
||||
return coraza.free_waf(waf)
|
||||
end
|
||||
|
||||
@@ -33,10 +33,8 @@ function _M.rules_add(waf, directives)
|
||||
return coraza.rules_add(waf, directives)
|
||||
end
|
||||
|
||||
function _M.do_access_filter(waf)
|
||||
-- each connection will be created a transaction
|
||||
local transaction = coraza.new_transaction(waf)
|
||||
ngx_ctx.transaction = transaction
|
||||
function _M.do_access_filter()
|
||||
local transaction = ngx_ctx.transaction
|
||||
|
||||
coraza.process_connection(transaction, ngx_var.remote_addr, ngx_var.remote_port,
|
||||
ngx_var.server_addr, ngx_var.server_port)
|
||||
@@ -57,7 +55,12 @@ function _M.do_access_filter(waf)
|
||||
|
||||
end
|
||||
|
||||
function _M.do_free()
|
||||
function _M.do_create_transaction(waf)
|
||||
-- each connection will be created a transaction
|
||||
ngx_ctx.transaction = coraza.new_transaction(waf)
|
||||
end
|
||||
|
||||
function _M.do_free_transaction()
|
||||
local transaction = ngx_ctx.transaction
|
||||
if transaction ~= nil then
|
||||
nlog(debug_fmt("transaction %s is freed by coraza_free_transaction", ngx_ctx.request_id))
|
||||
|
||||
Reference in New Issue
Block a user