diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-08-24 20:34:00 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-08-24 20:34:00 +0200 |
commit | 933132acfe560c0b0f4435961b9ac87c96775c17 (patch) | |
tree | d8e0d15880fc3c232c392f12a499505a0ac14a8b | |
parent | 9aa86079aa7b807cf32011b68a2c14f02932e4bf (diff) | |
download | prosody-933132acfe560c0b0f4435961b9ac87c96775c17.tar.gz prosody-933132acfe560c0b0f4435961b9ac87c96775c17.zip |
mod_adhoc: Simplify iq handling by hooking on iq-set/ instead of iq/.
-rw-r--r-- | plugins/adhoc/mod_adhoc.lua | 38 |
1 files changed, 18 insertions, 20 deletions
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); |