34 lines
784 B
Lua
34 lines
784 B
Lua
-- WAF统一入口模块
|
||
-- 功能:集中管理所有安全检查(IP限流、UA限制等)
|
||
|
||
local _M = {}
|
||
|
||
-- 尝试加载resty.core,如果失败则忽略(兼容旧版本OpenResty)
|
||
pcall(function()
|
||
require "resty.core"
|
||
end)
|
||
|
||
local rate_limiter = require "modules.rate_limiter"
|
||
local ua_limiter = require "modules.ua_limiter"
|
||
|
||
-- 执行所有安全检查
|
||
-- 返回值:
|
||
-- - true: 所有检查通过,允许访问
|
||
-- - false: 某个检查失败,已返回错误响应
|
||
function _M.check()
|
||
-- IP频率限制检查
|
||
if not rate_limiter.check_rate_limit() then
|
||
return false
|
||
end
|
||
|
||
-- User-Agent限制检查
|
||
if not ua_limiter.check_ua_limit() then
|
||
return false
|
||
end
|
||
|
||
-- 所有检查通过
|
||
return true
|
||
end
|
||
|
||
return _M
|