|
@@ -0,0 +1,27 @@
|
|
1
|
+-- Restricts access to a muc component to certain domains
|
|
2
|
+-- Copyright (C) 2023-present 8x8, Inc.
|
|
3
|
+
|
|
4
|
+-- a list of (authenticated)domains that can access rooms(send presence)
|
|
5
|
+local whitelist = module:get_option_set("muc_filter_whitelist");
|
|
6
|
+
|
|
7
|
+if not whitelist then
|
|
8
|
+ module:log("warn", "No 'muc_filter_whitelist' option set, disabling muc_filter_access, plugin inactive");
|
|
9
|
+ return
|
|
10
|
+end
|
|
11
|
+
|
|
12
|
+local jid_split = require "util.jid".split;
|
|
13
|
+
|
|
14
|
+local function incoming_presence_filter(event)
|
|
15
|
+ local stanza = event.stanza;
|
|
16
|
+ local _, domain, _ = jid_split(stanza.attr.from);
|
|
17
|
+
|
|
18
|
+ if not stanza.attr.from or not whitelist:contains(domain) then
|
|
19
|
+ -- Filter presence
|
|
20
|
+ module:log("error", "Filtering unauthorized presence: %s", stanza:top_tag());
|
|
21
|
+ return true;
|
|
22
|
+ end
|
|
23
|
+end
|
|
24
|
+
|
|
25
|
+for _, jid_type in ipairs({ "host", "bare", "full" }) do
|
|
26
|
+ module:hook("presence/"..jid_type, incoming_presence_filter, 2000);
|
|
27
|
+end
|