annotate mod_mam_adhoc/mod_mam_adhoc.lua @ 6082:1a6cd0bbb7ab

mod_compliance_2023: Add 2023 Version of the compliance module, basis is the 2021 Version. diff --git a/mod_compliance_2023/README.md b/mod_compliance_2023/README.md new file mode 100644 --- /dev/null +++ b/mod_compliance_2023/README.md @@ -0,0 +1,22 @@ +--- +summary: XMPP Compliance Suites 2023 self-test +labels: +- Stage-Beta +rockspec: + dependencies: + - mod_cloud_notify + +... + +Compare the list of enabled modules with +[XEP-0479: XMPP Compliance Suites 2023] and produce basic report to the +Prosody log file. + +If installed with the Prosody plugin installer then all modules needed for a green checkmark should be included. (With prosody 0.12 only [mod_cloud_notify] is not included with prosody and we need the community module) + +# Compatibility + + Prosody-Version Status + --------------- ---------------------- + trunk Works as of 2024-12-21 + 0.12 Works diff --git a/mod_compliance_2023/mod_compliance_2023.lua b/mod_compliance_2023/mod_compliance_2023.lua new file mode 100644 --- /dev/null +++ b/mod_compliance_2023/mod_compliance_2023.lua @@ -0,0 +1,79 @@ +-- Copyright (c) 2021 Kim Alvefur +-- +-- This module is MIT licensed. + +local hostmanager = require "core.hostmanager"; + +local array = require "util.array"; +local set = require "util.set"; + +local modules_enabled = module:get_option_inherited_set("modules_enabled"); + +for host in pairs(hostmanager.get_children(module.host)) do + local component = module:context(host):get_option_string("component_module"); + if component then + modules_enabled:add(component); + modules_enabled:include(module:context(host):get_option_set("modules_enabled", {})); + end +end + +local function check(suggested, alternate, ...) + if set.intersection(modules_enabled, set.new({suggested; alternate; ...})):empty() then return suggested; end + return false; +end + +local compliance = { + array {"Server"; check("tls"); check("disco")}; + + array {"Advanced Server"; check("pep", "pep_simple")}; + + array {"Web"; check("bosh"); check("websocket")}; + + -- No Server requirements for Advanced Web + + array {"IM"; check("vcard_legacy", "vcard"); check("carbons"); check("http_file_share", "http_upload")}; + + array { + "Advanced IM"; + check("vcard_legacy", "vcard"); + check("blocklist"); + check("muc"); + check("private"); + check("smacks"); + check("mam"); + check("bookmarks"); + }; + + array {"Mobile"; check("smacks"); check("csi_simple", "csi_battery_saver")}; + + array {"Advanced Mobile"; check("cloud_notify")}; + + array {"A/V Calling"; check("turn_external", "external_services", "turncredentials", "extdisco")}; + +}; + +function check_compliance() + local compliant = true; + for _, suite in ipairs(compliance) do + local section = suite:pop(1); + if module:get_option_boolean("compliance_" .. section:lower():gsub("%A", "_"), true) then + local missing = set.new(suite:filter(function(m) return type(m) == "string" end):map(function(m) return "mod_" .. m end)); + if suite[1] then + if compliant then + compliant = false; + module:log("warn", "Missing some modules for XMPP Compliance 2023"); + end + module:log("info", "%s Compliance: %s", section, missing); + end + end + end + + if compliant then module:log("info", "XMPP Compliance 2023: Compliant ✔️"); end +end + +if prosody.start_time then + check_compliance() +else + module:hook_global("server-started", check_compliance); +end +
author Menel <menel@snikket.de>
date Sun, 22 Dec 2024 16:06:28 +0100
parents 27b41ee61601
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
714
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 module:depends"adhoc";
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local dataforms_new = require "util.dataforms".new;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local jid_split = require "util.jid".split;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local t_insert = table.insert;
1115
91d210b6106a mod_mam_adhoc: Use mod_mam/mamprefs.lib
Kim Alvefur <zash@zash.se>
parents: 739
diff changeset
5 local prefs = module:require"mod_mam/mamprefs";
91d210b6106a mod_mam_adhoc: Use mod_mam/mamprefs.lib
Kim Alvefur <zash@zash.se>
parents: 739
diff changeset
6 local set_prefs, get_prefs = prefs.set, prefs.get;
714
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local mam_prefs_form = dataforms_new{
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 title = "Archive preferences";
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 --instructions = "";
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 name = "default",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 label = "Default storage policy",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 type = "list-single",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 value = {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 { value = "always", label = "Always" },
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 { value = "never", label = "Never", default = true},
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 { value = "roster", label = "Roster" },
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 },
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 name = "always",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 label = "Always store messages to/from",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 type = "jid-multi"
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 name = "never",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 label = "Never store messages to/from",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 type = "jid-multi"
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 local host = module.host;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 local default_attrs = {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 always = true, [true] = "always",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 never = false, [false] = "never",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 roster = "roster",
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 }
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 local function mam_prefs_handler(self, data, state)
1147
27b41ee61601 mod_mam_adhoc: Use the new adhoc permission level for local users
Kim Alvefur <zash@zash.se>
parents: 1115
diff changeset
42 local username = jid_split(data.from);
714
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 if state then -- the second return value
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 if data.action == "cancel" then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 return { status = "canceled" };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 local fields = mam_prefs_form:data(data.form);
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 local default, always, never = fields.default, fields.always, fields.never;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 local prefs = {};
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 if default then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 prefs[false] = default_attrs[default];
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 if always then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 for i=1,#always do
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 prefs[always[i]] = true;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 if never then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 for i=1,#never do
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 prefs[never[i]] = false;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 set_prefs(username, prefs);
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 return { status = "completed" }
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 else -- No state, send the form.
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 local prefs = get_prefs(username);
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 local values = {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 default = {
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 { value = "always", label = "Always" };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 { value = "never", label = "Never" };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 { value = "roster", label = "Roster" };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 always = {};
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 never = {};
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 };
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 for jid, p in pairs(prefs) do
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 if jid then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 t_insert(values[p and "always" or "never"], jid);
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 elseif p == true then -- Yes, this is ugly. FIXME later.
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 values.default[1].default = true;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 elseif p == false then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 values.default[2].default = true;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 elseif p == "roster" then
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 values.default[3].default = true;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 return { status = "executing", actions = { "complete" }, form = { layout = mam_prefs_form, values = values } }, true;
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 end
5879368d9ff7 mod_mam_adhoc: New module that allows clients to change MAM preferences through AdHoc.
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96
1147
27b41ee61601 mod_mam_adhoc: Use the new adhoc permission level for local users
Kim Alvefur <zash@zash.se>
parents: 1115
diff changeset
97 module:provides("adhoc", module:require"adhoc".new("Archive settings", "urn:xmpp:mam#configure", mam_prefs_handler, "local_user"));