Mercurial > prosody-modules
annotate mod_admin_web/admin_web/mod_admin_web.lua @ 3656:3e0f4d727825
mod_vcard_muc: Add an alternative method of signaling avatar change
When the avatar has been changed, a signal is sent that the room
configuration has changed. Clients then do a disco#info query to find
the SHA-1 of the new avatar. They can then fetch it as before, or not if
they have it cached already.
This is meant to be less disruptive than signaling via presence, which
caused problems for some clients.
If clients transition to the new method, the old one can eventually be removed.
The namespace is made up while waiting for standardization.
Otherwise it is very close to what's described in
https://xmpp.org/extensions/inbox/muc-avatars.html
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 25 Aug 2019 20:46:43 +0200 |
parents | 179424d557f2 |
children | a8aacfbdaea9 |
rev | line source |
---|---|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
1 -- Copyright (C) 2010 Florian Zeitz |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
2 -- |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
3 -- This file is MIT/X11 licensed. Please see the |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
4 -- COPYING file in the source package for more information. |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
5 -- |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
6 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
7 -- <session xmlns="http://prosody.im/streams/c2s" jid="alice@example.com/brussels"> |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
8 -- <encrypted/> |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
9 -- <compressed/> |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
10 -- </session> |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
11 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
12 -- <session xmlns="http://prosody.im/streams/s2s" jid="example.com"> |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
13 -- <encrypted> |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
14 -- <valid/> / <invalid/> |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
15 -- </encrypted> |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
16 -- <compressed/> |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
17 -- <in/> / <out/> |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
18 -- </session> |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
19 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
20 local st = require "util.stanza"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
21 local uuid_generate = require "util.uuid".generate; |
696
da69b65288e4
mod_admin_web: Correctly import usermanager
Florian Zeitz <florob@babelmonkeys.de>
parents:
663
diff
changeset
|
22 local is_admin = require "core.usermanager".is_admin; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
23 local pubsub = require "util.pubsub"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
24 local jid_bare = require "util.jid".bare; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
25 |
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
26 local hosts = prosody.hosts; |
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
27 local incoming_s2s = prosody.incoming_s2s; |
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
28 |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
29 module:set_global(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
30 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
31 local service = {}; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
32 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
33 local xmlns_adminsub = "http://prosody.im/adminsub"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
34 local xmlns_c2s_session = "http://prosody.im/streams/c2s"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
35 local xmlns_s2s_session = "http://prosody.im/streams/s2s"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
36 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
37 local idmap = {}; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
38 |
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
39 local function add_client(session, host) |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
40 local name = session.full_jid; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
41 local id = idmap[name]; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
42 if not id then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
43 id = uuid_generate(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
44 idmap[name] = id; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
45 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
46 local item = st.stanza("item", { id = id }):tag("session", {xmlns = xmlns_c2s_session, jid = name}):up(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
47 if session.secure then |
1117
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
48 local encrypted = item:tag("encrypted"); |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
49 local sock = session.conn and session.conn.socket and session.conn:socket() |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
50 local info = sock and sock.info and sock:info(); |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
51 for k, v in pairs(info or {}) do |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
52 encrypted:tag("info", { name = k }):text(tostring(v)):up(); |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
53 end |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
54 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
55 if session.compressed then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
56 item:tag("compressed"):up(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
57 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
58 service[host]:publish(xmlns_c2s_session, host, id, item); |
3567
179424d557f2
mod_admin_web: Fix to use format strings in logger calls (thanks Ge0rG)
Matthew Wild <mwild1@gmail.com>
parents:
3550
diff
changeset
|
59 module:log("debug", "Added client %s", name); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
60 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
61 |
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
62 local function del_client(session, host) |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
63 local name = session.full_jid; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
64 local id = idmap[name]; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
65 if id then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
66 local notifier = st.stanza("retract", { id = id }); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
67 service[host]:retract(xmlns_c2s_session, host, id, notifier); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
68 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
69 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
70 |
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
71 local function add_host(session, type, host) |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
72 local name = (type == "out" and session.to_host) or (type == "in" and session.from_host); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
73 local id = idmap[name.."_"..type]; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
74 if not id then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
75 id = uuid_generate(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
76 idmap[name.."_"..type] = id; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
77 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
78 local item = st.stanza("item", { id = id }):tag("session", {xmlns = xmlns_s2s_session, jid = name}) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
79 :tag(type):up(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
80 if session.secure then |
1117
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
81 local encrypted = item:tag("encrypted"); |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
82 |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
83 local sock = session.conn and session.conn.socket and session.conn:socket() |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
84 local info = sock and sock.info and sock:info(); |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
85 for k, v in pairs(info or {}) do |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
86 encrypted:tag("info", { name = k }):text(tostring(v)):up(); |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
87 end |
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
88 |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
89 if session.cert_identity_status == "valid" then |
1117
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
90 encrypted:tag("valid"); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
91 else |
1117
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
92 encrypted:tag("invalid"); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
93 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
94 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
95 if session.compressed then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
96 item:tag("compressed"):up(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
97 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
98 service[host]:publish(xmlns_s2s_session, host, id, item); |
3567
179424d557f2
mod_admin_web: Fix to use format strings in logger calls (thanks Ge0rG)
Matthew Wild <mwild1@gmail.com>
parents:
3550
diff
changeset
|
99 module:log("debug", "Added host %s s2s%s", name, type); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
100 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
101 |
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
102 local function del_host(session, type, host) |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
103 local name = (type == "out" and session.to_host) or (type == "in" and session.from_host); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
104 local id = idmap[name.."_"..type]; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
105 if id then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
106 local notifier = st.stanza("retract", { id = id }); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
107 service[host]:retract(xmlns_s2s_session, host, id, notifier); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
108 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
109 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
110 |
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
111 local function get_affiliation(jid, host) |
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
112 local bare_jid = jid_bare(jid); |
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
113 if is_admin(bare_jid, host) then |
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
114 return "member"; |
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
115 else |
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
116 return "none"; |
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
117 end |
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
118 end |
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
119 |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
120 function module.add_host(module) |
770
a85d86a7f24e
mod_admin_web: Add explicit dependencies on mod_admin_adhoc and mod_bosh
Florian Zeitz <florob@babelmonkeys.de>
parents:
769
diff
changeset
|
121 -- Dependencies |
a85d86a7f24e
mod_admin_web: Add explicit dependencies on mod_admin_adhoc and mod_bosh
Florian Zeitz <florob@babelmonkeys.de>
parents:
769
diff
changeset
|
122 module:depends("bosh"); |
a85d86a7f24e
mod_admin_web: Add explicit dependencies on mod_admin_adhoc and mod_bosh
Florian Zeitz <florob@babelmonkeys.de>
parents:
769
diff
changeset
|
123 module:depends("admin_adhoc"); |
a85d86a7f24e
mod_admin_web: Add explicit dependencies on mod_admin_adhoc and mod_bosh
Florian Zeitz <florob@babelmonkeys.de>
parents:
769
diff
changeset
|
124 module:depends("http"); |
3549
b059a3fb2a58
Update modules using mod_http_files to serve files for change in Prosody trunk
Kim Alvefur <zash@zash.se>
parents:
2871
diff
changeset
|
125 |
b059a3fb2a58
Update modules using mod_http_files to serve files for change in Prosody trunk
Kim Alvefur <zash@zash.se>
parents:
2871
diff
changeset
|
126 local serve; |
b059a3fb2a58
Update modules using mod_http_files to serve files for change in Prosody trunk
Kim Alvefur <zash@zash.se>
parents:
2871
diff
changeset
|
127 if not pcall(function () |
b059a3fb2a58
Update modules using mod_http_files to serve files for change in Prosody trunk
Kim Alvefur <zash@zash.se>
parents:
2871
diff
changeset
|
128 local http_files = require "net.http.files"; |
b059a3fb2a58
Update modules using mod_http_files to serve files for change in Prosody trunk
Kim Alvefur <zash@zash.se>
parents:
2871
diff
changeset
|
129 serve = http_files.serve; |
b059a3fb2a58
Update modules using mod_http_files to serve files for change in Prosody trunk
Kim Alvefur <zash@zash.se>
parents:
2871
diff
changeset
|
130 end) then |
b059a3fb2a58
Update modules using mod_http_files to serve files for change in Prosody trunk
Kim Alvefur <zash@zash.se>
parents:
2871
diff
changeset
|
131 serve = module:depends"http_files".serve; |
b059a3fb2a58
Update modules using mod_http_files to serve files for change in Prosody trunk
Kim Alvefur <zash@zash.se>
parents:
2871
diff
changeset
|
132 end |
b059a3fb2a58
Update modules using mod_http_files to serve files for change in Prosody trunk
Kim Alvefur <zash@zash.se>
parents:
2871
diff
changeset
|
133 local serve_file = serve { |
885
292ea8df7267
mod_admin_web: Let mod_http_files handle file serving
Kim Alvefur <zash@zash.se>
parents:
770
diff
changeset
|
134 path = module:get_directory() .. "/www_files"; |
292ea8df7267
mod_admin_web: Let mod_http_files handle file serving
Kim Alvefur <zash@zash.se>
parents:
770
diff
changeset
|
135 }; |
770
a85d86a7f24e
mod_admin_web: Add explicit dependencies on mod_admin_adhoc and mod_bosh
Florian Zeitz <florob@babelmonkeys.de>
parents:
769
diff
changeset
|
136 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
137 -- Setup HTTP server |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
138 module:provides("http", { |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
139 name = "admin"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
140 route = { |
637
210f4ce2697c
mod_admin_web: HTTP methods are now required
Florian Zeitz <florob@babelmonkeys.de>
parents:
636
diff
changeset
|
141 ["GET"] = function(event) |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
142 event.response.headers.location = event.request.path .. "/"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
143 return 301; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
144 end; |
637
210f4ce2697c
mod_admin_web: HTTP methods are now required
Florian Zeitz <florob@babelmonkeys.de>
parents:
636
diff
changeset
|
145 ["GET /*"] = serve_file; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
146 } |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
147 }); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
148 |
769
7076f58b9f48
mod_admin_web: Move comment to appropriate line
Florian Zeitz <florob@babelmonkeys.de>
parents:
761
diff
changeset
|
149 -- Setup adminsub service |
901
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
150 local function simple_broadcast(kind, node, jids, item) |
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
151 if item then |
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
152 item = st.clone(item); |
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
153 item.attr.xmlns = nil; -- Clear the pubsub namespace |
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
154 end |
761
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
155 local message = st.message({ from = module.host, type = "headline" }) |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
156 :tag("event", { xmlns = xmlns_adminsub .. "#event" }) |
901
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
157 :tag(kind, { node = node }) |
761
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
158 :add_child(item); |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
159 for jid in pairs(jids) do |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
160 module:log("debug", "Sending notification to %s", jid); |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
161 message.attr.to = jid; |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
162 module:send(message); |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
163 end |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
164 end |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
165 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
166 service[module.host] = pubsub.new({ |
761
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
167 broadcaster = simple_broadcast; |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
168 normalize_jid = jid_bare; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
169 get_affiliation = function(jid) return get_affiliation(jid, module.host) end; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
170 capabilities = { |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
171 member = { |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
172 create = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
173 publish = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
174 retract = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
175 get_nodes = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
176 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
177 subscribe = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
178 unsubscribe = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
179 get_subscription = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
180 get_subscriptions = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
181 get_items = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
182 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
183 subscribe_other = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
184 unsubscribe_other = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
185 get_subscription_other = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
186 get_subscriptions_other = false; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
187 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
188 be_subscribed = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
189 be_unsubscribed = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
190 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
191 set_affiliation = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
192 }; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
193 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
194 owner = { |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
195 create = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
196 publish = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
197 retract = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
198 get_nodes = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
199 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
200 subscribe = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
201 unsubscribe = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
202 get_subscription = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
203 get_subscriptions = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
204 get_items = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
205 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
206 subscribe_other = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
207 unsubscribe_other = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
208 get_subscription_other = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
209 get_subscriptions_other = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
210 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
211 be_subscribed = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
212 be_unsubscribed = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
213 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
214 set_affiliation = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
215 }; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
216 }; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
217 }); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
218 |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
219 -- Create node for s2s sessions |
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
220 local ok, err = service[module.host]:create(xmlns_s2s_session, true); |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
221 if not ok then |
3567
179424d557f2
mod_admin_web: Fix to use format strings in logger calls (thanks Ge0rG)
Matthew Wild <mwild1@gmail.com>
parents:
3550
diff
changeset
|
222 module:log("warn", "Could not create node %s: %s", xmlns_s2s_session, err); |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
223 else |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
224 service[module.host]:set_affiliation(xmlns_s2s_session, true, module.host, "owner") |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
225 end |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
226 |
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1118
diff
changeset
|
227 -- Add outgoing s2s sessions |
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
228 for _, session in pairs(hosts[module.host].s2sout) do |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
229 if session.type ~= "s2sout_unauthed" then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
230 add_host(session, "out", module.host); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
231 end |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
232 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
233 |
2871
c3317f61f3f9
mod_admin_web: Fix typo in comment [codespell]
Kim Alvefur <zash@zash.se>
parents:
1865
diff
changeset
|
234 -- Add incoming s2s sessions |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
235 for session in pairs(incoming_s2s) do |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
236 if session.to_host == module.host then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
237 add_host(session, "in", module.host); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
238 end |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
239 end |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
240 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
241 -- Create node for c2s sessions |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
242 ok, err = service[module.host]:create(xmlns_c2s_session, true); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
243 if not ok then |
3567
179424d557f2
mod_admin_web: Fix to use format strings in logger calls (thanks Ge0rG)
Matthew Wild <mwild1@gmail.com>
parents:
3550
diff
changeset
|
244 module:log("warn", "Could not create node %s: %s", xmlns_c2s_session, tostring(err)); |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
245 else |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
246 service[module.host]:set_affiliation(xmlns_c2s_session, true, module.host, "owner") |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
247 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
248 |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
249 -- Add c2s sessions |
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
250 for _, user in pairs(hosts[module.host].sessions or {}) do |
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
251 for _, session in pairs(user.sessions or {}) do |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
252 add_client(session, module.host); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
253 end |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
254 end |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
255 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
256 -- Register adminsub handler |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
257 module:hook("iq/host/http://prosody.im/adminsub:adminsub", function(event) |
3550
8079e9c6d419
mod_admin_web: Ignore shadowed 'ok' variable, nothing to worry about [luacheck]
Kim Alvefur <zash@zash.se>
parents:
3549
diff
changeset
|
258 -- luacheck: ignore 431/ok |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
259 local origin, stanza = event.origin, event.stanza; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
260 local adminsub = stanza.tags[1]; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
261 local action = adminsub.tags[1]; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
262 local reply; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
263 if action.name == "subscribe" then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
264 local ok, ret = service[module.host]:add_subscription(action.attr.node, stanza.attr.from, stanza.attr.from); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
265 if ok then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
266 reply = st.reply(stanza) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
267 :tag("adminsub", { xmlns = xmlns_adminsub }); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
268 else |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
269 reply = st.error_reply(stanza, "cancel", ret); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
270 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
271 elseif action.name == "unsubscribe" then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
272 local ok, ret = service[module.host]:remove_subscription(action.attr.node, stanza.attr.from, stanza.attr.from); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
273 if ok then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
274 reply = st.reply(stanza) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
275 :tag("adminsub", { xmlns = xmlns_adminsub }); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
276 else |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
277 reply = st.error_reply(stanza, "cancel", ret); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
278 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
279 elseif action.name == "items" then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
280 local node = action.attr.node; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
281 local ok, ret = service[module.host]:get_items(node, stanza.attr.from); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
282 if not ok then |
1865
db8b256f51ff
mod_admin_web,mod_carbons,mod_csi_compat,mod_mam_muc,mod_tcpproxy: Explicitly return true
Kim Alvefur <zash@zash.se>
parents:
1646
diff
changeset
|
283 origin.send(st.error_reply(stanza, "cancel", ret)); |
db8b256f51ff
mod_admin_web,mod_carbons,mod_csi_compat,mod_mam_muc,mod_tcpproxy: Explicitly return true
Kim Alvefur <zash@zash.se>
parents:
1646
diff
changeset
|
284 return true; |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
285 end |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
286 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
287 local data = st.stanza("items", { node = node }); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
288 for _, entry in pairs(ret) do |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
289 data:add_child(entry); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
290 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
291 if data then |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
292 reply = st.reply(stanza) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
293 :tag("adminsub", { xmlns = xmlns_adminsub }) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
294 :add_child(data); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
295 else |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
296 reply = st.error_reply(stanza, "cancel", "item-not-found"); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
297 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
298 elseif action.name == "adminfor" then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
299 local data = st.stanza("adminfor"); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
300 for host_name in pairs(hosts) do |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
301 if is_admin(stanza.attr.from, host_name) then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
302 data:tag("item"):text(host_name):up(); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
303 end |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
304 end |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
305 reply = st.reply(stanza) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
306 :tag("adminsub", { xmlns = xmlns_adminsub }) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
307 :add_child(data); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
308 else |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
309 reply = st.error_reply(stanza, "feature-not-implemented"); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
310 end |
1865
db8b256f51ff
mod_admin_web,mod_carbons,mod_csi_compat,mod_mam_muc,mod_tcpproxy: Explicitly return true
Kim Alvefur <zash@zash.se>
parents:
1646
diff
changeset
|
311 origin.send(reply); |
db8b256f51ff
mod_admin_web,mod_carbons,mod_csi_compat,mod_mam_muc,mod_tcpproxy: Explicitly return true
Kim Alvefur <zash@zash.se>
parents:
1646
diff
changeset
|
312 return true; |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
313 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
314 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
315 -- Add/remove c2s sessions |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
316 module:hook("resource-bind", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
317 add_client(event.session, module.host); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
318 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
319 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
320 module:hook("resource-unbind", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
321 del_client(event.session, module.host); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
322 service[module.host]:remove_subscription(xmlns_c2s_session, module.host, event.session.full_jid); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
323 service[module.host]:remove_subscription(xmlns_s2s_session, module.host, event.session.full_jid); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
324 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
325 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
326 -- Add/remove s2s sessions |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
327 module:hook("s2sout-established", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
328 add_host(event.session, "out", module.host); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
329 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
330 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
331 module:hook("s2sin-established", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
332 add_host(event.session, "in", module.host); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
333 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
334 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
335 module:hook("s2sout-destroyed", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
336 del_host(event.session, "out", module.host); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
337 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
338 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
339 module:hook("s2sin-destroyed", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
340 del_host(event.session, "in", module.host); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
341 end); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
342 end |