Annotate

mod_atom/mod_atom.lua @ 6110: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
parent 3573:5dd505c39c4b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2294
4915b8223b07 mod_atom: Expose Microbloging PEP data over HTTP
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- HTTP Access to PEP -> microblog
4915b8223b07 mod_atom: Expose Microbloging PEP data over HTTP
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 -- By Kim Alvefur <zash@zash.se>
4915b8223b07 mod_atom: Expose Microbloging PEP data over HTTP
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
3241
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
4 local mod_pep = module:depends"pep";
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
5
3424
6ae875c98daf mod_atom: Check whether user exists
Kim Alvefur <zash@zash.se>
parents: 3423
diff changeset
6 local um = require "core.usermanager";
2294
4915b8223b07 mod_atom: Expose Microbloging PEP data over HTTP
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local nodeprep = require "util.encodings".stringprep.nodeprep;
4915b8223b07 mod_atom: Expose Microbloging PEP data over HTTP
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local st = require "util.stanza";
3432
61368aec97d6 mod_atom: Apply nodeprep via redirect for cache-friendlyness
Kim Alvefur <zash@zash.se>
parents: 3424
diff changeset
9 local urlencode = require "util.http".urlencode;
2294
4915b8223b07 mod_atom: Expose Microbloging PEP data over HTTP
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
3241
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
11 module:depends("http")
2294
4915b8223b07 mod_atom: Expose Microbloging PEP data over HTTP
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 module:provides("http", {
4915b8223b07 mod_atom: Expose Microbloging PEP data over HTTP
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 route = {
3241
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
14 ["GET /*"] = function (event, user)
3573
5dd505c39c4b mod_atom: Return a message instead of 404 for root path
Kim Alvefur <zash@zash.se>
parents: 3432
diff changeset
15 if user == "" then
5dd505c39c4b mod_atom: Return a message instead of 404 for root path
Kim Alvefur <zash@zash.se>
parents: 3432
diff changeset
16 return [[<h1>Hello from mod_atom</h1><p>This module provides access to public microblogs of local users.</p>]];
5dd505c39c4b mod_atom: Return a message instead of 404 for root path
Kim Alvefur <zash@zash.se>
parents: 3432
diff changeset
17 end;
5dd505c39c4b mod_atom: Return a message instead of 404 for root path
Kim Alvefur <zash@zash.se>
parents: 3432
diff changeset
18
3423
4a8fa0364f35 mod_atom: Unpack event object
Kim Alvefur <zash@zash.se>
parents: 3276
diff changeset
19 local request, response = event.request, event.response;
4a8fa0364f35 mod_atom: Unpack event object
Kim Alvefur <zash@zash.se>
parents: 3276
diff changeset
20 local actor = request.ip;
3241
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
21
3432
61368aec97d6 mod_atom: Apply nodeprep via redirect for cache-friendlyness
Kim Alvefur <zash@zash.se>
parents: 3424
diff changeset
22 local prepped = nodeprep(user);
61368aec97d6 mod_atom: Apply nodeprep via redirect for cache-friendlyness
Kim Alvefur <zash@zash.se>
parents: 3424
diff changeset
23 if not prepped then return 400; end
61368aec97d6 mod_atom: Apply nodeprep via redirect for cache-friendlyness
Kim Alvefur <zash@zash.se>
parents: 3424
diff changeset
24 if prepped ~= user then
61368aec97d6 mod_atom: Apply nodeprep via redirect for cache-friendlyness
Kim Alvefur <zash@zash.se>
parents: 3424
diff changeset
25 response.headers.location = module:http_url() .. "/" .. urlencode(prepped);
61368aec97d6 mod_atom: Apply nodeprep via redirect for cache-friendlyness
Kim Alvefur <zash@zash.se>
parents: 3424
diff changeset
26 return 302;
61368aec97d6 mod_atom: Apply nodeprep via redirect for cache-friendlyness
Kim Alvefur <zash@zash.se>
parents: 3424
diff changeset
27 end
3424
6ae875c98daf mod_atom: Check whether user exists
Kim Alvefur <zash@zash.se>
parents: 3423
diff changeset
28 if not um.user_exists(user, module.host) then
6ae875c98daf mod_atom: Check whether user exists
Kim Alvefur <zash@zash.se>
parents: 3423
diff changeset
29 return 404;
6ae875c98daf mod_atom: Check whether user exists
Kim Alvefur <zash@zash.se>
parents: 3423
diff changeset
30 end
3241
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
31
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
32 local pubsub_service = mod_pep.get_pep_service(user);
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
33 local ok, items = pubsub_service:get_items("urn:xmpp:microblog:0", actor);
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
34 if ok then
3423
4a8fa0364f35 mod_atom: Unpack event object
Kim Alvefur <zash@zash.se>
parents: 3276
diff changeset
35 response.headers.content_type = "application/xml";
3272
119e22ccd64a mod_atom: Add some basic metadata to feed
Kim Alvefur <zash@zash.se>
parents: 3241
diff changeset
36 local feed = st.stanza("feed", { xmlns = "http://www.w3.org/2005/Atom" })
119e22ccd64a mod_atom: Add some basic metadata to feed
Kim Alvefur <zash@zash.se>
parents: 3241
diff changeset
37 :text_tag("generator", "Prosody", { uri = "xmpp:prosody.im", version = prosody.version })
3274
2acfb45fd9ec mod_atom: Expose title and description from node metadata in feed
Kim Alvefur <zash@zash.se>
parents: 3273
diff changeset
38 :text_tag("title", pubsub_service.nodes["urn:xmpp:microblog:0"].config.title or "Microblog feed")
2acfb45fd9ec mod_atom: Expose title and description from node metadata in feed
Kim Alvefur <zash@zash.se>
parents: 3273
diff changeset
39 :text_tag("subtitle", pubsub_service.nodes["urn:xmpp:microblog:0"].config.description)
3272
119e22ccd64a mod_atom: Add some basic metadata to feed
Kim Alvefur <zash@zash.se>
parents: 3241
diff changeset
40 :tag("author")
119e22ccd64a mod_atom: Add some basic metadata to feed
Kim Alvefur <zash@zash.se>
parents: 3241
diff changeset
41 :text_tag("name", user)
3273
78888f4ec7e3 mod_atom: Add node as portablecontacts preferredUsername
Kim Alvefur <zash@zash.se>
parents: 3272
diff changeset
42 :text_tag("preferredUsername", user, { xmlns = "http://portablecontacts.net/spec/1.0" });
3275
25b4cad8fee4 mod_atom: Include User Nickname (if configured to be public)
Kim Alvefur <zash@zash.se>
parents: 3274
diff changeset
43 local ok, _, nick = pubsub_service:get_last_item("http://jabber.org/protocol/nick", actor);
25b4cad8fee4 mod_atom: Include User Nickname (if configured to be public)
Kim Alvefur <zash@zash.se>
parents: 3274
diff changeset
44 if ok and nick then
25b4cad8fee4 mod_atom: Include User Nickname (if configured to be public)
Kim Alvefur <zash@zash.se>
parents: 3274
diff changeset
45 feed:text_tag("displayName", nick.tags[1][1], { xmlns = "http://portablecontacts.net/spec/1.0" });
25b4cad8fee4 mod_atom: Include User Nickname (if configured to be public)
Kim Alvefur <zash@zash.se>
parents: 3274
diff changeset
46 end
3272
119e22ccd64a mod_atom: Add some basic metadata to feed
Kim Alvefur <zash@zash.se>
parents: 3241
diff changeset
47
119e22ccd64a mod_atom: Add some basic metadata to feed
Kim Alvefur <zash@zash.se>
parents: 3241
diff changeset
48 feed:reset();
119e22ccd64a mod_atom: Add some basic metadata to feed
Kim Alvefur <zash@zash.se>
parents: 3241
diff changeset
49
3241
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
50 for i = #items, 1, -1 do
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
51 feed:add_direct_child(items[items[i]].tags[1]);
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
52 end
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
53 return tostring(feed);
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
54 elseif items == "forbidden" then
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
55 return 403;
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
56 elseif items == "item-not-found" then
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
57 return 404;
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
58 end
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
59 end;
4b52cafd5811 mod_atom: Update to the new mod_pep
Kim Alvefur <zash@zash.se>
parents: 2294
diff changeset
60 }
2294
4915b8223b07 mod_atom: Expose Microbloging PEP data over HTTP
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 });