Software /
code /
prosody
Changeset
9222:fe8abac62682
mod_adhoc: Simplify iq handling by hooking on iq-set/ instead of iq/.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 24 Aug 2018 20:34:00 +0200 |
parents | 9221:6dc1aeefa876 |
children | 9223:80dbb60d81e4 |
files | plugins/adhoc/mod_adhoc.lua |
diffstat | 1 files changed, 18 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/adhoc/mod_adhoc.lua Wed Aug 22 14:50:07 2018 +0200 +++ b/plugins/adhoc/mod_adhoc.lua Fri Aug 24 20:34:00 2018 +0200 @@ -69,28 +69,26 @@ 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);