Mercurial > prosody-modules
annotate mod_debug_omemo/mod_debug_omemo.lua @ 6299:5cf5ee23b361
mod_voipms: New Module to send and receive SMS/MMS via VoIP.ms APIs.
diff --git a/mod_voipms/README.md b/mod_voipms/README.md
new file mode 100644
--- /dev/null
+++ b/mod_voipms/README.md
@@ -0,0 +1,51 @@
+---
+labels:
+- 'Stage-Alpha'
+- 'Type-Web'
+summary: Send and receive SMS/MMS via VoIP.ms APIs.
+rockspec:
+ build:
+ modules:
+ mod_voipms: mod_voipms.lua
+...
+
+Introduction
+============
+
+This is a Prosody module to map JIDs to DIDs on VoIP.ms and support sending/receiving SMS/MMS.
+
+Configuration
+=============
+
+| option | type | default |
+|-----------------------|--------|---------|
+| voipms\_api\_username | string | nil |
+| voipms\_api\_password | string | nil |
+| voipms\_query\_key | string | nil |
+| voipms\_jid\_map | table | nil |
+```
+VirtualHost "sms.example.com"
+modules_enabled = {
+ "voipms";
+}
+voipms_api_username = john@example.com -- E-mail registered with VoIP.ms
+voipms_api_password = abcd1234 -- API password configured in VoIP.ms
+voipms_query_key = some_query_key -- query param 'key' part of your URL callback
+voipms_jid_map = {
+ ["your_jid@your_domain.com"] = "+1234567890"
+}
+```
+
+HTTP
+====
+
+The module is served on Prosody's default HTTP ports at the path /voipms. More details on configuring HTTP modules in Prosody can be found in the HTTP documentation.
+
+VoIP.ms Webhook URL
+===================
+
+This module receives the VoIP.ms Webhook URL (POST) at the /voipms endpoint. It uses the sendSMS/sendMMS GET methods against the VoIP.ms APIs. This is an example webhook to use in VoIP.ms:
+
+```
+https://sms.example.com/voipms?key=some_query_key
+```
diff --git a/mod_voipms/mod_voipms.lua b/mod_voipms/mod_voipms.lua
new file mode 100644
--- /dev/null
+++ b/mod_voipms/mod_voipms.lua
@@ -0,0 +1,166 @@
+local http = require "net.http"
+local json = require "util.json"
+local st = require "util.stanza"
+
+local api_username = module:get_option_string("voipms_api_username")
+local api_password = module:get_option_string("voipms_api_password")
+local query_key = module:get_option("voipms_query_key")
+local jid_map = module:get_option("voipms_jid_map") or {}
+local rest_endpoint = "https://voip.ms/api/v1/rest.php"
+
+if not api_username or not api_password or not query_key then
+ module:log("error", "Missing required config values (voipms_api_username, voipms_api_password, voipms_query_key)")
+ return
+end
+
+module:depends("http")
+
+local function normalize_number(num)
+ if not num then return nil end
+ if num:sub(1, 1) ~= "+" then
+ return "+1" .. num
+ end
+ return num
+end
+
+local function extract_query_key(event)
+ return (event.request.url.query or ""):match("key=([^&]+)")
+end
+
+module:provides("http", {
+ route = {
+ ["POST"] = function(event)
+ local req = event.request
+ local body = req.body or ""
+
+ if extract_query_key(event) ~= query_key then
+ module:log("warn", "Unauthorized webhook: missing or invalid key")
+ return { status_code = 403 }
+ end
+
+ local json_payload, err = json.decode(body)
+ if not json_payload then
+ module:log("warn", "Invalid JSON: %s", err or "unknown error")
+ return { status_code = 400 }
+ end
+
+ local payload = json_payload.data and json_payload.data.payload
+ if not payload then
+ module:log("warn", "Missing payload in JSON")
+ return { status_code = 400 }
+ end
+
+ local from = payload.from and payload.from.phone_number
+ local to_list = payload.to or {}
+ local to = #to_list > 0 and to_list[1].phone_number or nil
+
+ if not from or not to then
+ module:log("warn", "Missing phone numbers (from: %s, to: %s)", tostring(from), tostring(to))
+ return { status_code = 400 }
+ end
+
+ local normalized_to = normalize_number(to)
+ local target_jid = nil
+
+ for jid, did in pairs(jid_map) do
+ if normalize_number(did) == normalized_to then
+ target_jid = jid
+ break
+ end
+ end
+
+ if not target_jid then
+ module:log("warn", "No JID mapping for DID %s", normalized_to)
+ return { status_code = 404 }
+ end
+
+ local normalized_from = normalize_number(from)
+ local message_text = payload.text or ""
+
+ local message = st.message({
+ from = normalized_from .. "@" .. module.host,
+ to = target_jid,
+ type = "chat"
+ }):tag("body"):text(message_text):up()
+
+ if payload.media and #payload.media > 0 then
+ for _, media_item in ipairs(payload.media) do
+ if media_item.url then
+ message_text = message_text .. "\n" .. media_item.url
+ message:tag("x", { xmlns = "jabber:x:oob" })
+ :tag("url"):text(media_item.url):up():up()
+ end
+ end
+ end
+
+ module:send(message)
+ module:log("info", "Delivered SMS from %s to %s", normalized_from, target_jid)
+
+ return { status_code = 204 }
+ end
+ }
+})
+
+module:hook("message/bare", function(event)
+ local stanza = event.stanza
+ if stanza.attr.type ~= "chat" then return end
+
+ local from_jid = stanza.attr.from
+ local to_jid = stanza.attr.to
+ local body = stanza:get_child_text("body")
+ if not body or body == "" then return end
+
+ local from_number = jid_map[from_jid]
+ if not from_number then
+ module:log("warn", "No DID mapping for JID %s", from_jid)
+ return
+ end
+
+ local to_number = to_jid:match("^([^@]+)")
+ if not to_number then
+ module:log("warn", "Malformed JID in message.to: %s", to_jid)
+ return
+ end
+
+ to_number = normalize_number(to_number)
+
+ local media_urls = {}
+ for line in body:gmatch("[^\r\n]+") do
+ if line:match("^https?://") then
+ table.insert(media_urls, line)
+ end
+ end
+
+ local method = (#media_urls > 0) and "sendMMS" or "sendSMS"
+ local query = {
+ api_username = api_username,
+ api_password = api_password,
+ method = method,
+ did = from_number,
+ dst = to_number,
+ message = body
+ }
+
+ if method == "sendMMS" then
+ for i, url in ipairs(media_urls) do
+ query["media_url[" .. (i - 1) .. "]"] = url
+ end
+ end
+
+ local query_str = http.formencode(query)
+
+ http.request(rest_endpoint .. "?" .. query_str, {
+ method = "GET";
+ }, function(response_body, code)
+ if code == 200 then
+ local resp, err = json.decode(response_body)
+ if not resp or resp.status ~= "success" then
+ module:log("error", "Failed to send %s: %s", method, err or (resp and resp.status) or "unknown")
+ else
+ module:log("info", "Sent %s from %s to %s", method, from_number, to_number)
+ end
+ else
+ module:log("error", "HTTP error sending %s: code %s", method, tostring(code))
+ end
+ end)
+end)
| author | Chaz <menel@snikket.de> |
|---|---|
| date | Mon, 21 Jul 2025 23:57:37 +0200 |
| parents | ecfffbbcbf42 |
| children |
| rev | line source |
|---|---|
|
4682
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local array = require "util.array"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 local jid = require "util.jid"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local set = require "util.set"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local st = require "util.stanza"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 local url_escape = require "util.http".urlencode; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 local base_url = "https://"..module.host.."/"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 local render_html_template = require"util.interpolation".new("%b{}", st.xml_escape, { |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 urlescape = url_escape; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 lower = string.lower; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 classname = function (s) return (s:gsub("%W+", "-")); end; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 relurl = function (s) |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 if s:match("^%w+://") then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 return s; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 return base_url.."/"..s; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 end; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 }); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local render_url = require "util.interpolation".new("%b{}", url_escape, { |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 urlescape = url_escape; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 noscheme = function (url) |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 return (url:gsub("^[^:]+:", "")); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 end; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 }); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 local mod_pep = module:depends("pep"); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 local mam = module:open_store("archive", "archive"); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 local function get_user_omemo_info(username) |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 local everything_valid = true; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 local any_device = false; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 local omemo_status = {}; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local omemo_devices; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local pep_service = mod_pep.get_pep_service(username); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 if pep_service and pep_service.nodes then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 local ok, _, device_list = pep_service:get_last_item("eu.siacs.conversations.axolotl.devicelist", true); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 if ok and device_list then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 device_list = device_list:get_child("list", "eu.siacs.conversations.axolotl"); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 if device_list then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 omemo_devices = {}; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 for device_entry in device_list:childtags("device") do |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 any_device = true; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 local device_info = {}; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 local device_id = tonumber(device_entry.attr.id or ""); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 if device_id then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 device_info.id = device_id; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 local bundle_id = ("eu.siacs.conversations.axolotl.bundles:%d"):format(device_id); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 local have_bundle, _, bundle = pep_service:get_last_item(bundle_id, true); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 if have_bundle and bundle and bundle:get_child("bundle", "eu.siacs.conversations.axolotl") then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 device_info.have_bundle = true; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 local config_ok, bundle_config = pep_service:get_node_config(bundle_id, true); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 if config_ok and bundle_config then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 device_info.bundle_config = bundle_config; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 if bundle_config.max_items == 1 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 and bundle_config.access_model == "open" |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 and bundle_config.persist_items == true |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 and bundle_config.publish_model == "publishers" then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 device_info.valid = true; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 if device_info.valid == nil then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 device_info.valid = false; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 everything_valid = false; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 table.insert(omemo_devices, device_info); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 local config_ok, list_config = pep_service:get_node_config("eu.siacs.conversations.axolotl.devicelist", true); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 if config_ok and list_config then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 omemo_status.config = list_config; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 if list_config.max_items == 1 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 and list_config.access_model == "open" |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 and list_config.persist_items == true |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 and list_config.publish_model == "publishers" then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 omemo_status.config_valid = true; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 if omemo_status.config_valid == nil then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 omemo_status.config_valid = false; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 everything_valid = false; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 omemo_status.valid = everything_valid and any_device; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 return { |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 status = omemo_status; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 devices = omemo_devices; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 }; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 local access_model_text = { |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 open = "Public"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 whitelist = "Private"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 roster = "Contacts only"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 presence = "Contacts only"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 }; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 |
|
4689
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
103 local function get_message(username, message_id) |
|
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
104 if mam.get then |
|
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
105 return mam:get(username, message_id); |
|
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
106 end |
|
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
107 -- COMPAT |
|
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
108 local message; |
|
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
109 for _, result in mam:find(username, { key = message_id }) do |
|
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
110 message = result; |
|
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
111 end |
|
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
112 return message; |
|
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
113 end |
|
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
114 |
|
4682
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 local function render_message(event, path) |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 local username, message_id = path:match("^([^/]+)/(.+)$"); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 if not username then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 return 400; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 end |
|
4689
ecfffbbcbf42
mod_debug_omemo: Use archive single message retrieval method
Kim Alvefur <zash@zash.se>
parents:
4687
diff
changeset
|
120 local message = get_message(username, message_id); |
|
4682
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 if not message then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 return 404; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 local user_omemo_status = get_user_omemo_info(username); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 local user_rids = set.new(array.pluck(user_omemo_status.devices or {}, "id")) / tostring; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 local message_omemo_header = message:find("{eu.siacs.conversations.axolotl}encrypted/header"); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 local message_rids = set.new(); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 local rid_info = {}; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 if message_omemo_header then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 for key_el in message_omemo_header:childtags("key") do |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 local rid = key_el.attr.rid; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 if rid then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 message_rids:add(rid); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 local prekey = key_el.attr.prekey; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 rid_info = { |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 prekey = prekey and (prekey == "1" or prekey:lower() == "true"); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 }; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 local rids = user_rids + message_rids; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 local direction = jid.bare(message.attr.to) == (username.."@"..module.host) and "incoming" or "outgoing"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 local is_encrypted = not not message_omemo_header; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 local sender_id = message_omemo_header and message_omemo_header.attr.sid or nil; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 local f = module:load_resource("view.tpl.html"); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 if not f then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 return 500; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 local tpl = f:read("*a"); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 local data = { user = username, rids = {} }; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 for rid in rids do |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 data.rids[rid] = { |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 status = message_rids:contains(rid) and "Encrypted" or user_rids:contains(rid) and "Missing" or nil; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 prekey = rid_info.prekey; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 }; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 data.message = { |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 type = message.attr.type or "normal"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 direction = direction; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 encryption = is_encrypted and "encrypted" or "unencrypted"; |
|
4687
41ddb782320c
mod_debug_omemo: Improve no keys/devices cases
Matthew Wild <mwild1@gmail.com>
parents:
4686
diff
changeset
|
171 has_any_keys = not message_rids:empty(); |
|
41ddb782320c
mod_debug_omemo: Improve no keys/devices cases
Matthew Wild <mwild1@gmail.com>
parents:
4686
diff
changeset
|
172 has_no_keys = message_rids:empty(); |
|
4682
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 }; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 data.omemo = { |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 sender_id = sender_id; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 status = user_omemo_status.status.valid and "no known issues" or "problems"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 }; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 data.omemo.devices = {}; |
|
4686
76af816739f3
mod_debug_omemo: Fix traceback in case of zero devices
Kim Alvefur <zash@zash.se>
parents:
4685
diff
changeset
|
181 if user_omemo_status.devices then |
|
76af816739f3
mod_debug_omemo: Fix traceback in case of zero devices
Kim Alvefur <zash@zash.se>
parents:
4685
diff
changeset
|
182 for _, device_info in ipairs(user_omemo_status.devices) do |
|
76af816739f3
mod_debug_omemo: Fix traceback in case of zero devices
Kim Alvefur <zash@zash.se>
parents:
4685
diff
changeset
|
183 data.omemo.devices[("%d"):format(device_info.id)] = { |
|
76af816739f3
mod_debug_omemo: Fix traceback in case of zero devices
Kim Alvefur <zash@zash.se>
parents:
4685
diff
changeset
|
184 status = device_info.valid and "OK" or "Problem"; |
|
76af816739f3
mod_debug_omemo: Fix traceback in case of zero devices
Kim Alvefur <zash@zash.se>
parents:
4685
diff
changeset
|
185 bundle = device_info.have_bundle and "Published" or "Missing"; |
|
76af816739f3
mod_debug_omemo: Fix traceback in case of zero devices
Kim Alvefur <zash@zash.se>
parents:
4685
diff
changeset
|
186 access_model = access_model_text[device_info.bundle_config and device_info.bundle_config.access_model or nil]; |
|
76af816739f3
mod_debug_omemo: Fix traceback in case of zero devices
Kim Alvefur <zash@zash.se>
parents:
4685
diff
changeset
|
187 }; |
|
76af816739f3
mod_debug_omemo: Fix traceback in case of zero devices
Kim Alvefur <zash@zash.se>
parents:
4685
diff
changeset
|
188 end |
|
76af816739f3
mod_debug_omemo: Fix traceback in case of zero devices
Kim Alvefur <zash@zash.se>
parents:
4685
diff
changeset
|
189 else |
|
4687
41ddb782320c
mod_debug_omemo: Improve no keys/devices cases
Matthew Wild <mwild1@gmail.com>
parents:
4686
diff
changeset
|
190 data.omemo.devices[false] = { status = "No devices have published OMEMO keys on this account" }; |
|
4682
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 event.response.headers.content_type = "text/html; charset=utf-8"; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 return render_html_template(tpl, data); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 local function check_omemo_fallback(event) |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 local message = event.stanza; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 local message_omemo_header = message:find("{eu.siacs.conversations.axolotl}encrypted/header"); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 if not message_omemo_header then return; end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 local to_bare = jid.bare(message.attr.to); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 local archive_stanza_id; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 for stanza_id_tag in message:childtags("stanza-id", "urn:xmpp:sid:0") do |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 if stanza_id_tag.attr.by == to_bare then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 archive_stanza_id = stanza_id_tag.attr.id; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 if not archive_stanza_id then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 return; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 local debug_url = render_url(module:http_url().."/view/{username}/{message_id}", { |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 username = jid.node(to_bare); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 message_id = archive_stanza_id; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 }); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 local body = message:get_child("body"); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 if not body then |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 body = st.stanza("body") |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 :text("This message is encrypted using OMEMO, but could not be decrypted by your device.\nFor more information see: "..debug_url); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 message:reset():add_child(body); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 else |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 body:text("\n\nOMEMO debug information: "..debug_url); |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 end |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 |
|
4685
07b6f444bafb
mod_debug_omemo: Adjust priority to act after mod_mam archived
Kim Alvefur <zash@zash.se>
parents:
4682
diff
changeset
|
230 module:hook("message/bare", check_omemo_fallback, -0.5); |
|
07b6f444bafb
mod_debug_omemo: Adjust priority to act after mod_mam archived
Kim Alvefur <zash@zash.se>
parents:
4682
diff
changeset
|
231 module:hook("message/full", check_omemo_fallback, -0.5); |
|
4682
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 module:depends("http") |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 module:provides("http", { |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 route = { |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 ["GET /view/*"] = render_message; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 }; |
|
e4e5474420e6
mod_debug_omemo: OMEMO debugging tool
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 }); |
