summaryrefslogtreecommitdiff
path: root/modules/webcpanel
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2015-01-05 16:31:09 -0500
committerAdam <Adam@anope.org>2015-01-05 19:00:51 -0500
commitd79d8e2608e304760c42bdf87502e3bc51781b88 (patch)
tree179913b8b328f88d52d84c3453fceb28a2d63422 /modules/webcpanel
parent8ab1c71d7dc7a0d47e5711dc72e3fc9c3ee850bb (diff)
parentc46ec39e5088119cd21f5f7e16e64e61a876ca20 (diff)
Merge branch '2.0' into 2.1
Conflicts: CMakeLists.txt include/modules.h include/serialize.h modules/commands/bs_assign.cpp modules/commands/bs_badwords.cpp modules/commands/bs_bot.cpp modules/commands/bs_control.cpp modules/commands/bs_kick.cpp modules/commands/cs_access.cpp modules/commands/cs_akick.cpp modules/commands/cs_drop.cpp modules/commands/cs_entrymsg.cpp modules/commands/cs_flags.cpp modules/commands/cs_info.cpp modules/commands/cs_invite.cpp modules/commands/cs_kick.cpp modules/commands/cs_mode.cpp modules/commands/cs_register.cpp modules/commands/cs_seen.cpp modules/commands/cs_set.cpp modules/commands/cs_suspend.cpp modules/commands/cs_topic.cpp modules/commands/cs_unban.cpp modules/commands/cs_xop.cpp modules/commands/hs_del.cpp modules/commands/hs_list.cpp modules/commands/hs_request.cpp modules/commands/ms_ignore.cpp modules/commands/ms_send.cpp modules/commands/ns_recover.cpp modules/commands/ns_register.cpp modules/commands/ns_suspend.cpp modules/commands/os_dns.cpp modules/commands/os_noop.cpp modules/commands/os_oper.cpp modules/commands/os_session.cpp modules/database/db_sql_live.cpp modules/encryption/enc_bcrypt.cpp modules/extra/m_ldap_authentication.cpp modules/extra/m_ldap_oper.cpp modules/fantasy.cpp modules/m_dnsbl.cpp modules/m_sasl.cpp modules/protocol/hybrid.cpp modules/protocol/inspircd20.cpp modules/protocol/unreal.cpp modules/pseudoclients/chanserv.cpp modules/pseudoclients/nickserv.cpp modules/webcpanel/pages/chanserv/access.cpp modules/webcpanel/webcpanel.cpp modules/webcpanel/webcpanel.h src/command.cpp src/messages.cpp src/modulemanager.cpp src/regchannel.cpp src/serialize.cpp
Diffstat (limited to 'modules/webcpanel')
-rw-r--r--modules/webcpanel/pages/chanserv/access.cpp103
-rw-r--r--modules/webcpanel/pages/chanserv/modes.cpp6
-rw-r--r--modules/webcpanel/webcpanel.cpp39
-rw-r--r--modules/webcpanel/webcpanel.h4
4 files changed, 75 insertions, 77 deletions
diff --git a/modules/webcpanel/pages/chanserv/access.cpp b/modules/webcpanel/pages/chanserv/access.cpp
index 27659344d..e5d268dee 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";
- ::ChanServ::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,37 @@ 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)
{
-#if 0
- // Generic access add code here, works with any provider (so we can't call a command exactly)
- ServiceReference<::ChanServ::AccessProvider> a("AccessProvider", "access/" + message.post_data["provider"]);
+ const Anope::string &provider = message.post_data["provider"];
+
+ if (provider == "chanserv/access")
+ {
+ std::vector<Anope::string> params;
+ params.push_back(ci->GetName());
+ params.push_back("ADD");
+ params.push_back(message.post_data["mask"]);
+ params.push_back(message.post_data["access"]);
+
+ WebPanel::RunCommand(na->GetAccount()->GetDisplay(), na->GetAccount(), "ChanServ", "chanserv/access", params, replacements);
+ }
+ else if (provider == "chanserv/xop")
+ {
+ std::vector<Anope::string> params;
+ params.push_back(ci->GetName());
+ params.push_back("ADD");
+ params.push_back(message.post_data["mask"]);
- if (a)
+ WebPanel::RunCommandWithName(na->GetAccount(), "ChanServ", "chanserv/xop", message.post_data["access"], params, replacements);
+ }
+ else if (provider == "chanserv/flags")
{
- bool denied = false;
-
- for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i)
- {
- ::ChanServ::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)
- {
- ::ChanServ::ChanAccess *new_acc = a->Create();
- //new_acc->SetMask(message.post_data["mask"], ci);
- new_acc->SetCreator(na->GetAccount()->GetDisplay());
- 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->SetLastSeen(0);
- new_acc->SetCreated(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->GetName());
+ params.push_back("MODIFY");
+ params.push_back(message.post_data["mask"]);
+ params.push_back(message.post_data["access"]);
+
+ WebPanel::RunCommand(na->GetAccount()->GetDisplay(), na->GetAccount(), "ChanServ", "chanserv/flags", params, replacements);
}
-#endif
}
}
@@ -141,11 +105,12 @@ bool WebCPanel::ChanServ::Access::OnRequest(HTTPProvider *server, const Anope::s
replacements["CREATORS"] = HTTPUtils::Escape(access->GetCreator());
}
-#if 0
- if (::ChanServ::service)
- for (::ChanServ::AccessProvider *p : ::ChanServ::service->GetProviders())
- replacements["PROVIDERS"] = p->name;
-#endif
+ 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/pages/chanserv/modes.cpp b/modules/webcpanel/pages/chanserv/modes.cpp
index e9e2498a6..70b7a4f7b 100644
--- a/modules/webcpanel/pages/chanserv/modes.cpp
+++ b/modules/webcpanel/pages/chanserv/modes.cpp
@@ -94,9 +94,9 @@ bool WebCPanel::ChanServ::Modes::OnRequest(HTTPProvider *server, const Anope::st
WebPanel::RunCommand(na->GetAccount()->GetDisplay(), na->GetAccount(), "ChanServ", "chanserv/mode", params, replacements);
}
- std::pair<Channel::ModeList::iterator, Channel::ModeList::iterator> ml = c->GetModeList(cm->name);
- for (; ml.first != ml.second; ++ml.first)
- replacements["MASKS"] = HTTPUtils::Escape(ml.first->second);
+ std::vector<Anope::string> v = c->GetModeList(cm->name);
+ for (unsigned int i = 0; i < v.size(); ++i)
+ replacements["MASKS"] = HTTPUtils::Escape(v[i]);
}
Page.Serve(server, page_name, client, message, reply, replacements);
diff --git a/modules/webcpanel/webcpanel.cpp b/modules/webcpanel/webcpanel.cpp
index 324759f84..5da56a6d4 100644
--- a/modules/webcpanel/webcpanel.cpp
+++ b/modules/webcpanel/webcpanel.cpp
@@ -248,7 +248,7 @@ class ModuleWebCPanel : public Module
namespace WebPanel
{
- void RunCommand(const Anope::string &user, NickServ::Account *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, NickServ::Account *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)
@@ -279,14 +279,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(NickServ::Account *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);
+ ServiceBot *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(const MessageSource &, const Anope::string &msg) override
+ {
+ re[k] = msg;
+ }
+ }
+ my_reply(r, key);
+
+ CommandSource source(nc->GetDisplay(), NULL, nc, &my_reply, bi);
+
+ cmd->Run(source, cmdname, *info, params);
}
}
diff --git a/modules/webcpanel/webcpanel.h b/modules/webcpanel/webcpanel.h
index 66c6450c0..8e77b975a 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, NickServ::Account *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, NickServ::Account *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(NickServ::Account *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"