...
|
...
|
@@ -35,6 +35,8 @@ function rate_limit() |
|
|
-- read config
|
|
|
local common_config=lua_context.configs["common_conf"]
|
|
|
local limit_config=lua_context.configs["api_rate_limit_conf"]
|
|
|
local limit_ip_config=lua_context.configs["limit_ip_access"]
|
|
|
|
|
|
if (not common_config) or (not limit_config) then
|
|
|
return
|
|
|
end
|
...
|
...
|
@@ -79,6 +81,21 @@ function rate_limit() |
|
|
end
|
|
|
end
|
|
|
|
|
|
--check is in white ip list
|
|
|
function is_white()
|
|
|
if limit_ip_config then
|
|
|
local white_ips_length=#limit_ip_config.white_ips
|
|
|
if white_ips_length >0 then
|
|
|
for i=1,white_ips_length do
|
|
|
local is_in_white_ips=iptool:pcall_check_ip_in_ipblock(ngx.var.real_ip,limit_ip_config.white_ips[i],false)
|
|
|
if is_in_white_ips then
|
|
|
return true
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
return false
|
|
|
end
|
|
|
|
|
|
----- check weather ip is in black list
|
|
|
function check_malIp()
|
...
|
...
|
@@ -100,8 +117,16 @@ function init_read_body() |
|
|
end
|
|
|
end
|
|
|
|
|
|
init_read_body()
|
|
|
check_malIp()
|
|
|
rate_limit()
|
|
|
function main()
|
|
|
if is_white() then
|
|
|
return
|
|
|
else
|
|
|
init_read_body()
|
|
|
check_malIp()
|
|
|
rate_limit()
|
|
|
end
|
|
|
end
|
|
|
|
|
|
----- running ----
|
|
|
main()
|
|
|
|
...
|
...
|
|