Mercurial > prosody-modules
comparison mod_omemo_all_access/mod_omemo_all_access.lua @ 2856:08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
author | Daniel Gultsch <daniel@gultsch.de> |
---|---|
date | Fri, 29 Dec 2017 16:28:47 +0100 |
parents | |
children | 150a7bd59043 |
comparison
equal
deleted
inserted
replaced
2855:7713cd4fff8f | 2856:08f6b9d37a49 |
---|---|
1 -- OMEMO all access module | |
2 -- Copyright (c) 2017 Daniel Gultsch | |
3 -- | |
4 -- This module is MIT/X11 licensed | |
5 -- | |
6 | |
7 local jid_bare = require "util.jid".bare; | |
8 local st = require "util.stanza" | |
9 local white_listed_namespace = "eu.siacs.conversations.axolotl." | |
10 local disco_feature_namespace = white_listed_namespace .. "whitelisted" | |
11 | |
12 local mod_pep = module:depends"pep"; | |
13 local pep_data = mod_pep.module.save().data; | |
14 | |
15 local function on_account_disco_info(event) | |
16 (event.reply or event.stanza):tag("feature", {var=disco_feature_namespace}):up(); | |
17 end | |
18 | |
19 local function on_pep_request(event) | |
20 local session, stanza = event.origin, event.stanza | |
21 local payload = stanza.tags[1]; | |
22 if stanza.attr.type == 'get' then | |
23 local node, requested_id; | |
24 payload = payload.tags[1] | |
25 if payload and payload.name == 'items' then | |
26 node = payload.attr.node | |
27 local item = payload.tags[1]; | |
28 if item and item.name == 'item' then | |
29 requested_id = item.attr.id; | |
30 end | |
31 end | |
32 if node and string.sub(node,1,string.len(white_listed_namespace)) == white_listed_namespace then | |
33 local user = stanza.attr.to and jid_bare(stanza.attr.to) or session.username..'@'..session.host; | |
34 local user_data = pep_data[user]; | |
35 if user_data and user_data[node] then | |
36 local id, item = unpack(user_data[node]); | |
37 if not requested_id or id == requested_id then | |
38 local stanza = st.reply(stanza) | |
39 :tag('pubsub', {xmlns='http://jabber.org/protocol/pubsub'}) | |
40 :tag('items', {node=node}) | |
41 :add_child(item) | |
42 :up() | |
43 :up(); | |
44 session.send(stanza); | |
45 module:log("debug","provided access to omemo node",node) | |
46 return true; | |
47 end | |
48 end | |
49 module:log("debug","requested node was white listed", node) | |
50 end | |
51 end | |
52 end | |
53 | |
54 module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", on_pep_request, 10); | |
55 module:hook("account-disco-info", on_account_disco_info); |