comparison mod_firewall/mod_firewall.lua @ 5704:ad5c77793750

mod_firewall: Add FROM COUNTRY condition based on GeoIP DB
author Kim Alvefur <zash@zash.se>
date Sun, 12 Nov 2023 16:37:47 +0100
parents 048284447643
children e304e19536f2
comparison
equal deleted inserted replaced
5703:0ac4545cb4f9 5704:ad5c77793750
261 return code, { "search:"..search_name, "pattern:"..pattern_name }; 261 return code, { "search:"..search_name, "pattern:"..pattern_name };
262 end; 262 end;
263 }; 263 };
264 scan_list = { 264 scan_list = {
265 global_code = [[local function scan_list(list, items) for item in pairs(items) do if list:contains(item) then return true; end end end]]; 265 global_code = [[local function scan_list(list, items) for item in pairs(items) do if list:contains(item) then return true; end end end]];
266 } 266 };
267 iplib = {
268 global_code = [[local iplib = require "util.ip";]];
269 };
270 geoip_country = {
271 global_code = [[
272 local geoip_country = require "geoip.country";
273 local geov4 = geoip_country.open(module:get_option_string("geoip_ipv4_country", "/usr/share/GeoIP/GeoIP.dat"));
274 local geov6 = geoip_country.open(module:get_option_string("geoip_ipv6_country", "/usr/share/GeoIP/GeoIPv6.dat"));
275 local function get_geoip(ips, what)
276 if not ips then
277 return "--";
278 end
279 local ip = iplib.new_ip(ips);
280 if not ip then
281 return "--";
282 end
283 if ip.proto == "IPv6" and geov6 then
284 local geoinfo = geoinfo:query_by_addr6(ip.addr);
285 if geoinfo then
286 return geoinfo[what or "code"];
287 end
288 elseif ip.proto == "IPv4" and geov4 then
289 local geoinfo = geoinfo:query_by_addr(ip.addr);
290 if geoinfo then
291 return geoinfo[what or "code"];
292 end
293 end
294 return "--";
295 end
296 ]];
297 depends = {
298 "iplib"
299 }
300 };
267 }; 301 };
268 302
269 local function include_dep(dependency, code) 303 local function include_dep(dependency, code)
270 local dep, dep_param = dependency:match("^([^:]+):?(.*)$"); 304 local dep, dep_param = dependency:match("^([^:]+):?(.*)$");
271 local dep_info = available_deps[dep]; 305 local dep_info = available_deps[dep];