Software /
code /
prosody-modules
Comparison
mod_register_dnsbl/mod_register_dnsbl.lua @ 2112:0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 17 Mar 2016 13:05:38 +0100 |
child | 2135:42b095dab626 |
comparison
equal
deleted
inserted
replaced
2111:4e434abaf8fc | 2112:0890c4860f14 |
---|---|
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", "Registration from IP %s found in RBL", ip); | |
22 end | |
23 end, rbl_ip); | |
24 end | |
25 end); |