Add an ad-hoc command to disconnect some users

This commit is contained in:
Florent Le Coz
2014-05-31 17:06:36 +02:00
parent f5b61f0feb
commit 4e27298b3a
7 changed files with 180 additions and 13 deletions
+20 -3
View File
@@ -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())
{