comparison mod_register_dnsbl_warn/mod_register_dnsbl_warn.lua @ 2889:7fb82481b3db

mod_register_dnsbl_warn: Copy mod_register_dnsbl
author Kim Alvefur <zash@zash.se>
date Fri, 23 Feb 2018 21:50:47 +0100
parents mod_register_dnsbl/mod_register_dnsbl.lua@2dcc3079572c
children 76036fa34055
comparison
equal deleted inserted replaced
2888:59cc6f9e8e68 2889:7fb82481b3db
1 local adns = require "net.adns";
2 local rbl = module:get_option_string("registration_rbl");
3
4 local function reverse(ip, suffix)
5 local a,b,c,d = ip:match("^(%d+).(%d+).(%d+).(%d+)$");
6 if not a then return end
7 return ("%d.%d.%d.%d.%s"):format(d,c,b,a, suffix);
8 end
9
10 -- TODO async
11 -- module:hook("user-registering", function (event) end);
12
13 module:hook("user-registered", function (event)
14 local session = event.session;
15 local ip = session and session.ip;
16 local rbl_ip = ip and reverse(ip, rbl);
17 if rbl_ip then
18 local log = session.log;
19 adns.lookup(function (reply)
20 if reply and reply[1] then
21 log("warn", "Account %s@%s registered from IP %s found in RBL (%s)", event.username, event.host or module.host, ip, reply[1].a);
22 end
23 end, rbl_ip);
24 end
25 end);