11 local um_is_admin = require "core.usermanager".is_admin; |
11 local um_is_admin = require "core.usermanager".is_admin; |
12 local jid_split = require "util.jid".split; |
12 local jid_split = require "util.jid".split; |
13 local jid_bare = require "util.jid".bare; |
13 local jid_bare = require "util.jid".bare; |
14 local st = require "util.stanza" |
14 local st = require "util.stanza" |
15 local calculate_hash = require "util.caps".calculate_hash; |
15 local calculate_hash = require "util.caps".calculate_hash; |
|
16 |
|
17 local expose_admins = module:get_option_boolean("disco_expose_admins", false); |
16 |
18 |
17 local disco_items = module:get_option_array("disco_items", {}) |
19 local disco_items = module:get_option_array("disco_items", {}) |
18 do -- validate disco_items |
20 do -- validate disco_items |
19 for _, item in ipairs(disco_items) do |
21 for _, item in ipairs(disco_items) do |
20 local err; |
22 local err; |
164 if module:get_host_type() ~= "local" then return end -- skip for components |
166 if module:get_host_type() ~= "local" then return end -- skip for components |
165 module:hook("iq-get/bare/http://jabber.org/protocol/disco#info:query", function(event) |
167 module:hook("iq-get/bare/http://jabber.org/protocol/disco#info:query", function(event) |
166 local origin, stanza = event.origin, event.stanza; |
168 local origin, stanza = event.origin, event.stanza; |
167 local node = stanza.tags[1].attr.node; |
169 local node = stanza.tags[1].attr.node; |
168 local username = jid_split(stanza.attr.to) or origin.username; |
170 local username = jid_split(stanza.attr.to) or origin.username; |
169 if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
171 local is_admin = um_is_admin(stanza.attr.to or origin.full_jid, module.host) |
|
172 if not stanza.attr.to or (expose_admins and is_admin) or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then |
170 if node and node ~= "" then |
173 if node and node ~= "" then |
171 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info', node=node}); |
174 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info', node=node}); |
172 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
175 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
173 local node_event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; |
176 local node_event = { origin = origin, stanza = stanza, reply = reply, node = node, exists = false}; |
174 local ret = module:fire_event("account-disco-info-node", node_event); |
177 local ret = module:fire_event("account-disco-info-node", node_event); |
180 end |
183 end |
181 return true; |
184 return true; |
182 end |
185 end |
183 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info'}); |
186 local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info'}); |
184 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
187 if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account |
185 if um_is_admin(stanza.attr.to or origin.full_jid, module.host) then |
188 if is_admin then |
186 reply:tag('identity', {category='account', type='admin'}):up(); |
189 reply:tag('identity', {category='account', type='admin'}):up(); |
187 elseif prosody.hosts[module.host].users.name == "anonymous" then |
190 elseif prosody.hosts[module.host].users.name == "anonymous" then |
188 reply:tag('identity', {category='account', type='anonymous'}):up(); |
191 reply:tag('identity', {category='account', type='anonymous'}):up(); |
189 else |
192 else |
190 reply:tag('identity', {category='account', type='registered'}):up(); |
193 reply:tag('identity', {category='account', type='registered'}):up(); |