comparison mod_register_dnsbl/mod_register_dnsbl.lua @ 4118:82482e7e92cb

mod_register_dnsbl: Handle missing session in user-registering event (thanks meaz)
author Matthew Wild <mwild1@gmail.com>
date Mon, 14 Sep 2020 13:58:47 +0100
parents bf9fc41bf7ad
children
comparison
equal deleted inserted replaced
4117:a1c6eea971ce 4118:82482e7e92cb
16 end 16 end
17 end 17 end
18 18
19 module:hook("user-registering", function (event) 19 module:hook("user-registering", function (event)
20 local session, ip = event.session, event.ip; 20 local session, ip = event.session, event.ip;
21 local log = (session and session.log) or module._log;
21 if not ip then 22 if not ip then
22 session.log("debug", "Unable to check DNSBL when IP is unknown"); 23 log("debug", "Unable to check DNSBL when IP is unknown");
23 return; 24 return;
24 end 25 end
25 local rbl_ip, err = reverse(ip, rbl); 26 local rbl_ip, err = reverse(ip, rbl);
26 if not rbl_ip then 27 if not rbl_ip then
27 session.log("debug", "Unable to check DNSBL for ip %s: %s", ip, err); 28 log("debug", "Unable to check DNSBL for ip %s: %s", ip, err);
28 return; 29 return;
29 end 30 end
30 31
31 local wait, done = async.waiter(); 32 local wait, done = async.waiter();
32 adns.lookup(function (reply) 33 adns.lookup(function (reply)
33 if reply and reply[1] and reply[1].a then 34 if reply and reply[1] and reply[1].a then
34 session.log("debug", "DNSBL response: %s IN A %s", rbl_ip, reply[1].a); 35 log("debug", "DNSBL response: %s IN A %s", rbl_ip, reply[1].a);
35 session.log("info", "Blocking %s from registering %s (dnsbl hit)", ip, event.username); 36 log("info", "Blocking %s from registering %s (dnsbl hit)", ip, event.username);
36 event.allowed = false; 37 event.allowed = false;
37 event.reason = "Blocked by DNSBL"; 38 event.reason = "Blocked by DNSBL";
38 end 39 end
39 done(); 40 done();
40 end, rbl_ip); 41 end, rbl_ip);