summaryrefslogtreecommitdiff
path: root/src/xmpp/adhoc_commands_handler.cpp
diff options
context:
space:
mode:
authorFlorent Le Coz <louiz@louiz.org>2014-05-31 17:06:36 +0200
committerFlorent Le Coz <louiz@louiz.org>2014-05-31 17:06:36 +0200
commit4e27298b3a6389781893589b37f66260d6a34707 (patch)
tree5b33fe906f698c4b2789197d51d3712daf791489 /src/xmpp/adhoc_commands_handler.cpp
parentf5b61f0feba271770474c4d540d7bf48a6c2b180 (diff)
downloadbiboumi-4e27298b3a6389781893589b37f66260d6a34707.tar.gz
biboumi-4e27298b3a6389781893589b37f66260d6a34707.tar.bz2
biboumi-4e27298b3a6389781893589b37f66260d6a34707.tar.xz
biboumi-4e27298b3a6389781893589b37f66260d6a34707.zip
Add an ad-hoc command to disconnect some users
Diffstat (limited to 'src/xmpp/adhoc_commands_handler.cpp')
-rw-r--r--src/xmpp/adhoc_commands_handler.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/xmpp/adhoc_commands_handler.cpp b/src/xmpp/adhoc_commands_handler.cpp
index a669ca1..8657944 100644
--- a/src/xmpp/adhoc_commands_handler.cpp
+++ b/src/xmpp/adhoc_commands_handler.cpp
@@ -2,13 +2,17 @@
#include <xmpp/xmpp_component.hpp>
#include <logger/logger.hpp>
+#include <config/config.hpp>
+#include <xmpp/jid.hpp>
#include <iostream>
-AdhocCommandsHandler::AdhocCommandsHandler():
+AdhocCommandsHandler::AdhocCommandsHandler(XmppComponent* xmpp_component):
+ xmpp_component(xmpp_component),
commands{
{"ping", AdhocCommand({&PingStep1}, "Do a ping", false)},
- {"hello", AdhocCommand({&HelloStep1, &HelloStep2}, "Receive a custom greeting", false)}
+ {"hello", AdhocCommand({&HelloStep1, &HelloStep2}, "Receive a custom greeting", false)},
+ {"disconnect-user", AdhocCommand({&DisconnectUserStep1, &DisconnectUserStep2}, "Disconnect a user from the gateway", true)}
}
{
}
@@ -31,6 +35,8 @@ XmlNode&& AdhocCommandsHandler::handle_request(const std::string& executor_jid,
action = "execute";
command_node.del_tag("action");
+ Jid jid(executor_jid);
+
const std::string node = command_node.get_tag("node");
auto command_it = this->commands.find(node);
if (command_it == this->commands.end())
@@ -43,6 +49,17 @@ XmlNode&& AdhocCommandsHandler::handle_request(const std::string& executor_jid,
error.close();
command_node.add_child(std::move(error));
}
+ else if (command_it->second.is_admin_only() &&
+ Config::get("admin", "") != jid.local + "@" + jid.domain)
+ {
+ XmlNode error(ADHOC_NS":error");
+ error["type"] = "cancel";
+ XmlNode condition(STANZA_NS":forbidden");
+ condition.close();
+ error.add_child(std::move(condition));
+ error.close();
+ command_node.add_child(std::move(error));
+ }
else
{
std::string sessionid = command_node.get_tag("sessionid");
@@ -74,7 +91,7 @@ XmlNode&& AdhocCommandsHandler::handle_request(const std::string& executor_jid,
// execute the step
AdhocSession& session = session_it->second;
const AdhocStep& step = session.get_next_step();
- step(session, command_node);
+ step(this->xmpp_component, session, command_node);
if (session.remaining_steps() == 0 ||
session.is_terminated())
{