feat: 新增获取匹配规则日志的功能

This commit is contained in:
potatso 2023-07-04 12:32:19 +08:00
parent 9feba8f698
commit 3470d0403d
2 changed files with 15 additions and 1 deletions

View File

@ -137,4 +137,10 @@ function _M.do_header_filter()
ngx_ctx.action, ngx_ctx.status_code = coraza.intervention(ngx_ctx.transaction)
end
function _M.do_log()
local msg = coraza.get_matched_logmsg(ngx_ctx.transaction)
ngx_ctx.coraza_msg = msg
end
return _M

View File

@ -90,7 +90,8 @@ extern int coraza_free_transaction(coraza_transaction_t t);
extern int coraza_free_intervention(coraza_intervention_t* it);
extern int coraza_free_waf(coraza_waf_t t);
extern coraza_intervention_t* coraza_intervention(coraza_transaction_t tx);
extern char* coraza_get_matched_logmsg(coraza_transaction_t t);
extern int coraza_free_matched_logmsg(char* t);
]]
local _M = {
@ -326,4 +327,11 @@ function _M.process_response_body(transaction)
end
end
function _M.get_matched_logmsg(transaction)
local c_str = coraza.coraza_get_matched_logmsg(transaction)
local res = ffi.string(c_str)
coraza.coraza_free_matched_logmsg(c_str)
return res
end
return _M