Mercurial > prosody-modules
view mod_invites_page/mod_invites_page.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 | efdaffc878a9 |
| children | dfdf0bf1e84f |
line wrap: on
line source
local st = require "util.stanza"; local url_escape = require "util.http".urlencode; local base_url = "https://"..module.host.."/"; local render_html_template = require"util.interpolation".new("%b{}", st.xml_escape, { urlescape = url_escape; lower = string.lower; classname = function (s) return (s:gsub("%W+", "-")); end; relurl = function (s) if s:match("^%w+://") then return s; end return base_url.."/"..s; end; }); local render_url = require "util.interpolation".new("%b{}", url_escape, { urlescape = url_escape; noscheme = function (url) return (url:gsub("^[^:]+:", "")); end; }); local site_name = module:get_option_string("site_name", module.host); local site_apps; -- Enable/disable built-in invite pages local external_only = module:get_option_boolean("invites_page_external", false); local http_files; if not external_only then -- Load HTTP-serving dependencies if prosody.shutdown then -- not if running under prosodyctl module:depends("http"); if prosody.process_type == "prosody" then http_files = require "net.http.files"; else http_files = module:depends"http_files"; end elseif prosody.process_type and module.get_option_period then module:depends("http"); http_files = require "net.http.files"; end -- Calculate automatic base_url default base_url = module.http_url and module:http_url(); -- Load site apps info module:depends("register_apps"); site_apps = module:shared("register_apps/apps"); end local invites = module:depends("invites"); -- Point at eg https://github.com/ge0rg/easy-xmpp-invitation -- This URL must always be absolute, as it is shared standalone local invite_url_template = module:get_option_string("invites_page", base_url and (base_url.."?{invite.token}") or nil); -- This URL is relative to the invite page, or can be absolute local register_url_template = module:get_option_string("invites_registration_page", "register?t={invite.token}&c={app.id}"); local function add_landing_url(invite) if not invite_url_template then return; end -- TODO: we don't currently have a landing page for subscription-only invites, -- so the user will only receive a URI. The client should be able to handle this -- by automatically falling back to a client-specific landing page, per XEP-0401. if not invite.allow_registration then return; end invite.landing_page = render_url(invite_url_template, { host = module.host, invite = invite }); end module:hook("invite-created", add_landing_url); if external_only then return; end local function render_app_urls(apps, invite_vars) local rendered_apps = {}; for _, unrendered_app in ipairs(apps) do local app = setmetatable({}, { __index = unrendered_app }); local template_vars = { app = app, invite = invite_vars, base_url = base_url }; if app.magic_link_format then -- Magic link generally links directly to third-party app.proceed_url = render_url(app.magic_link_format or app.link or "#", template_vars); elseif app.supports_preauth_uri then -- Proceed to a page that guides the user to download, and then -- click the URI button app.proceed_url = render_url("{base_url!}/setup/{app.id}?{invite.token}", template_vars); else -- Manual means proceed to web registration, but include app id -- so it can show post-registration instructions app.proceed_url = render_url(register_url_template, template_vars); end table.insert(rendered_apps, app); end return rendered_apps; end function serve_invite_page(event) local invite_page_template = assert(module:load_resource("html/invite.html")):read("*a"); local invalid_invite_page_template = assert(module:load_resource("html/invite_invalid.html")):read("*a"); event.response.headers["Content-Type"] = "text/html; charset=utf-8"; local invite = invites.get(event.request.url.query); if not invite then return render_html_template(invalid_invite_page_template, { site_name = site_name; static = base_url.."/static"; }); end local template_vars = { site_name = site_name; token = invite.token; uri = invite.uri; type = invite.type; jid = invite.jid; inviter = invite.inviter; static = base_url.."/static"; }; template_vars.apps = render_app_urls(site_apps, template_vars); local invite_page = render_html_template(invite_page_template, template_vars); event.response.headers["Link"] = ([[<%s>; rel="alternate"]]):format(template_vars.uri); return invite_page; end function serve_setup_page(event, app_id) local invite_page_template = assert(module:load_resource("html/client.html")):read("*a"); local invalid_invite_page_template = assert(module:load_resource("html/invite_invalid.html")):read("*a"); event.response.headers["Content-Type"] = "text/html; charset=utf-8"; local invite = invites.get(event.request.url.query); if not invite then return render_html_template(invalid_invite_page_template, { site_name = site_name; static = base_url.."/static"; }); end local template_vars = { site_name = site_name; apps = site_apps; token = invite.token; uri = invite.uri; type = invite.type; jid = invite.jid; static = base_url.."/static"; }; template_vars.app = render_app_urls({ site_apps[app_id] }, template_vars)[1]; local invite_page = render_html_template(invite_page_template, template_vars); return invite_page; end local mime_map = { png = "image/png"; svg = "image/svg+xml"; js = "application/javascript"; }; module:provides("http", { route = { ["GET"] = serve_invite_page; ["GET /setup/*"] = serve_setup_page; ["GET /static/*"] = http_files and http_files.serve({ path = module:get_directory().."/static", mime_map = mime_map }); }; });
