Mercurial > prosody-modules
annotate mod_admin_web/admin_web/mod_admin_web_timber.lua @ 636:b3a3199255d7
mod_admin_web: Add timber version. Separate for now
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 27 Apr 2012 03:30:47 +0200 |
parents | |
children | 210f4ce2697c |
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; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
22 local is_admin = require "usermanager".is_admin; |
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) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
134 module:depends("http"); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
135 module:provides("http", { |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
136 name = "admin"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
137 route = { |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
138 ["/"] = function(event) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
139 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
|
140 return 301; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
141 end; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
142 ["/*"] = serve_file; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
143 } |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
144 }); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
145 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
146 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
147 prosody.events.add_handler("server-started", function () |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
148 for host_name, host_table in pairs(hosts) do |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
149 service[host_name] = pubsub.new({ |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
150 broadcaster = function(node, jids, item) return simple_broadcast(node, jids, item, host_name) end; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
151 normalize_jid = jid_bare; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
152 get_affiliation = function(jid) return get_affiliation(jid, host_name) end; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
153 capabilities = { |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
154 member = { |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
155 create = false; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
156 publish = false; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
157 retract = false; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
158 get_nodes = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
159 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
160 subscribe = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
161 unsubscribe = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
162 get_subscription = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
163 get_subscriptions = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
164 get_items = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
165 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
166 subscribe_other = false; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
167 unsubscribe_other = false; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
168 get_subscription_other = false; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
169 get_subscriptions_other = false; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
170 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
171 be_subscribed = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
172 be_unsubscribed = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
173 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
174 set_affiliation = false; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
175 }; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
176 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
177 owner = { |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
178 create = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
179 publish = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
180 retract = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
181 get_nodes = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
182 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
183 subscribe = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
184 unsubscribe = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
185 get_subscription = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
186 get_subscriptions = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
187 get_items = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
188 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
189 subscribe_other = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
190 unsubscribe_other = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
191 get_subscription_other = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
192 get_subscriptions_other = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
193 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
194 be_subscribed = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
195 be_unsubscribed = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
196 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
197 set_affiliation = true; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
198 }; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
199 }; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
200 }); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
201 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
202 if not select(2, service[host_name]:get_nodes(true))[xmlns_s2s_session] then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
203 local ok, errmsg = service[host_name]:create(xmlns_s2s_session, true); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
204 if not ok then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
205 module:log("warn", "Could not create node " .. xmlns_s2s_session .. ": " .. tostring(errmsg)); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
206 else |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
207 service[host_name]:set_affiliation(xmlns_s2s_session, true, host_name, "owner") |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
208 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
209 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
210 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
211 for remotehost, session in pairs(host_table.s2sout) do |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
212 if session.type ~= "s2sout_unauthed" then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
213 add_host(session, "out", host_name); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
214 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
215 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
216 for session in pairs(incoming_s2s) do |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
217 if session.to_host == host_name then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
218 add_host(session, "in", host_name); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
219 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
220 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
221 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
222 if not select(2, service[host_name]:get_nodes(true))[xmlns_c2s_session] then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
223 local ok, errmsg = service[host_name]:create(xmlns_c2s_session, true); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
224 if not ok then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
225 module:log("warn", "Could not create node " .. xmlns_c2s_session .. ": " .. tostring(errmsg)); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
226 else |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
227 service[host_name]:set_affiliation(xmlns_c2s_session, true, host_name, "owner") |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
228 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
229 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
230 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
231 for username, user in pairs(host_table.sessions or {}) do |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
232 for resource, session in pairs(user.sessions or {}) do |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
233 add_client(session, host_name); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
234 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
235 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
236 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
237 host_table.events.add_handler("iq/host/http://prosody.im/adminsub:adminsub", function(event) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
238 local origin, stanza = event.origin, event.stanza; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
239 local adminsub = stanza.tags[1]; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
240 local action = adminsub.tags[1]; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
241 local reply; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
242 if action.name == "subscribe" then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
243 local ok, ret = service[host_name]:add_subscription(action.attr.node, stanza.attr.from, stanza.attr.from); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
244 if ok then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
245 reply = st.reply(stanza) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
246 :tag("adminsub", { xmlns = xmlns_adminsub }); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
247 else |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
248 reply = st.error_reply(stanza, "cancel", ret); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
249 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
250 elseif action.name == "unsubscribe" then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
251 local ok, ret = service[host_name]:remove_subscription(action.attr.node, stanza.attr.from, stanza.attr.from); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
252 if ok then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
253 reply = st.reply(stanza) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
254 :tag("adminsub", { xmlns = xmlns_adminsub }); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
255 else |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
256 reply = st.error_reply(stanza, "cancel", ret); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
257 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
258 elseif action.name == "items" then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
259 local node = action.attr.node; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
260 local ok, ret = service[host_name]:get_items(node, stanza.attr.from); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
261 if not ok then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
262 return origin.send(st.error_reply(stanza, "cancel", ret)); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
263 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
264 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
265 local data = st.stanza("items", { node = node }); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
266 for _, entry in pairs(ret) do |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
267 data:add_child(entry); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
268 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
269 if data then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
270 reply = st.reply(stanza) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
271 :tag("adminsub", { xmlns = xmlns_adminsub }) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
272 :add_child(data); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
273 else |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
274 reply = st.error_reply(stanza, "cancel", "item-not-found"); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
275 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
276 elseif action.name == "adminfor" then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
277 local data = st.stanza("adminfor"); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
278 for host_name in pairs(hosts) do |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
279 if is_admin(stanza.attr.from, host_name) then |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
280 data:tag("item"):text(host_name):up(); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
281 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
282 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
283 reply = st.reply(stanza) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
284 :tag("adminsub", { xmlns = xmlns_adminsub }) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
285 :add_child(data); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
286 else |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
287 reply = st.error_reply(stanza, "feature-not-implemented"); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
288 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
289 return origin.send(reply); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
290 end); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
291 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
292 host_table.events.add_handler("resource-bind", function(event) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
293 add_client(event.session, host_name); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
294 end); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
295 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
296 host_table.events.add_handler("resource-unbind", function(event) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
297 del_client(event.session, host_name); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
298 service[host_name]:remove_subscription(xmlns_c2s_session, host_name, event.session.full_jid); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
299 service[host_name]:remove_subscription(xmlns_s2s_session, host_name, event.session.full_jid); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
300 end); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
301 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
302 host_table.events.add_handler("s2sout-established", function(event) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
303 add_host(event.session, "out", host_name); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
304 end); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
305 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
306 host_table.events.add_handler("s2sin-established", function(event) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
307 add_host(event.session, "in", host_name); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
308 end); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
309 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
310 host_table.events.add_handler("s2sout-destroyed", function(event) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
311 del_host(event.session, "out", host_name); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
312 end); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
313 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
314 host_table.events.add_handler("s2sin-destroyed", function(event) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
315 del_host(event.session, "in", host_name); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
316 end); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
317 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
318 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
319 end); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
320 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
321 function simple_broadcast(node, jids, item, host) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
322 item = st.clone(item); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
323 item.attr.xmlns = nil; -- Clear the pubsub namespace |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
324 local message = st.message({ from = host, type = "headline" }) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
325 :tag("event", { xmlns = xmlns_adminsub .. "#event" }) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
326 :tag("items", { node = node }) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
327 :add_child(item); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
328 for jid in pairs(jids) do |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
329 module:log("debug", "Sending notification to %s", jid); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
330 message.attr.to = jid; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
331 core_post_stanza(hosts[host], message); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
332 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
333 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
334 |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
335 function get_affiliation(jid, host) |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
336 local bare_jid = jid_bare(jid); |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
337 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
|
338 return "member"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
339 else |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
340 return "none"; |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
341 end |
b3a3199255d7
mod_admin_web: Add timber version. Separate for now
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
342 end |