Mercurial > prosody-modules
comparison mod_admin_web/admin_web/mod_admin_web.lua @ 1646:95b8b1f9a882
mod_admin_web: Cleanup
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Fri, 03 Apr 2015 23:54:03 +0200 |
parents | 7dbde05b48a9 |
children | db8b256f51ff |
comparison
equal
deleted
inserted
replaced
1645:9a862059bd97 | 1646:95b8b1f9a882 |
---|---|
21 local uuid_generate = require "util.uuid".generate; | 21 local uuid_generate = require "util.uuid".generate; |
22 local is_admin = require "core.usermanager".is_admin; | 22 local is_admin = require "core.usermanager".is_admin; |
23 local pubsub = require "util.pubsub"; | 23 local pubsub = require "util.pubsub"; |
24 local jid_bare = require "util.jid".bare; | 24 local jid_bare = require "util.jid".bare; |
25 | 25 |
26 local hosts = prosody.hosts; | |
27 local incoming_s2s = prosody.incoming_s2s; | |
28 | |
26 module:set_global(); | 29 module:set_global(); |
27 | 30 |
28 local service = {}; | 31 local service = {}; |
29 | 32 |
30 local xmlns_adminsub = "http://prosody.im/adminsub"; | 33 local xmlns_adminsub = "http://prosody.im/adminsub"; |
31 local xmlns_c2s_session = "http://prosody.im/streams/c2s"; | 34 local xmlns_c2s_session = "http://prosody.im/streams/c2s"; |
32 local xmlns_s2s_session = "http://prosody.im/streams/s2s"; | 35 local xmlns_s2s_session = "http://prosody.im/streams/s2s"; |
33 | 36 |
34 local idmap = {}; | 37 local idmap = {}; |
35 | 38 |
36 function add_client(session, host) | 39 local function add_client(session, host) |
37 local name = session.full_jid; | 40 local name = session.full_jid; |
38 local id = idmap[name]; | 41 local id = idmap[name]; |
39 if not id then | 42 if not id then |
40 id = uuid_generate(); | 43 id = uuid_generate(); |
41 idmap[name] = id; | 44 idmap[name] = id; |
54 end | 57 end |
55 service[host]:publish(xmlns_c2s_session, host, id, item); | 58 service[host]:publish(xmlns_c2s_session, host, id, item); |
56 module:log("debug", "Added client " .. name); | 59 module:log("debug", "Added client " .. name); |
57 end | 60 end |
58 | 61 |
59 function del_client(session, host) | 62 local function del_client(session, host) |
60 local name = session.full_jid; | 63 local name = session.full_jid; |
61 local id = idmap[name]; | 64 local id = idmap[name]; |
62 if id then | 65 if id then |
63 local notifier = st.stanza("retract", { id = id }); | 66 local notifier = st.stanza("retract", { id = id }); |
64 service[host]:retract(xmlns_c2s_session, host, id, notifier); | 67 service[host]:retract(xmlns_c2s_session, host, id, notifier); |
65 end | 68 end |
66 end | 69 end |
67 | 70 |
68 function add_host(session, type, host) | 71 local function add_host(session, type, host) |
69 local name = (type == "out" and session.to_host) or (type == "in" and session.from_host); | 72 local name = (type == "out" and session.to_host) or (type == "in" and session.from_host); |
70 local id = idmap[name.."_"..type]; | 73 local id = idmap[name.."_"..type]; |
71 if not id then | 74 if not id then |
72 id = uuid_generate(); | 75 id = uuid_generate(); |
73 idmap[name.."_"..type] = id; | 76 idmap[name.."_"..type] = id; |
94 end | 97 end |
95 service[host]:publish(xmlns_s2s_session, host, id, item); | 98 service[host]:publish(xmlns_s2s_session, host, id, item); |
96 module:log("debug", "Added host " .. name .. " s2s" .. type); | 99 module:log("debug", "Added host " .. name .. " s2s" .. type); |
97 end | 100 end |
98 | 101 |
99 function del_host(session, type, host) | 102 local function del_host(session, type, host) |
100 local name = (type == "out" and session.to_host) or (type == "in" and session.from_host); | 103 local name = (type == "out" and session.to_host) or (type == "in" and session.from_host); |
101 local id = idmap[name.."_"..type]; | 104 local id = idmap[name.."_"..type]; |
102 if id then | 105 if id then |
103 local notifier = st.stanza("retract", { id = id }); | 106 local notifier = st.stanza("retract", { id = id }); |
104 service[host]:retract(xmlns_s2s_session, host, id, notifier); | 107 service[host]:retract(xmlns_s2s_session, host, id, notifier); |
108 end | |
109 end | |
110 | |
111 local function get_affiliation(jid, host) | |
112 local bare_jid = jid_bare(jid); | |
113 if is_admin(bare_jid, host) then | |
114 return "member"; | |
115 else | |
116 return "none"; | |
105 end | 117 end |
106 end | 118 end |
107 | 119 |
108 function module.add_host(module) | 120 function module.add_host(module) |
109 -- Dependencies | 121 -- Dependencies |
141 message.attr.to = jid; | 153 message.attr.to = jid; |
142 module:send(message); | 154 module:send(message); |
143 end | 155 end |
144 end | 156 end |
145 | 157 |
146 local ok, err; | |
147 service[module.host] = pubsub.new({ | 158 service[module.host] = pubsub.new({ |
148 broadcaster = simple_broadcast; | 159 broadcaster = simple_broadcast; |
149 normalize_jid = jid_bare; | 160 normalize_jid = jid_bare; |
150 get_affiliation = function(jid) return get_affiliation(jid, module.host) end; | 161 get_affiliation = function(jid) return get_affiliation(jid, module.host) end; |
151 capabilities = { | 162 capabilities = { |
196 }; | 207 }; |
197 }; | 208 }; |
198 }); | 209 }); |
199 | 210 |
200 -- Create node for s2s sessions | 211 -- Create node for s2s sessions |
201 ok, err = service[module.host]:create(xmlns_s2s_session, true); | 212 local ok, err = service[module.host]:create(xmlns_s2s_session, true); |
202 if not ok then | 213 if not ok then |
203 module:log("warn", "Could not create node " .. xmlns_s2s_session .. ": " .. tostring(err)); | 214 module:log("warn", "Could not create node " .. xmlns_s2s_session .. ": " .. tostring(err)); |
204 else | 215 else |
205 service[module.host]:set_affiliation(xmlns_s2s_session, true, module.host, "owner") | 216 service[module.host]:set_affiliation(xmlns_s2s_session, true, module.host, "owner") |
206 end | 217 end |
207 | 218 |
208 -- Add outgoing s2s sessions | 219 -- Add outgoing s2s sessions |
209 for remotehost, session in pairs(hosts[module.host].s2sout) do | 220 for _, session in pairs(hosts[module.host].s2sout) do |
210 if session.type ~= "s2sout_unauthed" then | 221 if session.type ~= "s2sout_unauthed" then |
211 add_host(session, "out", module.host); | 222 add_host(session, "out", module.host); |
212 end | 223 end |
213 end | 224 end |
214 | 225 |
226 else | 237 else |
227 service[module.host]:set_affiliation(xmlns_c2s_session, true, module.host, "owner") | 238 service[module.host]:set_affiliation(xmlns_c2s_session, true, module.host, "owner") |
228 end | 239 end |
229 | 240 |
230 -- Add c2s sessions | 241 -- Add c2s sessions |
231 for username, user in pairs(hosts[module.host].sessions or {}) do | 242 for _, user in pairs(hosts[module.host].sessions or {}) do |
232 for resource, session in pairs(user.sessions or {}) do | 243 for _, session in pairs(user.sessions or {}) do |
233 add_client(session, module.host); | 244 add_client(session, module.host); |
234 end | 245 end |
235 end | 246 end |
236 | 247 |
237 -- Register adminsub handler | 248 -- Register adminsub handler |
316 | 327 |
317 module:hook("s2sin-destroyed", function(event) | 328 module:hook("s2sin-destroyed", function(event) |
318 del_host(event.session, "in", module.host); | 329 del_host(event.session, "in", module.host); |
319 end); | 330 end); |
320 end | 331 end |
321 | |
322 function get_affiliation(jid, host) | |
323 local bare_jid = jid_bare(jid); | |
324 if is_admin(bare_jid, host) then | |
325 return "member"; | |
326 else | |
327 return "none"; | |
328 end | |
329 end |