annotate mod_file_management/mod_file_management.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 d43623bdf91b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3663
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 -- mod_file_management
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 --
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 -- Copyright (C) 2019 Emmanuel Gil Peyrot
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 --
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 -- This file is MIT/X11 licensed.
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 --
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 module:depends("http_upload");
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9 local dataform_new = require "util.dataforms".new;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 local adhoc_new = module:require "adhoc".new;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 local adhoc_simple_form = require "util.adhoc".new_simple_form;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 local adhoc_initial_data_form = require "util.adhoc".new_initial_data_form;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 local url = require "socket.url";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 local lfs = require "lfs";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 local datamanager = require "util.datamanager";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 local jid_prepped_split = require "util.jid".prepped_split;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 local join_path = require "util.paths".join;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 local t_concat = table.concat;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19 local t_insert = table.insert;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 local storage_path = module:get_option_string("http_upload_path", join_path(prosody.paths.data, "http_upload"));
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 local function get_url(dir, filename)
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 local slot_url = url.parse(module:http_url("upload"));
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 slot_url.path = url.parse_path(slot_url.path or "/");
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 t_insert(slot_url.path, dir);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27 t_insert(slot_url.path, filename);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 slot_url.path.is_directory = false;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 slot_url.path = url.build_path(slot_url.path);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 return url.build(slot_url);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 local list_form = dataform_new {
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34 title = "List files for user";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 instructions = "Select the JID of a user to list the files they have uploaded.";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 {
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 type = "hidden";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 name = "FORM_TYPE";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 value = "http://prosody.im/protocol/file_management#list";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 {
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 type = "jid-single";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43 name = "accountjid";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 required = true;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 label = "JID";
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46 };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49 module:provides("adhoc", adhoc_new("File Management", "http://prosody.im/protocol/file_management#list", adhoc_simple_form(list_form, function (data, errors)
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 if errors then
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 local errmsg = {};
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 for name, text in pairs(errors) do
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 errmsg[#errmsg + 1] = name .. ": " .. text;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 return { status = "completed", error = { message = t_concat(errmsg, "\n") } };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 local jid = data.accountjid;
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 local user, host = jid_prepped_split(jid);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 local uploads, err = datamanager.list_load(user, host, "http_upload");
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 if err then
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 return { status = "completed", error = "File upload data not found for user "..jid.."." };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66 local result = {};
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 for i, upload in ipairs(uploads) do
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 module:log("debug", "http_upload_management#list %d %q", i, upload);
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 if upload.dir ~= nil then
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 t_insert(result, get_url(upload.dir, upload.filename));
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 else
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 -- upload.filename was pointing to a path on the file system…
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 -- TODO: Try to guess the URL from that.
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 end
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 return { status = "completed", info = t_concat(result, "\n") };
d43623bdf91b mod_upload_file_management: Add this new module, for now only listing files uploaded by a user as an admin.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 end), "admin"));