annotate mod_report_affiliations/mod_report_affiliations.lua @ 6319:04c3273cb81f

mod_auth_cyrus: Add empty 'profile' table to SASL handler objects This is for compatibility with Prosody's built-in util.sasl objects. A SASL profile table usually includes methods supported by the backend, which can be used by SASL mechanism handlers to perform operations (such as testing the password). It also optionally contains a 'cb' field with channel binding method handlers. The Cyrus backend doesn't support channel binding, and doesn't have the same concept of auth backend methods (it handles all that internally, and Prosody has no insight or control over it). Thus, we create an empty profile which informs Prosody that the SASL handler does not support any of the auth or channel binding methods. Some features will not work, but they didn't work anyway. This just makes it explicit. This fixes a traceback in mod_sasl2_fast, which expected SASL handlers to always contain a 'profile' field.
author Matthew Wild <mwild1@gmail.com>
date Thu, 04 Sep 2025 10:14:46 +0100
parents e905ef16efb7
children a41d5d511948
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6030
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local dt = require "util.datetime";
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local jid = require "util.jid";
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local st = require "util.stanza";
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local rm = require "core.rostermanager";
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 local um = require "core.usermanager";
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local traits = module:require("traits");
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local xmlns_aff = "urn:xmpp:raa:0";
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local is_host_anonymous = module:get_option_string("authentication") == "anonymous";
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local trusted_servers = module:get_option_inherited_set("report_affiliations_trusted_servers", {});
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 local roles = {
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 -- These affiliations are defined by XEP-0489, and we map a set of Prosody roles to each one
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 admin = module:get_option_set("report_affiliations_admin_roles", { "prosody:admin", "prosody:operator" });
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 member = module:get_option_set("report_affiliations_member_roles", { "prosody:member" });
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 registered = module:get_option_set("report_affiliations_registered", { "prosody:user", "prosody:registered" });
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 guest = module:get_option_set("report_affiliations_anonymous", { "prosody:guest" });
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 };
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 -- Map of role to affiliation
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local role_affs = {
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 -- [role (e.g. "prosody:guest")] = affiliation ("admin"|"member"|"registered"|"guest");
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 };
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 --Build the role->affiliation map based on the config
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 for aff, aff_roles in pairs(roles) do
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 for role in aff_roles do
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 role_affs[role] = aff;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 local account_details_store = module:open_store("account_details");
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 local lastlog2_store = module:open_store("lastlog2");
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 module:add_feature(xmlns_aff);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 module:add_feature(xmlns_aff.."#embed-presence-sub");
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 module:add_feature(xmlns_aff.."#embed-presence-directed");
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 local function get_registered_timestamp(username)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 if um.get_account_info then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 local ts = um.get_account_info(username, module.host);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 if ts then return ts.created; end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 local account_details = account_details_store:get(username);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 if account_details and account_details.registered then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 return account_details.registered;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 local lastlog2 = lastlog2_store:get(username);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 if lastlog2 and lastlog2.registered then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 return lastlog2.registered.timestamp;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 return nil;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 local function get_trust_score(username)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 return math.floor(100 * (1 - traits.get_probability_bad(username)));
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 local function get_account_type(username)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 if is_host_anonymous then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 return "anonymous";
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 if not um.get_user_role then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 return "registered"; -- COMPAT w/0.12
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 local user_role = um.get_user_role(username, module.host);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 return role_affs[user_role] or "registered";
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 function get_info_element(username)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 local account_type = get_account_type(username);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 local since, trust;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 if account_type == "registered" then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 since = get_registered_timestamp(username);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 trust = get_trust_score(username);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 return st.stanza("info", {
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 affiliation = account_type;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 since = since and dt.datetime(since - (since%86400)) or nil;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 trust = ("%d"):format(trust);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 xmlns = xmlns_aff;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 });
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 -- Outgoing presence
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 local function embed_in_outgoing_presence(pres_type)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 return function (event)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 local origin, stanza = event.origin, event.stanza;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 stanza:remove_children("info", xmlns_aff);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 -- Unavailable presence is pretty harmless, and blocking it may cause
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 -- weird issues.
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 if (pres_type == "bare" and stanza.attr.type == "unavailable")
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 or (pres_type == "full" and stanza.attr.type ~= nil) then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 return;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 -- Only attach info to stanzas sent to "strangers" (users that have not
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 -- approved us to see their presence)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 if rm.is_user_subscribed(origin.username, origin.host, stanza.attr.to) then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 return;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 local info = get_info_element(origin.username);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 if not info then return; end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 stanza:add_direct_child(info);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 end;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 module:hook("pre-presence/bare", embed_in_outgoing_presence("bare"));
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 module:hook("pre-presence/full", embed_in_outgoing_presence("full"));
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 -- Handle direct queries
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 local function should_permit_query(from_jid, to_username) --luacheck: ignore 212/to_username
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 local from_node, from_host = jid.split(from_jid);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 if from_node then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 return false;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 -- Who should we respond to?
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 -- Only respond to domains
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 -- Does user have a JID with this domain in directed presence? (doesn't work with bare JIDs)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 -- Does this user have a JID with domain in pending subscription requests?
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 if trusted_servers:contains(from_host) then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 return true;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 return false;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 module:hook("iq-get/bare/urn:xmpp:raa:0:query", function (event)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 local origin, stanza = event.origin, event.stanza;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 local username = jid.node(stanza.attr.to);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 if not should_permit_query(stanza.attr.from, username) then
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 origin.send(st.error_reply(stanza, "auth", "forbidden"));
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 return true;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 end
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 local info = get_info_element(username);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 local reply = st.reply(stanza)
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 :add_child(info);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 origin.send(reply);
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 return true;
e905ef16efb7 mod_report_affiliations: New module for XEP-0489: Reporting Account Affiliations
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 end);