Mercurial > prosody-modules
comparison mod_register_dnsbl_firewall_mark/mod_register_dnsbl_firewall_mark.lua @ 2895:589cc51209f7
mod_register_dnsbl_firewall_mark: Another copy of DNSBL module, this time creating "user marks" for mod_firewall
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 24 Feb 2018 21:42:54 +0100 |
parents | mod_register_dnsbl_warn/mod_register_dnsbl_warn.lua@7fb82481b3db |
children | 76036fa34055 |
comparison
equal
deleted
inserted
replaced
2894:165d2877eeac | 2895:589cc51209f7 |
---|---|
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); |