Software /
code /
prosody-modules
Annotate
mod_omemo_all_access/mod_omemo_all_access.lua @ 2981:cdc29ed803f9
mod_post_msg/README: Remove author, it's in the vcs metadata
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 04 Apr 2018 15:35:04 +0200 |
parent | 2858:150a7bd59043 |
child | 3209:5b02241a254e |
rev | line source |
---|---|
2856
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
1 -- OMEMO all access module |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
2 -- Copyright (c) 2017 Daniel Gultsch |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
3 -- |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
4 -- This module is MIT/X11 licensed |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
5 -- |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
6 |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
7 local jid_bare = require "util.jid".bare; |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
8 local st = require "util.stanza" |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
9 local white_listed_namespace = "eu.siacs.conversations.axolotl." |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
10 local disco_feature_namespace = white_listed_namespace .. "whitelisted" |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
11 |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
12 local mod_pep = module:depends"pep"; |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
13 local pep_data = mod_pep.module.save().data; |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
14 |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
15 local function on_account_disco_info(event) |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
16 (event.reply or event.stanza):tag("feature", {var=disco_feature_namespace}):up(); |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
17 end |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
18 |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
19 local function on_pep_request(event) |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
20 local session, stanza = event.origin, event.stanza |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
21 local payload = stanza.tags[1]; |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
22 if stanza.attr.type == 'get' then |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
23 local node, requested_id; |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
24 payload = payload.tags[1] |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
25 if payload and payload.name == 'items' then |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
26 node = payload.attr.node |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
27 local item = payload.tags[1]; |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
28 if item and item.name == 'item' then |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
29 requested_id = item.attr.id; |
2858
150a7bd59043
mod_omemo_all_access: fixed some linter warnings
Daniel Gultsch <daniel@gultsch.de>
parents:
2856
diff
changeset
|
30 end |
2856
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
31 end |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
32 if node and string.sub(node,1,string.len(white_listed_namespace)) == white_listed_namespace then |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
33 local user = stanza.attr.to and jid_bare(stanza.attr.to) or session.username..'@'..session.host; |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
34 local user_data = pep_data[user]; |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
35 if user_data and user_data[node] then |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
36 local id, item = unpack(user_data[node]); |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
37 if not requested_id or id == requested_id then |
2858
150a7bd59043
mod_omemo_all_access: fixed some linter warnings
Daniel Gultsch <daniel@gultsch.de>
parents:
2856
diff
changeset
|
38 local reply_stanza = st.reply(stanza) |
2856
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
39 :tag('pubsub', {xmlns='http://jabber.org/protocol/pubsub'}) |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
40 :tag('items', {node=node}) |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
41 :add_child(item) |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
42 :up() |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
43 :up(); |
2858
150a7bd59043
mod_omemo_all_access: fixed some linter warnings
Daniel Gultsch <daniel@gultsch.de>
parents:
2856
diff
changeset
|
44 session.send(reply_stanza); |
2856
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
45 module:log("debug","provided access to omemo node",node) |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
46 return true; |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
47 end |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
48 end |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
49 module:log("debug","requested node was white listed", node) |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
50 end |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
51 end |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
52 end |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
53 |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
54 module:hook("iq/bare/http://jabber.org/protocol/pubsub:pubsub", on_pep_request, 10); |
08f6b9d37a49
mod_omemo_all_access: initial commit. disable access control for all omemo related PEP nodes
Daniel Gultsch <daniel@gultsch.de>
parents:
diff
changeset
|
55 module:hook("account-disco-info", on_account_disco_info); |