annotate mod_inotify_reload/mod_inotify_reload.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 82207f936f1f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
652
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- mod_inotify_reload
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- Reloads modules when their files change
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Depends on linotify: https://github.com/hoelzro/linotify
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 module:set_global();
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local inotify = require "inotify";
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 local modulemanager = require "core.modulemanager";
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local inh = inotify.init();
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local watches = {};
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local watch_ids = {};
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
5395
82207f936f1f mod_inotify_reload: Update to use FD watching method
Kim Alvefur <zash@zash.se>
parents: 744
diff changeset
15 require"net.server".watchfd(inh:fileno(), function()
82207f936f1f mod_inotify_reload: Update to use FD watching method
Kim Alvefur <zash@zash.se>
parents: 744
diff changeset
16 local events = inh:read();
82207f936f1f mod_inotify_reload: Update to use FD watching method
Kim Alvefur <zash@zash.se>
parents: 744
diff changeset
17 for _, event in ipairs(events) do
82207f936f1f mod_inotify_reload: Update to use FD watching method
Kim Alvefur <zash@zash.se>
parents: 744
diff changeset
18 local mod = watches[watch_ids[event.wd]];
82207f936f1f mod_inotify_reload: Update to use FD watching method
Kim Alvefur <zash@zash.se>
parents: 744
diff changeset
19 if mod then
82207f936f1f mod_inotify_reload: Update to use FD watching method
Kim Alvefur <zash@zash.se>
parents: 744
diff changeset
20 local host, name = mod.host, mod.name;
82207f936f1f mod_inotify_reload: Update to use FD watching method
Kim Alvefur <zash@zash.se>
parents: 744
diff changeset
21 module:log("debug", "Reloading changed module mod_%s on %s", name, host);
82207f936f1f mod_inotify_reload: Update to use FD watching method
Kim Alvefur <zash@zash.se>
parents: 744
diff changeset
22 modulemanager.reload(host, name);
82207f936f1f mod_inotify_reload: Update to use FD watching method
Kim Alvefur <zash@zash.se>
parents: 744
diff changeset
23 else
82207f936f1f mod_inotify_reload: Update to use FD watching method
Kim Alvefur <zash@zash.se>
parents: 744
diff changeset
24 module:log("warn", "no watch for %d", event.wd);
652
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 end
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 end
5395
82207f936f1f mod_inotify_reload: Update to use FD watching method
Kim Alvefur <zash@zash.se>
parents: 744
diff changeset
27 end);
652
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 function watch_module(name, host, path)
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 local id, err = inh:addwatch(path, inotify.IN_CLOSE_WRITE);
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 if not id then return nil, err; end
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 local k = host.."\0"..name;
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 watches[k] = { id = id, path = path, name = name, host = host };
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 watch_ids[id] = k;
744
ab988e98a9f9 mod_inotify_reload: Add debug logging
Matthew Wild <mwild1@gmail.com>
parents: 652
diff changeset
35 module:log("debug", "Watching %s:%s with id %d", name, host, id);
652
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 return true;
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 end
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 function unwatch_module(name, host)
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 local k = host.."\0"..name;
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 if not watches[k] then
744
ab988e98a9f9 mod_inotify_reload: Add debug logging
Matthew Wild <mwild1@gmail.com>
parents: 652
diff changeset
42 module:log("warn", "Not watching %s:%s", name, host);
652
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 return nil, "not-watching";
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 end
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 local id = watches[k].id;
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 local ok, err = inh:rmwatch(id);
744
ab988e98a9f9 mod_inotify_reload: Add debug logging
Matthew Wild <mwild1@gmail.com>
parents: 652
diff changeset
47 module:log("info", "Removed watch %d", id);
652
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 watches[k] = nil;
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 watch_ids[id] = nil;
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 return ok, err;
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 end
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 function module_loaded(event)
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 local host, name = event.host, event.module;
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 local path = modulemanager.get_module(host, name).module.path;
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 if not path then
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 module:log("warn", "Couldn't watch mod_%s, no path", name);
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 return;
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 end
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 if watch_module(name, host, path) then
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 module:log("debug", "Watching mod_%s", name);
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 end
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 end
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 function module_unloaded(event)
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 unwatch_module(event.module, event.host);
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 end
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 function module.add_host(module)
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 module:hook("module-loaded", module_loaded);
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 module:hook("module-unloaded", module_unloaded);
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 end
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 module:hook("module-loaded", module_loaded);
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 module:hook("module-unloaded", module_unloaded);
3e6f43ab7e22 mod_inotify_reload: Reload modules when their code changes
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76