Mercurial > prosody-modules
annotate mod_muc_auto_role/mod_muc_auto_role.lua @ 6478:bd785f524fd2
mod_s2s_v6mesh: Fix various bugs, s2s auth policies now work as expected
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 18 Mar 2026 18:54:30 +0000 |
| parents | c41615686ce4 |
| children | fb7902f66c36 |
| rev | line source |
|---|---|
|
6422
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local jid = require "prosody.util.jid"; |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local xmlns_aff = "urn:xmpp:raa:0"; |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local raa_servers = module:get_option_set("muc_auto_role_trusted_servers", {}); |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 local trust_threshold = module:get_option_integer("muc_auto_role_trust_threshold", 51, 0, 100); |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 local untrusted_servers = module:get_option_set("muc_auto_role_untrusted_servers", {}); |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local default_role = module:get_option_enum("muc_default_role", "visitor", "participant"); |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 -- TODO: This should be a config option in mod_muc |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 module:hook("muc-get-default-role", function () |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 return default_role; |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 end, 5); |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 module:hook("muc-occupant-pre-join", function (event) |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local stanza = event.stanza; |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local from_host = jid.host(stanza.attr.from); |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 if untrusted_servers:contains(from_host) then |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 event.occupant.role = "visitor"; |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 end |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 if not raa_servers:contains(from_host) then |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 return; |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 end |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local raa = stanza:get_child("info", xmlns_aff); |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 if not raa then |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 return; |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local aff = raa.attr.affiliation; |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local trust = tonumber(raa.attr.trust) or 50; |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 if aff == "member" or aff == "admin" or trust >= trust_threshold then |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 event.occupant.role = "participant"; |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 else |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 event.occupant.role = "visitor"; |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 end |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 module:log("debug", "Assigning <%s> role '%s' due to affiliation %s and trust score %d of <%s>", |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 event.occupant.nick, event.occupant.role, aff, trust, stanza.attr.from |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 ); |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 |
|
c41615686ce4
mod_muc_auto_role: Set default role for MUC occupants based on policies
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 end); |
