Do not send the admin-only adhoc commands to non-admin users
They were not able to execute them anyway, so this was just a little usability issue.
This commit is contained in:
@@ -651,7 +651,7 @@ 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)
|
void XmppComponent::send_adhoc_commands_list(const std::string& id, const std::string& requester_jid, const bool with_admin_only)
|
||||||
{
|
{
|
||||||
Stanza iq("iq");
|
Stanza iq("iq");
|
||||||
iq["type"] = "result";
|
iq["type"] = "result";
|
||||||
@@ -663,6 +663,8 @@ void XmppComponent::send_adhoc_commands_list(const std::string& id, const std::s
|
|||||||
query["node"] = ADHOC_NS;
|
query["node"] = ADHOC_NS;
|
||||||
for (const auto& kv: this->adhoc_commands_handler.get_commands())
|
for (const auto& kv: this->adhoc_commands_handler.get_commands())
|
||||||
{
|
{
|
||||||
|
if (kv.second.is_admin_only() && !with_admin_only)
|
||||||
|
continue;
|
||||||
XmlNode item("item");
|
XmlNode item("item");
|
||||||
item["jid"] = this->served_hostname;
|
item["jid"] = this->served_hostname;
|
||||||
item["node"] = kv.first;
|
item["node"] = kv.first;
|
||||||
|
|||||||
@@ -184,7 +184,8 @@ public:
|
|||||||
* Send the list of all available ad-hoc commands to that JID. The list is
|
* Send the list of all available ad-hoc commands to that JID. The list is
|
||||||
* different depending on what JID made the request.
|
* different depending on what JID made the request.
|
||||||
*/
|
*/
|
||||||
void send_adhoc_commands_list(const std::string& id, const std::string& requester_jid);
|
void send_adhoc_commands_list(const std::string& id, const std::string& requester_jid,
|
||||||
|
const bool with_admin_only);
|
||||||
/**
|
/**
|
||||||
* Send an iq version request
|
* Send an iq version request
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ BiboumiComponent::BiboumiComponent(std::shared_ptr<Poller> poller, const std::st
|
|||||||
this->stanza_handlers.emplace("iq",
|
this->stanza_handlers.emplace("iq",
|
||||||
std::bind(&BiboumiComponent::handle_iq, this,std::placeholders::_1));
|
std::bind(&BiboumiComponent::handle_iq, this,std::placeholders::_1));
|
||||||
|
|
||||||
this->adhoc_commands_handler.get_commands()= {
|
this->adhoc_commands_handler.get_commands() = {
|
||||||
{"ping", AdhocCommand({&PingStep1}, "Do a ping", false)},
|
{"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)},
|
{"disconnect-user", AdhocCommand({&DisconnectUserStep1, &DisconnectUserStep2}, "Disconnect a user from the gateway", true)},
|
||||||
@@ -370,7 +370,10 @@ void BiboumiComponent::handle_iq(const Stanza& stanza)
|
|||||||
const std::string node = query->get_tag("node");
|
const std::string node = query->get_tag("node");
|
||||||
if (node == ADHOC_NS)
|
if (node == ADHOC_NS)
|
||||||
{
|
{
|
||||||
this->send_adhoc_commands_list(id, from);
|
Jid from_jid(from);
|
||||||
|
this->send_adhoc_commands_list(id, from,
|
||||||
|
(Config::get("admin", "") ==
|
||||||
|
from_jid.local + "@" + from_jid.domain));
|
||||||
stanza_error.disable();
|
stanza_error.disable();
|
||||||
}
|
}
|
||||||
else if (node.empty() && !iid.is_user && !iid.is_channel)
|
else if (node.empty() && !iid.is_user && !iid.is_channel)
|
||||||
|
|||||||
Reference in New Issue
Block a user