Mercurial > prosody-modules
annotate mod_block_s2s_subscriptions/mod_block_s2s_subscriptions.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 | 70ff25db37fa |
children |
rev | line source |
---|---|
775
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local jid_split = require "util.jid".split; |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local jid_bare = require "util.jid".bare; |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local load_roster = require "core.rostermanager".load_roster; |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local blocked_servers = module:get_option_set("block_s2s_subscriptions")._items; |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 function filter_presence(event) |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 if blocked_servers[event.origin.from_host] and event.stanza.attr.type == "subscribe" then |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local stanza = event.stanza; |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local to_user, to_host = jid_split(stanza.attr.to); |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local roster = load_roster(to_user, to_host); |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 if roster and roster[jid_bare(stanza.attr.from)] then |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 return; -- In roster, pass through |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 end |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 return true; -- Drop |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
70ff25db37fa
mod_block_s2s_subscriptions: New module to block incoming presence subscriptions from non-contacts on selected remote hosts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 module:hook("presence/bare", filter_presence, 200); -- Client receiving |