From 83c757c7861db1e15c7abd35198e038232c61c41 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 18 Oct 2021 13:50:36 +0100 Subject: [PATCH] prosody: Add module to expose stable client id across sessions --- ansible/files/prosody.cfg.lua | 1 + ansible/tasks/prosody.yml | 1 + .../mod_snikket_client_id/mod_snikket_client_id.lua | 13 +++++++++++++ 3 files changed, 15 insertions(+) create mode 100644 snikket-modules/mod_snikket_client_id/mod_snikket_client_id.lua diff --git a/ansible/files/prosody.cfg.lua b/ansible/files/prosody.cfg.lua index 29ade47..912484e 100644 --- a/ansible/files/prosody.cfg.lua +++ b/ansible/files/prosody.cfg.lua @@ -75,6 +75,7 @@ modules_enabled = { "update_notify"; "turncredentials"; "admin_shell"; + "snikket_client_id"; -- Spam/abuse management "spam_reporting"; -- Allow users to report spam/abuse diff --git a/ansible/tasks/prosody.yml b/ansible/tasks/prosody.yml index 6c9c480..4c7a405 100644 --- a/ansible/tasks/prosody.yml +++ b/ansible/tasks/prosody.yml @@ -131,6 +131,7 @@ - mod_update_notify - mod_invites_default_group - mod_invites_bootstrap + - mod_snikket_client_id - name: "Install lua-ossl for encrypted push notifications" apt: diff --git a/snikket-modules/mod_snikket_client_id/mod_snikket_client_id.lua b/snikket-modules/mod_snikket_client_id/mod_snikket_client_id.lua new file mode 100644 index 0000000..0abfb66 --- /dev/null +++ b/snikket-modules/mod_snikket_client_id/mod_snikket_client_id.lua @@ -0,0 +1,13 @@ +-- This module assigns a client_id to sessions if they are using a "Snikket.*" +-- resource identifier. We assume that a resource string in this format is +-- static for the same client instance across every session. +-- +-- In the future it is anticipated that this "hack" will be replaced by SASL 2 +-- (XEP-0388) and/or Bind 2 (XEP-0386), however this is not yet implemented in +-- Prosody or any clients. + +module:hook("resource-bind", function (event) + local id = event.session.resource:match("^Snikket%..+$"); + if not id then return; end + event.session.client_id = id; +end, 1000);