Software /
code /
prosody
Comparison
plugins/adhoc/mod_adhoc.lua @ 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 |
parent | 8563:50f2ad088589 |
child | 9331:2f634cc02eac |
comparison
equal
deleted
inserted
replaced
9221:6dc1aeefa876 | 9222:fe8abac62682 |
---|---|
67 end | 67 end |
68 end | 68 end |
69 event.exists = true; | 69 event.exists = true; |
70 end); | 70 end); |
71 | 71 |
72 module:hook("iq/host/"..xmlns_cmd..":command", function (event) | 72 module:hook("iq-set/host/"..xmlns_cmd..":command", function (event) |
73 local origin, stanza = event.origin, event.stanza; | 73 local origin, stanza = event.origin, event.stanza; |
74 if stanza.attr.type == "set" then | 74 local node = stanza.tags[1].attr.node |
75 local node = stanza.tags[1].attr.node | 75 local command = commands[node]; |
76 local command = commands[node]; | 76 if command then |
77 if command then | 77 local from = stanza.attr.from; |
78 local from = stanza.attr.from; | 78 local admin = is_admin(from, stanza.attr.to); |
79 local admin = is_admin(from, stanza.attr.to); | 79 local global_admin = is_admin(from); |
80 local global_admin = is_admin(from); | 80 local username, hostname = jid_split(from); |
81 local username, hostname = jid_split(from); | 81 if (command.permission == "admin" and not admin) |
82 if (command.permission == "admin" and not admin) | 82 or (command.permission == "global_admin" and not global_admin) |
83 or (command.permission == "global_admin" and not global_admin) | 83 or (command.permission == "local_user" and hostname ~= module.host) then |
84 or (command.permission == "local_user" and hostname ~= module.host) then | 84 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() |
85 origin.send(st.error_reply(stanza, "auth", "forbidden", "You don't have permission to execute this command"):up() | 85 :add_child(commands[node]:cmdtag("canceled") |
86 :add_child(commands[node]:cmdtag("canceled") | 86 :tag("note", {type="error"}):text("You don't have permission to execute this command"))); |
87 :tag("note", {type="error"}):text("You don't have permission to execute this command"))); | 87 return true |
88 return true | |
89 end | |
90 -- User has permission now execute the command | |
91 adhoc_handle_cmd(commands[node], origin, stanza); | |
92 return true; | |
93 end | 88 end |
89 -- User has permission now execute the command | |
90 adhoc_handle_cmd(commands[node], origin, stanza); | |
91 return true; | |
94 end | 92 end |
95 end, 500); | 93 end, 500); |
96 | 94 |
97 local function adhoc_added(event) | 95 local function adhoc_added(event) |
98 local item = event.item; | 96 local item = event.item; |