aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_disco.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mod_disco.lua')
-rw-r--r--plugins/mod_disco.lua24
1 files changed, 22 insertions, 2 deletions
diff --git a/plugins/mod_disco.lua b/plugins/mod_disco.lua
index a5479f4c..a98fc7ac 100644
--- a/plugins/mod_disco.lua
+++ b/plugins/mod_disco.lua
@@ -8,11 +8,14 @@
local get_children = require "core.hostmanager".get_children;
local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
+local um_is_admin = require "core.usermanager".is_admin;
local jid_split = require "util.jid".split;
local jid_bare = require "util.jid".bare;
local st = require "util.stanza"
local calculate_hash = require "util.caps".calculate_hash;
+local expose_admins = module:get_option_boolean("disco_expose_admins", false);
+
local disco_items = module:get_option_array("disco_items", {})
do -- validate disco_items
for _, item in ipairs(disco_items) do
@@ -71,6 +74,7 @@ local function build_server_disco_info()
ver = _cached_server_caps_hash;
});
end
+
local function clear_disco_cache()
_cached_server_disco_info, _cached_server_caps_feature, _cached_server_caps_hash = nil, nil, nil;
end
@@ -116,6 +120,7 @@ module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function(
origin.send(reply);
return true;
end);
+
module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function(event)
local origin, stanza = event.origin, event.stanza;
local node = stanza.tags[1].attr.node;
@@ -151,13 +156,20 @@ module:hook("stream-features", function (event)
end
end);
+module:hook("s2s-stream-features", function (event)
+ if event.origin.type == "s2sin" then
+ event.features:add_child(get_server_caps_feature());
+ end
+end);
+
-- Handle disco requests to user accounts
if module:get_host_type() ~= "local" then return end -- skip for components
module:hook("iq-get/bare/http://jabber.org/protocol/disco#info:query", function(event)
local origin, stanza = event.origin, event.stanza;
local node = stanza.tags[1].attr.node;
local username = jid_split(stanza.attr.to) or origin.username;
- if not stanza.attr.to or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then
+ local is_admin = um_is_admin(stanza.attr.to or origin.full_jid, module.host)
+ if not stanza.attr.to or (expose_admins and is_admin) or is_contact_subscribed(username, module.host, jid_bare(stanza.attr.from)) then
if node and node ~= "" then
local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info', node=node});
if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account
@@ -173,12 +185,19 @@ module:hook("iq-get/bare/http://jabber.org/protocol/disco#info:query", function(
end
local reply = st.reply(stanza):tag('query', {xmlns='http://jabber.org/protocol/disco#info'});
if not reply.attr.from then reply.attr.from = origin.username.."@"..origin.host; end -- COMPAT To satisfy Psi when querying own account
- reply:tag('identity', {category='account', type='registered'}):up();
+ if is_admin then
+ reply:tag('identity', {category='account', type='admin'}):up();
+ elseif prosody.hosts[module.host].users.name == "anonymous" then
+ reply:tag('identity', {category='account', type='anonymous'}):up();
+ else
+ reply:tag('identity', {category='account', type='registered'}):up();
+ end
module:fire_event("account-disco-info", { origin = origin, reply = reply });
origin.send(reply);
return true;
end
end);
+
module:hook("iq-get/bare/http://jabber.org/protocol/disco#items:query", function(event)
local origin, stanza = event.origin, event.stanza;
local node = stanza.tags[1].attr.node;
@@ -204,3 +223,4 @@ module:hook("iq-get/bare/http://jabber.org/protocol/disco#items:query", function
return true;
end
end);
+