Mercurial > prosody-modules
annotate mod_admin_web2/admin_web2/mod_admin_web2.lua @ 6556:7477e97a9045
mod_firewall: Apply pre-reload state before re-reading config
This change makes load/reload a bit more robust. module.load() runs before
module.restore() and it reads from the config and updates the state (if
needed).
However, after this, module.restore() could run and apply the old state again.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 24 May 2026 20:03:20 +0100 |
| parents | 7eb114975cec |
| children |
| 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 |
|
6520
7eb114975cec
mod_admin_web2: Fork of admin_web for prosody 13.0. It is a fork because it changes access rights and might be insecure. Mark as alpha.
Menel <menel@snikket.de>
parents:
6190
diff
changeset
|
20 module:default_permission("prosody:operator", ":web-operator") |
|
7eb114975cec
mod_admin_web2: Fork of admin_web for prosody 13.0. It is a fork because it changes access rights and might be insecure. Mark as alpha.
Menel <menel@snikket.de>
parents:
6190
diff
changeset
|
21 |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
22 local st = require "util.stanza"; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
23 local uuid_generate = require "util.uuid".generate; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
24 local pubsub = require "util.pubsub"; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
25 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
|
26 |
|
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
27 local hosts = prosody.hosts; |
|
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
28 local incoming_s2s = prosody.incoming_s2s; |
|
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
29 |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
30 module:set_global(); |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
31 |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
32 local service = {}; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
33 |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
34 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
|
35 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
|
36 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
|
37 |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
38 local idmap = {}; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
39 |
|
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
40 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
|
41 local name = session.full_jid; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
42 local id = idmap[name]; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
43 if not id then |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
44 id = uuid_generate(); |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
45 idmap[name] = id; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
46 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 end |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
55 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
56 if session.compressed then |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
57 item:tag("compressed"):up(); |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
58 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
59 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
|
60 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
|
61 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
62 |
|
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
63 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
|
64 local name = session.full_jid; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
65 local id = idmap[name]; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
66 if id then |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
67 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
|
68 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
|
69 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
70 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
71 |
|
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
72 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
|
73 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
|
74 local id = idmap[name.."_"..type]; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
75 if not id then |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
76 id = uuid_generate(); |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
77 idmap[name.."_"..type] = id; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
78 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
79 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
|
80 :tag(type):up(); |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
81 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
|
82 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
|
83 |
|
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 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
|
88 end |
|
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
89 |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
90 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
|
91 encrypted:tag("valid"); |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
92 else |
|
1117
d643c385d3f6
mod_admin_web: Provide some information about the TLS layer
Florian Zeitz <florob@babelmonkeys.de>
parents:
901
diff
changeset
|
93 encrypted:tag("invalid"); |
|
636
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 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
96 if session.compressed then |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
97 item:tag("compressed"):up(); |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
98 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
99 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
|
100 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
|
101 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
102 |
|
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
103 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
|
104 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
|
105 local id = idmap[name.."_"..type]; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
106 if id then |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
107 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
|
108 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
|
109 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
110 end |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
111 |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
112 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
|
113 -- Dependencies |
|
a85d86a7f24e
mod_admin_web: Add explicit dependencies on mod_admin_adhoc and mod_bosh
Florian Zeitz <florob@babelmonkeys.de>
parents:
769
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 |
|
6190
963c16e417d6
mod_admin_web: Remove compatibility with 0.11
Link Mauve <linkmauve@linkmauve.fr>
parents:
4197
diff
changeset
|
118 local http_files = require "net.http.files"; |
|
963c16e417d6
mod_admin_web: Remove compatibility with 0.11
Link Mauve <linkmauve@linkmauve.fr>
parents:
4197
diff
changeset
|
119 local serve_file = http_files.serve { |
|
4185
06a9ac93e2f1
Back out a8aacfbdaea9: Not needed since change in trunk
Kim Alvefur <zash@zash.se>
parents:
4181
diff
changeset
|
120 path = module:get_directory() .. "/www_files"; |
|
885
292ea8df7267
mod_admin_web: Let mod_http_files handle file serving
Kim Alvefur <zash@zash.se>
parents:
770
diff
changeset
|
121 }; |
|
770
a85d86a7f24e
mod_admin_web: Add explicit dependencies on mod_admin_adhoc and mod_bosh
Florian Zeitz <florob@babelmonkeys.de>
parents:
769
diff
changeset
|
122 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
123 -- Setup HTTP server |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
124 module:provides("http", { |
|
4197
2825fa4504f0
mod_admin_web: Add a title for mod_http_index
Kim Alvefur <zash@zash.se>
parents:
4185
diff
changeset
|
125 title = "Admin Interface"; |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
126 name = "admin"; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
127 route = { |
|
637
210f4ce2697c
mod_admin_web: HTTP methods are now required
Florian Zeitz <florob@babelmonkeys.de>
parents:
636
diff
changeset
|
128 ["GET"] = function(event) |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
129 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
|
130 return 301; |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
131 end; |
|
637
210f4ce2697c
mod_admin_web: HTTP methods are now required
Florian Zeitz <florob@babelmonkeys.de>
parents:
636
diff
changeset
|
132 ["GET /*"] = serve_file; |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
133 } |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
134 }); |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
135 |
|
769
7076f58b9f48
mod_admin_web: Move comment to appropriate line
Florian Zeitz <florob@babelmonkeys.de>
parents:
761
diff
changeset
|
136 -- Setup adminsub service |
|
901
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
137 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
|
138 if item then |
|
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
139 item = st.clone(item); |
|
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
140 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
|
141 end |
|
761
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
142 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
|
143 :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
|
144 :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
|
145 :add_child(item); |
|
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
146 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
|
147 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
|
148 message.attr.to = jid; |
|
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
149 module:send(message); |
|
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
150 end |
|
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
151 end |
|
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
152 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
153 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
|
154 broadcaster = simple_broadcast; |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
155 normalize_jid = jid_bare; |
|
6520
7eb114975cec
mod_admin_web2: Fork of admin_web for prosody 13.0. It is a fork because it changes access rights and might be insecure. Mark as alpha.
Menel <menel@snikket.de>
parents:
6190
diff
changeset
|
156 -- what was this for? prosody:operator has full rights everywhere, this shoud be fine? |
|
7eb114975cec
mod_admin_web2: Fork of admin_web for prosody 13.0. It is a fork because it changes access rights and might be insecure. Mark as alpha.
Menel <menel@snikket.de>
parents:
6190
diff
changeset
|
157 -- get_affiliation = function(jid) return get_affiliation(jid, module.host) end; |
|
7eb114975cec
mod_admin_web2: Fork of admin_web for prosody 13.0. It is a fork because it changes access rights and might be insecure. Mark as alpha.
Menel <menel@snikket.de>
parents:
6190
diff
changeset
|
158 get_affiliation = function() return "owner" end; |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
159 capabilities = { |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
160 member = { |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
161 create = false; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
162 publish = false; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
163 retract = false; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
164 get_nodes = true; |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
165 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
166 subscribe = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
167 unsubscribe = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
168 get_subscription = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
169 get_subscriptions = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
170 get_items = true; |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
171 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
172 subscribe_other = false; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
173 unsubscribe_other = false; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
174 get_subscription_other = false; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
175 get_subscriptions_other = false; |
|
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 be_subscribed = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
178 be_unsubscribed = true; |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
179 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
180 set_affiliation = false; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
181 }; |
|
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 owner = { |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
184 create = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
185 publish = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
186 retract = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
187 get_nodes = true; |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
188 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
189 subscribe = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
190 unsubscribe = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
191 get_subscription = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
192 get_subscriptions = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
193 get_items = true; |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
194 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
195 subscribe_other = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
196 unsubscribe_other = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
197 get_subscription_other = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
198 get_subscriptions_other = 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 be_subscribed = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
201 be_unsubscribed = true; |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
202 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
203 set_affiliation = true; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
204 }; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
205 }; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
206 }); |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
207 |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
208 -- Create node for s2s sessions |
|
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 else |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
213 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
|
214 end |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
215 |
|
1343
7dbde05b48a9
all the things: Remove trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
1118
diff
changeset
|
216 -- Add outgoing s2s sessions |
|
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
217 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
|
218 if session.type ~= "s2sout_unauthed" then |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
219 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
|
220 end |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
221 end |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
222 |
|
2871
c3317f61f3f9
mod_admin_web: Fix typo in comment [codespell]
Kim Alvefur <zash@zash.se>
parents:
1865
diff
changeset
|
223 -- Add incoming s2s sessions |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 end |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
228 end |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
229 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
230 -- Create node for c2s sessions |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 else |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
235 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
|
236 end |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
237 |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
238 -- Add c2s sessions |
|
1646
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
239 for _, user in pairs(hosts[module.host].sessions or {}) do |
|
95b8b1f9a882
mod_admin_web: Cleanup
Florian Zeitz <florob@babelmonkeys.de>
parents:
1343
diff
changeset
|
240 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
|
241 add_client(session, module.host); |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
242 end |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
243 end |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
244 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
245 -- Register adminsub handler |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
246 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
|
247 -- luacheck: ignore 431/ok |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
248 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
|
249 local adminsub = stanza.tags[1]; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
250 local action = adminsub.tags[1]; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
251 local reply; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
252 if action.name == "subscribe" then |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
253 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
|
254 if ok then |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
255 reply = st.reply(stanza) |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
256 :tag("adminsub", { xmlns = xmlns_adminsub }); |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
257 else |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
258 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
|
259 end |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
260 elseif action.name == "unsubscribe" then |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
261 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
|
262 if ok then |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
263 reply = st.reply(stanza) |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
264 :tag("adminsub", { xmlns = xmlns_adminsub }); |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
265 else |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
266 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
|
267 end |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
268 elseif action.name == "items" then |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
269 local node = action.attr.node; |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 return true; |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
274 end |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
275 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
276 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
|
277 for _, entry in pairs(ret) do |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
278 data:add_child(entry); |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
279 end |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
280 if data then |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
281 reply = st.reply(stanza) |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
282 :tag("adminsub", { xmlns = xmlns_adminsub }) |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
283 :add_child(data); |
|
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
284 else |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
285 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
|
286 end |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
287 elseif action.name == "adminfor" then |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
288 local data = st.stanza("adminfor"); |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
289 for host_name in pairs(hosts) do |
|
6520
7eb114975cec
mod_admin_web2: Fork of admin_web for prosody 13.0. It is a fork because it changes access rights and might be insecure. Mark as alpha.
Menel <menel@snikket.de>
parents:
6190
diff
changeset
|
290 -- new Permission API: |
|
7eb114975cec
mod_admin_web2: Fork of admin_web for prosody 13.0. It is a fork because it changes access rights and might be insecure. Mark as alpha.
Menel <menel@snikket.de>
parents:
6190
diff
changeset
|
291 if module:context(host_name):may(":web-operator", stanza.attr.from) then |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
292 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
|
293 end |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
294 end |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
295 reply = st.reply(stanza) |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
296 :tag("adminsub", { xmlns = xmlns_adminsub }) |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
297 :add_child(data); |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
298 else |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
299 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
|
300 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
|
301 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
|
302 return true; |
|
663
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 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
305 -- Add/remove c2s sessions |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
306 module:hook("resource-bind", function(event) |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
307 add_client(event.session, module.host); |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
308 end); |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
309 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
310 module:hook("resource-unbind", function(event) |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
311 del_client(event.session, module.host); |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
312 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
|
313 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
|
314 end); |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
315 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
316 -- Add/remove s2s sessions |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
317 module:hook("s2sout-established", function(event) |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
318 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
|
319 end); |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
320 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
321 module:hook("s2sin-established", function(event) |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
322 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
|
323 end); |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
324 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
325 module:hook("s2sout-destroyed", function(event) |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
326 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
|
327 end); |
|
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
328 |
|
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
329 module:hook("s2sin-destroyed", function(event) |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
330 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
|
331 end); |
|
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
332 end |
