mirror of
https://github.com/anope/anope.git
synced 2026-07-08 15:43:12 +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:
@@ -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;
|
||||
|
||||
@@ -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> ¶ms, 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> ¶ms, 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> ¶ms, 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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> ¶ms, 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> ¶ms, 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> ¶ms, TemplateFileServer::Replacements &r, const Anope::string &key = "MESSAGES");
|
||||
}
|
||||
|
||||
#include "pages/index.h"
|
||||
|
||||
Reference in New Issue
Block a user