-
Notifications
You must be signed in to change notification settings - Fork 17
/
country_check.lua
57 lines (54 loc) · 1.6 KB
/
country_check.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-- 根据ip地址获取国家
function getCountry()
local cjson=require "cjson"
local geo=require "area/maxminddb"
local now_ip = getClientIp()
if not geo.initted() then
geo.init("waf/area/GeoLite2-Country.mmdb")
end
local res,err=geo.lookup(now_ip)
if not res then
return "unknown_country"
else
return res["country"]["iso_code"]
end
end
-- 国家白名单验证;如果开启国家验证,建议开启蜘蛛验证,并在参数内填写你允许的搜索引擎蜘蛛
function country_white()
if CountryLimit then
if next(WhiteCountry) ~= nil then
local country = getCountry()
local items = Set(WhiteCountry)
if country == "unknown_country" then
return true
end
for country_iso in pairs(items) do
if country == string.upper(country_iso) then
return true
end
end
return false
end
return false
end
return false
end
-- 国家黑名单验证
function country_block()
if CountryLimit then
if next(BlockCountry) ~= nil then
local country = getCountry()
local items = Set(BlockCountry)
for country_iso in pairs(items) do
if country == string.upper(country_iso) then
log("-","BlockCountry: ".. country)
say_html("地域访问限制,请稍后再试")
return true
end
end
return false
end
return false
end
return false
end