瀏覽代碼

feat: Module to restrict muc access.

factor2
damencho 2 年之前
父節點
當前提交
67a9f35176
共有 1 個檔案被更改,包括 27 行新增0 行删除
  1. 27
    0
      resources/prosody-plugins/mod_muc_filter_access.lua

+ 27
- 0
resources/prosody-plugins/mod_muc_filter_access.lua 查看文件

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

Loading…
取消
儲存