Mercurial > prosody-modules
annotate mod_measure_active_users/mod_measure_active_users.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 | ca62f9984f4b |
| children | 908d44cfb693 |
| rev | line source |
|---|---|
|
4774
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local store = module:open_store("lastlog2"); |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local measure_d1 = module:measure("active_users_1d", "amount"); |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local measure_d7 = module:measure("active_users_7d", "amount"); |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local measure_d30 = module:measure("active_users_30d", "amount"); |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
|
5777
34b46d157797
mod_measure_active_users: Exclude disabled user accounts from counts
Matthew Wild <mwild1@gmail.com>
parents:
4774
diff
changeset
|
7 local is_enabled = require "core.usermanager".user_is_enabled; |
|
34b46d157797
mod_measure_active_users: Exclude disabled user accounts from counts
Matthew Wild <mwild1@gmail.com>
parents:
4774
diff
changeset
|
8 |
|
34b46d157797
mod_measure_active_users: Exclude disabled user accounts from counts
Matthew Wild <mwild1@gmail.com>
parents:
4774
diff
changeset
|
9 -- Exclude disabled user accounts from the counts if usermanager supports that API |
|
5791
9d3d719db285
mod_measure_active_users: Fix inverted logic (thanks mirux)
Matthew Wild <mwild1@gmail.com>
parents:
5778
diff
changeset
|
10 local count_disabled = module:get_option_boolean("measure_active_users_count_disabled", is_enabled == nil); |
|
5777
34b46d157797
mod_measure_active_users: Exclude disabled user accounts from counts
Matthew Wild <mwild1@gmail.com>
parents:
4774
diff
changeset
|
11 |
|
5778
32d662015a84
mod_measure_active_users: Use the new mod_lastlog2 API
Matthew Wild <mwild1@gmail.com>
parents:
5777
diff
changeset
|
12 local get_last_active = module:depends("lastlog2").get_last_active; |
|
32d662015a84
mod_measure_active_users: Use the new mod_lastlog2 API
Matthew Wild <mwild1@gmail.com>
parents:
5777
diff
changeset
|
13 |
|
4774
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 function update_calculations() |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 module:log("debug", "Calculating active users"); |
|
5777
34b46d157797
mod_measure_active_users: Exclude disabled user accounts from counts
Matthew Wild <mwild1@gmail.com>
parents:
4774
diff
changeset
|
16 local host = module.host; |
|
34b46d157797
mod_measure_active_users: Exclude disabled user accounts from counts
Matthew Wild <mwild1@gmail.com>
parents:
4774
diff
changeset
|
17 local host_user_sessions = prosody.hosts[host].sessions; |
|
4774
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local active_d1, active_d7, active_d30 = 0, 0, 0; |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local now = os.time(); |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 for username in store:users() do |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 if host_user_sessions[username] then |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 -- Active now |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 active_d1, active_d7, active_d30 = |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 active_d1 + 1, active_d7 + 1, active_d30 + 1; |
|
5777
34b46d157797
mod_measure_active_users: Exclude disabled user accounts from counts
Matthew Wild <mwild1@gmail.com>
parents:
4774
diff
changeset
|
25 elseif count_disabled or is_enabled(username, host) then |
|
5778
32d662015a84
mod_measure_active_users: Use the new mod_lastlog2 API
Matthew Wild <mwild1@gmail.com>
parents:
5777
diff
changeset
|
26 local last_active = get_last_active(username); |
|
32d662015a84
mod_measure_active_users: Use the new mod_lastlog2 API
Matthew Wild <mwild1@gmail.com>
parents:
5777
diff
changeset
|
27 if last_active then |
|
4774
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 if now - last_active < 86400 then |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 active_d1 = active_d1 + 1; |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 end |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 if now - last_active < 86400*7 then |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 active_d7 = active_d7 + 1; |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 if now - last_active < 86400*30 then |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 active_d30 = active_d30 + 1; |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 end |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 end |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 end |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 module:log("debug", "Active users (took %ds): %d (24h), %d (7d), %d (30d)", os.time()-now, active_d1, active_d7, active_d30); |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 measure_d1(active_d1); |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 measure_d7(active_d7); |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 measure_d30(active_d30); |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
|
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
|
5863
ca62f9984f4b
mod_measure_active_users: Switch to mod_cron for scheduling
Matthew Wild <mwild1@gmail.com>
parents:
5791
diff
changeset
|
46 -- Schedule at startup |
|
4774
1132f2888cd2
mod_measure_active_users: Calculate active user counts over fixed time periods
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 module:add_timer(15, update_calculations); |
|
5863
ca62f9984f4b
mod_measure_active_users: Switch to mod_cron for scheduling
Matthew Wild <mwild1@gmail.com>
parents:
5791
diff
changeset
|
48 |
|
ca62f9984f4b
mod_measure_active_users: Switch to mod_cron for scheduling
Matthew Wild <mwild1@gmail.com>
parents:
5791
diff
changeset
|
49 -- Recalculate hourly |
|
ca62f9984f4b
mod_measure_active_users: Switch to mod_cron for scheduling
Matthew Wild <mwild1@gmail.com>
parents:
5791
diff
changeset
|
50 module:hourly(update_calculations); |
