comparison mod_register_dnsbl/mod_register_dnsbl.lua @ 2892:bf9fc41bf7ad

mod_register_dnsbl: Add support for IPv6 DNSBL
author Kim Alvefur <zash@zash.se>
date Fri, 23 Feb 2018 22:00:18 +0100
parents 84670bac7348
children 82482e7e92cb
comparison
equal deleted inserted replaced
2891:84670bac7348 2892:bf9fc41bf7ad
1 local adns = require "net.adns"; 1 local adns = require "net.adns";
2 local async = require "util.async"; 2 local async = require "util.async";
3 local inet_pton = require "util.net".pton; 3 local inet_pton = require "util.net".pton;
4 local to_hex = require "util.hex".to;
4 5
5 local rbl = module:get_option_string("registration_rbl"); 6 local rbl = module:get_option_string("registration_rbl");
6 7
7 local function reverse(ip, suffix) 8 local function reverse(ip, suffix)
8 local n, err = inet_pton(ip); 9 local n, err = inet_pton(ip);
9 if not n then return n, err end 10 if not n then return n, err end
10 if #n == 4 then 11 if #n == 4 then
11 local a,b,c,d = n:byte(1,4); 12 local a,b,c,d = n:byte(1,4);
12 return ("%d.%d.%d.%d.%s"):format(d,c,b,a, suffix); 13 return ("%d.%d.%d.%d.%s"):format(d,c,b,a, suffix);
14 elseif #n == 16 then
15 return to_hex(n):reverse():gsub("%x", "%1.") .. suffix;
13 end 16 end
14 end 17 end
15 18
16 module:hook("user-registering", function (event) 19 module:hook("user-registering", function (event)
17 local session, ip = event.session, event.ip; 20 local session, ip = event.session, event.ip;