Include the Configure ad-hoc command on biboumi's JID for fixed_irc_server
Because a jid like “freenode.example.org” is both the JID for the configured IRC server, and biboumi’s JID. fix #3175
This commit is contained in:
@@ -11,10 +11,6 @@ AdhocCommand::AdhocCommand(std::vector<AdhocStep>&& callbacks, const std::string
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
AdhocCommand::~AdhocCommand()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AdhocCommand::is_admin_only() const
|
bool AdhocCommand::is_admin_only() const
|
||||||
{
|
{
|
||||||
return this->admin_only;
|
return this->admin_only;
|
||||||
|
|||||||
@@ -19,7 +19,11 @@ class AdhocCommand
|
|||||||
friend class AdhocSession;
|
friend class AdhocSession;
|
||||||
public:
|
public:
|
||||||
AdhocCommand(std::vector<AdhocStep>&& callback, const std::string& name, const bool admin_only);
|
AdhocCommand(std::vector<AdhocStep>&& callback, const std::string& name, const bool admin_only);
|
||||||
~AdhocCommand();
|
~AdhocCommand() = default;
|
||||||
|
AdhocCommand(const AdhocCommand&) = default;
|
||||||
|
AdhocCommand(AdhocCommand&&) = default;
|
||||||
|
AdhocCommand& operator=(AdhocCommand&&) = delete;
|
||||||
|
AdhocCommand& operator=(const AdhocCommand&) = delete;
|
||||||
|
|
||||||
const std::string name;
|
const std::string name;
|
||||||
|
|
||||||
|
|||||||
@@ -591,7 +591,9 @@ void XmppComponent::send_version(const std::string& id, const std::string& jid_t
|
|||||||
this->send_stanza(iq);
|
this->send_stanza(iq);
|
||||||
}
|
}
|
||||||
|
|
||||||
void XmppComponent::send_adhoc_commands_list(const std::string& id, const std::string& requester_jid, const std::string& from_jid, const bool with_admin_only, const AdhocCommandsHandler& adhoc_handler)
|
void XmppComponent::send_adhoc_commands_list(const std::string& id, const std::string& requester_jid,
|
||||||
|
const std::string& from_jid,
|
||||||
|
const bool with_admin_only, const AdhocCommandsHandler& adhoc_handler)
|
||||||
{
|
{
|
||||||
Stanza iq("iq");
|
Stanza iq("iq");
|
||||||
iq["type"] = "result";
|
iq["type"] = "result";
|
||||||
|
|||||||
@@ -118,16 +118,19 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com
|
|||||||
{
|
{
|
||||||
const Jid owner(session.get_owner_jid());
|
const Jid owner(session.get_owner_jid());
|
||||||
const Jid target(session.get_target_jid());
|
const Jid target(session.get_target_jid());
|
||||||
|
std::string server_domain;
|
||||||
|
if ((server_domain = Config::get("fixed_irc_server", "")).empty())
|
||||||
|
server_domain = target.local;
|
||||||
auto options = Database::get_irc_server_options(owner.local + "@" + owner.domain,
|
auto options = Database::get_irc_server_options(owner.local + "@" + owner.domain,
|
||||||
target.local);
|
server_domain);
|
||||||
|
|
||||||
XmlNode x("jabber:x:data:x");
|
XmlNode x("jabber:x:data:x");
|
||||||
x["type"] = "form";
|
x["type"] = "form";
|
||||||
XmlNode title("title");
|
XmlNode title("title");
|
||||||
title.set_inner("Configure the IRC server "s + target.local);
|
title.set_inner("Configure the IRC server "s + server_domain);
|
||||||
x.add_child(std::move(title));
|
x.add_child(std::move(title));
|
||||||
XmlNode instructions("instructions");
|
XmlNode instructions("instructions");
|
||||||
instructions.set_inner("Edit the form, to configure the settings of the IRC server "s + target.local);
|
instructions.set_inner("Edit the form, to configure the settings of the IRC server "s + server_domain);
|
||||||
x.add_child(std::move(instructions));
|
x.add_child(std::move(instructions));
|
||||||
|
|
||||||
XmlNode required("required");
|
XmlNode required("required");
|
||||||
@@ -285,8 +288,11 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com
|
|||||||
{
|
{
|
||||||
const Jid owner(session.get_owner_jid());
|
const Jid owner(session.get_owner_jid());
|
||||||
const Jid target(session.get_target_jid());
|
const Jid target(session.get_target_jid());
|
||||||
|
std::string server_domain;
|
||||||
|
if ((server_domain = Config::get("fixed_irc_server", "")).empty())
|
||||||
|
server_domain = target.local;
|
||||||
auto options = Database::get_irc_server_options(owner.local + "@" + owner.domain,
|
auto options = Database::get_irc_server_options(owner.local + "@" + owner.domain,
|
||||||
target.local);
|
server_domain);
|
||||||
for (const XmlNode* field: x->get_children("field", "jabber:x:data"))
|
for (const XmlNode* field: x->get_children("field", "jabber:x:data"))
|
||||||
{
|
{
|
||||||
const XmlNode* value = field->get_child("value", "jabber:x:data");
|
const XmlNode* value = field->get_child("value", "jabber:x:data");
|
||||||
|
|||||||
@@ -61,9 +61,18 @@ BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller> poller, const std::st
|
|||||||
{"reload", AdhocCommand({&Reload}, "Reload biboumi’s configuration", true)}
|
{"reload", AdhocCommand({&Reload}, "Reload biboumi’s configuration", true)}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifdef USE_DATABASE
|
||||||
|
AdhocCommand configure_server_command({&ConfigureIrcServerStep1, &ConfigureIrcServerStep2}, "Configure a few settings for that IRC server", false);
|
||||||
|
if (!Config::get("fixed_irc_server", "").empty())
|
||||||
|
{
|
||||||
|
this->adhoc_commands_handler.get_commands().emplace(std::make_pair("configure",
|
||||||
|
configure_server_command));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
this->irc_server_adhoc_commands_handler.get_commands() = {
|
this->irc_server_adhoc_commands_handler.get_commands() = {
|
||||||
#ifdef USE_DATABASE
|
#ifdef USE_DATABASE
|
||||||
{"configure", AdhocCommand({&ConfigureIrcServerStep1, &ConfigureIrcServerStep2}, "Configure a few settings for that IRC server", false)},
|
{"configure", configure_server_command},
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
this->irc_channel_adhoc_commands_handler.get_commands() = {
|
this->irc_channel_adhoc_commands_handler.get_commands() = {
|
||||||
|
|||||||
@@ -514,6 +514,31 @@ if __name__ == '__main__':
|
|||||||
partial(expect_stanza, ("/iq[@type='result']/disco_items:query[@node='http://jabber.org/protocol/commands']",
|
partial(expect_stanza, ("/iq[@type='result']/disco_items:query[@node='http://jabber.org/protocol/commands']",
|
||||||
"/iq/disco_items:query/disco_items:item[5]")),
|
"/iq/disco_items:query/disco_items:item[5]")),
|
||||||
], conf='fixed_server'),
|
], conf='fixed_server'),
|
||||||
|
|
||||||
|
|
||||||
|
Scenario("list_adhoc_irc",
|
||||||
|
[
|
||||||
|
handshake_sequence(),
|
||||||
|
partial(send_stanza, "<iq type='get' id='idwhatever' from='{jid_one}/{resource_one}' to='{irc_host_one}@{biboumi_host}'><query xmlns='http://jabber.org/protocol/disco#items' node='http://jabber.org/protocol/commands' /></iq>"),
|
||||||
|
partial(expect_stanza, ("/iq[@type='result']/disco_items:query[@node='http://jabber.org/protocol/commands']",
|
||||||
|
"/iq/disco_items:query/disco_items:item[1]")),
|
||||||
|
]),
|
||||||
|
Scenario("list_adhoc_irc_fixed_server",
|
||||||
|
[
|
||||||
|
handshake_sequence(),
|
||||||
|
partial(send_stanza, "<iq type='get' id='idwhatever' from='{jid_one}/{resource_one}' to='{biboumi_host}'><query xmlns='http://jabber.org/protocol/disco#items' node='http://jabber.org/protocol/commands' /></iq>"),
|
||||||
|
partial(expect_stanza, ("/iq[@type='result']/disco_items:query[@node='http://jabber.org/protocol/commands']",
|
||||||
|
"/iq/disco_items:query/disco_items:item[4]")),
|
||||||
|
], conf='fixed_server'),
|
||||||
|
Scenario("list_admin_adhoc_irc_fixed_server",
|
||||||
|
[
|
||||||
|
handshake_sequence(),
|
||||||
|
partial(send_stanza, "<iq type='get' id='idwhatever' from='{jid_admin}/{resource_one}' to='{biboumi_host}'><query xmlns='http://jabber.org/protocol/disco#items' node='http://jabber.org/protocol/commands' /></iq>"),
|
||||||
|
partial(expect_stanza, ("/iq[@type='result']/disco_items:query[@node='http://jabber.org/protocol/commands']",
|
||||||
|
"/iq/disco_items:query/disco_items:item[6]")),
|
||||||
|
], conf='fixed_server'),
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
failures = 0
|
failures = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user