aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/adhoc
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/adhoc')
-rw-r--r--plugins/adhoc/adhoc.lib.lua24
-rw-r--r--plugins/adhoc/mod_adhoc.lua42
2 files changed, 32 insertions, 34 deletions
diff --git a/plugins/adhoc/adhoc.lib.lua b/plugins/adhoc/adhoc.lib.lua
index 87415636..0b910299 100644
--- a/plugins/adhoc/adhoc.lib.lua
+++ b/plugins/adhoc/adhoc.lib.lua
@@ -36,30 +36,30 @@ function _M.handle_cmd(command, origin, stanza)
local data, state = command:handler(dataIn, states[sessionid]);
states[sessionid] = state;
- local cmdtag;
+ local cmdreply;
if data.status == "completed" then
states[sessionid] = nil;
- cmdtag = command:cmdtag("completed", sessionid);
+ cmdreply = command:cmdtag("completed", sessionid);
elseif data.status == "canceled" then
states[sessionid] = nil;
- cmdtag = command:cmdtag("canceled", sessionid);
+ cmdreply = command:cmdtag("canceled", sessionid);
elseif data.status == "error" then
states[sessionid] = nil;
local reply = st.error_reply(stanza, data.error.type, data.error.condition, data.error.message);
origin.send(reply);
return true;
else
- cmdtag = command:cmdtag("executing", sessionid);
+ cmdreply = command:cmdtag("executing", sessionid);
data.actions = data.actions or { "complete" };
end
for name, content in pairs(data) do
if name == "info" then
- cmdtag:tag("note", {type="info"}):text(content):up();
+ cmdreply:tag("note", {type="info"}):text(content):up();
elseif name == "warn" then
- cmdtag:tag("note", {type="warn"}):text(content):up();
+ cmdreply:tag("note", {type="warn"}):text(content):up();
elseif name == "error" then
- cmdtag:tag("note", {type="error"}):text(content.message):up();
+ cmdreply:tag("note", {type="error"}):text(content.message):up();
elseif name == "actions" then
local actions = st.stanza("actions", { execute = content.default });
for _, action in ipairs(content) do
@@ -70,17 +70,17 @@ function _M.handle_cmd(command, origin, stanza)
command.name, command.node, action);
end
end
- cmdtag:add_child(actions);
+ cmdreply:add_child(actions);
elseif name == "form" then
- cmdtag:add_child((content.layout or content):form(content.values));
+ cmdreply:add_child((content.layout or content):form(content.values));
elseif name == "result" then
- cmdtag:add_child((content.layout or content):form(content.values, "result"));
+ cmdreply:add_child((content.layout or content):form(content.values, "result"));
elseif name == "other" then
- cmdtag:add_child(content);
+ cmdreply:add_child(content);
end
end
local reply = st.reply(stanza);
- reply:add_child(cmdtag);
+ reply:add_child(cmdreply);
origin.send(reply);
return true;
diff --git a/plugins/adhoc/mod_adhoc.lua b/plugins/adhoc/mod_adhoc.lua
index 1c956021..12e24c08 100644
--- a/plugins/adhoc/mod_adhoc.lua
+++ b/plugins/adhoc/mod_adhoc.lua
@@ -45,8 +45,8 @@ module:hook("host-disco-info-node", function (event)
end);
module:hook("host-disco-items-node", function (event)
- local stanza, origin, reply, node = event.stanza, event.origin, event.reply, event.node;
- if node ~= xmlns_cmd then
+ local stanza, reply, disco_node = event.stanza, event.reply, event.node;
+ if disco_node ~= xmlns_cmd then
return;
end
@@ -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);