annotate mod_admin_web/admin_web/mod_admin_web.lua @ 926:f88381a39c56

mod_block_subscribes: Block inbound and outbound subscription requests (useful to prevent implicit roster modification)
author Matthew Wild <mwild1@gmail.com>
date Thu, 22 Nov 2012 18:59:10 +0000
parents a85d86a7f24e
children 292ea8df7267
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 local lfs = require "lfs";
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
26 local open = io.open;
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
27 local stat = lfs.attributes;
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
28
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
29 module:set_global();
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
30
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
31 local service = {};
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
32
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
33 local http_base = module.path:gsub("/[^/]+$","") .. "/www_files/";
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
34
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
35 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
36 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
37 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
38
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
39 local mime_map = {
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
40 html = "text/html";
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
41 xml = "text/xml";
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
42 js = "text/javascript";
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
43 css = "text/css";
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
44 };
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
45
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
46 local idmap = {};
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
48 function add_client(session, host)
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
49 local name = session.full_jid;
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
50 local id = idmap[name];
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
51 if not id then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
52 id = uuid_generate();
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
53 idmap[name] = id;
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
54 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
55 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
56 if session.secure then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
57 item:tag("encrypted"):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 if session.compressed then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
60 item:tag("compressed"):up();
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 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
63 module:log("debug", "Added client " .. name);
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
64 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
65
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
66 function del_client(session, host)
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
67 local name = session.full_jid;
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
68 local id = idmap[name];
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
69 if id then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
70 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
71 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
72 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
73 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
74
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
75 function add_host(session, type, host)
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
76 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
77 local id = idmap[name.."_"..type];
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
78 if not id then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
79 id = uuid_generate();
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
80 idmap[name.."_"..type] = id;
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 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
83 :tag(type):up();
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
84 if session.secure then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
85 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
86 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
87 else
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
88 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
89 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
90 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
91 if session.compressed then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
92 item:tag("compressed"):up();
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 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
95 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
96 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
97
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
98 function del_host(session, type, host)
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
99 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
100 local id = idmap[name.."_"..type];
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
101 if id then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
102 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
103 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
104 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
105 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
106
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
107 function serve_file(event, path)
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
108 local full_path = http_base .. path;
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
109
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
110 if stat(full_path, "mode") == "directory" then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
111 if stat(full_path.."/index.html", "mode") == "file" then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
112 return serve_file(event, path.."/index.html");
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
113 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
114 return 403;
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
115 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
116
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
117 local f, err = open(full_path, "rb");
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
118 if not f then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
119 return 404;
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
120 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
121
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
122 local data = f:read("*a");
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
123 f:close();
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
124 if not data then
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
125 return 403;
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
126 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
127
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
128 local ext = path:match("%.([^.]*)$");
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
129 event.response.headers.content_type = mime_map[ext]; -- Content-Type should be nil when not known
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
130 return data;
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
131 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
132
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
133 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
134 -- Dependencies
a85d86a7f24e mod_admin_web: Add explicit dependencies on mod_admin_adhoc and mod_bosh
Florian Zeitz <florob@babelmonkeys.de>
parents: 769
diff changeset
135 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
136 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
137 module:depends("http");
a85d86a7f24e mod_admin_web: Add explicit dependencies on mod_admin_adhoc and mod_bosh
Florian Zeitz <florob@babelmonkeys.de>
parents: 769
diff changeset
138
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
139 -- Setup HTTP server
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
140 module:provides("http", {
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
141 name = "admin";
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
142 route = {
637
210f4ce2697c mod_admin_web: HTTP methods are now required
Florian Zeitz <florob@babelmonkeys.de>
parents: 636
diff changeset
143 ["GET"] = function(event)
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
144 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
145 return 301;
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
146 end;
637
210f4ce2697c mod_admin_web: HTTP methods are now required
Florian Zeitz <florob@babelmonkeys.de>
parents: 636
diff changeset
147 ["GET /*"] = serve_file;
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
148 }
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
149 });
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
150
769
7076f58b9f48 mod_admin_web: Move comment to appropriate line
Florian Zeitz <florob@babelmonkeys.de>
parents: 761
diff changeset
151 -- Setup adminsub service
761
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
152 local function simple_broadcast(node, jids, item)
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
153 item = st.clone(item);
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
154 item.attr.xmlns = nil; -- Clear the pubsub namespace
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
155 local message = st.message({ from = module.host, type = "headline" })
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
156 :tag("event", { xmlns = xmlns_adminsub .. "#event" })
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
157 :tag("items", { node = node })
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
158 :add_child(item);
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
159 for jid in pairs(jids) do
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
160 module:log("debug", "Sending notification to %s", jid);
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
161 message.attr.to = jid;
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
162 module:send(message);
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
163 end
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
164 end
48f8b312a509 mod_admin_web: Replace core_post_stanza() with module:send()
Florian Zeitz <florob@babelmonkeys.de>
parents: 753
diff changeset
165
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
166 local ok, err;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
167 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
168 broadcaster = simple_broadcast;
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
169 normalize_jid = jid_bare;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
170 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
171 capabilities = {
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
172 member = {
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
173 create = false;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
174 publish = false;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
175 retract = false;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
176 get_nodes = true;
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
177
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
178 subscribe = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
179 unsubscribe = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
180 get_subscription = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
181 get_subscriptions = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
182 get_items = true;
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
183
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
184 subscribe_other = false;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
185 unsubscribe_other = false;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
186 get_subscription_other = false;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
187 get_subscriptions_other = false;
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 be_subscribed = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
190 be_unsubscribed = true;
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
191
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
192 set_affiliation = false;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
193 };
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 owner = {
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
196 create = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
197 publish = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
198 retract = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
199 get_nodes = true;
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
200
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
201 subscribe = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
202 unsubscribe = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
203 get_subscription = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
204 get_subscriptions = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
205 get_items = true;
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
206
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
207 subscribe_other = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
208 unsubscribe_other = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
209 get_subscription_other = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
210 get_subscriptions_other = true;
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
211
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
212 be_subscribed = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
213 be_unsubscribed = true;
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
214
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
215 set_affiliation = true;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
216 };
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
217 };
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
218 });
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
219
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
220 -- Create node for s2s sessions
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
221 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
222 if not ok then
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
223 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
224 else
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
225 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
226 end
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
227
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
228 -- Add outgoing s2s sessions
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
229 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
230 if session.type ~= "s2sout_unauthed" then
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
231 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
232 end
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
233 end
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
234
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
235 -- Add incomming s2s sessions
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
236 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
237 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
238 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
239 end
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
240 end
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
241
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
242 -- Create node for c2s sessions
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
243 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
244 if not ok then
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
245 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
246 else
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
247 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
248 end
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
249
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
250 -- Add c2s sessions
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
251 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
252 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
253 add_client(session, module.host);
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
254 end
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
255 end
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
256
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
257 -- Register adminsub handler
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
258 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
259 local origin, stanza = event.origin, event.stanza;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
260 local adminsub = stanza.tags[1];
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
261 local action = adminsub.tags[1];
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
262 local reply;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
263 if action.name == "subscribe" then
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
264 local ok, ret = service[module.host]:add_subscription(action.attr.node, stanza.attr.from, stanza.attr.from);
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
265 if ok then
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
266 reply = st.reply(stanza)
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
267 :tag("adminsub", { xmlns = xmlns_adminsub });
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
268 else
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
269 reply = st.error_reply(stanza, "cancel", ret);
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
270 end
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
271 elseif action.name == "unsubscribe" then
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
272 local ok, ret = service[module.host]:remove_subscription(action.attr.node, stanza.attr.from, stanza.attr.from);
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
273 if ok then
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
274 reply = st.reply(stanza)
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
275 :tag("adminsub", { xmlns = xmlns_adminsub });
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
276 else
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
277 reply = st.error_reply(stanza, "cancel", ret);
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
278 end
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
279 elseif action.name == "items" then
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
280 local node = action.attr.node;
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
281 local ok, ret = service[module.host]:get_items(node, stanza.attr.from);
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
282 if not ok then
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
283 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
284 end
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
285
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
286 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
287 for _, entry in pairs(ret) do
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
288 data:add_child(entry);
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
289 end
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
290 if data then
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
291 reply = st.reply(stanza)
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
292 :tag("adminsub", { xmlns = xmlns_adminsub })
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
293 :add_child(data);
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
294 else
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
295 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
296 end
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
297 elseif action.name == "adminfor" then
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
298 local data = st.stanza("adminfor");
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
299 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
300 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
301 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
302 end
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
303 end
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
304 reply = st.reply(stanza)
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
305 :tag("adminsub", { xmlns = xmlns_adminsub })
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
306 :add_child(data);
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
307 else
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
308 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
309 end
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
310 return origin.send(reply);
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
311 end);
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
312
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
313 -- Add/remove c2s sessions
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
314 module:hook("resource-bind", function(event)
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
315 add_client(event.session, module.host);
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
316 end);
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
317
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
318 module:hook("resource-unbind", function(event)
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
319 del_client(event.session, module.host);
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
320 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
321 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
322 end);
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
323
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
324 -- Add/remove s2s sessions
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
325 module:hook("s2sout-established", function(event)
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
326 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
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-established", function(event)
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
330 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
331 end);
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
332
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
333 module:hook("s2sout-destroyed", function(event)
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
334 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
335 end);
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
336
663
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
337 module:hook("s2sin-destroyed", function(event)
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
338 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
339 end);
a826b61c8f3a mod_admin_web: Utilize the shared module magic
Florian Zeitz <florob@babelmonkeys.de>
parents: 637
diff changeset
340 end
636
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
341
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
342 function get_affiliation(jid, host)
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
343 local bare_jid = jid_bare(jid);
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
344 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
345 return "member";
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
346 else
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
347 return "none";
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
348 end
b3a3199255d7 mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
349 end