summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2014-12-05 20:24:27 -0500
committerAdam <Adam@anope.org>2014-12-05 20:24:27 -0500
commite1f5e030bc8edac10da922e0402744b1e2f023c8 (patch)
tree4da3774510e5a3f1582e529cecb7f4abfba6b795
parentafffeb0a1d49c1ac8f06ac9850929a41a52cbc7e (diff)
Change webpanel access add to just add via the commands, split Command::Run into two so I can do this as I need to run named commands for it
-rw-r--r--include/commands.h2
-rw-r--r--modules/webcpanel/pages/chanserv/access.cpp104
-rw-r--r--modules/webcpanel/webcpanel.cpp39
-rw-r--r--modules/webcpanel/webcpanel.h4
-rw-r--r--src/command.cpp43
5 files changed, 98 insertions, 94 deletions
diff --git a/include/commands.h b/include/commands.h
index f2b0592d4..2a1b34da2 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -170,6 +170,8 @@ class CoreExport Command : public Service
*/
static void Run(CommandSource &source, const Anope::string &message);
+ void Run(CommandSource &source, const Anope::string &, const CommandInfo &, std::vector<Anope::string> &params);
+
/** Looks up a command name from the service name.
* Note that if the same command exists multiple places this will return the first one encountered
* @param command_service The command service to lookup, eg, nickserv/register
diff --git a/modules/webcpanel/pages/chanserv/access.cpp b/modules/webcpanel/pages/chanserv/access.cpp
index 39750a283..daa8e7406 100644
--- a/modules/webcpanel/pages/chanserv/access.cpp
+++ b/modules/webcpanel/pages/chanserv/access.cpp
@@ -46,8 +46,6 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s
replacements["ACCESS_LIST"] = "YES";
- const ChanAccess *highest = u_access.Highest();
-
if (u_access.HasPriv("ACCESS_CHANGE") || has_priv)
{
if (message.get_data["del"].empty() == false && message.get_data["mask"].empty() == false)
@@ -61,71 +59,36 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s
}
else if (message.post_data["mask"].empty() == false && message.post_data["access"].empty() == false && message.post_data["provider"].empty() == false)
{
- // Generic access add code here, works with any provider (so we can't call a command exactly)
- AccessProvider *a = NULL;
- for (std::list<AccessProvider *>::const_iterator it = AccessProvider::GetProviders().begin(); it != AccessProvider::GetProviders().end(); ++it)
- if ((*it)->name == message.post_data["provider"])
- a = *it;
+ const Anope::string &provider = message.post_data["provider"];
- if (a)
+ if (provider == "chanserv/access")
{
- bool denied = false;
-
- for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i)
- {
- ChanAccess *acc = ci->GetAccess(i);
-
- if (acc->Mask() == message.post_data["mask"])
- {
- if ((!highest || *acc >= *highest) && !u_access.founder && !has_priv)
- {
- replacements["MESSAGES"] = "Access denied";
- denied = true;
- }
- else
- delete acc;
- break;
- }
- }
-
-
- unsigned access_max = Config->GetModule("chanserv")->Get<unsigned>("accessmax", "1024");
- if (access_max && ci->GetAccessCount() >= access_max)
- replacements["MESSAGES"] = "Sorry, you can only have " + stringify(access_max) + " access entries on a channel.";
- else if (!denied)
- {
- ChanAccess *new_acc = a->Create();
- new_acc->SetMask(message.post_data["mask"], ci);
- new_acc->creator = na->nc->display;
- try
- {
- new_acc->AccessUnserialize(message.post_data["access"]);
- }
- catch (...)
- {
- replacements["MESSAGES"] = "Invalid access expression for the given type";
- delete new_acc;
- new_acc = NULL;
- }
- if (new_acc)
- {
- new_acc->last_seen = 0;
- new_acc->created = Anope::CurTime;
-
- if ((!highest || *highest <= *new_acc) && !u_access.founder && !has_priv)
- delete new_acc;
- else if (new_acc->AccessSerialize().empty())
- {
- replacements["MESSAGES"] = "Invalid access expression for the given type";
- delete new_acc;
- }
- else
- {
- ci->AddAccess(new_acc);
- replacements["MESSAGES"] = "Access for " + new_acc->Mask() + " set to " + new_acc->AccessSerialize();
- }
- }
- }
+ std::vector<Anope::string> params;
+ params.push_back(ci->name);
+ params.push_back("ADD");
+ params.push_back(message.post_data["mask"]);
+ params.push_back(message.post_data["access"]);
+
+ WebPanel::RunCommand(na->nc->display, na->nc, "ChanServ", "chanserv/access", params, replacements);
+ }
+ else if (provider == "chanserv/xop")
+ {
+ std::vector<Anope::string> params;
+ params.push_back(ci->name);
+ params.push_back("ADD");
+ params.push_back(message.post_data["mask"]);
+
+ WebPanel::RunCommandWithName(na->nc, "ChanServ", "chanserv/xop", message.post_data["access"], params, replacements);
+ }
+ else if (provider == "chanserv/flags")
+ {
+ std::vector<Anope::string> params;
+ params.push_back(ci->name);
+ params.push_back("MODIFY");
+ params.push_back(message.post_data["mask"]);
+ params.push_back(message.post_data["access"]);
+
+ WebPanel::RunCommand(na->nc->display, na->nc, "ChanServ", "chanserv/flags", params, replacements);
}
}
}
@@ -142,11 +105,12 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s
replacements["CREATORS"] = HTTPUtils::Escape(access->creator);
}
- for (std::list<AccessProvider *>::const_iterator it = AccessProvider::GetProviders().begin(); it != AccessProvider::GetProviders().end(); ++it)
- {
- const AccessProvider *a = *it;
- replacements["PROVIDERS"] = a->name;
- }
+ if (Service::FindService("Command", "chanserv/access"))
+ replacements["PROVIDERS"] = "chanserv/access";
+ if (Service::FindService("Command", "chanserv/xop"))
+ replacements["PROVIDERS"] = "chanserv/xop";
+ if (Service::FindService("Command", "chanserv/flags"))
+ replacements["PROVIDERS"] = "chanserv/flags";
Page.Serve(server, page_name, client, message, reply, replacements);
return true;
diff --git a/modules/webcpanel/webcpanel.cpp b/modules/webcpanel/webcpanel.cpp
index bf0a31540..134f07aa6 100644
--- a/modules/webcpanel/webcpanel.cpp
+++ b/modules/webcpanel/webcpanel.cpp
@@ -231,7 +231,7 @@ class ModuleWebCPanel : public Module
namespace WebPanel
{
- void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, const std::vector<Anope::string> &params, TemplateFileServer::Replacements &r, const Anope::string &key)
+ void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, std::vector<Anope::string> &params, TemplateFileServer::Replacements &r, const Anope::string &key)
{
ServiceReference<Command> cmd("Command", c);
if (!cmd)
@@ -266,14 +266,45 @@ namespace WebPanel
my_reply(r, key);
CommandSource source(user, NULL, nc, &my_reply, bi);
+ CommandInfo info;
+ info.name = c;
+ cmd->Run(source, "", info, params);
+ }
- if (!cmd->AllowUnregistered() && !source.nc)
+ void RunCommandWithName(NickCore *nc, const Anope::string &service, const Anope::string &c, const Anope::string &cmdname, std::vector<Anope::string> &params, TemplateFileServer::Replacements &r, const Anope::string &key)
+ {
+ ServiceReference<Command> cmd("Command", c);
+ if (!cmd)
{
- r[key] = "Access denied.";
+ r[key] = "Unable to find command " + c;
return;
}
- cmd->Execute(source, params);
+ BotInfo *bi = Config->GetClient(service);
+ if (!bi)
+ return;
+
+ CommandInfo *info = bi->GetCommand(cmdname);
+ if (!info)
+ return;
+
+ struct MyComandReply : CommandReply
+ {
+ TemplateFileServer::Replacements &re;
+ const Anope::string &k;
+
+ MyComandReply(TemplateFileServer::Replacements &_r, const Anope::string &_k) : re(_r), k(_k) { }
+
+ void SendMessage(BotInfo *source, const Anope::string &msg) anope_override
+ {
+ re[k] = msg;
+ }
+ }
+ my_reply(r, key);
+
+ CommandSource source(nc->display, NULL, nc, &my_reply, bi);
+
+ cmd->Run(source, cmdname, *info, params);
}
}
diff --git a/modules/webcpanel/webcpanel.h b/modules/webcpanel/webcpanel.h
index 7e4b5a556..4b57cec8e 100644
--- a/modules/webcpanel/webcpanel.h
+++ b/modules/webcpanel/webcpanel.h
@@ -151,7 +151,9 @@ namespace WebPanel
* @param r Replacements, reply from command goes back here into key
* @param key The key to put the replies into r
*/
- extern void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, const std::vector<Anope::string> &params, TemplateFileServer::Replacements &r, const Anope::string &key = "MESSAGES");
+ extern void RunCommand(const Anope::string &user, NickCore *nc, const Anope::string &service, const Anope::string &c, std::vector<Anope::string> &params, TemplateFileServer::Replacements &r, const Anope::string &key = "MESSAGES");
+
+ extern void RunCommandWithName(NickCore *nc, const Anope::string &service, const Anope::string &c, const Anope::string &cmdname, std::vector<Anope::string> &params, TemplateFileServer::Replacements &r, const Anope::string &key = "MESSAGES");
}
#include "pages/index.h"
diff --git a/src/command.cpp b/src/command.cpp
index 6aa2f744b..2786edecf 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -236,18 +236,6 @@ void Command::Run(CommandSource &source, const Anope::string &message)
return;
}
- if (c->RequireUser() && !source.GetUser())
- return;
-
- // Command requires registered users only
- if (!c->AllowUnregistered() && !source.nc)
- {
- source.Reply(NICK_IDENTIFY_REQUIRED);
- if (source.GetUser())
- Log(LOG_NORMAL, "access_denied_unreg", source.service) << "Access denied for unregistered user " << source.GetUser()->GetMask() << " with command " << it->first;
- return;
- }
-
for (unsigned i = 0, j = params.size() - (count - 1); i < j; ++i)
params.erase(params.begin());
@@ -257,17 +245,34 @@ void Command::Run(CommandSource &source, const Anope::string &message)
params.erase(params.begin() + c->max_params);
}
- source.command = it->first;
+ c->Run(source, it->first, info, params);
+}
+
+void Command::Run(CommandSource &source, const Anope::string &cmdname, const CommandInfo &info, std::vector<Anope::string> &params)
+{
+ if (this->RequireUser() && !source.GetUser())
+ return;
+
+ // Command requires registered users only
+ if (!this->AllowUnregistered() && !source.nc)
+ {
+ source.Reply(NICK_IDENTIFY_REQUIRED);
+ if (source.GetUser())
+ Log(LOG_NORMAL, "access_denied_unreg", source.service) << "Access denied for unregistered user " << source.GetUser()->GetMask() << " with command " << cmdname;
+ return;
+ }
+
+ source.command = cmdname;
source.permission = info.permission;
EventReturn MOD_RESULT;
- FOREACH_RESULT(OnPreCommand, MOD_RESULT, (source, c, params));
+ FOREACH_RESULT(OnPreCommand, MOD_RESULT, (source, this, params));
if (MOD_RESULT == EVENT_STOP)
return;
- if (params.size() < c->min_params)
+ if (params.size() < this->min_params)
{
- c->OnSyntaxError(source, !params.empty() ? params[params.size() - 1] : "");
+ this->OnSyntaxError(source, !params.empty() ? params[params.size() - 1] : "");
return;
}
@@ -276,12 +281,12 @@ void Command::Run(CommandSource &source, const Anope::string &message)
{
source.Reply(ACCESS_DENIED);
if (source.GetUser())
- Log(LOG_NORMAL, "access_denied", source.service) << "Access denied for user " << source.GetUser()->GetMask() << " with command " << it->first;
+ Log(LOG_NORMAL, "access_denied", source.service) << "Access denied for user " << source.GetUser()->GetMask() << " with command " << cmdname;
return;
}
- c->Execute(source, params);
- FOREACH_MOD(OnPostCommand, (source, c, params));
+ this->Execute(source, params);
+ FOREACH_MOD(OnPostCommand, (source, this, params));
}
bool Command::FindCommandFromService(const Anope::string &command_service, BotInfo* &bot, Anope::string &name)