Mercurial > prosody-modules
annotate mod_admin_web/admin_web/mod_admin_web.lua @ 975:08628703456a
mod_muc_log_http: do some more cleanup of the code.
author | Marco Cirillo <maranda@lightwitch.org> |
---|---|
date | Mon, 08 Apr 2013 00:52:16 +0200 |
parents | e3ad5f3aa6d4 |
children | d643c385d3f6 |
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 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
26 module:set_global(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
27 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
28 local service = {}; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
29 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
30 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
|
31 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
|
32 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
|
33 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
34 local idmap = {}; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
35 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
36 function add_client(session, host) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
37 local name = session.full_jid; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
38 local id = idmap[name]; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
39 if not id then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
40 id = uuid_generate(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
41 idmap[name] = id; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
42 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
43 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
|
44 if session.secure then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
45 item:tag("encrypted"):up(); |
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 if session.compressed then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
48 item:tag("compressed"):up(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
49 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
50 service[host]:publish(xmlns_c2s_session, host, id, item); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
51 module:log("debug", "Added client " .. name); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
52 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
53 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
54 function del_client(session, host) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
55 local name = session.full_jid; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
56 local id = idmap[name]; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
57 if id then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
58 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
|
59 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
|
60 end |
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 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
63 function add_host(session, type, host) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
64 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
|
65 local id = idmap[name.."_"..type]; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
66 if not id then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
67 id = uuid_generate(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
68 idmap[name.."_"..type] = id; |
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 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
|
71 :tag(type):up(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
72 if session.secure then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
73 if session.cert_identity_status == "valid" then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
74 item:tag("encrypted"):tag("valid"):up():up(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
75 else |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
76 item:tag("encrypted"):tag("invalid"):up():up(); |
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 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
79 if session.compressed then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
80 item:tag("compressed"):up(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
81 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
82 service[host]:publish(xmlns_s2s_session, host, id, item); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
83 module:log("debug", "Added host " .. name .. " s2s" .. type); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
84 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
85 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
86 function del_host(session, type, host) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
87 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
|
88 local id = idmap[name.."_"..type]; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
89 if id then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
90 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
|
91 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
|
92 end |
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 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
95 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
|
96 -- Dependencies |
a85d86a7f24e
mod_admin_web: Add explicit dependencies on mod_admin_adhoc and mod_bosh
Florian Zeitz <florob@babelmonkeys.de>
parents:
769
diff
changeset
|
97 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
|
98 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
|
99 module:depends("http"); |
885
292ea8df7267
mod_admin_web: Let mod_http_files handle file serving
Kim Alvefur <zash@zash.se>
parents:
770
diff
changeset
|
100 local serve_file = module:depends("http_files").serve { |
292ea8df7267
mod_admin_web: Let mod_http_files handle file serving
Kim Alvefur <zash@zash.se>
parents:
770
diff
changeset
|
101 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
|
102 }; |
770
a85d86a7f24e
mod_admin_web: Add explicit dependencies on mod_admin_adhoc and mod_bosh
Florian Zeitz <florob@babelmonkeys.de>
parents:
769
diff
changeset
|
103 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
104 -- Setup HTTP server |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
105 module:provides("http", { |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
106 name = "admin"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
107 route = { |
637
210f4ce2697c
mod_admin_web: HTTP methods are now required
Florian Zeitz <florob@babelmonkeys.de>
parents:
636
diff
changeset
|
108 ["GET"] = function(event) |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
109 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
|
110 return 301; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
111 end; |
637
210f4ce2697c
mod_admin_web: HTTP methods are now required
Florian Zeitz <florob@babelmonkeys.de>
parents:
636
diff
changeset
|
112 ["GET /*"] = serve_file; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
113 } |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
114 }); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
115 |
769
7076f58b9f48
mod_admin_web: Move comment to appropriate line
Florian Zeitz <florob@babelmonkeys.de>
parents:
761
diff
changeset
|
116 -- Setup adminsub service |
901
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
117 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
|
118 if item then |
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
119 item = st.clone(item); |
e3ad5f3aa6d4
mod_admin_web: Adapt to util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents:
885
diff
changeset
|
120 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
|
121 end |
761
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
122 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
|
123 :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
|
124 :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
|
125 :add_child(item); |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
126 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
|
127 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
|
128 message.attr.to = jid; |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
129 module:send(message); |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
130 end |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
131 end |
48f8b312a509
mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents:
753
diff
changeset
|
132 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
133 local ok, err; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
134 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
|
135 broadcaster = simple_broadcast; |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
136 normalize_jid = jid_bare; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
137 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
|
138 capabilities = { |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
139 member = { |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
140 create = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
141 publish = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
142 retract = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
143 get_nodes = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
144 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
145 subscribe = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
146 unsubscribe = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
147 get_subscription = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
148 get_subscriptions = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
149 get_items = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
150 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
151 subscribe_other = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
152 unsubscribe_other = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
153 get_subscription_other = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
154 get_subscriptions_other = false; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
155 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
156 be_subscribed = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
157 be_unsubscribed = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
158 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
159 set_affiliation = false; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
160 }; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
161 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
162 owner = { |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
163 create = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
164 publish = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
165 retract = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
166 get_nodes = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
167 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
168 subscribe = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
169 unsubscribe = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
170 get_subscription = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
171 get_subscriptions = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
172 get_items = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
173 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
174 subscribe_other = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
175 unsubscribe_other = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
176 get_subscription_other = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
177 get_subscriptions_other = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
178 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
179 be_subscribed = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
180 be_unsubscribed = true; |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
181 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
182 set_affiliation = true; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
183 }; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
184 }; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
185 }); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
186 |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
187 -- Create node for s2s sessions |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
188 ok, err = service[module.host]:create(xmlns_s2s_session, true); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
189 if not ok then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
190 module:log("warn", "Could not create node " .. xmlns_s2s_session .. ": " .. tostring(err)); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
191 else |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
192 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
|
193 end |
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 -- Add outgoing s2s sessions |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
196 for remotehost, session in pairs(hosts[module.host].s2sout) do |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
197 if session.type ~= "s2sout_unauthed" then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
198 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
|
199 end |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
200 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
201 |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
202 -- Add incomming s2s sessions |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
203 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
|
204 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
|
205 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
|
206 end |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
207 end |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
208 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
209 -- Create node for c2s sessions |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
210 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
|
211 if not ok then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
212 module:log("warn", "Could not create node " .. xmlns_c2s_session .. ": " .. tostring(err)); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
213 else |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
214 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
|
215 end |
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 -- Add c2s sessions |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
218 for username, user in pairs(hosts[module.host].sessions or {}) do |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
219 for resource, session in pairs(user.sessions or {}) do |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
220 add_client(session, module.host); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
221 end |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
222 end |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
223 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
224 -- Register adminsub handler |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
225 module:hook("iq/host/http://prosody.im/adminsub:adminsub", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
226 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
|
227 local adminsub = stanza.tags[1]; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
228 local action = adminsub.tags[1]; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
229 local reply; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
230 if action.name == "subscribe" then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
231 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
|
232 if ok then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
233 reply = st.reply(stanza) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
234 :tag("adminsub", { xmlns = xmlns_adminsub }); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
235 else |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
236 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
|
237 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
238 elseif action.name == "unsubscribe" then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
239 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
|
240 if ok then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
241 reply = st.reply(stanza) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
242 :tag("adminsub", { xmlns = xmlns_adminsub }); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
243 else |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
244 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
|
245 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
246 elseif action.name == "items" then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
247 local node = action.attr.node; |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
248 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
|
249 if not ok then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
250 return origin.send(st.error_reply(stanza, "cancel", ret)); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
251 end |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
252 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
253 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
|
254 for _, entry in pairs(ret) do |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
255 data:add_child(entry); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
256 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
257 if data then |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
258 reply = st.reply(stanza) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
259 :tag("adminsub", { xmlns = xmlns_adminsub }) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
260 :add_child(data); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
261 else |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
262 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
|
263 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
264 elseif action.name == "adminfor" then |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
265 local data = st.stanza("adminfor"); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
266 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
|
267 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
|
268 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
|
269 end |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
270 end |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
271 reply = st.reply(stanza) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
272 :tag("adminsub", { xmlns = xmlns_adminsub }) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
273 :add_child(data); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
274 else |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
275 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
|
276 end |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
277 return origin.send(reply); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
278 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
279 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
280 -- Add/remove c2s sessions |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
281 module:hook("resource-bind", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
282 add_client(event.session, module.host); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
283 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
284 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
285 module:hook("resource-unbind", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
286 del_client(event.session, module.host); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
287 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
|
288 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
|
289 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
290 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
291 -- Add/remove s2s sessions |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
292 module:hook("s2sout-established", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
293 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
|
294 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
295 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
296 module:hook("s2sin-established", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
297 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
|
298 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
299 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
300 module:hook("s2sout-destroyed", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
301 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
|
302 end); |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
303 |
663
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
304 module:hook("s2sin-destroyed", function(event) |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
305 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
|
306 end); |
a826b61c8f3a
mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents:
637
diff
changeset
|
307 end |
636
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
308 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
309 function get_affiliation(jid, host) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
310 local bare_jid = jid_bare(jid); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
311 if is_admin(bare_jid, host) then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
312 return "member"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
313 else |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
314 return "none"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
315 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
316 end |