|
|
|
@ -33,58 +33,14 @@ C.setConfData(config, site_config) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get_client_ip() |
|
|
|
|
local client_ip = "unknown" |
|
|
|
|
if site_config[server_name] then |
|
|
|
|
if site_config[server_name]['cdn'] then |
|
|
|
|
for _,v in ipairs(site_config[server_name]['cdn_header']) |
|
|
|
|
do |
|
|
|
|
if request_header[v] ~= nil and request_header[v] ~= "" then |
|
|
|
|
local header_tmp = request_header[v] |
|
|
|
|
if type(header_tmp) == "table" then header_tmp = header_tmp[1] end |
|
|
|
|
client_ip = split(header_tmp,',')[1] |
|
|
|
|
break; |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
if string.match(client_ip,"%d+%.%d+%.%d+%.%d+") == nil or not is_ipaddr(client_ip) then |
|
|
|
|
client_ip = ngx.var.remote_addr |
|
|
|
|
if client_ip == nil then |
|
|
|
|
client_ip = "unknown" |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
return client_ip |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function get_server_name() |
|
|
|
|
local c_name = ngx.var.server_name |
|
|
|
|
local my_name = ngx.shared.limit:get(c_name) |
|
|
|
|
if my_name then return my_name end |
|
|
|
|
local tmp = C:read_file_body(cpath .. 'domains.json') |
|
|
|
|
if not tmp then return c_name end |
|
|
|
|
local domains = json.decode(tmp) |
|
|
|
|
for _,v in ipairs(domains) |
|
|
|
|
do |
|
|
|
|
for _,d_name in ipairs(v['domains']) |
|
|
|
|
do |
|
|
|
|
if c_name == d_name then |
|
|
|
|
ngx.shared.limit:set(c_name,v['name'],3600) |
|
|
|
|
return v['name'] |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
return c_name |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
local args_rules = C:read_file_table('args') |
|
|
|
|
|
|
|
|
|
local retry = config['retry'] |
|
|
|
|
local retry_time = config['retry_time'] |
|
|
|
|
local retry_cycle = config['retry_cycle'] |
|
|
|
|
local ip |
|
|
|
|
local server_name |
|
|
|
|
local ip = C:get_client_ip() |
|
|
|
|
local server_name = string.gsub(C:get_server_name(),'_','.') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -253,7 +209,6 @@ function waf() |
|
|
|
|
|
|
|
|
|
-- server_name = string.gsub(get_server_name(),'_','.') |
|
|
|
|
ngx.header.content_type = "text/plain" |
|
|
|
|
-- ip = get_client_ip() |
|
|
|
|
C:t() |
|
|
|
|
-- ngx.say(read_file('args')); |
|
|
|
|
-- args() |
|
|
|
|