"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7316/resources/prosody-plugins/mod_muc_password_whitelist.lua" (5 Jun 2023, 1799 Bytes) of package /linux/misc/jitsi-meet-7316.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lua source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 --- AUTHOR: https://gist.github.com/legastero Lance Stout
2 local jid_split = require "util.jid".split;
3 local whitelist = module:get_option_set("muc_password_whitelist");
4
5 local MUC_NS = "http://jabber.org/protocol/muc";
6
7
8 module:hook("muc-occupant-pre-join", function (event)
9 local room, stanza = event.room, event.stanza;
10
11 local user, domain, res = jid_split(event.stanza.attr.from);
12
13 --no user object means no way to check whitelist
14 if user == nil then
15 return
16 end
17
18 if not whitelist then
19 return;
20 end
21 if not whitelist:contains(domain) and not whitelist:contains(user..'@'..domain) then
22 return;
23 end
24
25 local join = stanza:get_child("x", MUC_NS);
26 if not join then
27 join = stanza:tag("x", { xmlns = MUC_NS });
28 end
29
30 local password = join:get_child("password", MUC_NS);
31 if password then
32 -- removes <password... node,
33 -- seems like password:text( appends text, not replacing it
34 join:maptags(
35 function(tag)
36 for k, v in pairs(tag) do
37 if k == "name" and v == "password" then
38 return nil
39 end
40 end
41 return tag
42 end
43 );
44
45 end
46
47 join:tag("password", { xmlns = MUC_NS }):text(room:get_password());
48
49 module:log("debug", "Applied password access whitelist for %s in room %s", event.stanza.attr.from, room.jid);
50 end, -7); --- Run before the password check (priority -20), runs after lobby(priority -4) and members-only (priority -5).
51
52
53 module:hook_global("config-reloaded", function (event)
54 module:log("debug", "Reloading MUC password access whitelist");
55 whitelist = module:get_option_set("muc_password_whitelist");
56 end)