annotate mod_offline_email/mod_offline_email.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 ee724c7fa8e0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local jid_bare = require "util.jid".bare;
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local os_time = os.time;
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 local t_concat = table.concat;
3405
bd71c97de1d0 mod_offline_email: Allow LuaSocket to pollute the global scope, fixes traceback (*sigh*)
Kim Alvefur <zash@zash.se>
parents: 1285
diff changeset
5
bd71c97de1d0 mod_offline_email: Allow LuaSocket to pollute the global scope, fixes traceback (*sigh*)
Kim Alvefur <zash@zash.se>
parents: 1285
diff changeset
6 prosody.unlock_globals(); -- LuaSocket wants to pollute the global scope
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 local smtp = require "socket.smtp";
3405
bd71c97de1d0 mod_offline_email: Allow LuaSocket to pollute the global scope, fixes traceback (*sigh*)
Kim Alvefur <zash@zash.se>
parents: 1285
diff changeset
8 prosody.lock_globals();
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
10 local smtp_server = module:get_option_string("smtp_server", "localhost");
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
11 local smtp_user = module:get_option_string("smtp_username");
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
12 local smtp_pass = module:get_option_string("smtp_password");
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local smtp_address = module:get_option("smtp_from") or ((smtp_user or "xmpp").."@"..(smtp_server or module.host));
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 local queue_offline_emails = module:get_option("queue_offline_emails");
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 if queue_offline_emails == true then queue_offline_emails = 300; end
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local send_message_as_email;
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
21 module:hook("message/offline/handle", function(event)
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
22 local stanza = event.stanza;
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
23 local text = stanza:get_child_text("body");
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
24 if text then
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
25 return send_message_as_email(jid_bare(stanza.attr.to), jid_bare(stanza.attr.from), text);
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 end
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
27 end, 1);
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 function send_message_as_email(address, from_address, message_text, subject)
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
30 module:log("info", "Forwarding offline message to %s via email", address);
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
31 local rcpt = "<"..address..">";
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
32
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
33 local mesgt = {
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
34 headers = {
4231
ee724c7fa8e0 mod_offline_email: explicitly set charset to utf-8 to override mailclients default settings
Vladimir D. Seleznev <vseleznv@altlinux.org>
parents: 3405
diff changeset
35 ["content-type"] = 'text/plain; charset=utf-8';
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
36 to = address;
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
37 subject = subject or ("Offline message from "..jid_bare(from_address));
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 };
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
39 body = message_text;
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
40 };
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
41
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
42 local ok, err = smtp.send{ from = smtp_address, rcpt = rcpt, source = smtp.message(mesgt),
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 server = smtp_server, user = smtp_user, password = smtp_pass };
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
44
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 if not ok then
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 module:log("error", "Failed to deliver to %s: %s", tostring(address), tostring(err));
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
47 return;
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 end
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 return true;
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 end
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 if queue_offline_emails then
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 local queues = {};
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 local real_send_message_as_email = send_message_as_email;
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 function send_message_as_email(address, from_address, message_text)
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 local pair_key = address.."\0"..from_address;
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 local queue = queues[pair_key];
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 if not queue then
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
59 queue = { from = smtp_address, to = address, messages = {} };
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 queues[pair_key] = queue;
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
61
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
62 module:add_timer(queue_offline_emails+5, function ()
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 module:log("info", "Checking on %s", from_address);
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 local current_time = os_time();
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 local diff = current_time - queue.last_message_time;
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 if diff > queue_offline_emails then
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 module:log("info", "Enough silence, sending...");
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 real_send_message_as_email(address, from_address, t_concat(queue.messages, "\n"), "You have "..#queue.messages.." offline message"..(#queue.messages == 1 and "" or "s").." from "..from_address)
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 else
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 module:log("info", "Next check in %d", queue_offline_emails - diff + 5);
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 return queue_offline_emails - diff + 5;
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 end
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 end);
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 end
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
75
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 queue.last_message_time = os_time();
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 local messages = queue.messages;
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 messages[#messages+1] = message_text;
1285
f1a0a0754b87 mod_offline_email: Much cleanup. Very update to newer APIs. Wow.
Kim Alvefur <zash@zash.se>
parents: 0
diff changeset
80 return true;
0
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 end
010452cfaf53 mod_offline_email: Initial commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 end