Mercurial > prosody-modules
annotate mod_s2s_blacklist/mod_s2s_blacklist.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 |
parents | d958558e0058 |
children |
rev | line source |
---|---|
1179
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local st = require "util.stanza"; |
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
1325
b21236b6b8d8
Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents:
1324
diff
changeset
|
3 local blacklist = module:get_option_inherited_set("s2s_blacklist", {}); |
1179
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 module:hook("route/remote", function (event) |
1325
b21236b6b8d8
Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents:
1324
diff
changeset
|
6 if blacklist:contains(event.to_host) then |
2893
d958558e0058
mod_s2s_blacklist: Don't send error replies for error stanzas
Kim Alvefur <zash@zash.se>
parents:
1325
diff
changeset
|
7 if event.stanza.attr.type ~= "error" then |
d958558e0058
mod_s2s_blacklist: Don't send error replies for error stanzas
Kim Alvefur <zash@zash.se>
parents:
1325
diff
changeset
|
8 module:send(st.error_reply(event.stanza, "cancel", "not-allowed", "Communication with this domain is restricted")); |
d958558e0058
mod_s2s_blacklist: Don't send error replies for error stanzas
Kim Alvefur <zash@zash.se>
parents:
1325
diff
changeset
|
9 end |
1179
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 return true; |
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 end |
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 end, 100); |
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 |
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 module:hook("s2s-stream-features", function (event) |
1325
b21236b6b8d8
Backed out changeset 853a382c9bd6
Kim Alvefur <zash@zash.se>
parents:
1324
diff
changeset
|
15 if blacklist:contains(event.origin.from_host) then |
1179
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 event.origin:close({ |
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 condition = "policy-violation"; |
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 text = "Communication with this domain is restricted"; |
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 }); |
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
27b4e01ddbc4
mod_s2s_blacklist: A new _simple_ s2s blacklist module
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 end, 1000); |