|
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 module:hook("user-registered", function (event) |
|
11 local session = event.session; |
|
12 local ip = session and session.ip; |
|
13 local rbl_ip = ip and reverse(ip, rbl); |
|
14 if rbl_ip then |
|
15 local registration_time = os.time(); |
|
16 local log = session.log; |
|
17 adns.lookup(function (reply) |
|
18 if reply and reply[1] then |
|
19 log("warn", "Account %s@%s registered from IP %s found in RBL (%s)", event.username, event.host or module.host, ip, reply[1].a); |
|
20 local user = prosody.bare_sessions[event.username .. "@" .. module.host]; |
|
21 if user and user.firewall_marks then |
|
22 user.firewall_marks.dnsbl_hit = registration_time; |
|
23 else |
|
24 module:open_store("firewall_marks", "map"):set(event.username, "dnsbl_hit", registration_time); |
|
25 end |
|
26 end |
|
27 end, rbl_ip); |
|
28 end |
|
29 end); |