Changeset

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 4117:a1c6eea971ce
children 4119:559ca8d93302
files mod_register_dnsbl/mod_register_dnsbl.lua
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mod_register_dnsbl/mod_register_dnsbl.lua	Mon Sep 14 13:57:59 2020 +0100
+++ b/mod_register_dnsbl/mod_register_dnsbl.lua	Mon Sep 14 13:58:47 2020 +0100
@@ -18,21 +18,22 @@
 
 module:hook("user-registering", function (event)
 	local session, ip = event.session, event.ip;
+	local log = (session and session.log) or module._log;
 	if not ip then
-		session.log("debug", "Unable to check DNSBL when IP is unknown");
+		log("debug", "Unable to check DNSBL when IP is unknown");
 		return;
 	end
 	local rbl_ip, err = reverse(ip, rbl);
 	if not rbl_ip then
-		session.log("debug", "Unable to check DNSBL for ip %s: %s", ip, err);
+		log("debug", "Unable to check DNSBL for ip %s: %s", ip, err);
 		return;
 	end
 
 	local wait, done = async.waiter();
 	adns.lookup(function (reply)
 		if reply and reply[1] and reply[1].a then
-			session.log("debug", "DNSBL response: %s IN A %s", rbl_ip, reply[1].a);
-			session.log("info", "Blocking %s from registering %s (dnsbl hit)", ip, event.username);
+			log("debug", "DNSBL response: %s IN A %s", rbl_ip, reply[1].a);
+			log("info", "Blocking %s from registering %s (dnsbl hit)", ip, event.username);
 			event.allowed = false;
 			event.reason = "Blocked by DNSBL";
 		end