Mercurial > prosody-modules
annotate mod_register_dnsbl_firewall_mark/mod_register_dnsbl_firewall_mark.lua @ 6562:5da6fb562df9 default tip
mod_unified_push: Fix push error handling (fixes #2000)
Use the error object that send_iq() passes
as an argument to it's reject callback instead of attempting
and failing to do the parsing in the callback itself.
| author | kmq |
|---|---|
| date | Mon, 06 Jul 2026 14:23:57 +0200 |
| parents | 7d4386cc73d3 |
| children |
| rev | line source |
|---|---|
|
2112
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local adns = require "net.adns"; |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local rbl = module:get_option_string("registration_rbl"); |
|
4011
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
3 local rbl_message = module:get_option_string("registration_rbl_message"); |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
4 local st = require "util.stanza"; |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
5 |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
6 |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
7 local function cleanup_ip(ip) |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
8 if ip:sub(1,7):lower() == "::ffff:" then |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
9 return ip:sub(8); |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
10 end |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
11 return ip; |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
12 end |
|
2112
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local function reverse(ip, suffix) |
|
2135
42b095dab626
mod_register_dnsbl: Fix matching pattern (Thanks Ge0rG)
Kim Alvefur <zash@zash.se>
parents:
2112
diff
changeset
|
15 local a,b,c,d = ip:match("^(%d+).(%d+).(%d+).(%d+)$"); |
|
2112
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 if not a then return end |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 return ("%d.%d.%d.%d.%s"):format(d,c,b,a, suffix); |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 end |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 |
|
6037
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
20 local store = module:open_store("firewall_marks", "map"); |
|
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
21 |
|
2112
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 module:hook("user-registered", function (event) |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local session = event.session; |
|
4011
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
24 local ip = session and session.ip and cleanup_ip(session.ip); |
|
2112
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 local rbl_ip = ip and reverse(ip, rbl); |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 if rbl_ip then |
|
2895
589cc51209f7
mod_register_dnsbl_firewall_mark: Another copy of DNSBL module, this time creating "user marks" for mod_firewall
Kim Alvefur <zash@zash.se>
parents:
2889
diff
changeset
|
27 local registration_time = os.time(); |
|
2112
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 local log = session.log; |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 adns.lookup(function (reply) |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 if reply and reply[1] then |
|
2203
2dcc3079572c
mod_register_dnsbl: Include more information in log message
Kim Alvefur <zash@zash.se>
parents:
2135
diff
changeset
|
31 log("warn", "Account %s@%s registered from IP %s found in RBL (%s)", event.username, event.host or module.host, ip, reply[1].a); |
|
2895
589cc51209f7
mod_register_dnsbl_firewall_mark: Another copy of DNSBL module, this time creating "user marks" for mod_firewall
Kim Alvefur <zash@zash.se>
parents:
2889
diff
changeset
|
32 local user = prosody.bare_sessions[event.username .. "@" .. module.host]; |
|
589cc51209f7
mod_register_dnsbl_firewall_mark: Another copy of DNSBL module, this time creating "user marks" for mod_firewall
Kim Alvefur <zash@zash.se>
parents:
2889
diff
changeset
|
33 if user and user.firewall_marks then |
|
589cc51209f7
mod_register_dnsbl_firewall_mark: Another copy of DNSBL module, this time creating "user marks" for mod_firewall
Kim Alvefur <zash@zash.se>
parents:
2889
diff
changeset
|
34 user.firewall_marks.dnsbl_hit = registration_time; |
|
589cc51209f7
mod_register_dnsbl_firewall_mark: Another copy of DNSBL module, this time creating "user marks" for mod_firewall
Kim Alvefur <zash@zash.se>
parents:
2889
diff
changeset
|
35 else |
|
6037
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
36 store:set(event.username, "dnsbl_hit", registration_time); |
|
2895
589cc51209f7
mod_register_dnsbl_firewall_mark: Another copy of DNSBL module, this time creating "user marks" for mod_firewall
Kim Alvefur <zash@zash.se>
parents:
2889
diff
changeset
|
37 end |
|
4011
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
38 if rbl_message then |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
39 module:log("debug", "Warning RBL registered user %s@%s", event.username, event.host); |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
40 event.ip = ip; |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
41 local rbl_stanza = |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
42 st.message({ to = event.username.."@"..event.host, from = event.host }, |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
43 rbl_message:gsub("$(%w+)", event)); |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
44 module:send(rbl_stanza); |
|
de40686ae9c8
mod_register_dnsbl_firewall_mark: introduce optional registration_rbl_message with mod_welcome inspired syntax
Georg Lukas <georg@op-co.de>
parents:
3993
diff
changeset
|
45 end |
|
2112
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 end |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 end, rbl_ip); |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 end |
|
0890c4860f14
mod_register_dnsbl: Initial commit of module to check users registering against an DNS block list
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 end); |
|
6037
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
50 |
|
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
51 module:add_item("account-trait", { |
|
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
52 name = "register-dnsbl-hit"; |
|
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
53 prob_bad_true = 0.6; |
|
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
54 prob_bad_false = 0.4; |
|
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
55 }); |
|
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
56 |
|
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
57 module:hook("get-account-traits", function (event) |
|
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
58 event.traits["register-dnsbl-hit"] = not not store:get(event.username, "dnsbl_hit"); |
|
7d4386cc73d3
mod_register_dnsbl_firewall_mark: Add account trait for mod_report_affiliations
Matthew Wild <mwild1@gmail.com>
parents:
4011
diff
changeset
|
59 end); |
