...
|
...
|
@@ -134,31 +134,24 @@ function M:mal_ip() |
|
|
ngx.say('{"code": 400, "msg": "params error!"}')
|
|
|
ngx.exit(ngx.HTTP_OK)
|
|
|
end
|
|
|
local exists={}
|
|
|
if method == 'pubAdd' then
|
|
|
if method == 'publish' then
|
|
|
local t={}
|
|
|
t.ips=ips
|
|
|
t.expire=expire
|
|
|
t.type="add"
|
|
|
redis_limit_ip:cmd("publish","mal_ips",cjson.encode(t))
|
|
|
elseif method == 'pubDel' then
|
|
|
local t={}
|
|
|
t.ips=ips
|
|
|
t.type="del"
|
|
|
redis_limit_ip:cmd("publish","mal_ips",cjson.encode(t))
|
|
|
else
|
|
|
for ip in string.gmatch(ips,"[^',']+") do
|
|
|
if method == 'add' then
|
|
|
local expire= (not expire) and 43200 or expire
|
|
|
cache:set("yh:mip:" .. ip,"1",expire)
|
|
|
elseif method == 'del' then
|
|
|
cache:delete("yh:mip:" .. ip)
|
|
|
elseif method == 'exists' then
|
|
|
local res=cache:get("yh:mip:" .. ip)
|
|
|
res= res and true or false
|
|
|
exists[#exists+1]=tostring(res)
|
|
|
end
|
|
|
end
|
|
|
end
|
|
|
local exists={}
|
|
|
for ip in string.gmatch(ips,"[^',']+") do
|
|
|
if method == 'add' then
|
|
|
local expire= (not expire) and 86400 or expire
|
|
|
cache:set("yh:mip:" .. ip,"1",expire)
|
|
|
elseif method == 'del' then
|
|
|
cache:delete("yh:mip:" .. ip)
|
|
|
elseif method == 'exists' then
|
|
|
local res=cache:get("yh:mip:" .. ip)
|
|
|
res= res and true or false
|
|
|
exists[#exists+1]=tostring(res)
|
|
|
end
|
|
|
end
|
|
|
local body=table.concat(exists,",")
|
|
|
ngx.say('{"code": 200, "msg": "'.. body ..'"}')
|
...
|
...
|
|