Annotate

mod_muc_rtbl/mod_muc_rtbl.lua @ 5173:460f78654864

mod_muc_rtbl: also filter messages This was a bit tricky because we don't want to run the JIDs through SHA256 on each message. Took a while to come up with this simple plan of just caching the SHA256 of the JIDs on the occupants. This will leave some dirt in the occupants after unloading the module, but that should be ok; once they cycle the room, the hashes will be gone. This is direly needed, otherwise, there is a tight race between the moderation activities and the actors joining the room.
author Jonas Schäfer <jonas@wielicki.name>
date Tue, 21 Feb 2023 21:37:27 +0100
parent 4813:0a257d1402c3
child 5174:354832098f2f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4808
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
1 local array = require "util.array";
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
2 local it = require "util.iterators";
4807
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local jid = require "util.jid";
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local sha256 = require "util.hashes".sha256;
4808
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
5 local set = require "util.set";
4807
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local st = require "util.stanza";
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local rtbl_service_jid = assert(module:get_option_string("muc_rtbl_jid"), "No RTBL JID supplied");
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local rtbl_node = module:get_option_string("muc_rtbl_node", "muc_bans_sha256");
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local banned_hashes = module:shared("banned_hashes");
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 module:depends("pubsub_subscription");
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 module:add_item("pubsub-subscription", {
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 service = rtbl_service_jid;
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 node = rtbl_node;
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 -- Callbacks:
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 on_subscribed = function()
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 module:log("info", "RTBL active");
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 end;
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 on_error = function(err)
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 module:log("error", "Failed to subscribe to RTBL: %s::%s: %s", err.type, err.condition, err.text);
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 end;
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 on_item = function(event)
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 local hash = event.item.attr.id;
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 if not hash then return; end
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 module:log("debug", "Received new hash: %s", hash);
4808
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
32 banned_hashes[hash] = true;
4807
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 end;
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 on_retract = function (event)
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 local hash = event.item.attr.id;
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 if not hash then return; end
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 module:log("debug", "Retracted hash: %s", hash);
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 banned_hashes[hash] = nil;
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 end;
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 });
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
4808
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
43 function request_list()
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
44 local items_request = st.iq({ to = rtbl_service_jid, from = module.host, type = "get", id = "rtbl-request" })
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
45 :tag("pubsub", { xmlns = "http://jabber.org/protocol/pubsub" })
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
46 :tag("items", { node = rtbl_node }):up()
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
47 :up();
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
48
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
49 module:send(items_request);
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
50 end
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
51
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
52 function update_list(event)
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
53 local from_jid = event.stanza.attr.from;
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
54 if from_jid ~= rtbl_service_jid then
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
55 module:log("debug", "Ignoring RTBL response from unknown sender");
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
56 return;
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
57 end
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
58 local items_el = event.stanza:find("{http://jabber.org/protocol/pubsub}pubsub/items");
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
59 if not items_el then
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
60 module:log("warn", "Invalid items response from RTBL service");
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
61 return;
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
62 end
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
63
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
64 local old_entries = set.new(array.collect(it.keys(banned_hashes)));
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
65
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
66 local n_added, n_removed, n_total = 0, 0, 0;
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
67 for item in items_el:childtags("item") do
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
68 local hash = item.attr.id;
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
69 if hash then
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
70 n_total = n_total + 1;
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
71 if not old_entries:contains(hash) then
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
72 -- New entry
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
73 n_added = n_added + 1;
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
74 banned_hashes[hash] = true;
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
75 else
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
76 -- Entry already existed
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
77 old_entries:remove(hash);
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
78 end
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
79 end
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
80 end
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
81
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
82 -- Remove old entries that weren't in the received list
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
83 for hash in old_entries do
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
84 n_removed = n_removed + 1;
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
85 banned_hashes[hash] = nil;
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
86 end
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
87
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
88 module:log("info", "%d RTBL entries received from %s (%d added, %d removed)", n_total, from_jid, n_added, n_removed);
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
89 return true;
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
90 end
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
91
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
92 module:hook("iq-result/host/rtbl-request", update_list);
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
93
5173
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
94 function update_hashes(occupant)
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
95 if not occupant.mod_muc_rtbl_bare_hash then
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
96 local bare_hash = sha256(jid.bare(event.stanza.attr.from), true);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
97 occupant.mod_muc_rtbl_bare_hash = bare_hash;
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
98 end
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
99 if not occupant.mod_muc_rtbl_host_hash then
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
100 local host_hash = sha256(jid.host(event.stanza.attr.from), true);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
101 event.occupant.mod_muc_rtbl_host_hash = host_hash;
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
102 end
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
103 end
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
104
4807
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 module:hook("muc-occupant-pre-join", function (event)
4813
0a257d1402c3 mod_muc_rtbl: Optimize case with zero hashes
Kim Alvefur <zash@zash.se>
parents: 4812
diff changeset
106 if next(banned_hashes) == nil then return end
0a257d1402c3 mod_muc_rtbl: Optimize case with zero hashes
Kim Alvefur <zash@zash.se>
parents: 4812
diff changeset
107
4807
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 local from_bare = jid.bare(event.stanza.attr.from);
4810
181738ae4117 mod_muc_rtbl: Skip check if user has any explicit affiliation with the MUC
Matthew Wild <mwild1@gmail.com>
parents: 4809
diff changeset
109
181738ae4117 mod_muc_rtbl: Skip check if user has any explicit affiliation with the MUC
Matthew Wild <mwild1@gmail.com>
parents: 4809
diff changeset
110 local affiliation = event.room:get_affiliation(from_bare);
4811
a1fe59c06c48 mod_muc_rtbl: Fix typo in variable name in previous commit (thanks luacheck)
Matthew Wild <mwild1@gmail.com>
parents: 4810
diff changeset
111 if affiliation and affiliation ~= "none" then
4810
181738ae4117 mod_muc_rtbl: Skip check if user has any explicit affiliation with the MUC
Matthew Wild <mwild1@gmail.com>
parents: 4809
diff changeset
112 -- Skip check for affiliated users
181738ae4117 mod_muc_rtbl: Skip check if user has any explicit affiliation with the MUC
Matthew Wild <mwild1@gmail.com>
parents: 4809
diff changeset
113 return;
181738ae4117 mod_muc_rtbl: Skip check if user has any explicit affiliation with the MUC
Matthew Wild <mwild1@gmail.com>
parents: 4809
diff changeset
114 end
181738ae4117 mod_muc_rtbl: Skip check if user has any explicit affiliation with the MUC
Matthew Wild <mwild1@gmail.com>
parents: 4809
diff changeset
115
5173
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
116 update_hashes(event.occupant);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
117 if banned_hashes[event.occupant.mod_muc_rtbl_bare_hash] or banned_hashes[event.occupant.mod_muc_rtbl_host_hash] then
4807
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 module:log("info", "Blocked user <%s> from room <%s> due to RTBL match", from_bare, event.stanza.attr.to);
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 local error_reply = st.error_reply(event.stanza, "cancel", "forbidden", "You are banned from this service", event.room.jid);
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 event.origin.send(error_reply);
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 return true;
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 end
62a65c52c3f5 mod_muc_rtbl: Real-time blocklist checks for MUC services
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 end);
4808
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
124
5173
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
125 module:hook("muc-occupant-groupchat", function(event)
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
126 update_hashes(event.occupant);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
127 if banned_hashes[event.occupant.mod_muc_rtbl_bare_hash] or banned_hashes[event.occupant.mod_muc_rtbl_host_hash] then
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
128 module:log("debug", "Blocked message from user <%s> to room <%s> due to RTBL match", event.stanza.attr.from, event.stanza.attr.to);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
129 local error_reply = st.error_reply(event.stanza, "cancel", "forbidden", "You are banned from this service", event.room.jid);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
130 event.origin.send(error_reply);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
131 return true;
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
132 end
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
133 end);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
134
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
135 module:hook("muc-private-message", function(event)
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
136 local occupant = event.room:get_occupant_by_nick(event.stanza.attr.from);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
137 update_hashes(occupant);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
138 if banned_hashes[occupant.mod_muc_rtbl_bare_hash] or banned_hashes[occupant.mod_muc_rtbl_host_hash] then
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
139 module:log("debug", "Blocked private message from user <%s> from room <%s> due to RTBL match", occupant.bare_jid, event.stanza.attr.to);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
140 local error_reply = st.error_reply(event.stanza, "cancel", "forbidden", "You are banned from this service", event.room.jid);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
141 event.origin.send(error_reply);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
142 return true;
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
143 end
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
144 end);
460f78654864 mod_muc_rtbl: also filter messages
Jonas Schäfer <jonas@wielicki.name>
parents: 4813
diff changeset
145
4808
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
146 if prosody.start_time then
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
147 request_list();
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
148 else
4809
9e9ec0f0b128 mod_muc_rtbl: Fix to hook server-started globally, to fetch entries at startup (thanks mirux)
Matthew Wild <mwild1@gmail.com>
parents: 4808
diff changeset
149 module:hook_global("server-started", function ()
9e9ec0f0b128 mod_muc_rtbl: Fix to hook server-started globally, to fetch entries at startup (thanks mirux)
Matthew Wild <mwild1@gmail.com>
parents: 4808
diff changeset
150 request_list();
9e9ec0f0b128 mod_muc_rtbl: Fix to hook server-started globally, to fetch entries at startup (thanks mirux)
Matthew Wild <mwild1@gmail.com>
parents: 4808
diff changeset
151 end);
4808
8a63a0daf129 mod_muc_rtbl: Sync existing list entries when first loaded
Matthew Wild <mwild1@gmail.com>
parents: 4807
diff changeset
152 end