1
0
mirror of https://github.com/anope/anope.git synced 2026-06-29 11:16:38 +02:00

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

This commit is contained in:
Adam
2014-12-05 20:24:27 -05:00
parent afffeb0a1d
commit e1f5e030bc
5 changed files with 95 additions and 91 deletions
+2
View File
@@ -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
+31 -67
View File
@@ -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;
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"]);
for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i)
{
ChanAccess *acc = ci->GetAccess(i);
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"]);
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;
}
}
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"]);
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();
}
}
}
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;
+35 -4
View File
@@ -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);
}
}
+3 -1
View File
@@ -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"
+24 -19
View File
@@ -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)