Software /
code /
prosody-modules
Comparison
mod_muc_rtbl/mod_muc_rtbl.lua @ 4807:62a65c52c3f5
mod_muc_rtbl: Real-time blocklist checks for MUC services
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 05 Dec 2021 18:22:47 +0000 |
child | 4808:8a63a0daf129 |
comparison
equal
deleted
inserted
replaced
4806:80f871bedcdf | 4807:62a65c52c3f5 |
---|---|
1 local jid = require "util.jid"; | |
2 local sha256 = require "util.hashes".sha256; | |
3 local st = require "util.stanza"; | |
4 | |
5 local rtbl_service_jid = assert(module:get_option_string("muc_rtbl_jid"), "No RTBL JID supplied"); | |
6 local rtbl_node = module:get_option_string("muc_rtbl_node", "muc_bans_sha256"); | |
7 | |
8 local banned_hashes = module:shared("banned_hashes"); | |
9 | |
10 module:depends("pubsub_subscription"); | |
11 | |
12 module:add_item("pubsub-subscription", { | |
13 service = rtbl_service_jid; | |
14 node = rtbl_node; | |
15 | |
16 -- Callbacks: | |
17 on_subscribed = function() | |
18 module:log("info", "RTBL active"); | |
19 end; | |
20 | |
21 on_error = function(err) | |
22 module:log("error", "Failed to subscribe to RTBL: %s::%s: %s", err.type, err.condition, err.text); | |
23 end; | |
24 | |
25 on_item = function(event) | |
26 local hash = event.item.attr.id; | |
27 if not hash then return; end | |
28 module:log("debug", "Received new hash: %s", hash); | |
29 banned_hashes[hash] = hash; | |
30 end; | |
31 | |
32 on_retract = function (event) | |
33 local hash = event.item.attr.id; | |
34 if not hash then return; end | |
35 module:log("debug", "Retracted hash: %s", hash); | |
36 banned_hashes[hash] = nil; | |
37 end; | |
38 }); | |
39 | |
40 module:hook("muc-occupant-pre-join", function (event) | |
41 local from_bare = jid.bare(event.stanza.attr.from); | |
42 local hash = sha256(jid.bare(event.stanza.attr.from), true); | |
43 if banned_hashes[hash] then | |
44 module:log("info", "Blocked user <%s> from room <%s> due to RTBL match", from_bare, event.stanza.attr.to); | |
45 local error_reply = st.error_reply(event.stanza, "cancel", "forbidden", "You are banned from this service", event.room.jid); | |
46 event.origin.send(error_reply); | |
47 return true; | |
48 end | |
49 end); |