From 933132acfe560c0b0f4435961b9ac87c96775c17 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Fri, 24 Aug 2018 20:34:00 +0200 Subject: mod_adhoc: Simplify iq handling by hooking on iq-set/ instead of iq/. --- plugins/adhoc/mod_adhoc.lua | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'plugins/adhoc') diff --git a/plugins/adhoc/mod_adhoc.lua b/plugins/adhoc/mod_adhoc.lua index 8ffdc7de..12e24c08 100644 --- a/plugins/adhoc/mod_adhoc.lua +++ b/plugins/adhoc/mod_adhoc.lua @@ -69,28 +69,26 @@ module:hook("host-disco-items-node", function (event) event.exists = true; end); -module:hook("iq/host/"..xmlns_cmd..":command", function (event) +module:hook("iq-set/host/"..xmlns_cmd..":command", function (event) local origin, stanza = event.origin, event.stanza; - if stanza.attr.type == "set" then - local node = stanza.tags[1].attr.node - local command = commands[node]; - if command then - local from = stanza.attr.from; - local admin = is_admin(from, stanza.attr.to); - local global_admin = is_admin(from); - local username, hostname = jid_split(from); - if (command.permission == "admin" and not admin) - or (command.permission == "global_admin" and not global_admin) - or (command.permission == "local_user" and hostname ~= module.host) then - origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() - :add_child(commands[node]:cmdtag("canceled") - :tag("note", {type="error"}):text("You don't have permission to execute this command"))); - return true - end - -- User has permission now execute the command - adhoc_handle_cmd(commands[node], origin, stanza); - return true; + local node = stanza.tags[1].attr.node + local command = commands[node]; + if command then + local from = stanza.attr.from; + local admin = is_admin(from, stanza.attr.to); + local global_admin = is_admin(from); + local username, hostname = jid_split(from); + if (command.permission == "admin" and not admin) + or (command.permission == "global_admin" and not global_admin) + or (command.permission == "local_user" and hostname ~= module.host) then + origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() + :add_child(commands[node]:cmdtag("canceled") + :tag("note", {type="error"}):text("You don't have permission to execute this command"))); + return true end + -- User has permission now execute the command + adhoc_handle_cmd(commands[node], origin, stanza); + return true; end end, 500); -- cgit v1.2.3