1 function ipValidator(ip)
\r
2 local chunks = {ip:match("(%d+)%.(%d+)%.(%d+)%.(%d+)")}
\r
4 for _,v in pairs(chunks) do
\r
5 if tonumber(v) > 255 then return R.STRING end
\r
9 local chunks = {ip:match(("([a-fA-F0-9]*):"):rep(8):gsub(":$","$"))}
\r
10 if #chunks == 8 then
\r
11 for _,v in pairs(chunks) do
\r
12 if #v > 0 and tonumber(v, 16) > 65535 then return R.STRING end
\r
19 if ngx.req.get_method() == "POST" then
\r
21 local body = ngx.req.get_body_data()
\r
22 local json = require('cjson')
\r
23 local tab = json.decode(body)
\r
24 local ip = tab["passIp"]
\r
26 ngx.log(ngx.WARN, "ip is nil.")
\r
29 if ipValidator(ip) then
\r
30 local cache = ngx.shared.ceryx
\r
31 local succ, err, forcible = cache:set(ip, "place_holder", 3600)
\r
33 ngx.log(ngx.WARN, err)
\r
37 ngx.log(ngx.WARN, "not a valid ip.")
\r
42 ngx.log(ngx.WARN, "not a POST request.")
\r