annotate mod_admin_web/admin_web/mod_admin_web.lua @ 318:84caab2bc02c

mod_data_access: New plugin providing a HTTP interface to Prosodys datamanager
author Kim Alvefur <zash@zash.se>
date Wed, 19 Jan 2011 20:18:38 +0100
parents 4f78f5020aa9
children ba2e78661ea8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
1 -- Copyright (C) 2010 Florian Zeitz
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
2 --
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
3 -- This file is MIT/X11 licensed. Please see the
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
4 -- COPYING file in the source package for more information.
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
5 --
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
6
301
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
7 -- <session xmlns="http://prosody.im/streams/c2s" jid="alice@example.com/brussels">
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
8 -- <encrypted/>
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
9 -- <compressed/>
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
10 -- </session>
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
11
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
12 -- <session xmlns="http://prosody.im/streams/s2s" jid="example.com">
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
13 -- <encrypted/>
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
14 -- <compressed/>
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
15 -- <in/> / <out/>
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
16 -- </session>
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
17
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
18 local st = require "util.stanza";
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
19 local uuid_generate = require "util.uuid".generate;
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
20 local is_admin = require "usermanager".is_admin;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
21 local pubsub = require "util.pubsub";
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
22 local httpserver = require "net.httpserver";
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
23 local jid_bare = require "util.jid".bare;
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
24 local lfs = require "lfs";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
25 local open = io.open;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
26 local stat = lfs.attributes;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
27
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
28 local host = module:get_host();
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
29 local service;
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
30
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
31 local http_base = (prosody.paths.plugins or "./plugins/") .. "admin_web/www_files";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
32
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
33 local xmlns_adminsub = "http://prosody.im/adminsub";
301
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
34 local xmlns_c2s_session = "http://prosody.im/streams/c2s";
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
35 local xmlns_s2s_session = "http://prosody.im/streams/s2s";
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
36
309
5ec9125575fc mod_admin_web: Handle paths without trailing slash
Florian Zeitz <florob@babelmonkeys.de>
parents: 304
diff changeset
37 local response_301 = { status = "301 Moved Permanently" };
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
38 local response_400 = { status = "400 Bad Request", body = "<h1>Bad Request</h1>Sorry, we didn't understand your request :(" };
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
39 local response_403 = { status = "403 Forbidden", body = "<h1>Forbidden</h1>You don't have permission to view the contents of this directory :(" };
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
40 local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" };
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
41
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
42 local mime_map = {
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
43 html = "text/html";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
44 xml = "text/xml";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
45 js = "text/javascript";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
46 css = "text/css";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
47 };
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
48
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
49 local idmap = {};
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
50
301
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
51 function add_client(session)
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
52 local name = session.full_jid;
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
53 local id = idmap[name];
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
54 if not id then
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
55 id = uuid_generate();
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
56 idmap[name] = id;
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
57 end
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
58 local item = st.stanza("item", { id = id }):tag("session", {xmlns = xmlns_c2s_session, jid = name}):up();
301
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
59 if session.secure then
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
60 item:tag("encrypted"):up();
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
61 end
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
62 if session.compressed then
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
63 item:tag("compressed"):up();
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
64 end
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
65 service:publish(xmlns_c2s_session, host, id, item);
301
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
66 module:log("debug", "Added client " .. name);
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
67 end
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
68
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
69 function del_client(session)
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
70 local name = session.full_jid;
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
71 local id = idmap[name];
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
72 if id then
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
73 local notifier = st.stanza("retract", { id = id });
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
74 service:retract(xmlns_c2s_session, host, id, notifier);
301
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
75 end
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
76 end
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
77
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
78 function add_host(session, type)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
79 local name = (type == "out" and session.to_host) or (type == "in" and session.from_host);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
80 local id = idmap[name.."_"..type];
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
81 if not id then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
82 id = uuid_generate();
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
83 idmap[name.."_"..type] = id;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
84 end
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
85 local item = st.stanza("item", { id = id }):tag("session", {xmlns = xmlns_s2s_session, jid = name})
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
86 :tag(type):up();
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
87 if session.secure then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
88 item:tag("encrypted"):up();
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
89 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
90 if session.compressed then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
91 item:tag("compressed"):up();
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
92 end
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
93 service:publish(xmlns_s2s_session, host, id, item);
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
94 module:log("debug", "Added host " .. name .. " s2s" .. type);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
95 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
96
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
97 function del_host(session, type)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
98 local name = (type == "out" and session.to_host) or (type == "in" and session.from_host);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
99 local id = idmap[name.."_"..type];
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
100 if id then
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
101 local notifier = st.stanza("retract", { id = id });
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
102 service:retract(xmlns_s2s_session, host, id, notifier);
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
103 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
104 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
105
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
106 local function preprocess_path(path)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
107 if path:sub(1,1) ~= "/" then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
108 path = "/"..path;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
109 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
110 local level = 0;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
111 for component in path:gmatch("([^/]+)/") do
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
112 if component == ".." then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
113 level = level - 1;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
114 elseif component ~= "." then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
115 level = level + 1;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
116 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
117 if level < 0 then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
118 return nil;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
119 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
120 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
121 return path;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
122 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
123
309
5ec9125575fc mod_admin_web: Handle paths without trailing slash
Florian Zeitz <florob@babelmonkeys.de>
parents: 304
diff changeset
124 function serve_file(path, base)
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
125 local full_path = http_base..path;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
126 if stat(full_path, "mode") == "directory" then
309
5ec9125575fc mod_admin_web: Handle paths without trailing slash
Florian Zeitz <florob@babelmonkeys.de>
parents: 304
diff changeset
127 if not path:find("/$") then
5ec9125575fc mod_admin_web: Handle paths without trailing slash
Florian Zeitz <florob@babelmonkeys.de>
parents: 304
diff changeset
128 local response = response_301;
5ec9125575fc mod_admin_web: Handle paths without trailing slash
Florian Zeitz <florob@babelmonkeys.de>
parents: 304
diff changeset
129 response.headers = { ["Location"] = base .. "/" };
5ec9125575fc mod_admin_web: Handle paths without trailing slash
Florian Zeitz <florob@babelmonkeys.de>
parents: 304
diff changeset
130 return response;
5ec9125575fc mod_admin_web: Handle paths without trailing slash
Florian Zeitz <florob@babelmonkeys.de>
parents: 304
diff changeset
131 end
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
132 if stat(full_path.."/index.html", "mode") == "file" then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
133 return serve_file(path.."/index.html");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
134 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
135 return response_403;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
136 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
137 local f, err = open(full_path, "rb");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
138 if not f then return response_404; end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
139 local data = f:read("*a");
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
140 data = data:gsub("%%ADMINSUBHOST%%", host);
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
141 f:close();
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
142 if not data then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
143 return response_403;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
144 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
145 local ext = path:match("%.([^.]*)$");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
146 local mime = mime_map[ext]; -- Content-Type should be nil when not known
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
147 return {
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
148 headers = { ["Content-Type"] = mime; };
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
149 body = data;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
150 };
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
151 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
152
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
153 local function handle_file_request(method, body, request)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
154 local path = preprocess_path(request.url.path);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
155 if not path then return response_400; end
309
5ec9125575fc mod_admin_web: Handle paths without trailing slash
Florian Zeitz <florob@babelmonkeys.de>
parents: 304
diff changeset
156 path_stripped = path:gsub("^/[^/]+", ""); -- Strip /admin/
5ec9125575fc mod_admin_web: Handle paths without trailing slash
Florian Zeitz <florob@babelmonkeys.de>
parents: 304
diff changeset
157 return serve_file(path_stripped, path);
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
158 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
159
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
160 function module.load()
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
161 local http_conf = config.get("*", "core", "webadmin_http_ports");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
162
303
0f53c88bab9a mod_admin_web: Move pubsub service initialisation into a server-started handler, in case we get loaded before the service
Matthew Wild <mwild1@gmail.com>
parents: 301
diff changeset
163 httpserver.new_from_config(http_conf, handle_file_request, { base = "admin" });
0f53c88bab9a mod_admin_web: Move pubsub service initialisation into a server-started handler, in case we get loaded before the service
Matthew Wild <mwild1@gmail.com>
parents: 301
diff changeset
164 end
0f53c88bab9a mod_admin_web: Move pubsub service initialisation into a server-started handler, in case we get loaded before the service
Matthew Wild <mwild1@gmail.com>
parents: 301
diff changeset
165
304
8f3499ae1e27 mod_admin_web: Fix initialisation code, undeclared variable and wrong event scope
Matthew Wild <mwild1@gmail.com>
parents: 303
diff changeset
166 prosody.events.add_handler("server-started", function ()
8f3499ae1e27 mod_admin_web: Fix initialisation code, undeclared variable and wrong event scope
Matthew Wild <mwild1@gmail.com>
parents: 303
diff changeset
167 local host_session = prosody.hosts[host];
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
168 if not select(2, service:get_nodes(true))[xmlns_s2s_session] then
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
169 local ok, errmsg = service:create(xmlns_s2s_session, true);
295
e373de5907aa mod_admin_web: Only create the node once when loading onto multiple hosts
Florian Zeitz <florob@babelmonkeys.de>
parents: 292
diff changeset
170 if not ok then
301
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
171 module:log("warn", "Could not create node " .. xmlns_s2s_session .. ": " .. tostring(errmsg));
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
172 else
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
173 service:set_affiliation(xmlns_s2s_session, true, host, "owner")
295
e373de5907aa mod_admin_web: Only create the node once when loading onto multiple hosts
Florian Zeitz <florob@babelmonkeys.de>
parents: 292
diff changeset
174 end
292
a9e69088e678 mod_adhoc_web: Put pubsubHost into js from lua. Compat with util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 288
diff changeset
175 end
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
176
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
177 for remotehost, session in pairs(host_session.s2sout) do
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
178 if session.type ~= "s2sout_unauthed" then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
179 add_host(session, "out");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
180 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
181 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
182 for session in pairs(incoming_s2s) do
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
183 if session.to_host == host then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
184 add_host(session, "in");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
185 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
186 end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
187
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
188 if not select(2, service:get_nodes(true))[xmlns_c2s_session] then
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
189 local ok, errmsg = service:create(xmlns_c2s_session, true);
301
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
190 if not ok then
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
191 module:log("warn", "Could not create node " .. xmlns_c2s_session .. ": " .. tostring(errmsg));
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
192 else
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
193 service:set_affiliation(xmlns_c2s_session, true, host, "owner")
301
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
194 end
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
195 end
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
196
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
197 for username, user in pairs(host_session.sessions or {}) do
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
198 for resource, session in pairs(user.sessions or {}) do
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
199 add_client(session);
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
200 end
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
201 end
303
0f53c88bab9a mod_admin_web: Move pubsub service initialisation into a server-started handler, in case we get loaded before the service
Matthew Wild <mwild1@gmail.com>
parents: 301
diff changeset
202 end);
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
203
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
204 function simple_broadcast(node, jids, item)
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
205 item = st.clone(item);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
206 item.attr.xmlns = nil; -- Clear the pubsub namespace
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
207 local message = st.message({ from = module.host, type = "headline" })
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
208 :tag("event", { xmlns = xmlns_adminsub .. "#event" })
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
209 :tag("items", { node = node })
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
210 :add_child(item);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
211 for jid in pairs(jids) do
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
212 module:log("debug", "Sending notification to %s", jid);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
213 message.attr.to = jid;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
214 core_post_stanza(hosts[host], message);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
215 end
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
216 end
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
217
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
218 function get_affiliation(jid)
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
219 local bare_jid = jid_bare(jid);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
220 if is_admin(bare_jid, host) then
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
221 return "member";
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
222 else
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
223 return "none";
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
224 end
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
225 end
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
226
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
227 module:hook("iq/host/http://prosody.im/adminsub:adminsub", function(event)
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
228 local origin, stanza = event.origin, event.stanza;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
229 local adminsub = stanza.tags[1];
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
230 local action = adminsub.tags[1];
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
231 local reply;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
232 if action.name == "subscribe" then
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
233 local ok, ret = service:add_subscription(action.attr.node, stanza.attr.from, stanza.attr.from);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
234 if ok then
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
235 reply = st.reply(stanza)
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
236 :tag("adminsub", { xmlns = xmlns_adminsub });
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
237 else
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
238 reply = st.error_reply(stanza, "cancel", ret);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
239 end
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
240 elseif action.name == "items" then
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
241 local node = action.attr.node;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
242 local ok, ret = service:get_items(node, stanza.attr.from);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
243 if not ok then
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
244 return origin.send(st.error_reply(stanza, "cancel", ret));
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
245 end
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
246
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
247 local data = st.stanza("items", { node = node });
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
248 for _, entry in pairs(ret) do
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
249 data:add_child(entry);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
250 end
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
251 if data then
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
252 reply = st.reply(stanza)
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
253 :tag("adminsub", { xmlns = xmlns_adminsub })
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
254 :add_child(data);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
255 else
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
256 reply = st.error_reply(stanza, "cancel", "item-not-found");
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
257 end
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
258 else
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
259 reply = st.error_reply(stanza, "feature-not-implemented");
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
260 end
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
261 return origin.send(reply);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
262 end);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
263
301
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
264 module:hook("resource-bind", function(event)
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
265 add_client(event.session);
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
266 end);
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
267
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
268 module:hook("resource-unbind", function(event)
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
269 del_client(event.session);
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
270 service:remove_subscription(xmlns_c2s_session, host, event.session.full_jid);
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
271 service:remove_subscription(xmlns_s2s_session, host, event.session.full_jid);
301
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
272 end);
b241c79a0eb7 mod_admin_web: Add a live view for C2S connections
Florian Zeitz <florob@babelmonkeys.de>
parents: 295
diff changeset
273
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
274 module:hook("s2sout-established", function(event)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
275 add_host(event.session, "out");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
276 end);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
277
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
278 module:hook("s2sin-established", function(event)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
279 add_host(event.session, "in");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
280 end);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
281
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
282 module:hook("s2sout-destroyed", function(event)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
283 del_host(event.session, "out");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
284 end);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
285
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
286 module:hook("s2sin-destroyed", function(event)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
287 del_host(event.session, "in");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
288 end);
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
289
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
290 service = pubsub.new({
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
291 broadcaster = simple_broadcast;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
292 normalize_jid = jid_bare;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
293 get_affiliation = get_affiliation;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
294 capabilities = {
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
295 member = {
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
296 create = false;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
297 publish = false;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
298 retract = false;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
299 get_nodes = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
300
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
301 subscribe = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
302 unsubscribe = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
303 get_subscription = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
304 get_subscriptions = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
305 get_items = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
306
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
307 subscribe_other = false;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
308 unsubscribe_other = false;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
309 get_subscription_other = false;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
310 get_subscriptions_other = false;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
311
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
312 be_subscribed = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
313 be_unsubscribed = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
314
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
315 set_affiliation = false;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
316 };
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
317
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
318 owner = {
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
319 create = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
320 publish = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
321 retract = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
322 get_nodes = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
323
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
324 subscribe = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
325 unsubscribe = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
326 get_subscription = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
327 get_subscriptions = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
328 get_items = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
329
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
330 subscribe_other = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
331 unsubscribe_other = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
332 get_subscription_other = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
333 get_subscriptions_other = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
334
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
335 be_subscribed = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
336 be_unsubscribed = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
337
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
338 set_affiliation = true;
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
339 };
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
340 };
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
341 });
4f78f5020aa9 mod_admin_web: Get rid of the mod_pubsub dependency
Florian Zeitz <florob@babelmonkeys.de>
parents: 309
diff changeset
342