mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 04:19:26 +08:00
debug 1
This commit is contained in:
@@ -553,28 +553,39 @@ local function initmaxminddb()
|
||||
if geo ==nil then
|
||||
maxminddb ,geo = pcall(function() return require 'waf_maxminddb' end)
|
||||
if not maxminddb then
|
||||
C:D("debug error on :"..tostring(geo))
|
||||
return nil
|
||||
end
|
||||
end
|
||||
C:D("----1-----")
|
||||
if type(geo)=='number' then return nil end
|
||||
local ok2,data=pcall(function()
|
||||
if not geo.initted() then
|
||||
C:D("----2--ok---")
|
||||
geo.init("{$WAF_ROOT}/GeoLite2-City.mmdb")
|
||||
end
|
||||
end )
|
||||
|
||||
C:D("----3-----"..tostring(ok2))
|
||||
if not ok2 then
|
||||
geo=nil
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local geo=nil
|
||||
local waf_country=""
|
||||
local geo2=nil
|
||||
|
||||
local function get_ip_Country()
|
||||
initmaxminddb()
|
||||
C:D("----ip-----"..params['ip'])
|
||||
if type(geo)=='number' then return "21" end
|
||||
if geo==nil then return "22" end
|
||||
if geo.lookup==nil then return "23" end
|
||||
local res,err=geo.lookup(param['ip'] or ngx.var.remote_addr)
|
||||
|
||||
-- local res,err=geo.lookup(param['ip'] or ngx.var.remote_addr)
|
||||
local res,err=geo.lookup("182.96.210.214")
|
||||
if not res then
|
||||
return "2"
|
||||
else
|
||||
@@ -588,8 +599,8 @@ function waf()
|
||||
min_route()
|
||||
-- C:D("min_route")
|
||||
|
||||
overcon = get_ip_Country()
|
||||
C:D(tostring(overcon))
|
||||
waf_country = get_ip_Country()
|
||||
C:D(tostring(waf_country))
|
||||
|
||||
if site_config[server_name] and site_config[server_name]['open'] then
|
||||
-- white ip
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
a lua interface (build with luajit ffi) for maxminddb to get country code from ip address
|
||||
]]
|
||||
|
||||
local json = require('cjson');
|
||||
local json_encode = json.encode
|
||||
local json_decode = json.decode
|
||||
local ht_print = ngx.print
|
||||
local ngx_log = ngx.log
|
||||
local ngx_ERR = ngx.ERR
|
||||
local ngx_CRIT = ngx.CRIT
|
||||
local ngx_INFO = ngx.INFO
|
||||
local json = require('cjson');
|
||||
local json_encode = json.encode
|
||||
local json_decode = json.decode
|
||||
local ht_print = ngx.print
|
||||
local ngx_log = ngx.log
|
||||
local ngx_ERR = ngx.ERR
|
||||
local ngx_CRIT = ngx.CRIT
|
||||
local ngx_INFO = ngx.INFO
|
||||
|
||||
local ngx_sub = ngx.re.sub;
|
||||
local ngx_gsub = ngx.re.gsub;
|
||||
@@ -134,7 +134,7 @@ local MMDB_DATA_TYPE_BYTES = 4
|
||||
|
||||
|
||||
-- you should install the libmaxminddb to your system
|
||||
local maxm = ffi.load('libmaxminddb.so')
|
||||
local maxm = ffi.load('{$WAF_ROOT}/mmdb/lib/libmaxminddb.so')
|
||||
--https://github.com/maxmind/libmaxminddb
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user