summaryrefslogtreecommitdiff
path: root/modules/operserv
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2015-12-14 16:52:24 -0500
committerAdam <Adam@anope.org>2015-12-14 16:52:24 -0500
commit6302f980fe6dad83aab7d2dc1046dadea5ffd939 (patch)
tree4c27d33f55fc32ce34827977932dac4b3e5ceedd /modules/operserv
parent64dac60071fab652745a6e7a06cf6b7bdbbd3625 (diff)
New source tree structure for modules. From commands/cs_access => chanserv/access etc.
Diffstat (limited to 'modules/operserv')
-rw-r--r--modules/operserv/CMakeLists.txt1
-rw-r--r--modules/operserv/akill.cpp437
-rw-r--r--modules/operserv/chankill.cpp113
-rw-r--r--modules/operserv/config.cpp147
-rw-r--r--modules/operserv/defcon.cpp619
-rw-r--r--modules/operserv/dns.cpp1012
-rw-r--r--modules/operserv/forbid.cpp577
-rw-r--r--modules/operserv/ignore.cpp393
-rw-r--r--modules/operserv/info.cpp260
-rw-r--r--modules/operserv/jupe.cpp72
-rw-r--r--modules/operserv/kick.cpp81
-rw-r--r--modules/operserv/kill.cpp63
-rw-r--r--modules/operserv/list.cpp238
-rw-r--r--modules/operserv/login.cpp148
-rw-r--r--modules/operserv/logsearch.cpp151
-rw-r--r--modules/operserv/main/CMakeLists.txt1
-rw-r--r--modules/operserv/main/operserv.cpp337
-rw-r--r--modules/operserv/mode.cpp187
-rw-r--r--modules/operserv/modinfo.cpp214
-rw-r--r--modules/operserv/module.cpp179
-rw-r--r--modules/operserv/news.cpp459
-rw-r--r--modules/operserv/noop.cpp98
-rw-r--r--modules/operserv/oline.cpp74
-rw-r--r--modules/operserv/oper.cpp241
-rw-r--r--modules/operserv/reload.cpp62
-rw-r--r--modules/operserv/session.cpp768
-rw-r--r--modules/operserv/set.cpp243
-rw-r--r--modules/operserv/shutdown.cpp101
-rw-r--r--modules/operserv/stats.cpp271
-rw-r--r--modules/operserv/svs.cpp171
-rw-r--r--modules/operserv/sxline.cpp673
-rw-r--r--modules/operserv/update.cpp49
32 files changed, 8440 insertions, 0 deletions
diff --git a/modules/operserv/CMakeLists.txt b/modules/operserv/CMakeLists.txt
new file mode 100644
index 000000000..cd225a94d
--- /dev/null
+++ b/modules/operserv/CMakeLists.txt
@@ -0,0 +1 @@
+build_modules(${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/modules/operserv/akill.cpp b/modules/operserv/akill.cpp
new file mode 100644
index 000000000..7f366e0c9
--- /dev/null
+++ b/modules/operserv/akill.cpp
@@ -0,0 +1,437 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline");
+
+class CommandOSAKill : public Command
+{
+ private:
+ void DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ Anope::string expiry, mask;
+
+ if (params.size() < 2)
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ spacesepstream sep(params[1]);
+ sep.GetToken(mask);
+
+ if (mask[0] == '+')
+ {
+ expiry = mask;
+ sep.GetToken(mask);
+ }
+
+ time_t expires = !expiry.empty() ? Anope::DoTime(expiry) : Config->GetModule("operserv")->Get<time_t>("autokillexpiry", "30d");
+ /* If the expiry given does not contain a final letter, it's in days,
+ * said the doc. Ah well.
+ */
+ if (!expiry.empty() && isdigit(expiry[expiry.length() - 1]))
+ expires *= 86400;
+ /* Do not allow less than a minute expiry time */
+ if (expires && expires < 60)
+ {
+ source.Reply(_("Invalid expiry time \002{0}\002."), expiry);
+ return;
+ }
+ else if (expires > 0)
+ expires += Anope::CurTime;
+
+ if (sep.StreamEnd())
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ Anope::string reason;
+ if (mask.find('#') != Anope::string::npos)
+ {
+ Anope::string remaining = sep.GetRemaining();
+
+ size_t co = remaining[0] == ':' ? 0 : remaining.rfind(" :");
+ if (co == Anope::string::npos)
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ if (co != 0)
+ ++co;
+
+ reason = remaining.substr(co + 1);
+ mask += " " + remaining.substr(0, co);
+ mask.trim();
+ }
+ else
+ reason = sep.GetRemaining();
+
+ if (mask[0] == '/' && mask[mask.length() - 1] == '/')
+ {
+ if (!Config->regex_flags)
+ {
+ source.Reply(_("Regex is disabled."));
+ return;
+ }
+
+ Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
+ try
+ {
+ std::regex(stripped_mask.str(), Config->regex_flags);
+ }
+ catch (const std::regex_error &ex)
+ {
+ source.Reply("%s", ex.what());
+ return;
+ }
+ }
+
+ User *targ = User::Find(mask, true);
+ if (targ)
+ mask = "*@" + targ->host;
+
+ if (Config->GetModule("operserv")->Get<bool>("addakiller", "yes") && !source.GetNick().empty())
+ reason = "[" + source.GetNick() + "] " + reason;
+
+ if (!akills->CanAdd(source, mask, expires, reason))
+ return;
+
+ if (mask.find_first_not_of("/~@.*?") == Anope::string::npos)
+ {
+ source.Reply(_("\002{0}\002 coverage is too wide; Please use a more specific mask."), mask);
+ return;
+ }
+
+ if (mask.find('@') == Anope::string::npos)
+ {
+ source.Reply(_("Mask must be in the form \037user\037@\037host\037."));
+ return;
+ }
+
+ XLine *x = new XLine(mask, source.GetNick(), expires, reason);
+ if (Config->GetModule("operserv")->Get<bool>("akillids"))
+ x->SetID(XLineManager::GenerateUID());
+
+ unsigned int affected = 0;
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (akills->Check(it->second, x))
+ ++affected;
+ float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
+
+ if (percent > 95)
+ {
+ source.Reply(_("\002{0}\002 coverage is too wide; Please use a more specific mask."), mask);
+ Log(LOG_ADMIN, source, this) << "tried to akill " << percent << "% of the network (" << affected << " users)";
+ delete x;
+ return;
+ }
+
+ EventReturn MOD_RESULT;
+ MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, akills);
+ if (MOD_RESULT == EVENT_STOP)
+ {
+ delete x;
+ return;
+ }
+
+ akills->AddXLine(x);
+ if (Config->GetModule("operserv")->Get<bool>("akillonadd"))
+ akills->Send(NULL, x);
+
+ source.Reply(_("\002{0}\002 added to the akill list."), mask);
+
+ Log(LOG_ADMIN, source, this) << "on " << mask << " (" << x->GetReason() << "), expires in " << (expires ? Anope::Duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]";
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ }
+
+ void DoDel(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string &mask = params.size() > 1 ? params[1] : "";
+
+ if (mask.empty())
+ {
+ this->OnSyntaxError(source, "DEL");
+ return;
+ }
+
+ if (akills->GetXLines().empty())
+ {
+ source.Reply(_("The akill list is empty."));
+ return;
+ }
+
+ if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
+ {
+ unsigned int deleted = 0;
+
+ NumberList(mask, true,
+ [&](unsigned int number)
+ {
+ XLine *x = akills->GetEntry(number - 1);
+
+ if (!x)
+ return;
+
+ Log(LOG_ADMIN, source, this) << "to remove " << x->GetMask() << " from the list";
+
+ ++deleted;
+ x->Delete();
+ },
+ [&]()
+ {
+ if (!deleted)
+ source.Reply(_("No matching entries on the akill list."));
+ else if (deleted == 1)
+ source.Reply(_("Deleted \0021\002 entry from the akill list."));
+ else
+ source.Reply(_("Deleted \002{0}\002 entries from the akill list."), deleted);
+ });
+ }
+ else
+ {
+ XLine *x = akills->HasEntry(mask);
+
+ if (!x)
+ {
+ source.Reply(_("\002{0}\002 was not found on the akill list."), mask);
+ return;
+ }
+
+ do
+ {
+ Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, akills);
+
+ Log(LOG_ADMIN, source, this) << "to remove " << x->GetMask() << " from the list";
+ source.Reply(_("\002{0}\002 deleted from the akill list."), x->GetMask());
+ x->Delete();
+ }
+ while ((x = akills->HasEntry(mask)));
+
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ }
+
+ void ProcessList(CommandSource &source, const std::vector<Anope::string> &params, ListFormatter &list)
+ {
+ const Anope::string &mask = params.size() > 1 ? params[1] : "";
+
+ if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
+ {
+ NumberList(mask, false,
+ [&](unsigned int number)
+ {
+ XLine *x = akills->GetEntry(number - 1);
+
+ if (!x)
+ return;
+
+ ListFormatter::ListEntry entry;
+ entry["Number"] = stringify(number);
+ entry["Mask"] = x->GetMask();
+ entry["Creator"] = x->GetBy();
+ entry["Created"] = Anope::strftime(x->GetCreated(), NULL, true);
+ entry["Expires"] = Anope::Expires(x->GetExpires(), source.nc);
+ entry["Reason"] = x->GetReason();
+ list.AddEntry(entry);
+ },
+ [&]{});
+ }
+ else
+ {
+ unsigned int i = 0;
+ for (XLine *x : akills->GetXLines())
+ {
+ if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->id || Anope::Match(x->GetMask(), mask, false, true))
+ {
+ ListFormatter::ListEntry entry;
+ entry["Number"] = stringify(++i);
+ entry["Mask"] = x->GetMask();
+ entry["Creator"] = x->GetBy();
+ entry["Created"] = Anope::strftime(x->GetCreated(), NULL, true);
+ entry["Expires"] = Anope::Expires(x->GetExpires(), source.nc);
+ entry["Reason"] = x->GetReason();
+ list.AddEntry(entry);
+ }
+ }
+ }
+
+ if (list.IsEmpty())
+ {
+ source.Reply(_("There are no matching entries on the akill list."));
+ return;
+ }
+
+ source.Reply(_("Current akill list:"));
+
+ std::vector<Anope::string> replies;
+ list.Process(replies);
+
+ for (unsigned i = 0; i < replies.size(); ++i)
+ source.Reply(replies[i]);
+
+ source.Reply(_("End of akill list."));
+ }
+
+ void DoList(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ if (akills->GetXLines().empty())
+ {
+ source.Reply(_("The akill list is empty."));
+ return;
+ }
+
+ ListFormatter list(source.GetAccount());
+ list.AddColumn(_("Number")).AddColumn(_("Mask")).AddColumn(_("Reason"));
+
+ this->ProcessList(source, params, list);
+ }
+
+ void DoView(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ if (akills->GetXLines().empty())
+ {
+ source.Reply(_("The akill list is empty."));
+ return;
+ }
+
+ ListFormatter list(source.GetAccount());
+ list.AddColumn(_("Number")).AddColumn(_("Mask")).AddColumn(_("Creator")).AddColumn(_("Created")).AddColumn(_("Expires")).AddColumn(_("Reason"));
+
+ this->ProcessList(source, params, list);
+ }
+
+ void DoClear(CommandSource &source)
+ {
+ for (XLine *x : akills->GetXLines())
+ {
+ Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, akills);
+ x->Delete();
+ }
+
+ Log(LOG_ADMIN, source, this) << "to CLEAR the list";
+ source.Reply(_("The akill list has been cleared."));
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ }
+ public:
+ CommandOSAKill(Module *creator) : Command(creator, "operserv/akill", 1, 2)
+ {
+ this->SetDesc(_("Manipulate the AKILL list"));
+ this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037 \037reason\037"));
+ this->SetSyntax(_("DEL {\037mask\037 | \037entry-num\037 | \037list\037 | \037id\037}"));
+ this->SetSyntax(_("LIST [\037mask\037 | \037list\037 | \037id\037]"));
+ this->SetSyntax(_("VIEW [\037mask\037 | \037list\037 | \037id\037]"));
+ this->SetSyntax("CLEAR");
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &cmd = params[0];
+
+ if (!akills)
+ return;
+
+ if (cmd.equals_ci("ADD"))
+ return this->DoAdd(source, params);
+ else if (cmd.equals_ci("DEL"))
+ return this->DoDel(source, params);
+ else if (cmd.equals_ci("LIST"))
+ return this->DoList(source, params);
+ else if (cmd.equals_ci("VIEW"))
+ return this->DoView(source, params);
+ else if (cmd.equals_ci("CLEAR"))
+ return this->DoClear(source);
+ else
+ this->OnSyntaxError(source, "");
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ if (subcommand.equals_ci("ADD"))
+ {
+ source.Reply(_("The \002{0} ADD\002 command adds \037mask\037 to the auto kill list with the given \037reason\037."
+ "\037mask\037 can be in the format of nickname!username@hostname#realname."
+ " If a real name is specified, the reason must be prefixed with a :."
+ " \037expiry\037 is optional, and if specified must be an integer followed by one of \037d\037 (days), \037h\037 (hours), or \037m\037 (minutes)."
+ " If a unit specifier is not included, the default is days, so \037+30\037 means 30 days."
+ " To add an auto kill which does not expire, use \037+0\037. "
+ " The default auto kill expiry time is \002{1}\002"),
+ source.command, Anope::Duration(Config->GetModule("operserv")->Get<time_t>("autokillexpiry", "30d"), source.GetAccount()));
+
+ const Anope::string &regexengine = Config->GetBlock("options")->Get<Anope::string>("regexengine");
+ if (!regexengine.empty())
+ {
+ source.Reply(" ");
+ source.Reply(_("Regex matches are also supported using the %s engine. Enclose your mask in // if this is desired."), regexengine);
+ }
+ }
+ else if (subcommand.equals_ci("DEL"))
+ source.Reply(_("The \002{0} DEL\002 command removes the given \037mask\037 from the auto kill list, if present."
+ " If a list of entry numbers is given, those entries are deleted."),
+ source.command);
+ else if (subcommand.equals_ci("LIST") || subcommand.equals_ci("VIEW"))
+ source.Reply(_("The \002{0} LIST\002 and \002{0} VIEW\002 commands display the auto kill list."
+ " If a wildcard \037mask\037 is given, only those entries matching the mask are displayed."
+ " If a list of entry numbers is given, only those entries are shown."
+ " \002VIEW\002 is similar to \002LIST\002 but also shows who created the auto kill, when it was created, and when it expires.\n"
+ "\n"
+ "Example:\n"
+ "\n"
+ " {0} LIST 2-5,7-9\n"
+ " Lists auto kill entries numbered 2 through 5 and 7 through 9."),
+ source.command);
+ else if (subcommand.equals_ci("CLEAR"))
+ source.Reply(_("The \002{0} CLEAR\002 command removes all auto kills from the auto kill list."),
+ source.command);
+ else
+ {
+ CommandInfo *help = source.service->FindCommand("generic/help");
+ source.Reply(_("Allows manipulating the AKILL list."
+ " If a user matching an AKILL mask connects, services will issue a kill the user and prevent them from reconnecting.\n"
+ "\n"
+ "The \002ADD\002 command adds \037mask\037 to the auto kill list.\n"
+ "\002{msg}{service} {help} {command} ADD\002 for more information.\n"
+ "\n"
+ "The \002DEL\002 command removes \037mask\037 from the auto kill list.\n"
+ "\002{msg}{service} {help} {command} DEL\002 for more information.\n"
+ "\n"
+ "The \002LIST\002 and \002VIEW\002 commands both show the auto kill list, but \002VIEW\002 also shows who created the auto kill entry, when it was created, and when it expires.\n"
+ "\002{msg}{service} {help} {command} [LIST | VIEW]\002 for more information.\n"
+ "\n"
+ "The \002CLEAR\002 command clears th auto kill list."
+ "\002{msg}{service} {help} {command} CLEAR\002 for more information.\n"),
+ "msg"_kw = Config->StrictPrivmsg, "service"_kw = source.service->nick, "help"_kw = help->cname, "command"_kw = source.command);
+ }
+ return true;
+ }
+};
+
+class OSAKill : public Module
+{
+ CommandOSAKill commandosakill;
+
+ public:
+ OSAKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosakill(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSAKill)
diff --git a/modules/operserv/chankill.cpp b/modules/operserv/chankill.cpp
new file mode 100644
index 000000000..8d3773e9d
--- /dev/null
+++ b/modules/operserv/chankill.cpp
@@ -0,0 +1,113 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline");
+
+class CommandOSChanKill : public Command
+{
+ public:
+ CommandOSChanKill(Module *creator) : Command(creator, "operserv/chankill", 2, 3)
+ {
+ this->SetDesc(_("AKILL all users on a specific channel"));
+ this->SetSyntax(_("[+\037expiry\037] \037channel\037 \037reason\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ if (!akills)
+ return;
+
+ Anope::string expiry, channel;
+ unsigned last_param = 1;
+
+ channel = params[0];
+ if (!channel.empty() && channel[0] == '+')
+ {
+ expiry = channel;
+ channel = params[1];
+ last_param = 2;
+ }
+
+ time_t expires = !expiry.empty() ? Anope::DoTime(expiry) : Config->GetModule("operserv")->Get<time_t>("autokillexpiry", "30d");
+ if (!expiry.empty() && isdigit(expiry[expiry.length() - 1]))
+ expires *= 86400;
+
+ if (expires)
+ {
+ if (expires < 60)
+ {
+ source.Reply(_("Invalid expiry time \002{0}\002."), expiry);
+ return;
+ }
+
+ expires += Anope::CurTime;
+ }
+
+ if (params.size() <= last_param)
+ {
+ this->OnSyntaxError(source, "");
+ return;
+ }
+
+ Anope::string reason = params[last_param];
+ if (params.size() > last_param + 1)
+ reason += params[last_param + 1];
+
+ Anope::string realreason;
+ if (Config->GetModule("operserv")->Get<bool>("addakiller") && !source.GetNick().empty())
+ realreason = "[" + source.GetNick() + "] " + reason;
+ else
+ realreason = reason;
+
+ Channel *c = Channel::Find(channel);
+ if (!c)
+ {
+ source.Reply(_("Channel \002{0}\002 doesn't exist."), channel);
+ return;
+ }
+
+ for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it)
+ {
+ ChanUserContainer *uc = it->second;
+
+ if (uc->user->server == Me || uc->user->HasMode("OPER"))
+ continue;
+
+ XLine *x = new XLine("*@" + uc->user->host, source.GetNick(), expires, realreason, XLineManager::GenerateUID());
+ akills->AddXLine(x);
+ akills->OnMatch(uc->user, x);
+ }
+
+ Log(LOG_ADMIN, source, this) << "on " << c->name << " (" << realreason << ")";
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Adds an auto kill for every user on \037channel\037, except for IRC operators."));
+ return true;
+ }
+};
+
+class OSChanKill : public Module
+{
+ CommandOSChanKill commandoschankill;
+
+ public:
+ OSChanKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandoschankill(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSChanKill)
diff --git a/modules/operserv/config.cpp b/modules/operserv/config.cpp
new file mode 100644
index 000000000..257f8fee4
--- /dev/null
+++ b/modules/operserv/config.cpp
@@ -0,0 +1,147 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSConfig : public Command
+{
+ public:
+ CommandOSConfig(Module *creator) : Command(creator, "operserv/config", 1, 4)
+ {
+ this->SetDesc(_("View and change configuration file settings"));
+ this->SetSyntax(_("{\037MODIFY\037|\037VIEW\037} [\037block name\037 \037item name\037 \037item value\037]"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &what = params[0];
+
+ if (what.equals_ci("MODIFY") && params.size() > 3)
+ {
+ if (!source.HasPriv("operserv/config"))
+ {
+ source.Reply(_("Access denied. You do not have the operator privilege \002{0}\002."), "operserv/config");
+ return;
+ }
+
+ Configuration::Block *block = Config->GetBlock(params[1]);
+ if (!block)
+ block = Config->GetModule(params[1]);
+
+ if (!block)
+ {
+ source.Reply(_("There is no such configuration block \002{0}\002."), params[1]);
+ return;
+ }
+
+ block->Set(params[2], params[3]);
+
+ Log(LOG_ADMIN, source, this) << "to change the configuration value of " << params[1] << ":" << params[2] << " to " << params[3];
+ source.Reply(_("Value of \002{0}:{1}\002 changed to \002{2}\002."), params[1], params[2], params[3]);
+ }
+ else if (what.equals_ci("VIEW"))
+ {
+ /* Blocks we should show */
+ const Anope::string show_blocks[] = { "serverinfo", "networkinfo", "options", "" };
+
+ Log(LOG_ADMIN, source, this) << "VIEW";
+
+ for (unsigned i = 0; !show_blocks[i].empty(); ++i)
+ {
+ Configuration::Block *block = Config->GetBlock(show_blocks[i]);
+ const Configuration::Block::item_map *items = block->GetItems();
+
+ if (!items)
+ continue;
+
+ ListFormatter lflist(source.GetAccount());
+ lflist.AddColumn(_("Name")).AddColumn(_("Value"));
+
+ for (Configuration::Block::item_map::const_iterator it = items->begin(), it_end = items->end(); it != it_end; ++it)
+ {
+ ListFormatter::ListEntry entry;
+ entry["Name"] = it->first;
+ entry["Value"] = it->second;
+ lflist.AddEntry(entry);
+ }
+
+ std::vector<Anope::string> replies;
+ lflist.Process(replies);
+
+ source.Reply(_("%s settings:"), block->GetName());
+
+ for (unsigned j = 0; j < replies.size(); ++j)
+ source.Reply(replies[j]);
+
+ source.Reply(" ");
+ }
+
+ ListFormatter lflist(source.GetAccount());
+ lflist.AddColumn(_("Module Name")).AddColumn(_("Name")).AddColumn(_("Value"));
+
+ for (int i = 0; i < Config->CountBlock("module"); ++i)
+ {
+ Configuration::Block *block = Config->GetBlock("module", i);
+ const Configuration::Block::item_map *items = block->GetItems();
+
+ if (!items || items->size() <= 1)
+ continue;
+
+ ListFormatter::ListEntry entry;
+ entry["Module Name"] = block->Get<Anope::string>("name");
+
+ for (Configuration::Block::item_map::const_iterator it = items->begin(), it_end = items->end(); it != it_end; ++it)
+ {
+ entry["Name"] = it->first;
+ entry["Value"] = it->second;
+ lflist.AddEntry(entry);
+ }
+ }
+
+ std::vector<Anope::string> replies;
+ lflist.Process(replies);
+
+ source.Reply(_("Module settings:"));
+
+ for (unsigned j = 0; j < replies.size(); ++j)
+ source.Reply(replies[j]);
+
+ source.Reply(_("End of configuration."));
+ }
+ else
+ this->OnSyntaxError(source, what);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Allows you to change and view configuration settings. Settings changed by this command are temporary and will not be reflected back into the configuration file, and will be lost if Anope is shut down, restarted, or the configuration is reloaded.\n"
+ "Use of the \002MODIFY\002 command requires the \002{0}\002 operator privilege.\n"
+ "\n"
+ "Example:\n"
+ " {0} MODIFY nickserv forcemail no"
+ " Changes the \"forceemail\" setting of the module configuration for \"nickserv\" to \"no\""));
+ return true;
+ }
+};
+
+class OSConfig : public Module
+{
+ CommandOSConfig commandosconfig;
+
+ public:
+ OSConfig(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosconfig(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSConfig)
diff --git a/modules/operserv/defcon.cpp b/modules/operserv/defcon.cpp
new file mode 100644
index 000000000..804b66c27
--- /dev/null
+++ b/modules/operserv/defcon.cpp
@@ -0,0 +1,619 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+#include "modules/os_session.h"
+#include "modules/os_defcon.h"
+#include "modules/global.h"
+
+enum DefconLevel
+{
+ DEFCON_NO_NEW_CHANNELS,
+ DEFCON_NO_NEW_NICKS,
+ DEFCON_NO_MLOCK_CHANGE,
+ DEFCON_FORCE_CHAN_MODES,
+ DEFCON_REDUCE_SESSION,
+ DEFCON_NO_NEW_CLIENTS,
+ DEFCON_OPER_ONLY,
+ DEFCON_SILENT_OPER_ONLY,
+ DEFCON_AKILL_NEW_CLIENTS,
+ DEFCON_NO_NEW_MEMOS
+};
+
+bool DefConModesSet = false;
+
+struct DefconConfig
+{
+ std::vector<std::bitset<32> > DefCon;
+ std::set<Anope::string> DefConModesOn, DefConModesOff;
+ std::map<Anope::string, Anope::string> DefConModesOnParams;
+
+ int defaultlevel, sessionlimit;
+ Anope::string chanmodes, message, offmessage, akillreason;
+ std::vector<Anope::string> defcons;
+ time_t akillexpire, timeout;
+ bool globalondefcon;
+
+ unsigned max_session_kill;
+ time_t session_autokill_expiry;
+ Anope::string sle_reason, sle_detailsloc;
+
+ DefconConfig()
+ {
+ this->DefCon.resize(6);
+ this->defcons.resize(5);
+ }
+
+ bool Check(DefconLevel level)
+ {
+ return this->Check(this->defaultlevel, level);
+ }
+
+ bool Check(int dlevel, DefconLevel level)
+ {
+ return this->DefCon[dlevel].test(level);
+ }
+
+ void Add(int dlevel, DefconLevel level)
+ {
+ this->DefCon[dlevel][level] = true;
+ }
+
+ void Del(int dlevel, DefconLevel level)
+ {
+ this->DefCon[dlevel][level] = false;
+ }
+
+ bool SetDefConParam(const Anope::string &name, const Anope::string &buf)
+ {
+ return DefConModesOnParams.insert(std::make_pair(name, buf)).second;
+ }
+
+ void UnsetDefConParam(const Anope::string &name)
+ {
+ DefConModesOnParams.erase(name);
+ }
+
+ bool GetDefConParam(const Anope::string &name, Anope::string &buf)
+ {
+ std::map<Anope::string, Anope::string>::iterator it = DefConModesOnParams.find(name);
+
+ buf.clear();
+
+ if (it != DefConModesOnParams.end())
+ {
+ buf = it->second;
+ return true;
+ }
+
+ return false;
+ }
+};
+
+static DefconConfig DConfig;
+
+static void runDefCon();
+static Anope::string defconReverseModes(const Anope::string &modes);
+
+static Timer *timeout;
+
+class DefConTimeout : public Timer
+{
+ EventHandlers<Event::DefconLevel> &eventdefcon;
+ int level;
+
+ public:
+ DefConTimeout(EventHandlers<Event::DefconLevel> &ev, Module *mod, int newlevel) : Timer(mod, DConfig.timeout), eventdefcon(ev), level(newlevel)
+ {
+ timeout = this;
+ }
+
+ ~DefConTimeout()
+ {
+ timeout = NULL;
+ }
+
+ void Tick(time_t) override
+ {
+ if (DConfig.defaultlevel != level)
+ {
+ DConfig.defaultlevel = level;
+ this->eventdefcon(&Event::DefconLevel::OnDefconLevel, level);
+ Log(Config->GetClient("OperServ"), "operserv/defcon") << "Defcon level timeout, returning to level " << level;
+
+ if (DConfig.globalondefcon && Global::service)
+ {
+ if (!DConfig.offmessage.empty())
+ Global::service->SendGlobal(NULL, "", DConfig.offmessage);
+ else
+ Global::service->SendGlobal(NULL, "", Anope::printf(Language::Translate(_("The Defcon level is now at: \002%d\002")), DConfig.defaultlevel));
+
+ if (!DConfig.message.empty())
+ Global::service->SendGlobal(NULL, "", DConfig.message);
+ }
+
+ runDefCon();
+ }
+ }
+};
+
+class CommandOSDefcon : public Command
+{
+ void SendLevels(CommandSource &source)
+ {
+ if (DConfig.Check(DEFCON_NO_NEW_CHANNELS))
+ source.Reply(_("* No new channel registrations"));
+ if (DConfig.Check(DEFCON_NO_NEW_NICKS))
+ source.Reply(_("* No new nick registrations"));
+ if (DConfig.Check(DEFCON_NO_MLOCK_CHANGE))
+ source.Reply(_("* No mode lock changes"));
+ if (DConfig.Check(DEFCON_FORCE_CHAN_MODES) && !DConfig.chanmodes.empty())
+ source.Reply(_("* Force channel modes (\002{0}\002) to be set on all channels"), DConfig.chanmodes);
+ if (DConfig.Check(DEFCON_REDUCE_SESSION))
+ source.Reply(_("* Use the reduced session limit of \002{0}\002"), DConfig.sessionlimit);
+ if (DConfig.Check(DEFCON_NO_NEW_CLIENTS))
+ source.Reply(_("* Kill any new clients connecting"));
+ if (DConfig.Check(DEFCON_OPER_ONLY))
+ source.Reply(_("* Ignore non-opers with a message"));
+ if (DConfig.Check(DEFCON_SILENT_OPER_ONLY))
+ source.Reply(_("* Silently ignore non-opers"));
+ if (DConfig.Check(DEFCON_AKILL_NEW_CLIENTS))
+ source.Reply(_("* AKILL any new clients connecting"));
+ if (DConfig.Check(DEFCON_NO_NEW_MEMOS))
+ source.Reply(_("* No new memos sent"));
+ }
+
+ EventHandlers<Event::DefconLevel> &ondefconlevel;
+
+ public:
+ CommandOSDefcon(Module *creator, EventHandlers<Event::DefconLevel> &event) : Command(creator, "operserv/defcon", 1, 1), ondefconlevel(event)
+ {
+ this->SetDesc(_("Manipulate the DefCon system"));
+ this->SetSyntax(_("[\0021\002|\0022\002|\0023\002|\0024\002|\0025\002]"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &lvl = params[0];
+
+ if (lvl.empty())
+ {
+ source.Reply(_("Services are now at defcon \002{0}\002."), DConfig.defaultlevel);
+ this->SendLevels(source);
+ return;
+ }
+
+ int newLevel = 0;
+ try
+ {
+ newLevel = convertTo<int>(lvl);
+ }
+ catch (const ConvertException &) { }
+
+ if (newLevel < 1 || newLevel > 5)
+ {
+ this->OnSyntaxError(source, "");
+ return;
+ }
+
+ DConfig.defaultlevel = newLevel;
+
+ this->ondefconlevel(&Event::DefconLevel::OnDefconLevel, newLevel);
+
+ delete timeout;
+
+ if (DConfig.timeout)
+ timeout = new DefConTimeout(this->ondefconlevel, this->module, 5);
+
+ source.Reply(_("Services are now at defcon \002{0}\002."), DConfig.defaultlevel);
+ this->SendLevels(source);
+ Log(LOG_ADMIN, source, this) << "to change defcon level to " << newLevel;
+
+ /* Global notice the user what is happening. Also any Message that
+ the Admin would like to add. Set in config file. */
+ if (DConfig.globalondefcon && Global::service)
+ {
+ if (DConfig.defaultlevel == 5 && !DConfig.offmessage.empty())
+ Global::service->SendGlobal(NULL, "", DConfig.offmessage);
+ else if (DConfig.defaultlevel != 5)
+ {
+ Global::service->SendGlobal(NULL, "", Anope::printf(_("The defcon level is now at \002%d\002"), DConfig.defaultlevel));
+ if (!DConfig.message.empty())
+ Global::service->SendGlobal(NULL, "", DConfig.message);
+ }
+ }
+
+ /* Run any defcon functions, e.g. FORCE CHAN MODE */
+ runDefCon();
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("The defcon system can be used to implement a pre-defined set of restrictions to services useful during an attempted attack on the network."));
+ // XXX actually explain what this does
+ return true;
+ }
+};
+
+class OSDefcon : public Module
+ , public EventHook<Event::ChannelModeSet>
+ , public EventHook<Event::ChannelModeUnset>
+ , public EventHook<Event::PreCommand>
+ , public EventHook<Event::UserConnect>
+ , public EventHook<Event::ChannelModeAdd>
+ , public EventHook<Event::ChannelSync>
+{
+ ServiceReference<SessionService> session_service;
+ ServiceReference<XLineManager> akills;
+ CommandOSDefcon commandosdefcon;
+ EventHandlers<Event::DefconLevel> ondefconlevel;
+
+ void ParseModeString()
+ {
+ int add = -1; /* 1 if adding, 0 if deleting, -1 if neither */
+ unsigned char mode;
+ ChannelMode *cm;
+ ChannelModeParam *cmp;
+ Anope::string modes, param;
+
+ spacesepstream ss(DConfig.chanmodes);
+
+ DConfig.DefConModesOn.clear();
+ DConfig.DefConModesOff.clear();
+ ss.GetToken(modes);
+
+ /* Loop while there are modes to set */
+ for (unsigned i = 0, end = modes.length(); i < end; ++i)
+ {
+ mode = modes[i];
+
+ switch (mode)
+ {
+ case '+':
+ add = 1;
+ continue;
+ case '-':
+ add = 0;
+ continue;
+ default:
+ if (add < 0)
+ continue;
+ }
+
+ if ((cm = ModeManager::FindChannelModeByChar(mode)))
+ {
+ if (cm->type == MODE_STATUS || cm->type == MODE_LIST)
+ {
+ Log(this) << "DefConChanModes mode character '" << mode << "' cannot be locked";
+ continue;
+ }
+ else if (add)
+ {
+ DConfig.DefConModesOn.insert(cm->name);
+ DConfig.DefConModesOff.erase(cm->name);
+
+ if (cm->type == MODE_PARAM)
+ {
+ cmp = anope_dynamic_static_cast<ChannelModeParam *>(cm);
+
+ if (!ss.GetToken(param))
+ {
+ Log(this) << "DefConChanModes mode character '" << mode << "' has no parameter while one is expected";
+ continue;
+ }
+
+ if (!cmp->IsValid(param))
+ continue;
+
+ DConfig.SetDefConParam(cmp->name, param);
+ }
+ }
+ else if (DConfig.DefConModesOn.count(cm->name))
+ {
+ DConfig.DefConModesOn.erase(cm->name);
+
+ if (cm->type == MODE_PARAM)
+ DConfig.UnsetDefConParam(cm->name);
+ }
+ }
+ }
+
+ /* We can't mlock +L if +l is not mlocked as well. */
+ if ((cm = ModeManager::FindChannelModeByName("REDIRECT")) && DConfig.DefConModesOn.count(cm->name) && !DConfig.DefConModesOn.count("LIMIT"))
+ {
+ DConfig.DefConModesOn.erase("REDIRECT");
+
+ Log(this) << "DefConChanModes must lock mode +l as well to lock mode +L";
+ }
+ }
+
+ public:
+ OSDefcon(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , session_service("SessionService", "session")
+ , akills("XLineManager", "xlinemanager/sgline")
+ , commandosdefcon(this, ondefconlevel)
+ , ondefconlevel(this)
+ {
+
+ }
+
+ ~OSDefcon()
+ {
+ delete timeout;
+ }
+
+ void OnReload(Configuration::Conf *conf) override
+ {
+ Configuration::Block *block = conf->GetModule(this);
+ DefconConfig dconfig;
+
+ dconfig.defaultlevel = block->Get<int>("defaultlevel");
+ dconfig.defcons[4] = block->Get<Anope::string>("level4");
+ dconfig.defcons[3] = block->Get<Anope::string>("level3");
+ dconfig.defcons[2] = block->Get<Anope::string>("level2");
+ dconfig.defcons[1] = block->Get<Anope::string>("level1");
+ dconfig.sessionlimit = block->Get<int>("sessionlimit");
+ dconfig.akillreason = block->Get<Anope::string>("akillreason");
+ dconfig.akillexpire = block->Get<time_t>("akillexpire");
+ dconfig.chanmodes = block->Get<Anope::string>("chanmodes");
+ dconfig.timeout = block->Get<time_t>("timeout");
+ dconfig.globalondefcon = block->Get<bool>("globalondefcon");
+ dconfig.message = block->Get<Anope::string>("message");
+ dconfig.offmessage = block->Get<Anope::string>("offmessage");
+
+ Module *session = ModuleManager::FindModule("os_session");
+ block = conf->GetModule(session);
+
+ dconfig.max_session_kill = block->Get<int>("maxsessionkill");
+ dconfig.session_autokill_expiry = block->Get<time_t>("sessionautokillexpiry");
+ dconfig.sle_reason = block->Get<Anope::string>("sessionlimitexceeded");
+ dconfig.sle_detailsloc = block->Get<Anope::string>("sessionlimitdetailsloc");
+
+ if (dconfig.defaultlevel < 1 || dconfig.defaultlevel > 5)
+ throw ConfigException("The value for <defcon:defaultlevel> must be between 1 and 5");
+ else if (dconfig.akillexpire <= 0)
+ throw ConfigException("The value for <defcon:akillexpire> must be greater than zero!");
+
+ for (unsigned level = 1; level < 5; ++level)
+ {
+ spacesepstream operations(dconfig.defcons[level]);
+ Anope::string operation;
+ while (operations.GetToken(operation))
+ {
+ if (operation.equals_ci("nonewchannels"))
+ dconfig.Add(level, DEFCON_NO_NEW_CHANNELS);
+ else if (operation.equals_ci("nonewnicks"))
+ dconfig.Add(level, DEFCON_NO_NEW_NICKS);
+ else if (operation.equals_ci("nomlockchanges"))
+ dconfig.Add(level, DEFCON_NO_MLOCK_CHANGE);
+ else if (operation.equals_ci("forcechanmodes"))
+ dconfig.Add(level, DEFCON_FORCE_CHAN_MODES);
+ else if (operation.equals_ci("reducedsessions"))
+ dconfig.Add(level, DEFCON_REDUCE_SESSION);
+ else if (operation.equals_ci("nonewclients"))
+ dconfig.Add(level, DEFCON_NO_NEW_CLIENTS);
+ else if (operation.equals_ci("operonly"))
+ dconfig.Add(level, DEFCON_OPER_ONLY);
+ else if (operation.equals_ci("silentoperonly"))
+ dconfig.Add(level, DEFCON_SILENT_OPER_ONLY);
+ else if (operation.equals_ci("akillnewclients"))
+ dconfig.Add(level, DEFCON_AKILL_NEW_CLIENTS);
+ else if (operation.equals_ci("nonewmemos"))
+ dconfig.Add(level, DEFCON_NO_NEW_MEMOS);
+ }
+
+ if (dconfig.Check(level, DEFCON_REDUCE_SESSION) && dconfig.sessionlimit <= 0)
+ throw ConfigException("The value for <defcon:sessionlimit> must be greater than zero!");
+ else if (dconfig.Check(level, DEFCON_AKILL_NEW_CLIENTS) && dconfig.akillreason.empty())
+ throw ConfigException("The value for <defcon:akillreason> must not be empty!");
+ else if (dconfig.Check(level, DEFCON_FORCE_CHAN_MODES) && dconfig.chanmodes.empty())
+ throw ConfigException("The value for <defcon:chanmodes> must not be empty!");
+ }
+
+ DConfig = dconfig;
+ this->ParseModeString();
+ }
+
+ EventReturn OnChannelModeSet(Channel *c, const MessageSource &source, ChannelMode *mode, const Anope::string &param) override
+ {
+ if (DConfig.Check(DEFCON_FORCE_CHAN_MODES) && DConfig.DefConModesOff.count(mode->name) && source.GetUser() && !source.GetBot())
+ {
+ c->RemoveMode(Config->GetClient("OperServ"), mode, param);
+
+ return EVENT_STOP;
+ }
+
+ return EVENT_CONTINUE;
+ }
+
+ EventReturn OnChannelModeUnset(Channel *c, const MessageSource &source, ChannelMode *mode, const Anope::string &) override
+ {
+ if (DConfig.Check(DEFCON_FORCE_CHAN_MODES) && DConfig.DefConModesOn.count(mode->name) && source.GetUser() && !source.GetBot())
+ {
+ Anope::string param;
+
+ if (DConfig.GetDefConParam(mode->name, param))
+ c->SetMode(Config->GetClient("OperServ"), mode, param);
+ else
+ c->SetMode(Config->GetClient("OperServ"), mode);
+
+ return EVENT_STOP;
+
+ }
+
+ return EVENT_CONTINUE;
+ }
+
+ EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) override
+ {
+ if (DConfig.Check(DEFCON_OPER_ONLY) && !source.IsOper())
+ {
+ source.Reply(_("Services are in DefCon mode, please try again later."));
+ return EVENT_STOP;
+ }
+ else if (DConfig.Check(DEFCON_SILENT_OPER_ONLY) && !source.IsOper())
+ {
+ return EVENT_STOP;
+ }
+ else if (command->name == "nickserv/register" || command->name == "nickserv/group")
+ {
+ if (DConfig.Check(DEFCON_NO_NEW_NICKS))
+ {
+ source.Reply(_("Services are in defcon mode, please try again later."));
+ return EVENT_STOP;
+ }
+ }
+ else if (command->name == "chanserv/mode" && params.size() > 1 && params[1].equals_ci("LOCK"))
+ {
+ if (DConfig.Check(DEFCON_NO_MLOCK_CHANGE))
+ {
+ source.Reply(_("Services are in defcon mode, please try again later."));
+ return EVENT_STOP;
+ }
+ }
+ else if (command->name == "chanserv/register")
+ {
+ if (DConfig.Check(DEFCON_NO_NEW_CHANNELS))
+ {
+ source.Reply(_("Services are in defcon mode, please try again later."));
+ return EVENT_STOP;
+ }
+ }
+ else if (command->name == "memoserv/send")
+ {
+ if (DConfig.Check(DEFCON_NO_NEW_MEMOS))
+ {
+ source.Reply(_("Services are in defcon mode, please try again later."));
+ return EVENT_STOP;
+ }
+ }
+
+ return EVENT_CONTINUE;
+ }
+
+ void OnUserConnect(User *u, bool &exempt) override
+ {
+ if (exempt || u->Quitting() || !u->server->IsSynced() || u->server->IsULined())
+ return;
+
+ ServiceBot *OperServ = Config->GetClient("OperServ");
+ if (DConfig.Check(DEFCON_AKILL_NEW_CLIENTS) && akills)
+ {
+ Log(OperServ, "operserv/defcon") << "DEFCON: adding akill for *@" << u->host;
+ XLine x("*@" + u->host, OperServ ? OperServ->nick : "defcon", Anope::CurTime + DConfig.akillexpire, DConfig.akillreason, XLineManager::GenerateUID());
+ akills->Send(NULL, &x);
+ }
+
+ if (DConfig.Check(DEFCON_NO_NEW_CLIENTS) || DConfig.Check(DEFCON_AKILL_NEW_CLIENTS))
+ {
+ u->Kill(OperServ, DConfig.akillreason);
+ return;
+ }
+
+ if (DConfig.sessionlimit <= 0 || !session_service)
+ return;
+
+ Session *session = session_service->FindSession(u->ip.addr());
+ Exception *e = session_service->FindException(u);
+
+ if (DConfig.Check(DEFCON_REDUCE_SESSION) && !e)
+ {
+ if (session && session->count > static_cast<unsigned>(DConfig.sessionlimit))
+ {
+ if (!DConfig.sle_reason.empty())
+ {
+ Anope::string message = DConfig.sle_reason.replace_all_cs("%IP%", u->ip.addr());
+ u->SendMessage(OperServ, message);
+ }
+ if (!DConfig.sle_detailsloc.empty())
+ u->SendMessage(OperServ, DConfig.sle_detailsloc);
+
+ ++session->hits;
+ if (akills && DConfig.max_session_kill && session->hits >= DConfig.max_session_kill)
+ {
+ XLine x("*@" + session->addr.mask(), OperServ ? OperServ->nick : "", Anope::CurTime + DConfig.session_autokill_expiry, "Defcon session limit exceeded", XLineManager::GenerateUID());
+ akills->Send(NULL, &x);
+ Log(OperServ, "akill/defcon") << "[DEFCON] Added a temporary AKILL for \002*@" << session->addr.mask() << "\002 due to excessive connections";
+ }
+ else
+ {
+ u->Kill(OperServ, "Defcon session limit exceeded");
+ }
+ }
+ }
+ }
+
+ void OnChannelModeAdd(ChannelMode *cm) override
+ {
+ if (DConfig.chanmodes.find(cm->mchar) != Anope::string::npos)
+ this->ParseModeString();
+ }
+
+ void OnChannelSync(Channel *c) override
+ {
+ if (DConfig.Check(DEFCON_FORCE_CHAN_MODES))
+ c->SetModes(Config->GetClient("OperServ"), false, "%s", DConfig.chanmodes.c_str());
+ }
+};
+
+static void runDefCon()
+{
+ ServiceBot *OperServ = Config->GetClient("OperServ");
+ if (DConfig.Check(DEFCON_FORCE_CHAN_MODES))
+ {
+ if (!DConfig.chanmodes.empty() && !DefConModesSet)
+ {
+ if (DConfig.chanmodes[0] == '+' || DConfig.chanmodes[0] == '-')
+ {
+ Log(OperServ, "operserv/defcon") << "DEFCON: setting " << DConfig.chanmodes << " on all channels";
+ DefConModesSet = true;
+ for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
+ it->second->SetModes(OperServ, false, "%s", DConfig.chanmodes.c_str());
+ }
+ }
+ }
+ else
+ {
+ if (!DConfig.chanmodes.empty() && DefConModesSet)
+ {
+ if (DConfig.chanmodes[0] == '+' || DConfig.chanmodes[0] == '-')
+ {
+ DefConModesSet = false;
+ Anope::string newmodes = defconReverseModes(DConfig.chanmodes);
+ if (!newmodes.empty())
+ {
+ Log(OperServ, "operserv/defcon") << "DEFCON: setting " << newmodes << " on all channels";
+ for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
+ it->second->SetModes(OperServ, true, "%s", newmodes.c_str());
+ }
+ }
+ }
+ }
+}
+
+static Anope::string defconReverseModes(const Anope::string &modes)
+{
+ if (modes.empty())
+ return "";
+ Anope::string newmodes;
+ for (unsigned i = 0, end = modes.length(); i < end; ++i)
+ {
+ if (modes[i] == '+')
+ newmodes += '-';
+ else if (modes[i] == '-')
+ newmodes += '+';
+ else
+ newmodes += modes[i];
+ }
+ return newmodes;
+}
+
+MODULE_INIT(OSDefcon)
diff --git a/modules/operserv/dns.cpp b/modules/operserv/dns.cpp
new file mode 100644
index 000000000..a231a1e74
--- /dev/null
+++ b/modules/operserv/dns.cpp
@@ -0,0 +1,1012 @@
+/*
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "module.h"
+#include "modules/dns.h"
+#include "modules/os_dns.h"
+
+static std::map<Anope::string, std::list<time_t> > server_quit_times;
+
+class DNSZoneImpl : public DNSZone
+{
+ public:
+ DNSZoneImpl(Serialize::TypeBase *type) : DNSZone(type) { }
+ DNSZoneImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSZone(type, id) { }
+
+ Anope::string GetName() override;
+ void SetName(const Anope::string &) override;
+
+ static DNSZone *Find(const Anope::string &name)
+ {
+ for (DNSZone *zone : Serialize::GetObjects<DNSZone *>(dnszone))
+ if (zone->GetName().equals_ci(name))
+ return zone;
+ return nullptr;
+ }
+};
+
+class DNSZoneType : public Serialize::Type<DNSZoneImpl>
+{
+ public:
+ Serialize::Field<DNSZoneImpl, Anope::string> name;
+
+ DNSZoneType(Module *creator) : Serialize::Type<DNSZoneImpl>(creator, "DNSZone")
+ , name(this, "name")
+ {
+ }
+};
+
+Anope::string DNSZoneImpl::GetName()
+{
+ return Get(&DNSZoneType::name);
+}
+
+void DNSZoneImpl::SetName(const Anope::string &name)
+{
+ Set(&DNSZoneType::name, name);
+}
+
+class DNSServerImpl : public DNSServer
+{
+ /* is actually in the pool */
+ bool active = false;
+
+ public:
+ std::set<Anope::string, ci::less> zones;
+ time_t repool = 0;
+
+ DNSServerImpl(Serialize::TypeBase *type) : DNSServer(type) { }
+ DNSServerImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSServer(type, id) { }
+
+ DNSZone *GetZone() override;
+ void SetZone(DNSZone *) override;
+
+ Anope::string GetName() override;
+ void SetName(const Anope::string &) override;
+
+ unsigned int GetLimit() override;
+ void SetLimit(const unsigned int &) override;
+
+ bool GetPooled() override;
+ void SetPool(const bool &) override;
+
+ bool Active()
+ {
+ return GetPooled() && active;
+ }
+
+ void SetActive(bool p)
+ {
+ if (p)
+ this->SetPool(p);
+ active = p;
+
+ if (DNS::manager)
+ {
+ DNS::manager->UpdateSerial();
+ for (std::set<Anope::string, ci::less>::iterator it = zones.begin(), it_end = zones.end(); it != it_end; ++it)
+ DNS::manager->Notify(*it);
+ }
+ }
+
+ static DNSServerImpl *Find(const Anope::string &s)
+ {
+ for (DNSServerImpl *server : Serialize::GetObjects<DNSServerImpl *>(dnsserver))
+ if (server->GetName().equals_ci(s))
+ return server;
+ return nullptr;
+ }
+};
+
+class DNSServerType : public Serialize::Type<DNSServerImpl>
+{
+ public:
+ Serialize::ObjectField<DNSServerImpl, DNSZone *> zone;
+ Serialize::Field<DNSServerImpl, Anope::string> name;
+ Serialize::Field<DNSServerImpl, unsigned int> limit;
+ Serialize::Field<DNSServerImpl, bool> pooled;
+
+ DNSServerType(Module *creator) : Serialize::Type<DNSServerImpl>(creator, "DNSServer")
+ , zone(this, "zone")
+ , name(this, "name")
+ , limit(this, "limit")
+ , pooled(this, "pooled")
+ {
+ }
+};
+
+DNSZone *DNSServerImpl::GetZone()
+{
+ return Get(&DNSServerType::zone);
+}
+
+void DNSServerImpl::SetZone(DNSZone *z)
+{
+ Set(&DNSServerType::zone, z);
+}
+
+Anope::string DNSServerImpl::GetName()
+{
+ return Get(&DNSServerType::name);
+}
+
+void DNSServerImpl::SetName(const Anope::string &n)
+{
+ Set(&DNSServerType::name, n);
+}
+
+unsigned int DNSServerImpl::GetLimit()
+{
+ return Get(&DNSServerType::limit);
+}
+
+void DNSServerImpl::SetLimit(const unsigned int &l)
+{
+ Set(&DNSServerType::limit, l);
+}
+
+bool DNSServerImpl::GetPooled()
+{
+ return Get(&DNSServerType::pooled);
+}
+
+void DNSServerImpl::SetPool(const bool &p)
+{
+ Set(&DNSServerType::pooled, p);
+}
+
+class DNSZoneMembershipImpl : public DNSZoneMembership
+{
+ public:
+ DNSZoneMembershipImpl(Serialize::TypeBase *type) : DNSZoneMembership(type) { }
+ DNSZoneMembershipImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSZoneMembership(type, id) { }
+
+ DNSServer *GetServer() override;
+ void SetServer(DNSServer *) override;
+
+ DNSZone *GetZone() override;
+ void SetZone(DNSZone *) override;
+
+ static DNSZoneMembership *Find(DNSServer *server, DNSZone *zone)
+ {
+ for (DNSZoneMembership *mem : Serialize::GetObjects<DNSZoneMembership *>(dnszonemembership))
+ if (mem->GetServer() == server && mem->GetZone() == zone)
+ return mem;
+ return nullptr;
+ }
+};
+
+class DNSZoneMembershipType : public Serialize::Type<DNSZoneMembershipImpl>
+{
+ public:
+ Serialize::ObjectField<DNSZoneMembershipImpl, DNSServer *> server;
+ Serialize::ObjectField<DNSZoneMembershipImpl, DNSZone *> zone;
+
+ DNSZoneMembershipType(Module *creator) : Serialize::Type<DNSZoneMembershipImpl>(creator, "DNSZoneMembership")
+ , server(this, "server")
+ , zone(this, "zone")
+ {
+ }
+};
+
+DNSServer *DNSZoneMembershipImpl::GetServer()
+{
+ return Get(&DNSZoneMembershipType::server);
+}
+
+void DNSZoneMembershipImpl::SetServer(DNSServer *s)
+{
+ Set(&DNSZoneMembershipType::server, s);
+}
+
+DNSZone *DNSZoneMembershipImpl::GetZone()
+{
+ return Get(&DNSZoneMembershipType::zone);
+}
+
+void DNSZoneMembershipImpl::SetZone(DNSZone *z)
+{
+ Set(&DNSZoneMembershipType::zone, z);
+}
+
+class DNSIPImpl : public DNSIP
+{
+ public:
+ DNSIPImpl(Serialize::TypeBase *type) : DNSIP(type) { }
+ DNSIPImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSIP(type, id) { }
+
+ DNSServer *GetServer() override;
+ void SetServer(DNSServer *) override;
+
+ Anope::string GetIP() override;
+ void SetIP(const Anope::string &) override;
+};
+
+class DNSIPType : public Serialize::Type<DNSIPImpl>
+{
+ public:
+ Serialize::ObjectField<DNSServerImpl, DNSServer *> server;
+ Serialize::Field<DNSServerImpl, Anope::string> ip;
+
+ DNSIPType(Module *creator) : Serialize::Type<DNSIPImpl>(creator, "DNSIP")
+ , server(this, "server")
+ , ip(this, "ip")
+ {
+ }
+};
+
+DNSServer *DNSIPImpl::GetServer()
+{
+ return Get(&DNSIPType::server);
+}
+
+void DNSIPImpl::SetServer(DNSServer *s)
+{
+ Set(&DNSIPType::server, s);
+}
+
+Anope::string DNSIPImpl::GetIP()
+{
+ return Get(&DNSIPType::ip);
+}
+
+void DNSIPImpl::SetIP(const Anope::string &ip)
+{
+ Set(&DNSIPType::ip, ip);
+}
+
+class CommandOSDNS : public Command
+{
+ void DisplayPoolState(CommandSource &source)
+ {
+ std::vector<DNSServerImpl *> servers = Serialize::GetObjects<DNSServerImpl *>(dnsserver);
+
+ if (servers.empty())
+ {
+ source.Reply(_("There are no configured servers."));
+ return;
+ }
+
+ ListFormatter lf(source.GetAccount());
+ lf.AddColumn(_("Server")).AddColumn(_("IP")).AddColumn(_("Limit")).AddColumn(_("State"));
+ for (DNSServerImpl *s : servers)
+ {
+ Server *srv = Server::Find(s->GetName(), true);
+
+ ListFormatter::ListEntry entry;
+ entry["Server"] = s->GetName();
+ entry["Limit"] = s->GetLimit() ? stringify(s->GetLimit()) : Language::Translate(source.GetAccount(), _("None"));
+
+ Anope::string ip_str;
+ for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ ip_str += ip->GetIP() + " ";
+ ip_str.trim();
+ if (ip_str.empty())
+ ip_str = "None";
+ entry["IP"] = ip_str;
+
+ if (s->Active())
+ entry["State"] = Language::Translate(source.GetAccount(), _("Pooled/Active"));
+ else if (s->GetPooled())
+ entry["State"] = Language::Translate(source.GetAccount(), _("Pooled/Not Active"));
+ else
+ entry["State"] = Language::Translate(source.GetAccount(), _("Unpooled"));
+
+ if (!srv)
+ entry["State"] += Anope::string(" ") + Language::Translate(source.GetAccount(), _("(Split)"));
+
+ lf.AddEntry(entry);
+ }
+
+ std::vector<Anope::string> replies;
+ lf.Process(replies);
+
+ std::vector<DNSZone *> zones = Serialize::GetObjects<DNSZone *>(dnszone);
+ if (!zones.empty())
+ {
+ ListFormatter lf2(source.GetAccount());
+ lf2.AddColumn(_("Zone")).AddColumn(_("Servers"));
+
+ for (DNSZone *z : zones)
+ {
+ ListFormatter::ListEntry entry;
+ entry["Zone"] = z->GetName();
+
+ Anope::string server_str;
+ for (DNSServer *s : z->GetRefs<DNSServer *>(dnsserver))
+ server_str += s->GetName() + " ";
+ server_str.trim();
+
+ if (server_str.empty())
+ server_str = "None";
+
+ entry["Servers"] = server_str;
+
+ lf2.AddEntry(entry);
+ }
+
+ lf2.Process(replies);
+ }
+
+ for (const Anope::string &r : replies)
+ source.Reply(r);
+ }
+
+ void AddZone(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string &zone = params[1];
+
+ if (DNSZoneImpl::Find(zone))
+ {
+ source.Reply(_("Zone \002{0}\002 already exists."), zone);
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ Log(LOG_ADMIN, source, this) << "to add zone " << zone;
+
+ DNSZone *z = dnszone.Create();
+ z->SetName(zone);
+ source.Reply(_("Added zone \002{0}\002."), zone);
+ }
+
+ void DelZone(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string &zone = params[1];
+
+ DNSZone *z = DNSZoneImpl::Find(zone);
+ if (!z)
+ {
+ source.Reply(_("Zone \002{0}\002 does not exist."), zone);
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ Log(LOG_ADMIN, source, this) << "to delete zone " << z->GetName();
+
+ for (DNSZoneMembership *mem : z->GetRefs<DNSZoneMembership *>(dnszonemembership))
+ mem->Delete();
+
+ if (DNS::manager)
+ {
+ DNS::manager->UpdateSerial();
+ DNS::manager->Notify(z->GetName());
+ }
+
+ source.Reply(_("Zone \002{0}\002 removed."), z->GetName());
+ z->Delete();
+ }
+
+ void AddServer(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ DNSServer *s = DNSServerImpl::Find(params[1]);
+ const Anope::string &zone = params.size() > 2 ? params[2] : "";
+
+ if (s)
+ {
+ if (zone.empty())
+ {
+ source.Reply(_("Server \002{0}\002 already exists."), s->GetName());
+ }
+ else
+ {
+ DNSZone *z = DNSZoneImpl::Find(zone);
+ if (!z)
+ {
+ source.Reply(_("Zone \002{0}\002 does not exist."), zone);
+ return;
+ }
+
+ DNSZoneMembership *mem = DNSZoneMembershipImpl::Find(s, z);
+ if (mem)
+ {
+ source.Reply(_("Server \002{0}\002 is already in zone \002{1}\002."), s->GetName(), z->GetName());
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ mem = dnszonemembership.Create();
+ mem->SetZone(z);
+ mem->SetServer(s);
+
+ if (DNS::manager)
+ {
+ DNS::manager->UpdateSerial();
+ DNS::manager->Notify(zone);
+ }
+
+ Log(LOG_ADMIN, source, this) << "to add server " << s->GetName() << " to zone " << z->GetName();
+
+ source.Reply(_("Server \002{0}\002 added to zone \002{1}\002."), s->GetName(), z->GetName());
+ }
+
+ return;
+ }
+
+ Server *serv = Server::Find(params[1], true);
+ if (!serv || serv == Me || serv->IsJuped())
+ {
+ source.Reply(_("Server \002{0}\002 is not linked to the network."), params[1]);
+ return;
+ }
+
+ s = dnsserver.Create();
+ s->SetName(params[1]);
+ if (zone.empty())
+ {
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ Log(LOG_ADMIN, source, this) << "to add server " << s->GetName();
+ source.Reply(_("Added server \002{0}\002."), s->GetName());
+ }
+ else
+ {
+ DNSZone *z = DNSZoneImpl::Find(zone);
+ if (!z)
+ {
+ source.Reply(_("Zone \002{0}\002 does not exist."), zone);
+ s->Delete();
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ Log(LOG_ADMIN, source, this) << "to add server " << s->GetName() << " to zone " << zone;
+
+ DNSZoneMembership *mem = dnszonemembership.Create();
+ mem->SetServer(s);
+ mem->SetZone(z);
+
+ if (DNS::manager)
+ {
+ DNS::manager->UpdateSerial();
+ DNS::manager->Notify(z->GetName());
+ }
+ }
+ }
+
+ void DelServer(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ DNSServer *s = DNSServerImpl::Find(params[1]);
+ const Anope::string &zone = params.size() > 2 ? params[2] : "";
+
+ if (!s)
+ {
+ source.Reply(_("Server \002{0}\002 does not exist."), params[1]);
+ return;
+ }
+
+ if (!zone.empty())
+ {
+ DNSZone *z = DNSZoneImpl::Find(zone);
+ if (!z)
+ {
+ source.Reply(_("Zone \002{0}\002 does not exist."), zone);
+ return;
+ }
+
+ DNSZoneMembership *mem = DNSZoneMembershipImpl::Find(s, z);
+ if (!mem)
+ {
+ source.Reply(_("Server \002{0}\002 is not in zone \002{1}\002."), s->GetName(), z->GetName());
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ Log(LOG_ADMIN, source, this) << "to remove server " << s->GetName() << " from zone " << z->GetName();
+
+ if (DNS::manager)
+ {
+ DNS::manager->UpdateSerial();
+ DNS::manager->Notify(z->GetName());
+ }
+
+ mem->Delete();
+ source.Reply(_("Removed server \002{0}\002 from zone \002{1}\002."), s->GetName(), z->GetName());
+ return;
+ }
+
+ if (Server::Find(s->GetName(), true))
+ {
+ source.Reply(_("Server \002{0}\002 must be quit before it can be deleted."), s->GetName());
+ return;
+ }
+
+ for (DNSZoneMembership *mem : s->GetRefs<DNSZoneMembership *>(dnszonemembership))
+ mem->Delete();
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ if (DNS::manager)
+ DNS::manager->UpdateSerial();
+
+ Log(LOG_ADMIN, source, this) << "to delete server " << s->GetName();
+ source.Reply(_("Removed server \002{0}\002."), s->GetName());
+ s->Delete();
+ }
+
+ void AddIP(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ DNSServerImpl *s = DNSServerImpl::Find(params[1]);
+
+ if (!s)
+ {
+ source.Reply(_("Server \002{0}\002 does not exist."), params[1]);
+ return;
+ }
+
+ for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ if (params[2].equals_ci(ip->GetIP()))
+ {
+ source.Reply(_("IP \002{0}\002 already exists for \002{1}\002."), ip->GetIP(), s->GetName());
+ return;
+ }
+
+ sockaddrs addr(params[2]);
+ if (!addr.valid())
+ {
+ source.Reply(_("\002{0}\002 is not a valid IP address."), params[2]);
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ DNSIP *ip = dnsip.Create();
+ ip->SetServer(s);
+ ip->SetIP(params[2]);
+
+ source.Reply(_("Added IP \002{0}\002 to \002{1}\002."), params[2], s->GetName());
+ Log(LOG_ADMIN, source, this) << "to add IP " << params[2] << " to " << s->GetName();
+
+ if (s->Active() && DNS::manager)
+ {
+ DNS::manager->UpdateSerial();
+ for (DNSZone *zone : s->GetRefs<DNSZone *>(dnszone))
+ DNS::manager->Notify(zone->GetName());
+ }
+ }
+
+ void DelIP(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ DNSServerImpl *s = DNSServerImpl::Find(params[1]);
+
+ if (!s)
+ {
+ source.Reply(_("Server \002{0}\002 does not exist."), params[1]);
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ if (params[2].equals_ci(ip->GetIP()))
+ {
+ ip->Delete();
+
+ source.Reply(_("Removed IP \002{0}\002 from \002{1}\002."), params[2], s->GetName());
+ Log(LOG_ADMIN, source, this) << "to remove IP " << params[2] << " from " << s->GetName();
+
+ if (s->GetRefs<DNSIP *>(dnsip).empty())
+ {
+ s->repool = 0;
+ s->SetPool(false);
+ }
+
+ if (s->Active() && DNS::manager)
+ {
+ DNS::manager->UpdateSerial();
+ for (DNSZone *zone : s->GetRefs<DNSZone *>(dnszone))
+ DNS::manager->Notify(zone->GetName());
+ }
+
+ return;
+ }
+
+ source.Reply(_("IP \002{0}\002 does not exist for \002{1}\002."), params[2], s->GetName());
+ }
+
+ void OnSet(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ DNSServer *s = DNSServerImpl::Find(params[1]);
+
+ if (!s)
+ {
+ source.Reply(_("Server \002{0}\002 does not exist."), params[1]);
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ if (params[2].equals_ci("LIMIT"))
+ {
+ try
+ {
+ unsigned l = convertTo<unsigned>(params[3]);
+ s->SetLimit(l);
+ if (l)
+ source.Reply(_("User limit for \002{0}\002 set to \002{1}\002."), s->GetName(), l);
+ else
+ source.Reply(_("User limit for \002{0}\002 removed."), s->GetName());
+ }
+ catch (const ConvertException &ex)
+ {
+ source.Reply(_("Invalid value for limit. Must be numerical."));
+ }
+ }
+ else
+ source.Reply(_("Unknown SET option."));
+ }
+
+ void OnPool(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ DNSServerImpl *s = DNSServerImpl::Find(params[1]);
+
+ if (!s)
+ {
+ source.Reply(_("Server \002{0}\002 does not exist."), params[1]);
+ return;
+ }
+
+ if (!Server::Find(s->GetName(), true))
+ {
+ source.Reply(_("Server \002{0}\002 is not currently linked."), s->GetName());
+ return;
+ }
+
+ if (s->GetPooled())
+ {
+ source.Reply(_("Server \002{0}\002 is already pooled."), s->GetName());
+ return;
+ }
+
+ if (s->GetRefs<DNSIP *>(dnsip).empty())
+ {
+ source.Reply(_("Server \002{0}\002 has no configured IPs."), s->GetName());
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ s->SetActive(true);
+
+ source.Reply(_("Pooled \002{0}\002."), s->GetName());
+ Log(LOG_ADMIN, source, this) << "to pool " << s->GetName();
+ }
+
+
+ void OnDepool(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ DNSServer *s = DNSServerImpl::Find(params[1]);
+
+ if (!s)
+ {
+ source.Reply(_("Server \002{0}\002 does not exist."), params[1]);
+ return;
+ }
+
+ if (!s->GetPooled())
+ {
+ source.Reply(_("Server \002{0}\002 is not pooled."), s->GetName());
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ s->SetPool(false);
+
+ source.Reply(_("Depooled \002{0}\002."), s->GetName());
+ Log(LOG_ADMIN, source, this) << "to depool " << s->GetName();
+ }
+
+ public:
+ CommandOSDNS(Module *creator) : Command(creator, "operserv/dns", 0, 4)
+ {
+ this->SetDesc(_("Manage DNS zones for this network"));
+ this->SetSyntax(_("ADDZONE \037zone.name\037"));
+ this->SetSyntax(_("DELZONE \037zone.name\037"));
+ this->SetSyntax(_("ADDSERVER \037server.name\037 [\037zone.name\037]"));
+ this->SetSyntax(_("DELSERVER \037server.name\037 [\037zone.name\037]"));
+ this->SetSyntax(_("ADDIP \037server.name\037 \037ip\037"));
+ this->SetSyntax(_("DELIP \037server.name\037 \037ip\037"));
+ this->SetSyntax(_("SET \037server.name\037 \037option\037 \037value\037"));
+ this->SetSyntax(_("POOL \037server.name\037"));
+ this->SetSyntax(_("DEPOOL \037server.name\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ if (params.empty())
+ this->DisplayPoolState(source);
+ else if (params[0].equals_ci("ADDZONE") && params.size() > 1)
+ this->AddZone(source, params);
+ else if (params[0].equals_ci("DELZONE") && params.size() > 1)
+ this->DelZone(source, params);
+ else if (params[0].equals_ci("ADDSERVER") && params.size() > 1)
+ this->AddServer(source, params);
+ else if (params[0].equals_ci("DELSERVER") && params.size() > 1)
+ this->DelServer(source, params);
+ else if (params[0].equals_ci("ADDIP") && params.size() > 2)
+ this->AddIP(source, params);
+ else if (params[0].equals_ci("DELIP") && params.size() > 2)
+ this->DelIP(source, params);
+ else if (params[0].equals_ci("SET") && params.size() > 3)
+ this->OnSet(source, params);
+ else if (params[0].equals_ci("POOL") && params.size() > 1)
+ this->OnPool(source, params);
+ else if (params[0].equals_ci("DEPOOL") && params.size() > 1)
+ this->OnDepool(source, params);
+ else
+ this->OnSyntaxError(source, "");
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("This command allows managing DNS zones used for controlling what servers users are directed to when connecting."
+ " Omitting all parameters prints out the status of the DNS zone.\n"
+ "\n"
+ "\002{0} ADDZONE\002 adds a zone, eg. us.example.com. Servers can then be added to this zone with the \002ADDSERVER\002 command.\n"
+ "\n"
+ "The \002{0} ADDSERVER\002 command adds a server to the given zone."
+ " When a DNS query is done, the zone in question is served if it exists, otherwise all servers in all zones are served."
+ " A server may be in more than one zone.\n"
+ "\n"
+ "The \002{0} ADDIP\002 command associates an IP with a server.\n"
+ " \n"
+ "The \002{0} POOL\002 and \002{0} DEPOOL\002 commands actually add and remove servers to their given zones."),
+ source.command);
+ return true;
+ }
+};
+
+class ModuleDNS : public Module
+ , public EventHook<Event::NewServer>
+ , public EventHook<Event::ServerQuit>
+ , public EventHook<Event::UserConnect>
+ , public EventHook<Event::PreUserLogoff>
+ , public EventHook<Event::DnsRequest>
+{
+ DNSZoneType zonetype;
+ DNSServerType servertype;
+ DNSZoneMembershipType zonemembtype;
+ DNSIPType iptype;
+ CommandOSDNS commandosdns;
+
+ time_t ttl;
+ int user_drop_mark;
+ time_t user_drop_time;
+ time_t user_drop_readd_time;
+ bool remove_split_servers;
+ bool readd_connected_servers;
+
+ time_t last_warn;
+
+ public:
+ ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
+ , zonetype(this)
+ , servertype(this)
+ , zonemembtype(this)
+ , iptype(this)
+ , commandosdns(this)
+ , last_warn(0)
+ {
+#if 0
+ for (unsigned j = 0; j < dns_servers->size(); ++j)
+ {
+ DNSServer *s = dns_servers->at(j);
+ if (s->Pooled() && Server::Find(s->GetName(), true))
+ s->SetActive(true);
+ }
+#endif
+ }
+
+ ~ModuleDNS()
+ {
+ }
+
+ void OnReload(Configuration::Conf *conf) override
+ {
+ Configuration::Block *block = conf->GetModule(this);
+ this->ttl = block->Get<time_t>("ttl");
+ this->user_drop_mark = block->Get<int>("user_drop_mark");
+ this->user_drop_time = block->Get<time_t>("user_drop_time");
+ this->user_drop_readd_time = block->Get<time_t>("user_drop_readd_time");
+ this->remove_split_servers = block->Get<bool>("remove_split_servers");
+ this->readd_connected_servers = block->Get<bool>("readd_connected_servers");
+ }
+
+ void OnNewServer(Server *s) override
+ {
+ if (s == Me || s->IsJuped())
+ return;
+ if (!Me->IsSynced() || this->readd_connected_servers)
+ {
+ DNSServerImpl *dns = DNSServerImpl::Find(s->GetName());
+ if (dns && dns->GetPooled() && !dns->Active() && !dns->GetRefs<DNSIP *>(dnsip).empty())
+ {
+ dns->SetActive(true);
+ Log(this) << "Pooling server " << s->GetName();
+ }
+ }
+ }
+
+ void OnServerQuit(Server *s) override
+ {
+ DNSServerImpl *dns = DNSServerImpl::Find(s->GetName());
+ if (remove_split_servers && dns && dns->GetPooled() && dns->Active())
+ {
+ if (readd_connected_servers)
+ dns->SetActive(false); // Will be reactivated when it comes back
+ else
+ dns->SetPool(false); // Otherwise permanently pull this
+ Log(this) << "Depooling delinked server " << s->GetName();
+ }
+ }
+
+ void OnUserConnect(User *u, bool &exempt) override
+ {
+ if (!u->Quitting() && u->server)
+ {
+ DNSServerImpl *s = DNSServerImpl::Find(u->server->GetName());
+ /* Check for user limit reached */
+ if (s && s->GetPooled() && s->Active() && s->GetLimit() && u->server->users >= s->GetLimit())
+ {
+ Log(this) << "Depooling full server " << s->GetName() << ": " << u->server->users << " users";
+ s->SetActive(false);
+ }
+ }
+ }
+
+ void OnPreUserLogoff(User *u) override
+ {
+ if (u && u->server)
+ {
+ DNSServerImpl *s = DNSServerImpl::Find(u->server->GetName());
+ if (!s || !s->GetPooled())
+ return;
+
+ /* Check for dropping under userlimit */
+ if (s->GetLimit() && !s->Active() && s->GetLimit() > u->server->users)
+ {
+ Log(this) << "Pooling server " << s->GetName();
+ s->SetActive(true);
+ }
+
+ if (this->user_drop_mark > 0)
+ {
+ std::list<time_t>& times = server_quit_times[u->server->GetName()];
+ times.push_back(Anope::CurTime);
+ if (times.size() > static_cast<unsigned>(this->user_drop_mark))
+ times.pop_front();
+
+ if (times.size() == static_cast<unsigned>(this->user_drop_mark))
+ {
+ time_t diff = Anope::CurTime - *times.begin();
+
+ /* Check for very fast user drops */
+ if (s->Active() && diff <= this->user_drop_time)
+ {
+ Log(this) << "Depooling server " << s->GetName() << ": dropped " << this->user_drop_mark << " users in " << diff << " seconds";
+ s->repool = Anope::CurTime + this->user_drop_readd_time;
+ s->SetActive(false);
+ }
+ /* Check for needing to re-pool a server that dropped users */
+ else if (!s->Active() && s->repool && s->repool <= Anope::CurTime)
+ {
+ s->SetActive(true);
+ s->repool = 0;
+ Log(this) << "Pooling server " << s->GetName();
+ }
+ }
+ }
+ }
+ }
+
+ void OnDnsRequest(DNS::Query &req, DNS::Query *packet) override
+ {
+ if (req.questions.empty())
+ return;
+ /* Currently we reply to any QR for A/AAAA */
+ const DNS::Question& q = req.questions[0];
+ if (q.type != DNS::QUERY_A && q.type != DNS::QUERY_AAAA && q.type != DNS::QUERY_AXFR && q.type != DNS::QUERY_ANY)
+ return;
+
+ DNSZone *zone = DNSZoneImpl::Find(q.name);
+ size_t answer_size = packet->answers.size();
+ if (zone)
+ {
+ for (DNSServerImpl *s : zone->GetRefs<DNSServerImpl *>(dnsserver))
+ {
+ if (!s->Active())
+ continue;
+
+ for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ {
+ DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
+
+ if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type)
+ {
+ DNS::ResourceRecord rr(q.name, q_type);
+ rr.ttl = this->ttl;
+ rr.rdata = ip->GetIP();
+ packet->answers.push_back(rr);
+ }
+ }
+ }
+ }
+
+ if (packet->answers.size() == answer_size)
+ {
+ /* Default zone */
+ for (DNSServerImpl *s : Serialize::GetObjects<DNSServerImpl *>(dnsserver))
+ {
+ if (!s->Active())
+ continue;
+
+ for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ {
+ DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
+
+ if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type)
+ {
+ DNS::ResourceRecord rr(q.name, q_type);
+ rr.ttl = this->ttl;
+ rr.rdata = ip->GetIP();
+ packet->answers.push_back(rr);
+ }
+ }
+ }
+ }
+
+ if (packet->answers.size() == answer_size)
+ {
+ if (last_warn + 60 < Anope::CurTime)
+ {
+ last_warn = Anope::CurTime;
+ Log(this) << "Warning! There are no pooled servers!";
+ }
+
+ /* Something messed up, just return them all and hope one is available */
+ for (DNSServer *s : Serialize::GetObjects<DNSServer *>(dnsserver))
+ for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ {
+ DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
+
+ if (q.type == DNS::QUERY_AXFR || q.type == DNS::QUERY_ANY || q_type == q.type)
+ {
+ DNS::ResourceRecord rr(q.name, q_type);
+ rr.ttl = this->ttl;
+ rr.rdata = ip->GetIP();
+ packet->answers.push_back(rr);
+ }
+ }
+
+ if (packet->answers.size() == answer_size)
+ {
+ Log(this) << "Error! There are no servers with any IPs of type " << q.type;
+ /* Send back an empty answer anyway */
+ }
+ }
+ }
+};
+
+MODULE_INIT(ModuleDNS)
diff --git a/modules/operserv/forbid.cpp b/modules/operserv/forbid.cpp
new file mode 100644
index 000000000..0a7b1c209
--- /dev/null
+++ b/modules/operserv/forbid.cpp
@@ -0,0 +1,577 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+#include "modules/os_forbid.h"
+#include "modules/nickserv.h"
+#include "modules/chanserv.h"
+
+class ForbidDataImpl : public ForbidData
+{
+ public:
+ ForbidDataImpl(Serialize::TypeBase *type) : ForbidData(type) { }
+ ForbidDataImpl(Serialize::TypeBase *type, Serialize::ID id) : ForbidData(type, id) { }
+
+ Anope::string GetMask() override;
+ void SetMask(const Anope::string &) override;
+
+ Anope::string GetCreator() override;
+ void SetCreator(const Anope::string &) override;
+
+ Anope::string GetReason() override;
+ void SetReason(const Anope::string &) override;
+
+ time_t GetCreated() override;
+ void SetCreated(const time_t &) override;
+
+ time_t GetExpires() override;
+ void SetExpires(const time_t &) override;
+
+ ForbidType GetType() override;
+ void SetType(const ForbidType &) override;
+};
+
+class ForbidDataType : public Serialize::Type<ForbidDataImpl>
+{
+ public:
+ Serialize::Field<ForbidDataImpl, Anope::string> mask, creator, reason;
+ Serialize::Field<ForbidDataImpl, time_t> created, expires;
+ Serialize::Field<ForbidDataImpl, ForbidType> type;
+
+ ForbidDataType(Module *me) : Serialize::Type<ForbidDataImpl>(me, "ForbidData")
+ , mask(this, "mask")
+ , creator(this, "creator")
+ , reason(this, "reason")
+ , created(this, "created")
+ , expires(this, "expires")
+ , type(this, "type")
+ {
+ }
+};
+
+Anope::string ForbidDataImpl::GetMask()
+{
+ return Get(&ForbidDataType::mask);
+}
+
+void ForbidDataImpl::SetMask(const Anope::string &m)
+{
+ Set(&ForbidDataType::mask, m);
+}
+
+Anope::string ForbidDataImpl::GetCreator()
+{
+ return Get(&ForbidDataType::creator);
+}
+
+void ForbidDataImpl::SetCreator(const Anope::string &c)
+{
+ Set(&ForbidDataType::creator, c);
+}
+
+Anope::string ForbidDataImpl::GetReason()
+{
+ return Get(&ForbidDataType::reason);
+}
+
+void ForbidDataImpl::SetReason(const Anope::string &r)
+{
+ Set(&ForbidDataType::reason, r);
+}
+
+time_t ForbidDataImpl::GetCreated()
+{
+ return Get(&ForbidDataType::created);
+}
+
+void ForbidDataImpl::SetCreated(const time_t &t)
+{
+ Set(&ForbidDataType::created, t);
+}
+
+time_t ForbidDataImpl::GetExpires()
+{
+ return Get(&ForbidDataType::expires);
+}
+
+void ForbidDataImpl::SetExpires(const time_t &t)
+{
+ Set(&ForbidDataType::expires, t);
+}
+
+ForbidType ForbidDataImpl::GetType()
+{
+ return Get(&ForbidDataType::type);
+}
+
+void ForbidDataImpl::SetType(const ForbidType &t)
+{
+ Set(&ForbidDataType::type, t);
+}
+
+class MyForbidService : public ForbidService
+{
+ public:
+ MyForbidService(Module *m) : ForbidService(m)
+ {
+ }
+
+ ForbidData *FindForbid(const Anope::string &mask, ForbidType ftype) override
+ {
+ for (ForbidData *d : GetForbids())
+ if (d->GetType() == ftype && Anope::Match(mask, d->GetMask(), false, true))
+ return d;
+ return NULL;
+ }
+
+ std::vector<ForbidData *> GetForbids() override
+ {
+ for (ForbidData *d : Serialize::GetObjects<ForbidData *>(forbiddata))
+ if (d->GetExpires() && !Anope::NoExpire && Anope::CurTime >= d->GetExpires())
+ {
+ Anope::string ftype = "none";
+ if (d->GetType() == FT_NICK)
+ ftype = "nick";
+ else if (d->GetType() == FT_CHAN)
+ ftype = "chan";
+ else if (d->GetType() == FT_EMAIL)
+ ftype = "email";
+
+ Log(LOG_NORMAL, "expire/forbid", Config->GetClient("OperServ")) << "Expiring forbid for " << d->GetMask() << " type " << ftype;
+ d->Delete();
+ }
+ return Serialize::GetObjects<ForbidData *>(forbiddata);
+ }
+};
+
+class CommandOSForbid : public Command
+{
+ ServiceReference<ForbidService> fs;
+ public:
+ CommandOSForbid(Module *creator) : Command(creator, "operserv/forbid", 1, 5), fs("ForbidService", "forbid")
+ {
+ this->SetDesc(_("Forbid usage of nicknames, channels, and emails"));
+ this->SetSyntax(_("ADD {NICK|CHAN|EMAIL|REGISTER} [+\037expiry\037] \037entry\037 \037reason\037"));
+ this->SetSyntax(_("DEL {NICK|CHAN|EMAIL|REGISTER} \037entry\037"));
+ this->SetSyntax("LIST [NICK|CHAN|EMAIL|REGISTER]");
+ }
+
+ void OnUserNickChange(User *u)
+ {
+ if (u->HasMode("OPER"))
+ return;
+
+ ForbidData *d = fs->FindForbid(u->nick, FT_NICK);
+ if (d != NULL)
+ {
+ ServiceBot *bi = Config->GetClient("NickServ");
+ if (!bi)
+ bi = Config->GetClient("OperServ");
+ if (bi)
+ u->SendMessage(bi, _("This nickname has been forbidden: \002{0}\002"), d->GetReason());
+ if (NickServ::service)
+ NickServ::service->Collide(u, NULL);
+ }
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ if (!this->fs)
+ return;
+
+ const Anope::string &command = params[0];
+ const Anope::string &subcommand = params.size() > 1 ? params[1] : "";
+
+ ForbidType ftype = FT_SIZE;
+ if (subcommand.equals_ci("NICK"))
+ ftype = FT_NICK;
+ else if (subcommand.equals_ci("CHAN"))
+ ftype = FT_CHAN;
+ else if (subcommand.equals_ci("EMAIL"))
+ ftype = FT_EMAIL;
+ else if (subcommand.equals_ci("REGISTER"))
+ ftype = FT_REGISTER;
+
+ if (command.equals_ci("ADD") && params.size() > 3 && ftype != FT_SIZE)
+ {
+ const Anope::string &expiry = params[2][0] == '+' ? params[2] : "";
+ const Anope::string &entry = !expiry.empty() ? params[3] : params[2];
+ Anope::string reason;
+ if (expiry.empty())
+ reason = params[3] + " ";
+ if (params.size() > 4)
+ reason += params[4];
+ reason.trim();
+
+ if (entry.replace_all_cs("?*", "").empty())
+ {
+ source.Reply(_("The mask must contain at least one non wildcard character."));
+ return;
+ }
+
+ time_t expiryt = 0;
+
+ if (!expiry.empty())
+ {
+ expiryt = Anope::DoTime(expiry);
+ if (expiryt == -1)
+ {
+ source.Reply(_("Invalid expiry time \002{0}\002."), expiry);
+ return;
+ }
+ else if (expiryt)
+ expiryt += Anope::CurTime;
+ }
+
+ NickServ::Nick *target = NickServ::FindNick(entry);
+ if (target != NULL && Config->GetModule("nickserv")->Get<bool>("secureadmins", "yes") && target->GetAccount()->IsServicesOper())
+ {
+ source.Reply(_("Access denied."));
+ return;
+ }
+
+ ForbidData *d = this->fs->FindForbid(entry, ftype);
+ bool created = false;
+ if (d == NULL)
+ {
+ d = forbiddata.Create();
+ created = true;
+ }
+
+ d->SetMask(entry);
+ d->SetCreator(source.GetNick());
+ d->SetReason(reason);
+ d->SetCreated(Anope::CurTime);
+ d->SetExpires(expiryt);
+ d->SetType(ftype);
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ Log(LOG_ADMIN, source, this) << "to add a forbid on " << entry << " of type " << subcommand;
+ source.Reply(_("Added a forbid on \002{0}\002 of type \002{1}\002 to expire on \002{2}\002."), entry, subcommand.lower(), expiryt ? Anope::strftime(expiryt, source.GetAccount()) : "never");
+
+ /* apply forbid */
+ switch (ftype)
+ {
+ case FT_NICK:
+ {
+ int na_matches = 0;
+
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ this->OnUserNickChange(it->second);
+
+ for (auto it = NickServ::service->GetNickList().begin(); it != NickServ::service->GetNickList().end();)
+ {
+ NickServ::Nick *na = *it;
+ ++it;
+
+ d = this->fs->FindForbid(na->GetNick(), FT_NICK);
+ if (d == NULL)
+ continue;
+
+ ++na_matches;
+
+ delete na;
+ }
+
+ source.Reply(_("\002{0}\002 nickname(s) dropped."), na_matches);
+ break;
+ }
+ case FT_CHAN:
+ {
+ int chan_matches = 0, ci_matches = 0;
+
+ for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end;)
+ {
+ Channel *c = it->second;
+ ++it;
+
+ d = this->fs->FindForbid(c->name, FT_CHAN);
+ if (d == NULL)
+ continue;
+
+ ServiceBot *OperServ = Config->GetClient("OperServ");
+ if (IRCD->CanSQLineChannel && OperServ)
+ {
+ time_t inhabit = Config->GetModule("chanserv")->Get<time_t>("inhabit", "15s");
+ XLine x(c->name, OperServ->nick, Anope::CurTime + inhabit, d->GetReason());
+ IRCD->SendSQLine(NULL, &x);
+ }
+ else if (ChanServ::service)
+ {
+ ChanServ::service->Hold(c);
+ }
+
+ ++chan_matches;
+
+ for (Channel::ChanUserList::const_iterator cit = c->users.begin(), cit_end = c->users.end(); cit != cit_end;)
+ {
+ User *u = cit->first;
+ ++cit;
+
+ if (u->server == Me || u->HasMode("OPER"))
+ continue;
+
+ reason = Anope::printf(Language::Translate(u, _("This channel has been forbidden: \002%s\002")), d->GetReason().c_str());
+
+ c->Kick(source.service, u, "%s", reason.c_str());
+ }
+ }
+
+ for (auto it = ChanServ::service->GetChannels().begin(); it != ChanServ::service->GetChannels().end();)
+ {
+ ChanServ::Channel *ci = it->second;
+ ++it;
+
+ d = this->fs->FindForbid(ci->GetName(), FT_CHAN);
+ if (d == NULL)
+ continue;
+
+ ++ci_matches;
+
+ delete ci;
+ }
+
+ source.Reply(_("\002{0}\002 channel(s) cleared, and \002{1}\002 channel(s) dropped."), chan_matches, ci_matches);
+
+ break;
+ }
+ default:
+ break;
+ }
+
+ }
+ else if (command.equals_ci("DEL") && params.size() > 2 && ftype != FT_SIZE)
+ {
+ const Anope::string &entry = params[2];
+
+ ForbidData *d = this->fs->FindForbid(entry, ftype);
+ if (d == nullptr)
+ {
+ source.Reply(_("Forbid on \002{0}\002 was not found."), entry);
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ Log(LOG_ADMIN, source, this) << "to remove forbid on " << d->GetMask() << " of type " << subcommand;
+ source.Reply(_("\002{0}\002 deleted from the \002{1}\002 forbid list."), d->GetMask(), subcommand);
+ d->Delete();
+ }
+ else if (command.equals_ci("LIST"))
+ {
+ const std::vector<ForbidData *> &forbids = this->fs->GetForbids();
+ if (forbids.empty())
+ {
+ source.Reply(_("Forbid list is empty."));
+ return;
+ }
+
+ ListFormatter list(source.GetAccount());
+ list.AddColumn(_("Mask")).AddColumn(_("Type")).AddColumn(_("Creator")).AddColumn(_("Expires")).AddColumn(_("Reason"));
+
+ unsigned shown = 0;
+ for (unsigned i = 0; i < forbids.size(); ++i)
+ {
+ ForbidData *d = forbids[i];
+
+ if (ftype != FT_SIZE && ftype != d->GetType())
+ continue;
+
+ Anope::string stype;
+ if (d->GetType() == FT_NICK)
+ stype = "NICK";
+ else if (d->GetType() == FT_CHAN)
+ stype = "CHAN";
+ else if (d->GetType() == FT_EMAIL)
+ stype = "EMAIL";
+ else if (d->GetType() == FT_REGISTER)
+ stype = "REGISTER";
+ else
+ continue;
+
+ ListFormatter::ListEntry entry;
+ entry["Mask"] = d->GetMask();
+ entry["Type"] = stype;
+ entry["Creator"] = d->GetCreator();
+ entry["Expires"] = d->GetExpires() ? Anope::strftime(d->GetExpires(), NULL, true).c_str() : Language::Translate(source.GetAccount(), _("Never"));
+ entry["Reason"] = d->GetReason();
+ list.AddEntry(entry);
+ ++shown;
+ }
+
+ if (!shown)
+ {
+ source.Reply(_("There are no forbids of type \002{0}\002."), subcommand.upper());
+ return;
+ }
+
+ source.Reply(_("Forbid list:"));
+
+ std::vector<Anope::string> replies;
+ list.Process(replies);
+
+ for (unsigned i = 0; i < replies.size(); ++i)
+ source.Reply(replies[i]);
+
+ if (shown >= forbids.size())
+ source.Reply(_("End of forbid list."));
+ else
+ source.Reply(_("End of forbid list - \002{0}\002/\002{1}\002 entries shown."), shown, forbids.size());
+ }
+ else
+ this->OnSyntaxError(source, command);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Forbid allows you to forbid usage of certain nicknames, channels, and email addresses. Wildcards are accepted for all entries."));
+
+ const Anope::string &regexengine = Config->GetBlock("options")->Get<Anope::string>("regexengine");
+ if (!regexengine.empty())
+ {
+ source.Reply(" ");
+ source.Reply(_("Regex matches are also supported using the %s engine. Enclose your pattern in // if this is desired."), regexengine);
+ }
+
+ return true;
+ }
+};
+
+class OSForbid : public Module
+ , public EventHook<Event::UserConnect>
+ , public EventHook<Event::UserNickChange>
+ , public EventHook<Event::CheckKick>
+ , public EventHook<Event::PreCommand>
+{
+ MyForbidService forbid_service;
+ ForbidDataType type;
+ CommandOSForbid commandosforbid;
+
+ public:
+ OSForbid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , forbid_service(this)
+ , type(this)
+ , commandosforbid(this)
+ {
+ }
+
+ void OnUserConnect(User *u, bool &exempt) override
+ {
+ if (u->Quitting() || exempt)
+ return;
+
+ commandosforbid.OnUserNickChange(u);
+ }
+
+ void OnUserNickChange(User *u, const Anope::string &) override
+ {
+ commandosforbid.OnUserNickChange(u);
+ }
+
+ EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override
+ {
+ ServiceBot *OperServ = Config->GetClient("OperServ");
+ if (u->HasMode("OPER") || !OperServ)
+ return EVENT_CONTINUE;
+
+ ForbidData *d = this->forbid_service.FindForbid(c->name, FT_CHAN);
+ if (d != NULL)
+ {
+ if (IRCD->CanSQLineChannel)
+ {
+ time_t inhabit = Config->GetModule("chanserv")->Get<time_t>("inhabit", "15s");
+ XLine x(c->name, OperServ->nick, Anope::CurTime + inhabit, d->GetReason());
+ IRCD->SendSQLine(NULL, &x);
+ }
+ else if (ChanServ::service)
+ {
+ ChanServ::service->Hold(c);
+ }
+
+ reason = Anope::printf(Language::Translate(u, _("This channel has been forbidden: %s")), d->GetReason().c_str());
+
+ return EVENT_STOP;
+ }
+
+ return EVENT_CONTINUE;
+ }
+
+ EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> &params) override
+ {
+ if (command->name == "nickserv/info" && params.size() > 0)
+ {
+ ForbidData *d = this->forbid_service.FindForbid(params[0], FT_NICK);
+ if (d != NULL)
+ {
+ if (source.IsOper())
+ source.Reply(_("Nick \002%s\002 is forbidden by %s: %s"), params[0], d->GetCreator(), d->GetReason());
+ else
+ source.Reply(_("Nick \002%s\002 is forbidden."), params[0]);
+ return EVENT_STOP;
+ }
+ }
+ else if (command->name == "chanserv/info" && params.size() > 0)
+ {
+ ForbidData *d = this->forbid_service.FindForbid(params[0], FT_CHAN);
+ if (d != NULL)
+ {
+ if (source.IsOper())
+ source.Reply(_("Channel \002%s\002 is forbidden by %s: %s"), params[0], d->GetCreator(), d->GetReason());
+ else
+ source.Reply(_("Channel \002%s\002 is forbidden."), params[0]);
+ return EVENT_STOP;
+ }
+ }
+ else if (source.IsOper())
+ return EVENT_CONTINUE;
+ else if (command->name == "nickserv/register" && params.size() > 1)
+ {
+ ForbidData *d = this->forbid_service.FindForbid(source.GetNick(), FT_REGISTER);
+ if (d != NULL)
+ {
+ source.Reply(_("\002{0}\002 may not be registered."), source.GetNick());
+ return EVENT_STOP;
+ }
+
+ d = this->forbid_service.FindForbid(params[1], FT_EMAIL);
+ if (d != NULL)
+ {
+ source.Reply(_("Your email address is not allowed, choose a different one."));
+ return EVENT_STOP;
+ }
+ }
+ else if (command->name == "nickserv/set/email" && params.size() > 0)
+ {
+ ForbidData *d = this->forbid_service.FindForbid(params[0], FT_EMAIL);
+ if (d != NULL)
+ {
+ source.Reply(_("Your email address is not allowed, choose a different one."));
+ return EVENT_STOP;
+ }
+ }
+ else if (command->name == "chanserv/register" && !params.empty())
+ {
+ ForbidData *d = this->forbid_service.FindForbid(params[0], FT_REGISTER);
+ if (d != NULL)
+ {
+ source.Reply(_("Channel \002{0}\002 is currently suspended."), params[0]);
+ return EVENT_STOP;
+ }
+ }
+
+ return EVENT_CONTINUE;
+ }
+};
+
+MODULE_INIT(OSForbid)
diff --git a/modules/operserv/ignore.cpp b/modules/operserv/ignore.cpp
new file mode 100644
index 000000000..d9563cc29
--- /dev/null
+++ b/modules/operserv/ignore.cpp
@@ -0,0 +1,393 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+#include "modules/os_ignore.h"
+
+class IgnoreImpl : public Ignore
+{
+ public:
+ IgnoreImpl(Serialize::TypeBase *type) : Ignore(type) { }
+ IgnoreImpl(Serialize::TypeBase *type, Serialize::ID id) : Ignore(type, id) { }
+
+ Anope::string GetMask();
+ void SetMask(const Anope::string &);
+
+ Anope::string GetCreator();
+ void SetCreator(const Anope::string &);
+
+ Anope::string GetReason();
+ void SetReason(const Anope::string &);
+
+ time_t GetTime();
+ void SetTime(const time_t &);
+};
+
+class IgnoreType : public Serialize::Type<IgnoreImpl>
+{
+ public:
+ Serialize::Field<IgnoreImpl, Anope::string> mask, creator, reason;
+ Serialize::Field<IgnoreImpl, time_t> time;
+
+ IgnoreType(Module *me) : Serialize::Type<IgnoreImpl>(me, "IgnoreData")
+ , mask(this, "mask")
+ , creator(this, "creator")
+ , reason(this, "reason")
+ , time(this, "time")
+ {
+ }
+};
+
+Anope::string IgnoreImpl::GetMask()
+{
+ return Get(&IgnoreType::mask);
+}
+
+void IgnoreImpl::SetMask(const Anope::string &m)
+{
+ Set(&IgnoreType::mask, m);
+}
+
+Anope::string IgnoreImpl::GetCreator()
+{
+ return Get(&IgnoreType::creator);
+}
+
+void IgnoreImpl::SetCreator(const Anope::string &c)
+{
+ Set(&IgnoreType::creator, c);
+}
+
+Anope::string IgnoreImpl::GetReason()
+{
+ return Get(&IgnoreType::reason);
+}
+
+void IgnoreImpl::SetReason(const Anope::string &r)
+{
+ Set(&IgnoreType::reason, r);
+}
+
+time_t IgnoreImpl::GetTime()
+{
+ return Get(&IgnoreType::time);
+}
+
+void IgnoreImpl::SetTime(const time_t &t)
+{
+ Set(&IgnoreType::time, t);
+}
+
+class OSIgnoreService : public IgnoreService
+{
+ public:
+ OSIgnoreService(Module *o) : IgnoreService(o)
+ {
+ }
+
+ Ignore *Find(const Anope::string &mask) override
+ {
+ User *u = User::Find(mask, true);
+ std::vector<Ignore *> ignores = Serialize::GetObjects<Ignore *>(ignoretype);
+ std::vector<Ignore *>::iterator ign = ignores.begin(), ign_end = ignores.end();
+
+ if (u)
+ {
+ for (; ign != ign_end; ++ign)
+ {
+ Entry ignore_mask("", (*ign)->GetMask());
+ if (ignore_mask.Matches(u, true))
+ break;
+ }
+ }
+ else
+ {
+ size_t user, host;
+ Anope::string tmp;
+ /* We didn't get a user.. generate a valid mask. */
+ if ((host = mask.find('@')) != Anope::string::npos)
+ {
+ if ((user = mask.find('!')) != Anope::string::npos)
+ {
+ /* this should never happen */
+ if (user > host)
+ return NULL;
+ tmp = mask;
+ }
+ else
+ /* We have user@host. Add nick wildcard. */
+ tmp = "*!" + mask;
+ }
+ /* We only got a nick.. */
+ else
+ tmp = mask + "!*@*";
+
+ for (; ign != ign_end; ++ign)
+ if (Anope::Match(tmp, (*ign)->GetMask(), false, true))
+ break;
+ }
+
+ /* Check whether the entry has timed out */
+ if (ign != ign_end)
+ {
+ Ignore *id = *ign;
+
+ if (id->GetTime() && !Anope::NoExpire && id->GetTime() <= Anope::CurTime)
+ {
+ Log(LOG_NORMAL, "expire/ignore", Config->GetClient("OperServ")) << "Expiring ignore entry " << id->GetMask();
+ id->Delete();
+ }
+ else
+ return id;
+ }
+
+ return NULL;
+ }
+};
+
+class CommandOSIgnore : public Command
+{
+ private:
+ Anope::string RealMask(const Anope::string &mask)
+ {
+ /* If it s an existing user, we ignore the hostmask. */
+ User *u = User::Find(mask, true);
+ if (u)
+ return "*!*@" + u->host;
+
+ size_t host = mask.find('@');
+ /* Determine whether we get a nick or a mask. */
+ if (host != Anope::string::npos)
+ {
+ size_t user = mask.find('!');
+ /* Check whether we have a nick too.. */
+ if (user != Anope::string::npos)
+ {
+ if (user > host)
+ /* this should never happen */
+ return "";
+ else
+ return mask;
+ }
+ else
+ /* We have user@host. Add nick wildcard. */
+ return "*!" + mask;
+ }
+
+ /* We only got a nick.. */
+ return mask + "!*@*";
+ }
+
+ void DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string &time = params.size() > 1 ? params[1] : "";
+ const Anope::string &nick = params.size() > 2 ? params[2] : "";
+ const Anope::string &reason = params.size() > 3 ? params[3] : "";
+
+ if (time.empty() || nick.empty())
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ time_t t = Anope::DoTime(time);
+
+ if (t <= -1)
+ {
+ source.Reply(_("Invalid expiry time \002{0}\002."), time);
+ return;
+ }
+
+ Anope::string mask = RealMask(nick);
+ if (mask.empty())
+ {
+ source.Reply(_("Mask must be in the form \037user\037@\037host\037."));
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ Ignore *ign = ignoretype.Create();
+ ign->SetMask(mask);
+ ign->SetCreator(source.GetNick());
+ ign->SetReason(reason);
+ ign->SetTime(t ? Anope::CurTime + t : 0);
+
+ if (!t)
+ {
+ source.Reply(_("\002{0}\002 will now permanently be ignored."), mask);
+ Log(LOG_ADMIN, source, this) << "to add a permanent ignore for " << mask;
+ }
+ else
+ {
+ source.Reply(_("\002{0}\002 will now be ignored for \002{1}\002."), mask, Anope::Duration(t, source.GetAccount()));
+ Log(LOG_ADMIN, source, this) << "to add an ignore on " << mask << " for " << Anope::Duration(t);
+ }
+ }
+
+ void DoList(CommandSource &source)
+ {
+ std::vector<Ignore *> ignores = Serialize::GetObjects<Ignore *>(ignoretype);
+
+ for (Ignore *id : ignores)
+ {
+ if (id->GetTime() && !Anope::NoExpire && id->GetTime() <= Anope::CurTime)
+ {
+ Log(LOG_NORMAL, "expire/ignore", Config->GetClient("OperServ")) << "Expiring ignore entry " << id->GetMask();
+ id->Delete();
+ }
+ }
+
+ ignores = Serialize::GetObjects<Ignore *>(ignoretype);
+ if (ignores.empty())
+ {
+ source.Reply(_("Ignore list is empty."));
+ return;
+ }
+
+ ListFormatter list(source.GetAccount());
+ list.AddColumn(_("Mask")).AddColumn(_("Creator")).AddColumn(_("Reason")).AddColumn(_("Expires"));
+
+ for (Ignore *ignore : ignores)
+ {
+ ListFormatter::ListEntry entry;
+ entry["Mask"] = ignore->GetMask();
+ entry["Creator"] = ignore->GetCreator();
+ entry["Reason"] = ignore->GetReason();
+ entry["Expires"] = Anope::Expires(ignore->GetTime(), source.GetAccount());
+ list.AddEntry(entry);
+ }
+
+ source.Reply(_("Services ignore list:"));
+
+ std::vector<Anope::string> replies;
+ list.Process(replies);
+
+ for (const Anope::string &r : replies)
+ source.Reply(r);
+ }
+
+ void DoDel(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string nick = params.size() > 1 ? params[1] : "";
+ if (nick.empty())
+ {
+ this->OnSyntaxError(source, "DEL");
+ return;
+ }
+
+ Anope::string mask = RealMask(nick);
+ if (mask.empty())
+ {
+ source.Reply(_("Mask must be in the form \037user\037@\037host\037."));
+ return;
+ }
+
+ Ignore *ign = ignore_service->Find(mask);
+ if (!ign)
+ {
+ source.Reply(_("\002{0}\002 not found on ignore list."), mask);
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ Log(LOG_ADMIN, source, this) << "to remove an ignore on " << mask;
+ source.Reply(_("\002{0}\002 will no longer be ignored."), mask);
+ ign->Delete();
+ }
+
+ void DoClear(CommandSource &source)
+ {
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ for (Ignore *ign : Serialize::GetObjects<Ignore *>(ignoretype))
+ ign->Delete();
+
+ Log(LOG_ADMIN, source, this) << "to CLEAR the list";
+ source.Reply(_("Ignore list has been cleared."));
+ }
+
+ public:
+ CommandOSIgnore(Module *creator) : Command(creator, "operserv/ignore", 1, 4)
+ {
+ this->SetDesc(_("Modify the Services ignore list"));
+ this->SetSyntax(_("ADD \037expiry\037 {\037nick\037|\037mask\037} [\037reason\037]"));
+ this->SetSyntax(_("DEL {\037nick\037|\037mask\037}"));
+ this->SetSyntax("LIST");
+ this->SetSyntax("CLEAR");
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &cmd = params[0];
+
+ if (cmd.equals_ci("ADD"))
+ return this->DoAdd(source, params);
+ else if (cmd.equals_ci("LIST"))
+ return this->DoList(source);
+ else if (cmd.equals_ci("DEL"))
+ return this->DoDel(source, params);
+ else if (cmd.equals_ci("CLEAR"))
+ return this->DoClear(source);
+ else
+ this->OnSyntaxError(source, "");
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("The \002{0}\002 command allows you to make services ignore a user or hostmask."
+ " \037expiry\037 must be an integer and can be followed by one of \037d\037 (days), \037h\037 (hours), or \037m\037 (minutes)."
+ " If a unit specifier is not included, the default is seconds."
+ " To make services permanently ignore the user, use 0 as the expiry time."
+ " When adding a \037mask\037, it should be in the format nick!user@host, everything else will be considered a nicknames. Wildcards are permitted."),
+ source.command);
+
+ const Anope::string &regexengine = Config->GetBlock("options")->Get<Anope::string>("regexengine");
+ if (!regexengine.empty())
+ {
+ source.Reply(" ");
+ source.Reply(_("Regex matches are also supported using the \002{0}\002 engine. Enclose your pattern in // if this is desired."), regexengine);
+ }
+
+ return true;
+ }
+};
+
+class OSIgnore : public Module
+ , public EventHook<Event::BotPrivmsg>
+{
+ IgnoreType ignoretype;
+ OSIgnoreService osignoreservice;
+ CommandOSIgnore commandosignore;
+
+ public:
+ OSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , ignoretype(this)
+ , osignoreservice(this)
+ , commandosignore(this)
+ {
+
+ }
+
+ EventReturn OnBotPrivmsg(User *u, ServiceBot *bi, Anope::string &message) override
+ {
+ if (!u->HasMode("OPER") && this->osignoreservice.Find(u->nick))
+ return EVENT_STOP;
+
+ return EVENT_CONTINUE;
+ }
+};
+
+MODULE_INIT(OSIgnore)
diff --git a/modules/operserv/info.cpp b/modules/operserv/info.cpp
new file mode 100644
index 000000000..7b292d4b2
--- /dev/null
+++ b/modules/operserv/info.cpp
@@ -0,0 +1,260 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ */
+
+#include "module.h"
+#include "modules/ns_info.h"
+#include "modules/cs_info.h"
+#include "modules/os_info.h"
+
+class OperInfoImpl : public OperInfo
+{
+ public:
+ OperInfoImpl(Serialize::TypeBase *type) : OperInfo(type) { }
+ OperInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : OperInfo(type, id) { }
+
+ Serialize::Object *GetTarget();
+ void SetTarget(Serialize::Object *);
+
+ Anope::string GetInfo();
+ void SetInfo(const Anope::string &);
+
+ Anope::string GetCreator();
+ void SetCreator(const Anope::string &);
+
+ time_t GetCreated();
+ void SetCreated(const time_t &);
+};
+
+class OperInfoType : public Serialize::Type<OperInfoImpl>
+{
+ public:
+ Serialize::ObjectField<OperInfoImpl, Serialize::Object *> target;
+ Serialize::Field<OperInfoImpl, Anope::string> info, creator;
+ Serialize::Field<OperInfoImpl, time_t> created;
+
+ OperInfoType(Module *c) : Serialize::Type<OperInfoImpl>(c, "OperInfo")
+ , target(this, "target", true)
+ , info(this, "info")
+ , creator(this, "adder")
+ , created(this, "created")
+ {
+ }
+};
+
+Serialize::Object *OperInfoImpl::GetTarget()
+{
+ return Get(&OperInfoType::target);
+}
+
+void OperInfoImpl::SetTarget(Serialize::Object *t)
+{
+ Set(&OperInfoType::target, t);
+}
+
+Anope::string OperInfoImpl::GetInfo()
+{
+ return Get(&OperInfoType::info);
+}
+
+void OperInfoImpl::SetInfo(const Anope::string &i)
+{
+ Set(&OperInfoType::info, i);
+}
+
+Anope::string OperInfoImpl::GetCreator()
+{
+ return Get(&OperInfoType::creator);
+}
+
+void OperInfoImpl::SetCreator(const Anope::string &c)
+{
+ Set(&OperInfoType::creator, c);
+}
+
+time_t OperInfoImpl::GetCreated()
+{
+ return Get(&OperInfoType::created);
+}
+
+void OperInfoImpl::SetCreated(const time_t &t)
+{
+ Set(&OperInfoType::created, t);
+}
+
+class CommandOSInfo : public Command
+{
+ public:
+ CommandOSInfo(Module *creator) : Command(creator, "operserv/info", 2, 3)
+ {
+ this->SetDesc(_("Associate oper info with a nick or channel"));
+ this->SetSyntax(_("ADD \037target\037 \037info\037"));
+ this->SetSyntax(_("DEL \037target\037 \037info\037"));
+ this->SetSyntax(_("CLEAR \037target\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &cmd = params[0], target = params[1], info = params.size() > 2 ? params[2] : "";
+
+ Serialize::Object *e;
+ if (IRCD->IsChannelValid(target))
+ {
+ ChanServ::Channel *ci = ChanServ::Find(target);
+ if (!ci)
+ {
+ source.Reply(_("Channel \002{0}\002 isn't registered."), target);
+ return;
+ }
+
+ e = ci;
+ }
+ else
+ {
+ NickServ::Nick *na = NickServ::FindNick(target);
+ if (!na)
+ {
+ source.Reply(_("\002{0}\002 isn't registered."), target);
+ return;
+ }
+
+ e = na->GetAccount();
+ }
+
+ if (cmd.equals_ci("ADD"))
+ {
+ if (info.empty())
+ {
+ this->OnSyntaxError(source, cmd);
+ return;
+ }
+
+ std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(operinfo);
+ if (oinfos.size() >= Config->GetModule(this->module)->Get<unsigned int>("max", "10"))
+ {
+ source.Reply(_("The oper info list for \002{0}\002 is full."), target);
+ return;
+ }
+
+ for (OperInfo *o : oinfos)
+ if (o->GetInfo().equals_ci(info))
+ {
+ source.Reply(_("The oper info already exists on \002{0}\002."), target);
+ return;
+ }
+
+ OperInfo *o = operinfo.Create();
+ o->SetTarget(e);
+ o->SetInfo(info);
+ o->SetCreator(source.GetNick());
+ o->SetCreated(Anope::CurTime);
+
+ source.Reply(_("Added info to \002{0}\002."), target);
+ Log(LOG_ADMIN, source, this) << "to add information to " << target;
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ }
+ else if (cmd.equals_ci("DEL"))
+ {
+ if (info.empty())
+ {
+ this->OnSyntaxError(source, cmd);
+ return;
+ }
+
+ std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(operinfo);
+ if (oinfos.empty())
+ {
+ source.Reply(_("Oper info list for \002{0}\002 is empty."), target);
+ return;
+ }
+
+ for (OperInfo *o : oinfos)
+ {
+ if (o->GetInfo().equals_ci(info))
+ {
+ o->Delete();
+
+ source.Reply(_("Deleted info from \002{0}\002."), target);
+ Log(LOG_ADMIN, source, this) << "to remove information from " << target;
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ return;
+ }
+ }
+
+ source.Reply(_("No such info \002{0}\002 on \002{1}\002."), info, target);
+ }
+ else if (cmd.equals_ci("CLEAR"))
+ {
+ std::vector<OperInfo *> oinfos = e->GetRefs<OperInfo *>(operinfo);
+
+ if (oinfos.empty())
+ {
+ source.Reply(_("Oper info list for \002{0}\002 is empty."), target);
+ return;
+ }
+
+ for (OperInfo *o : oinfos)
+ o->Delete();
+
+ source.Reply(_("Cleared info from \002{0}\002."), target);
+ Log(LOG_ADMIN, source, this) << "to clear information for " << target;
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ }
+ else
+ {
+ this->OnSyntaxError(source, cmd);
+ }
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Add or delete oper information for a given accpint or channel. This informaition will show to opers in the respective info command for the account or channel."));
+ return true;
+ }
+};
+
+class OSInfo : public Module
+ , public EventHook<Event::NickInfo>
+ , public EventHook<Event::ChanInfo>
+{
+ CommandOSInfo commandosinfo;
+ OperInfoType oinfotype;
+
+ void OnInfo(CommandSource &source, Serialize::Object *e, InfoFormatter &info)
+ {
+ if (!source.IsOper())
+ return;
+
+ for (OperInfo *o : e->GetRefs<OperInfo *>(operinfo))
+ info[_("Oper Info")] = Anope::printf(_("(by %s on %s) %s"), o->GetCreator().c_str(), Anope::strftime(o->GetCreated(), source.GetAccount(), true).c_str(), o->GetInfo().c_str());
+ }
+
+ public:
+ OSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosinfo(this)
+ , oinfotype(this)
+ {
+ }
+
+ void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) override
+ {
+ OnInfo(source, na->GetAccount(), info);
+ }
+
+ void OnChanInfo(CommandSource &source, ChanServ::Channel *ci, InfoFormatter &info, bool show_hidden) override
+ {
+ OnInfo(source, ci, info);
+ }
+};
+
+MODULE_INIT(OSInfo)
diff --git a/modules/operserv/jupe.cpp b/modules/operserv/jupe.cpp
new file mode 100644
index 000000000..e2dd30b3a
--- /dev/null
+++ b/modules/operserv/jupe.cpp
@@ -0,0 +1,72 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSJupe : public Command
+{
+ public:
+ CommandOSJupe(Module *creator) : Command(creator, "operserv/jupe", 1, 2)
+ {
+ this->SetDesc(_("\"Jupiter\" a server"));
+ this->SetSyntax(_("\037server\037 [\037reason\037]"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &jserver = params[0];
+ const Anope::string &reason = params.size() > 1 ? params[1] : "";
+ Server *server = Server::Find(jserver, true);
+
+ if (!IRCD->IsHostValid(jserver) || jserver.find('.') == Anope::string::npos)
+ source.Reply(_("\002{0}\002 is not a valid server name."), jserver);
+ else if (server == Me || server == Servers::GetUplink() || server->IsULined())
+ source.Reply(_("You can not jupe Servoces or its uplink server."));
+ else if (server && server->IsJuped())
+ source.Reply(_("You can not jupe an already juped server."));
+ else
+ {
+ Anope::string rbuf = "Juped by " + source.GetNick() + (!reason.empty() ? ": " + reason : "");
+ /* Generate the new sid before quitting the old server, so they can't collide */
+ Anope::string sid = IRCD->SID_Retrieve();
+ if (server)
+ {
+ IRCD->SendSquit(server, rbuf);
+ server->Delete(rbuf);
+ }
+ Server *juped_server = new Server(Me, jserver, 1, rbuf, sid, true);
+ IRCD->SendServer(juped_server);
+
+ Log(LOG_ADMIN, source, this) << "on " << jserver << " (" << rbuf << ")";
+ }
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Tells services to jupiter a server -- that is, to create a fake \"server\" connected to Services which prevents the real server of that name from connecting."
+ " The jupe may be removed using a standard \002SQUIT\002. If a reason is given, it is placed in the server information field; otherwise, the server information field will contain the text \"Juped by <nick>\", showing the nickname of the person who jupitered the server."));
+ return true;
+ }
+};
+
+class OSJupe : public Module
+{
+ CommandOSJupe commandosjupe;
+
+ public:
+ OSJupe(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosjupe(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSJupe)
diff --git a/modules/operserv/kick.cpp b/modules/operserv/kick.cpp
new file mode 100644
index 000000000..d97e21602
--- /dev/null
+++ b/modules/operserv/kick.cpp
@@ -0,0 +1,81 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSKick : public Command
+{
+ public:
+ CommandOSKick(Module *creator) : Command(creator, "operserv/kick", 3, 3)
+ {
+ this->SetDesc(_("Kick a user from a channel"));
+ this->SetSyntax(_("\037channel\037 \037user\037 \037reason\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &chan = params[0];
+ const Anope::string &nick = params[1];
+ const Anope::string &s = params[2];
+ Channel *c;
+ User *u2;
+
+ if (!(c = Channel::Find(chan)))
+ {
+ source.Reply(_("Channel \002%s\002 doesn't exist."), chan);
+ return;
+ }
+
+ if (c->bouncy_modes)
+ {
+ source.Reply(_("Services is unable to change modes. Are your servers' U:lines configured correctly?"));
+ return;
+ }
+
+ if (!(u2 = User::Find(nick, true)))
+ {
+ source.Reply(_("\002{0}\002 isn't currently online."), nick);
+ return;
+ }
+
+ if (!c->Kick(source.service, u2, "%s (%s)", source.GetNick().c_str(), s.c_str()))
+ {
+ source.Reply(_("Access denied."));
+ return;
+ }
+
+ Log(LOG_ADMIN, source, this) << "on " << u2->nick << " in " << c->name << " (" << s << ")";
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Allows you to kick a user from any channel. Parameters are the same as for the standard /KICK command."
+ " The kick message will have the nickname of the IRCop sending the KICK command prepended; for example:\n"
+ "\n"
+ "*** SpamMan has been kicked off channel #my_channel by {0} (Alcan (Flood))"),
+ source.service->nick);
+ return true;
+ }
+};
+
+class OSKick : public Module
+{
+ CommandOSKick commandoskick;
+
+ public:
+ OSKick(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandoskick(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSKick)
diff --git a/modules/operserv/kill.cpp b/modules/operserv/kill.cpp
new file mode 100644
index 000000000..ef6f11ebe
--- /dev/null
+++ b/modules/operserv/kill.cpp
@@ -0,0 +1,63 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSKill : public Command
+{
+ public:
+ CommandOSKill(Module *creator) : Command(creator, "operserv/kill", 1, 2)
+ {
+ this->SetDesc(_("Kill a user"));
+ this->SetSyntax(_("\037user\037 [\037reason\037]"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &nick = params[0];
+ Anope::string reason = params.size() > 1 ? params[1] : "";
+
+ User *u2 = User::Find(nick, true);
+ if (u2 == NULL)
+ source.Reply(_("\002{0}\002 isn't currently online."), nick);
+ else if (u2->IsProtected() || u2->server == Me)
+ source.Reply(_("\002{0}\002 is protected and cannot be killed."), u2->nick);
+ else
+ {
+ if (reason.empty())
+ reason = "No reason specified";
+ if (Config->GetModule("operserv")->Get<bool>("addakiller"))
+ reason = "(" + source.GetNick() + ") " + reason;
+ Log(LOG_ADMIN, source, this) << "on " << u2->nick << " for " << reason;
+ u2->Kill(*source.service, reason);
+ }
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Allows you to kill a user from the network. Parameters are the same as for the standard /KILL command."));
+ return true;
+ }
+};
+
+class OSKill : public Module
+{
+ CommandOSKill commandoskill;
+
+ public:
+ OSKill(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandoskill(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSKill)
diff --git a/modules/operserv/list.cpp b/modules/operserv/list.cpp
new file mode 100644
index 000000000..ed825f373
--- /dev/null
+++ b/modules/operserv/list.cpp
@@ -0,0 +1,238 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSChanList : public Command
+{
+ public:
+ CommandOSChanList(Module *creator) : Command(creator, "operserv/chanlist", 0, 2)
+ {
+ this->SetDesc(_("Lists all channel records"));
+ this->SetSyntax(_("[{\037pattern\037 | \037nick\037} [\037SECRET\037]]"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &pattern = !params.empty() ? params[0] : "";
+ const Anope::string &opt = params.size() > 1 ? params[1] : "";
+ std::set<Anope::string> modes;
+ User *u2;
+
+ if (!pattern.empty())
+ Log(LOG_ADMIN, source, this) << "for " << pattern;
+ else
+ Log(LOG_ADMIN, source, this);
+
+ if (!opt.empty() && opt.equals_ci("SECRET"))
+ {
+ modes.insert("SECRET");
+ modes.insert("PRIVATE");
+ }
+
+ ListFormatter list(source.GetAccount());
+ list.AddColumn(_("Name")).AddColumn(_("Users")).AddColumn(_("Modes")).AddColumn(_("Topic"));
+
+ if (!pattern.empty() && (u2 = User::Find(pattern, true)))
+ {
+ source.Reply(_("Channel list for \002{0}\002:"), u2->nick);
+
+ for (User::ChanUserList::iterator uit = u2->chans.begin(), uit_end = u2->chans.end(); uit != uit_end; ++uit)
+ {
+ ChanUserContainer *cc = uit->second;
+
+ if (!modes.empty())
+ for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it)
+ if (!cc->chan->HasMode(*it))
+ continue;
+
+ ListFormatter::ListEntry entry;
+ entry["Name"] = cc->chan->name;
+ entry["Users"] = stringify(cc->chan->users.size());
+ entry["Modes"] = cc->chan->GetModes(true, true);
+ entry["Topic"] = cc->chan->topic;
+ list.AddEntry(entry);
+ }
+ }
+ else
+ {
+ source.Reply(_("Channel list:"));
+
+ for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit)
+ {
+ Channel *c = cit->second;
+
+ if (!pattern.empty() && !Anope::Match(c->name, pattern, false, true))
+ continue;
+ if (!modes.empty())
+ for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it)
+ if (!c->HasMode(*it))
+ continue;
+
+ ListFormatter::ListEntry entry;
+ entry["Name"] = c->name;
+ entry["Users"] = stringify(c->users.size());
+ entry["Modes"] = c->GetModes(true, true);
+ entry["Topic"] = c->topic;
+ list.AddEntry(entry);
+ }
+ }
+
+ std::vector<Anope::string> replies;
+ list.Process(replies);
+
+ for (unsigned i = 0; i < replies.size(); ++i)
+ source.Reply(replies[i]);
+
+ source.Reply(_("End of channel list."));
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Lists all channels currently in use on the IRC network, whether they are registered or not.\n"
+ "\n"
+ "If \002pattern\002 is given, lists only channels that match it. If a nicknam is given, lists only the channels the user using it is on."
+ " If SECRET is specified, lists only channels matching \002pattern\002 that have the +s or +p mode."));
+
+ const Anope::string &regexengine = Config->GetBlock("options")->Get<Anope::string>("regexengine");
+ if (!regexengine.empty())
+ {
+ source.Reply(" ");
+ source.Reply(_("Regex matches are also supported using the {0} engine. Enclose your pattern in // if this is desired."), regexengine);
+ }
+
+ return true;
+ }
+};
+
+class CommandOSUserList : public Command
+{
+ public:
+ CommandOSUserList(Module *creator) : Command(creator, "operserv/userlist", 0, 2)
+ {
+ this->SetDesc(_("Lists all user records"));
+ this->SetSyntax(_("[{\037pattern\037 | \037channel\037} [\037INVISIBLE\037]]"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &pattern = !params.empty() ? params[0] : "";
+ const Anope::string &opt = params.size() > 1 ? params[1] : "";
+ Channel *c;
+ std::set<Anope::string> modes;
+
+ if (!pattern.empty())
+ Log(LOG_ADMIN, source, this) << "for " << pattern;
+ else
+ Log(LOG_ADMIN, source, this);
+
+ if (!opt.empty() && opt.equals_ci("INVISIBLE"))
+ modes.insert("INVIS");
+
+ ListFormatter list(source.GetAccount());
+ list.AddColumn(_("Name")).AddColumn(_("Mask"));
+
+ if (!pattern.empty() && (c = Channel::Find(pattern)))
+ {
+ source.Reply(_("User list for \002{0}\002:"), pattern);
+
+ for (Channel::ChanUserList::iterator cuit = c->users.begin(), cuit_end = c->users.end(); cuit != cuit_end; ++cuit)
+ {
+ ChanUserContainer *uc = cuit->second;
+
+ if (!modes.empty())
+ for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it)
+ if (!uc->user->HasMode(*it))
+ continue;
+
+ ListFormatter::ListEntry entry;
+ entry["Name"] = uc->user->nick;
+ entry["Mask"] = uc->user->GetIdent() + "@" + uc->user->GetDisplayedHost();
+ list.AddEntry(entry);
+ }
+ }
+ else
+ {
+ /* Historically this has been ordered, so... */
+ Anope::map<User *> ordered_map;
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ ordered_map[it->first] = it->second;
+
+ source.Reply(_("Users list:"));
+
+ for (Anope::map<User *>::const_iterator it = ordered_map.begin(); it != ordered_map.end(); ++it)
+ {
+ User *u2 = it->second;
+
+ if (!pattern.empty())
+ {
+ Anope::string mask = u2->nick + "!" + u2->GetIdent() + "@" + u2->GetDisplayedHost(), mask2 = u2->nick + "!" + u2->GetIdent() + "@" + u2->host, mask3 = u2->nick + "!" + u2->GetIdent() + "@" + u2->ip.addr();
+ if (!Anope::Match(mask, pattern) && !Anope::Match(mask2, pattern) && !Anope::Match(mask3, pattern))
+ continue;
+ if (!modes.empty())
+ for (std::set<Anope::string>::iterator mit = modes.begin(), mit_end = modes.end(); mit != mit_end; ++mit)
+ if (!u2->HasMode(*mit))
+ continue;
+ }
+
+ ListFormatter::ListEntry entry;
+ entry["Name"] = u2->nick;
+ entry["Mask"] = u2->GetIdent() + "@" + u2->GetDisplayedHost();
+ list.AddEntry(entry);
+ }
+ }
+
+ std::vector<Anope::string> replies;
+ list.Process(replies);
+
+ for (unsigned i = 0; i < replies.size(); ++i)
+ source.Reply(replies[i]);
+
+ source.Reply(_("End of users list."));
+ return;
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ this->SendSyntax(source);
+ source.Reply(" ");
+ source.Reply(_("Lists all users currently online on the IRC network, whether their nickname is registered or not.\n"
+ "\n"
+ "If \002pattern\002 is given, lists only users that match it (it must be in the format nick!user@host)."
+ " If \002channel\002 is given, lists only users that are on the given channel. If INVISIBLE is specified, only users with the +i flag will be listed."));
+
+ const Anope::string &regexengine = Config->GetBlock("options")->Get<Anope::string>("regexengine");
+ if (!regexengine.empty())
+ {
+ source.Reply(" ");
+ source.Reply(_("Regex matches are also supported using the %s engine.\n"
+ "Enclose your pattern in // if this is desired."), regexengine.c_str());
+ }
+
+ return true;
+ }
+};
+
+class OSList : public Module
+{
+ CommandOSChanList commandoschanlist;
+ CommandOSUserList commandosuserlist;
+
+ public:
+ OSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandoschanlist(this)
+ , commandosuserlist(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSList)
diff --git a/modules/operserv/login.cpp b/modules/operserv/login.cpp
new file mode 100644
index 000000000..650c48e3d
--- /dev/null
+++ b/modules/operserv/login.cpp
@@ -0,0 +1,148 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ *
+ *
+ */
+#include "module.h"
+
+class CommandOSLogin : public Command
+{
+ public:
+ CommandOSLogin(Module *creator) : Command(creator, "operserv/login", 1, 1)
+ {
+ this->SetSyntax(_("\037password\037"));
+ this->RequireUser(true);
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &password = params[0];
+
+ User *u = source.GetUser();
+ Oper *o = source.nc->o;
+ if (o == NULL)
+ {
+ source.Reply(_("No oper block for your nickname."));
+ return;
+ }
+
+ if (o->GetPassword().empty())
+ {
+ source.Reply(_("Your oper block doesn't require logging in."));
+ return;
+ }
+
+ if (u->HasExtOK("os_login"))
+ {
+ source.Reply(_("You are already logged in."));
+ return;
+ }
+
+ if (o->GetPassword() != password)
+ {
+ source.Reply(_("Password incorrect."));
+ u->BadPassword();
+ return;
+ }
+
+ Log(LOG_ADMIN, source, this) << "and successfully identified to " << source.service->nick;
+ u->Extend<bool>("os_login", true);
+ source.Reply(_("Password accepted."));
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Logs you in to {0} so you gain Services Operator privileges. This command is unnecessary if your oper block is configured without a password."), source.service->nick);
+ return true;
+ }
+
+ const Anope::string GetDesc(CommandSource &source) const override
+ {
+ return Anope::printf(Language::Translate(source.GetAccount(), _("Login to %s")), source.service->nick.c_str());
+ }
+};
+
+class CommandOSLogout : public Command
+{
+ public:
+ CommandOSLogout(Module *creator) : Command(creator, "operserv/logout", 0, 0)
+ {
+ this->RequireUser(true);
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ User *u = source.GetUser();
+ Oper *o = source.nc->o;
+ if (o == NULL)
+ {
+ source.Reply(_("No oper block for your nick."));
+ return;
+ }
+
+ if (o->GetPassword().empty())
+ {
+ source.Reply(_("Your oper block doesn't require logging in."));
+ return;
+ }
+
+ if (!u->HasExtOK("os_login"))
+ {
+ source.Reply(_("You are not identified."));
+ return;
+ }
+
+ Log(LOG_ADMIN, source, this);
+ u->ShrinkOK<bool>("os_login");
+ source.Reply(_("You have been logged out."));
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Logs you out from %s so you lose Services Operator privileges. This command is only useful if your oper block is configured with a password."), source.service->nick);
+ return true;
+ }
+
+ const Anope::string GetDesc(CommandSource &source) const override
+ {
+ return Anope::printf(Language::Translate(source.GetAccount(), _("Logout from %s")), source.service->nick.c_str());
+ }
+};
+
+class OSLogin : public Module
+ , public EventHook<Event::IsServicesOperEvent>
+{
+ CommandOSLogin commandoslogin;
+ CommandOSLogout commandoslogout;
+ ExtensibleItem<bool> os_login;
+
+ public:
+ OSLogin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandoslogin(this)
+ , commandoslogout(this)
+ , os_login(this, "os_login")
+ {
+
+ }
+
+ EventReturn IsServicesOper(User *u) override
+ {
+ if (!u->Account()->o->GetPassword().empty())
+ {
+ if (os_login.HasExt(u))
+ return EVENT_ALLOW;
+ return EVENT_STOP;
+ }
+
+ return EVENT_CONTINUE;
+ }
+};
+
+MODULE_INIT(OSLogin)
diff --git a/modules/operserv/logsearch.cpp b/modules/operserv/logsearch.cpp
new file mode 100644
index 000000000..0fa425aba
--- /dev/null
+++ b/modules/operserv/logsearch.cpp
@@ -0,0 +1,151 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSLogSearch : public Command
+{
+ static inline Anope::string CreateLogName(const Anope::string &file, time_t t = Anope::CurTime)
+ {
+ char timestamp[32];
+
+ tm *tm = localtime(&t);
+
+ strftime(timestamp, sizeof(timestamp), "%Y%m%d", tm);
+
+ return Anope::LogDir + "/" + file + "." + timestamp;
+ }
+
+ public:
+ CommandOSLogSearch(Module *creator) : Command(creator, "operserv/logsearch", 1, 3)
+ {
+ this->SetDesc(_("Searches logs for a matching pattern"));
+ this->SetSyntax(_("[+\037days\037d] [+\037limit\037l] \037pattern\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ int days = 7, replies = 50;
+
+ unsigned i;
+ for (i = 0; i < params.size() && params[i][0] == '+'; ++i)
+ {
+ switch (params[i][params[i].length() - 1])
+ {
+ case 'd':
+ if (params[i].length() > 2)
+ {
+ Anope::string dur = params[i].substr(1, params[i].length() - 2);
+ try
+ {
+ days = convertTo<int>(dur);
+ if (days <= 0)
+ throw ConvertException();
+ }
+ catch (const ConvertException &)
+ {
+ source.Reply(_("Invalid duration \002{0}\002, using \002{1}\002 days."), dur, days);
+ }
+ }
+ break;
+ case 'l':
+ if (params[i].length() > 2)
+ {
+ Anope::string dur = params[i].substr(1, params[i].length() - 2);
+ try
+ {
+ replies = convertTo<int>(dur);
+ if (replies <= 0)
+ throw ConvertException();
+ }
+ catch (const ConvertException &)
+ {
+ source.Reply(_("Invalid limit \002{0}\002, using \002{1}\002."), dur, replies);
+ }
+ }
+ break;
+ default:
+ source.Reply(_("Unknown parameter: {0}"), params[i]);
+ }
+ }
+
+ if (i >= params.size())
+ {
+ this->OnSyntaxError(source, "");
+ return;
+ }
+
+ Anope::string search_string = params[i++];
+ for (; i < params.size(); ++i)
+ search_string += " " + params[i];
+
+ Log(LOG_ADMIN, source, this) << "for " << search_string;
+
+ const Anope::string &logfile_name = Config->GetModule(this->owner)->Get<Anope::string>("logname");
+ std::list<Anope::string> matches;
+ for (int d = days - 1; d >= 0; --d)
+ {
+ Anope::string lf_name = CreateLogName(logfile_name, Anope::CurTime - (d * 86400));
+ Log(LOG_DEBUG) << "Searching " << lf_name;
+ std::fstream fd(lf_name.c_str(), std::ios_base::in);
+ if (!fd.is_open())
+ continue;
+
+ for (Anope::string buf, token; std::getline(fd, buf.str());)
+ if (Anope::Match(buf, "*" + search_string + "*"))
+ matches.push_back(buf);
+
+ fd.close();
+ }
+
+ unsigned found = matches.size();
+ if (!found)
+ {
+ source.Reply(_("No matches for \002{0}\002 found."), search_string);
+ return;
+ }
+
+ while (matches.size() > static_cast<unsigned>(replies))
+ matches.pop_front();
+
+ source.Reply(_("Matches for \002{0}\002:"), search_string);
+ unsigned count = 0;
+ for (std::list<Anope::string>::iterator it = matches.begin(), it_end = matches.end(); it != it_end; ++it)
+ source.Reply("#%d: %s", ++count, it->c_str());
+ source.Reply(_("Showed \002{0}/{1}\002 matches for \002{2}\002."), matches.size(), found, search_string);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("This command searches the Services logfiles for messages that match the given pattern."
+ " The day and limit argument may be used to specify how many days of logs to search and the number of replies to limit to."
+ " By default this command searches one week of logs, and limits replies to 50.\n"
+ "\n"
+ "Example:\n"
+ " {0} +21d +500l Anope\n"
+ " Searches the last 21 days worth of logs for messages containing \"Anope\" and lists the most recent 500 of them."),
+ source.command);
+ return true;
+ }
+};
+
+class OSLogSearch : public Module
+{
+ CommandOSLogSearch commandoslogsearch;
+
+ public:
+ OSLogSearch(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandoslogsearch(this)
+ {
+ }
+};
+
+MODULE_INIT(OSLogSearch)
diff --git a/modules/operserv/main/CMakeLists.txt b/modules/operserv/main/CMakeLists.txt
new file mode 100644
index 000000000..781f0ef1f
--- /dev/null
+++ b/modules/operserv/main/CMakeLists.txt
@@ -0,0 +1 @@
+build_subdir(${CMAKE_CURRENT_SOURCE_DIR})
diff --git a/modules/operserv/main/operserv.cpp b/modules/operserv/main/operserv.cpp
new file mode 100644
index 000000000..0a4f1b692
--- /dev/null
+++ b/modules/operserv/main/operserv.cpp
@@ -0,0 +1,337 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+#include "modules/help.h"
+#include "modules/nickserv.h"
+
+class SGlineType : public XLineType
+{
+ public:
+ SGlineType(Module *creator) : XLineType(creator, "SGLine")
+ {
+ SetParent(xline);
+ }
+};
+
+class SGLineManager : public XLineManager
+{
+ public:
+ SGLineManager(Module *creator) : XLineManager(creator, "xlinemanager/sgline", 'G') { }
+
+ void OnMatch(User *u, XLine *x) override
+ {
+ this->Send(u, x);
+ }
+
+ void OnExpire(XLine *x) override
+ {
+ ::Log(Config->GetClient("OperServ"), "expire/akill") << "AKILL on \002" << x->GetMask() << "\002 has expired";
+ }
+
+ void Send(User *u, XLine *x) override
+ {
+ IRCD->SendAkill(u, x);
+ }
+
+ void SendDel(XLine *x) override
+ {
+ IRCD->SendAkillDel(x);
+ }
+
+ bool Check(User *u, XLine *x) override
+ {
+ if (x->regex)
+ {
+ Anope::string uh = u->GetIdent() + "@" + u->host, nuhr = u->nick + "!" + uh + "#" + u->realname;
+ return std::regex_match(uh.str(), *x->regex) || std::regex_match(nuhr.str(), *x->regex);
+ }
+
+ if (!x->GetNick().empty() && !Anope::Match(u->nick, x->GetNick()))
+ return false;
+
+ if (!x->GetUser().empty() && !Anope::Match(u->GetIdent(), x->GetUser()))
+ return false;
+
+ if (!x->GetReal().empty() && !Anope::Match(u->realname, x->GetReal()))
+ return false;
+
+ if (x->c && x->c->match(u->ip))
+ return true;
+
+ if (x->GetHost().empty() || Anope::Match(u->host, x->GetHost()) || Anope::Match(u->ip.addr(), x->GetHost()))
+ return true;
+
+ return false;
+ }
+};
+
+class SQlineType : public XLineType
+{
+ public:
+ SQlineType(Module *creator) : XLineType(creator, "SQLine")
+ {
+ SetParent(xline);
+ }
+};
+
+class SQLineManager : public XLineManager
+{
+ public:
+ SQLineManager(Module *creator) : XLineManager(creator, "xlinemanager/sqline", 'Q') { }
+
+ void OnMatch(User *u, XLine *x) override
+ {
+ this->Send(u, x);
+ }
+
+ void OnExpire(XLine *x) override
+ {
+ ::Log(Config->GetClient("OperServ"), "expire/sqline") << "SQLINE on \002" << x->GetMask() << "\002 has expired";
+ }
+
+ void Send(User *u, XLine *x) override
+ {
+ if (!IRCD->CanSQLine)
+ {
+ if (!u)
+ ;
+ else if (NickServ::service)
+ NickServ::service->Collide(u, NULL);
+ else
+ u->Kill(Config->GetClient("OperServ"), "Q-Lined: " + x->GetReason());
+ }
+ else if (x->IsRegex())
+ ;
+ else if (x->GetMask()[0] != '#' || IRCD->CanSQLineChannel)
+ IRCD->SendSQLine(u, x);
+ }
+
+ void SendDel(XLine *x) override
+ {
+ if (!IRCD->CanSQLine || x->IsRegex())
+ ;
+ else if (x->GetMask()[0] != '#' || IRCD->CanSQLineChannel)
+ IRCD->SendSQLineDel(x);
+ }
+
+ bool Check(User *u, XLine *x) override
+ {
+ if (x->regex)
+ return std::regex_match(u->nick.c_str(), *x->regex);
+ return Anope::Match(u->nick, x->GetMask());
+ }
+
+ XLine *CheckChannel(Channel *c)
+ {
+ for (XLine *x : this->GetXLines())
+ {
+ if (x->regex)
+ {
+ if (std::regex_match(c->name.str(), *x->regex))
+ return x;
+ }
+ else
+ {
+ if (x->GetMask().empty() || x->GetMask()[0] != '#')
+ continue;
+
+ if (Anope::Match(c->name, x->GetMask(), false, true))
+ return x;
+ }
+ }
+ return nullptr;
+ }
+};
+
+class SNlineType : public XLineType
+{
+ public:
+ SNlineType(Module *creator) : XLineType(creator, "SNLine")
+ {
+ SetParent(xline);
+ }
+};
+
+class SNLineManager : public XLineManager
+{
+ public:
+ SNLineManager(Module *creator) : XLineManager(creator, "xlinemanager/snline", 'N') { }
+
+ void OnMatch(User *u, XLine *x) override
+ {
+ this->Send(u, x);
+ }
+
+ void OnExpire(XLine *x) override
+ {
+ ::Log(Config->GetClient("OperServ"), "expire/snline") << "SNLINE on \002" << x->GetMask() << "\002 has expired";
+ }
+
+ void Send(User *u, XLine *x) override
+ {
+ if (IRCD->CanSNLine && !x->IsRegex())
+ IRCD->SendSGLine(u, x);
+
+ if (u)
+ u->Kill(Config->GetClient("OperServ"), "SNLined: " + x->GetReason());
+ }
+
+ void SendDel(XLine *x) override
+ {
+ if (IRCD->CanSNLine && !x->IsRegex())
+ IRCD->SendSGLineDel(x);
+ }
+
+ bool Check(User *u, XLine *x) override
+ {
+ if (x->regex)
+ return std::regex_match(u->realname.str(), *x->regex);
+ return Anope::Match(u->realname, x->GetMask(), false, true);
+ }
+};
+
+class OperServCore : public Module
+ , public EventHook<Event::BotPrivmsg>
+ , public EventHook<Event::ServerQuit>
+ , public EventHook<Event::UserModeSet>
+ , public EventHook<Event::UserModeUnset>
+ , public EventHook<Event::UserConnect>
+ , public EventHook<Event::UserNickChange>
+ , public EventHook<Event::CheckKick>
+ , public EventHook<Event::Help>
+ , public EventHook<Event::Log>
+{
+ Reference<ServiceBot> OperServ;
+ SGlineType sgtype;
+ SGLineManager sglines;
+ SQlineType sqtype;
+ SQLineManager sqlines;
+ SNlineType sntype;
+ SNLineManager snlines;
+
+ public:
+ OperServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
+ , sgtype(this)
+ , sglines(this)
+ , sqtype(this)
+ , sqlines(this)
+ , sntype(this)
+ , snlines(this)
+ {
+
+ /* Yes, these are in this order for a reason. Most violent->least violent. */
+ XLineManager::RegisterXLineManager(&sglines);
+ XLineManager::RegisterXLineManager(&sqlines);
+ XLineManager::RegisterXLineManager(&snlines);
+ }
+
+ ~OperServCore()
+ {
+ this->sglines.Clear();
+ this->sqlines.Clear();
+ this->snlines.Clear();
+
+ XLineManager::UnregisterXLineManager(&sglines);
+ XLineManager::UnregisterXLineManager(&sqlines);
+ XLineManager::UnregisterXLineManager(&snlines);
+ }
+
+ void OnReload(Configuration::Conf *conf) override
+ {
+ const Anope::string &osnick = conf->GetModule(this)->Get<Anope::string>("client");
+
+ if (osnick.empty())
+ throw ConfigException(this->name + ": <client> must be defined");
+
+ ServiceBot *bi = ServiceBot::Find(osnick, true);
+ if (!bi)
+ throw ConfigException(this->name + ": no bot named " + osnick);
+
+ OperServ = bi;
+ }
+
+ EventReturn OnBotPrivmsg(User *u, ServiceBot *bi, Anope::string &message) override
+ {
+ if (bi == OperServ && !u->HasMode("OPER") && Config->GetModule(this)->Get<bool>("opersonly"))
+ {
+ u->SendMessage(bi, "Access denied.");
+ ::Log(bi, "bados") << "Denied access to " << bi->nick << " from " << u->GetMask() << " (non-oper)";
+ return EVENT_STOP;
+ }
+
+ return EVENT_CONTINUE;
+ }
+
+ void OnServerQuit(Server *server) override
+ {
+ if (server->IsJuped())
+ ::Log(server, "squit", OperServ) << "Received SQUIT for juped server " << server->GetName();
+ }
+
+ void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override
+ {
+ if (mname == "OPER")
+ ::Log(u, "oper", OperServ) << "is now an IRC operator.";
+ }
+
+ void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) override
+ {
+ if (mname == "OPER")
+ ::Log(u, "oper", OperServ) << "is no longer an IRC operator";
+ }
+
+ void OnUserConnect(User *u, bool &exempt) override
+ {
+ if (!u->Quitting() && !exempt)
+ XLineManager::CheckAll(u);
+ }
+
+ void OnUserNickChange(User *u, const Anope::string &oldnick) override
+ {
+ if (!u->HasMode("OPER"))
+ this->sqlines.CheckAllXLines(u);
+ }
+
+ EventReturn OnCheckKick(User *u, Channel *c, Anope::string &mask, Anope::string &reason) override
+ {
+ XLine *x = this->sqlines.CheckChannel(c);
+ if (x)
+ {
+ this->sqlines.OnMatch(u, x);
+ reason = x->GetReason();
+ return EVENT_STOP;
+ }
+
+ return EVENT_CONTINUE;
+ }
+
+ EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ if (!params.empty() || source.c || source.service != *OperServ)
+ return EVENT_CONTINUE;
+ source.Reply(_("%s commands:"), OperServ->nick.c_str());
+ return EVENT_CONTINUE;
+ }
+
+ void OnPostHelp(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ }
+
+ void OnLog(::Log *l) override
+ {
+ if (l->type == LOG_SERVER)
+ l->bi = OperServ;
+ }
+};
+
+MODULE_INIT(OperServCore)
+
diff --git a/modules/operserv/mode.cpp b/modules/operserv/mode.cpp
new file mode 100644
index 000000000..30e1d502b
--- /dev/null
+++ b/modules/operserv/mode.cpp
@@ -0,0 +1,187 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSMode : public Command
+{
+ public:
+ CommandOSMode(Module *creator) : Command(creator, "operserv/mode", 2, 3)
+ {
+ this->SetDesc(_("Change channel modes"));
+ this->SetSyntax(_("\037channel\037 \037modes\037"));
+ this->SetSyntax(_("\037channel\037 CLEAR [ALL]"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &target = params[0];
+ const Anope::string &modes = params[1];
+
+ Reference<Channel> c = Channel::Find(target);
+ if (!c)
+ source.Reply(_("Channel \002{0}\002 doesn't exist."), target);
+ else if (c->bouncy_modes)
+ source.Reply(_("Services is unable to change modes. Are your servers' U:lines configured correctly?"));
+ else if (modes.equals_ci("CLEAR"))
+ {
+ bool all = params.size() > 2 && params[2].equals_ci("ALL");
+
+ const Channel::ModeList chmodes = c->GetModes();
+ for (Channel::ModeList::const_iterator it = chmodes.begin(), it_end = chmodes.end(); it != it_end && c; ++it)
+ c->RemoveMode(c->ci->WhoSends(), it->first, it->second, false);
+
+ if (!c)
+ {
+ source.Reply(_("Modes cleared on %s and the channel destroyed."), target.c_str());
+ return;
+ }
+
+ if (all)
+ {
+ for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it)
+ {
+ ChanUserContainer *uc = it->second;
+
+ if (uc->user->HasMode("OPER"))
+ continue;
+
+ for (size_t i = uc->status.Modes().length(); i > 0; --i)
+ c->RemoveMode(c->ci->WhoSends(), ModeManager::FindChannelModeByChar(uc->status.Modes()[i - 1]), uc->user->GetUID(), false);
+ }
+
+ source.Reply(_("All modes cleared on \002{0}\002."), c->name);
+ }
+ else
+ source.Reply(_("Non-status modes cleared on \002{0}\002."), c->name);
+ }
+ else
+ {
+ spacesepstream sep(modes + (params.size() > 2 ? " " + params[2] : ""));
+ Anope::string mode;
+ int add = 1;
+ Anope::string log_modes, log_params;
+
+ sep.GetToken(mode);
+ for (unsigned i = 0; i < mode.length() && c; ++i)
+ {
+ char ch = mode[i];
+
+ if (ch == '+')
+ {
+ add = 1;
+ log_modes += "+";
+ continue;
+ }
+ else if (ch == '-')
+ {
+ add = 0;
+ log_modes += "-";
+ continue;
+ }
+
+ ChannelMode *cm = ModeManager::FindChannelModeByChar(ch);
+ if (!cm)
+ continue;
+
+ Anope::string param, param_log;
+ if (cm->type != MODE_REGULAR)
+ {
+ if (cm->type == MODE_PARAM && !add && anope_dynamic_static_cast<ChannelModeParam *>(cm)->minus_no_arg)
+ ;
+ else if (!sep.GetToken(param))
+ continue;
+
+ param_log = param;
+
+ if (cm->type == MODE_STATUS)
+ {
+ User *targ = User::Find(param, true);
+ if (targ == NULL || c->FindUser(targ) == NULL)
+ continue;
+ param = targ->GetUID();
+ }
+ }
+
+ log_modes += cm->mchar;
+ if (!param.empty())
+ log_params += " " + param_log;
+
+ if (add)
+ c->SetMode(source.service, cm, param, false);
+ else
+ c->RemoveMode(source.service, cm, param, false);
+ }
+
+ if (!log_modes.replace_all_cs("+", "").replace_all_cs("-", "").empty())
+ Log(LOG_ADMIN, source, this) << log_modes << log_params << " on " << (c ? c->name : target);
+ }
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Allows Services Operators to change modes for any channel. Parameters are the same as for the standard /MODE command.\n"
+ "Alternatively, CLEAR may be given to clear all modes on the channel.\n"
+ "If CLEAR ALL is given then all modes, including user status, is removed."));
+ return true;
+ }
+};
+
+class CommandOSUMode : public Command
+{
+ public:
+ CommandOSUMode(Module *creator) : Command(creator, "operserv/umode", 2, 2)
+ {
+ this->SetDesc(_("Change user modes"));
+ this->SetSyntax(_("\037user\037 \037modes\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &target = params[0];
+ const Anope::string &modes = params[1];
+
+ User *u2 = User::Find(target, true);
+ if (!u2)
+ source.Reply(_("\002{0}\002 isn't currently online."), target);
+ else
+ {
+ u2->SetModes(source.service, "%s", modes.c_str());
+ source.Reply(_("Changed usermodes of \002{0}\002 to \002{1}\002."), u2->nick.c_str(), modes.c_str());
+
+ u2->SendMessage(*source.service, _("\002{0}\002 changed your usermodes to \002{1}\002."), source.GetNick(), modes);
+
+ Log(LOG_ADMIN, source, this) << modes << " on " << target;
+ }
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Allows Services Operators to change modes for any user. Parameters are the same as for the standard /MODE command."));
+ return true;
+ }
+};
+
+class OSMode : public Module
+{
+ CommandOSMode commandosmode;
+ CommandOSUMode commandosumode;
+
+ public:
+ OSMode(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosmode(this)
+ , commandosumode(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSMode)
diff --git a/modules/operserv/modinfo.cpp b/modules/operserv/modinfo.cpp
new file mode 100644
index 000000000..f3c6db00f
--- /dev/null
+++ b/modules/operserv/modinfo.cpp
@@ -0,0 +1,214 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSModInfo : public Command
+{
+ public:
+ CommandOSModInfo(Module *creator) : Command(creator, "operserv/modinfo", 1, 1)
+ {
+ this->SetDesc(_("Info about a loaded module"));
+ this->SetSyntax(_("\037modname\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &file = params[0];
+
+ Log(LOG_ADMIN, source, this) << "on " << file;
+
+ Module *m = ModuleManager::FindModule(file);
+ if (m)
+ {
+ source.Reply(_("Module: \002{0}\002 Version: \002{1}\002 Author: \002{2}\002 Loaded: \002{3}\002"), m->name, !m->version.empty() ? m->version : "?", !m->author.empty() ? m->author : "Unknown", Anope::strftime(m->created, source.GetAccount()));
+ if (Anope::Debug)
+ source.Reply(_(" Loaded at: {0}"), Anope::printf("%o", m->handle));
+
+ std::vector<Anope::string> servicekeys = Service::GetServiceKeys("Command");
+ for (unsigned i = 0; i < servicekeys.size(); ++i)
+ {
+ ServiceReference<Command> c("Command", servicekeys[i]);
+ if (!c || c->owner != m)
+ continue;
+
+ source.Reply(_(" Providing service: \002{0}\002"), c->name);
+
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ {
+ User *u = it->second;
+
+ if (u->type != UserType::BOT)
+ continue;
+
+ ServiceBot *bi = anope_dynamic_static_cast<ServiceBot *>(u);
+
+ for (CommandInfo::map::const_iterator cit = bi->commands.begin(), cit_end = bi->commands.end(); cit != cit_end; ++cit)
+ {
+ const Anope::string &c_name = cit->first;
+ const CommandInfo &info = cit->second;
+ if (info.name != c->name)
+ continue;
+ source.Reply(_(" Command \002{0}\002 on \002{1}\002 is linked to \002{2}\002"), c_name, bi->nick, c->name);
+ }
+ }
+ }
+ }
+ else
+ source.Reply(_("No information about module \002{0}\002 is available."), file);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("This command lists information about the specified loaded module."));
+ return true;
+ }
+};
+
+class CommandOSModList : public Command
+{
+ public:
+ CommandOSModList(Module *creator) : Command(creator, "operserv/modlist", 0, 1)
+ {
+ this->SetDesc(_("List loaded modules"));
+ this->SetSyntax("[all|third|vendor|extra|database|encryption|pseudoclient|protocol]");
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &param = !params.empty() ? params[0] : "";
+
+ if (!param.empty())
+ Log(LOG_ADMIN, source, this) << "for " << param;
+ else
+ Log(LOG_ADMIN, source, this);
+
+ bool third = false, vendor = false, extra = false, database = false, encryption = false, pseudoclient = false, protocol = false;
+
+ if (param.equals_ci("all"))
+ third = vendor = extra = database = encryption = pseudoclient = protocol = true;
+ else if (param.equals_ci("third"))
+ third = true;
+ else if (param.equals_ci("vendor"))
+ vendor = true;
+ else if (param.equals_ci("extra"))
+ extra = true;
+ else if (param.equals_ci("database"))
+ database = true;
+ else if (param.equals_ci("encryption"))
+ encryption = true;
+ else if (param.equals_ci("pseudoclient"))
+ pseudoclient = true;
+ else if (param.equals_ci("protocol"))
+ protocol = true;
+ else
+ third = extra = database = encryption = protocol = true;
+
+ Module *protomod = ModuleManager::FindFirstOf(PROTOCOL);
+
+ source.Reply(_("Current module list:"));
+
+ int count = 0;
+ for (std::list<Module *>::iterator it = ModuleManager::Modules.begin(), it_end = ModuleManager::Modules.end(); it != it_end; ++it)
+ {
+ Module *m = *it;
+
+ bool show = false;
+ Anope::string mtype;
+
+ if (m->type & PROTOCOL)
+ {
+ show |= protocol;
+ if (!mtype.empty())
+ mtype += ", ";
+ mtype += "Protocol";
+ }
+ if (m->type & PSEUDOCLIENT)
+ {
+ show |= pseudoclient;
+ if (!mtype.empty())
+ mtype += ", ";
+ mtype += "Pseudoclient";
+ }
+ if (m->type & ENCRYPTION)
+ {
+ show |= encryption;
+ if (!mtype.empty())
+ mtype += ", ";
+ mtype += "Encryption";
+ }
+ if (m->type & DATABASE)
+ {
+ show |= database;
+ if (!mtype.empty())
+ mtype += ", ";
+ mtype += "Database";
+ }
+ if (m->type & EXTRA)
+ {
+ show |= extra;
+ if (!mtype.empty())
+ mtype += ", ";
+ mtype += "Extra";
+ }
+ if (m->type & VENDOR)
+ {
+ show |= vendor;
+ if (!mtype.empty())
+ mtype += ", ";
+ mtype += "Vendor";
+ }
+ if (m->type & THIRD)
+ {
+ show |= third;
+ if (!mtype.empty())
+ mtype += ", ";
+ mtype += "Third";
+ }
+
+ if (!show)
+ continue;
+ else if (m->type & PROTOCOL && param.empty() && m != protomod)
+ continue;
+
+ ++count;
+
+ source.Reply(_("Module: \002{0}\002 [{1}] [{2}]"), m->name, m->version, mtype);
+ }
+
+ if (!count)
+ source.Reply(_("No modules currently loaded matching that criteria."));
+ else
+ source.Reply(_("\002{0}\002 modules loaded."), count);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Lists currently loaded modules."));
+ return true;
+ }
+};
+
+class OSModInfo : public Module
+{
+ CommandOSModInfo commandosmodinfo;
+ CommandOSModList commandosmodlist;
+
+ public:
+ OSModInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosmodinfo(this)
+ , commandosmodlist(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSModInfo)
diff --git a/modules/operserv/module.cpp b/modules/operserv/module.cpp
new file mode 100644
index 000000000..14bc897e3
--- /dev/null
+++ b/modules/operserv/module.cpp
@@ -0,0 +1,179 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSModLoad : public Command
+{
+ public:
+ CommandOSModLoad(Module *creator) : Command(creator, "operserv/modload", 1, 1)
+ {
+ this->SetDesc(_("Load a module"));
+ this->SetSyntax(_("\037modname\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &mname = params[0];
+
+ ModuleReturn status = ModuleManager::LoadModule(mname, source.GetUser());
+ if (status == MOD_ERR_OK)
+ {
+ Log(LOG_ADMIN, source, this) << "to load module " << mname;
+ source.Reply(_("Module \002{0}\002 loaded."), mname);
+ }
+ else if (status == MOD_ERR_EXISTS)
+ source.Reply(_("Module \002{0}\002 is already loaded."), mname);
+ else
+ source.Reply(_("Unable to load module \002{0}\002."), mname);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("This command loads the module named \037modname\037."));
+ return true;
+ }
+};
+
+class CommandOSModReLoad : public Command
+{
+ public:
+ CommandOSModReLoad(Module *creator) : Command(creator, "operserv/modreload", 1, 1)
+ {
+ this->SetDesc(_("Reload a module"));
+ this->SetSyntax(_("\037modname\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &mname = params[0];
+
+ Module *m = ModuleManager::FindModule(mname);
+ if (!m)
+ {
+ source.Reply(_("Module \002{0}\002 isn't loaded."), mname);
+ return;
+ }
+
+ if (!m->handle || m->GetPermanent())
+ {
+ source.Reply(_("Unable to remove module \002{0}\002."), m->name);
+ return;
+ }
+
+ Module *protocol = ModuleManager::FindFirstOf(PROTOCOL);
+ if (m->type == PROTOCOL && m != protocol)
+ {
+ source.Reply(_("You can not reload this module directly, instead reload {0}."), protocol ? protocol->name : "(unknown)");
+ return;
+ }
+
+ /* Unrecoverable */
+ bool fatal = m->type == PROTOCOL;
+ ModuleReturn status = ModuleManager::UnloadModule(m, source.GetUser());
+
+ if (status != MOD_ERR_OK)
+ {
+ source.Reply(_("Unable to remove module \002{0}\002."), mname);
+ return;
+ }
+
+ status = ModuleManager::LoadModule(mname, source.GetUser());
+ if (status == MOD_ERR_OK)
+ {
+ Log(LOG_ADMIN, source, this) << "to reload module " << mname;
+ source.Reply(_("Module \002{0}\002 reloaded."), mname);
+ }
+ else
+ {
+ if (fatal)
+ {
+ Anope::QuitReason = "Unable to reload module " + mname;
+ Anope::Quitting = true;
+ }
+ else
+ source.Reply(_("Unable to load module \002{0}\002."), mname);
+ }
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("This command reloads the module named \037modname\037."));
+ return true;
+ }
+};
+
+class CommandOSModUnLoad : public Command
+{
+ public:
+ CommandOSModUnLoad(Module *creator) : Command(creator, "operserv/modunload", 1, 1)
+ {
+ this->SetDesc(_("Un-Load a module"));
+ this->SetSyntax(_("\037modname\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &mname = params[0];
+
+ Module *m = ModuleManager::FindModule(mname);
+ if (!m)
+ {
+ source.Reply(_("Module \002{0}\002 isn't loaded."), mname);
+ return;
+ }
+
+ if (!m->handle || m->GetPermanent() || m->type == PROTOCOL)
+ {
+ source.Reply(_("Unable to remove module \002{0}\002."), m->name);
+ return;
+ }
+
+ Log(this->owner) << "Trying to unload module [" << mname << "]";
+
+ ModuleReturn status = ModuleManager::UnloadModule(m, source.GetUser());
+
+ if (status == MOD_ERR_OK)
+ {
+ Log(LOG_ADMIN, source, this) << "to unload module " << mname;
+ source.Reply(_("Module \002{0}\002 unloaded."), mname);
+ }
+ else
+ source.Reply(_("Unable to remove module \002{0}\002."), mname);
+
+ return;
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("This command unloads the module named \037modname\037."));
+ return true;
+ }
+};
+
+class OSModule : public Module
+{
+ CommandOSModLoad commandosmodload;
+ CommandOSModReLoad commandosmodreload;
+ CommandOSModUnLoad commandosmodunload;
+
+ public:
+ OSModule(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosmodload(this)
+ , commandosmodreload(this)
+ , commandosmodunload(this)
+ {
+ this->SetPermanent(true);
+
+ }
+};
+
+MODULE_INIT(OSModule)
diff --git a/modules/operserv/news.cpp b/modules/operserv/news.cpp
new file mode 100644
index 000000000..03a1e3a57
--- /dev/null
+++ b/modules/operserv/news.cpp
@@ -0,0 +1,459 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at info@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+#include "modules/os_news.h"
+
+/* List of messages for each news type. This simplifies message sending. */
+
+enum
+{
+ MSG_SYNTAX,
+ MSG_LIST_HEADER,
+ MSG_LIST_NONE,
+ MSG_ADDED,
+ MSG_DEL_NOT_FOUND,
+ MSG_DELETED,
+ MSG_DEL_NONE,
+ MSG_DELETED_ALL,
+ MSG_SIZE
+};
+
+static struct NewsMessages
+{
+ NewsType type;
+ Anope::string name;
+ const char *msgs[MSG_SIZE];
+} msgarray[] = {
+ {NEWS_LOGON, "LOGON",
+ {_("LOGONNEWS {ADD|DEL|LIST} [\037text\037|\037num\037]\002"),
+ _("Logon news items:"),
+ _("There is no logon news."),
+ _("Added new logon news item."),
+ _("Logon news item #{0} not found!"),
+ _("Logon news item #{0} deleted."),
+ _("No logon news items to delete!"),
+ _("All logon news items deleted.")}
+ },
+ {NEWS_OPER, "OPER",
+ {_("OPERNEWS {ADD|DEL|LIST} [\037text\037|\037num\037]\002"),
+ _("Oper news items:"),
+ _("There is no oper news."),
+ _("Added new oper news item."),
+ _("Oper news item #{0} not found!"),
+ _("Oper news item #{0} deleted."),
+ _("No oper news items to delete!"),
+ _("All oper news items deleted.")}
+ },
+ {NEWS_RANDOM, "RANDOM",
+ {_("RANDOMNEWS {ADD|DEL|LIST} [\037text\037|\037num\037]\002"),
+ _("Random news items:"),
+ _("There is no random news."),
+ _("Added new random news item."),
+ _("Random news item #{0} not found!"),
+ _("Random news item #{0} deleted."),
+ _("No random news items to delete!"),
+ _("All random news items deleted.")}
+ }
+};
+
+class NewsItemImpl : public NewsItem
+{
+ public:
+ NewsItemImpl(Serialize::TypeBase *type) : NewsItem(type) { }
+ NewsItemImpl(Serialize::TypeBase *type, Serialize::ID id) : NewsItem(type, id) { }
+
+ NewsType GetNewsType() override;
+ void SetNewsType(const NewsType &) override;
+
+ Anope::string GetText() override;
+ void SetText(const Anope::string &) override;
+
+ Anope::string GetWho() override;
+ void SetWho(const Anope::string &) override;
+
+ time_t GetTime() override;
+ void SetTime(const time_t &) override;
+};
+
+class NewsItemType : public Serialize::Type<NewsItemImpl>
+{
+ public:
+ Serialize::Field<NewsItemImpl, NewsType> type;
+ Serialize::Field<NewsItemImpl, Anope::string> text;
+ Serialize::Field<NewsItemImpl, Anope::string> who;
+ Serialize::Field<NewsItemImpl, time_t> time;
+
+ NewsItemType(Module *me) : Serialize::Type<NewsItemImpl>(me, "NewsItem")
+ , type(this, "type")
+ , text(this, "text")
+ , who(this, "who")
+ , time(this, "time")
+ {
+ }
+};
+
+NewsType NewsItemImpl::GetNewsType()
+{
+ return Get(&NewsItemType::type);
+}
+
+void NewsItemImpl::SetNewsType(const NewsType &t)
+{
+ Set(&NewsItemType::type, t);
+}
+
+Anope::string NewsItemImpl::GetText()
+{
+ return Get(&NewsItemType::text);
+}
+
+void NewsItemImpl::SetText(const Anope::string &t)
+{
+ Set(&NewsItemType::text, t);
+}
+
+Anope::string NewsItemImpl::GetWho()
+{
+ return Get(&NewsItemType::who);
+}
+
+void NewsItemImpl::SetWho(const Anope::string &w)
+{
+ Set(&NewsItemType::who, w);
+}
+
+time_t NewsItemImpl::GetTime()
+{
+ return Get(&NewsItemType::time);
+}
+
+void NewsItemImpl::SetTime(const time_t &t)
+{
+ Set(&NewsItemType::time, t);
+}
+
+static const char **findmsgs(NewsType type)
+{
+ for (unsigned i = 0; i < sizeof(msgarray) / sizeof(*msgarray); ++i)
+ if (msgarray[i].type == type)
+ return msgarray[i].msgs;
+ return NULL;
+}
+
+class NewsBase : public Command
+{
+ protected:
+ void DoList(CommandSource &source, NewsType ntype, const char **msgs)
+ {
+ std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(newsitem);
+
+ if (list.empty())
+ {
+ source.Reply(msgs[MSG_LIST_NONE]);
+ return;
+ }
+
+ ListFormatter lflist(source.GetAccount());
+ lflist.AddColumn(_("Number")).AddColumn(_("Creator")).AddColumn(_("Created")).AddColumn(_("Text"));
+
+ unsigned int i = 1;
+ for (NewsItem *n : list)
+ {
+ ListFormatter::ListEntry entry;
+ entry["Number"] = stringify(i++ + 1);
+ entry["Creator"] = n->GetWho();
+ entry["Created"] = Anope::strftime(n->GetTime(), NULL, true);
+ entry["Text"] = n->GetText();
+ lflist.AddEntry(entry);
+ }
+
+ source.Reply(msgs[MSG_LIST_HEADER]);
+
+ std::vector<Anope::string> replies;
+ lflist.Process(replies);
+
+ for (i = 0; i < replies.size(); ++i)
+ source.Reply(replies[i]);
+
+ source.Reply(_("End of news list."));
+ }
+
+ void DoAdd(CommandSource &source, const std::vector<Anope::string> &params, NewsType ntype, const char **msgs)
+ {
+ const Anope::string text = params.size() > 1 ? params[1] : "";
+
+ if (text.empty())
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ NewsItem *ni = newsitem.Create();
+ ni->SetNewsType(ntype);
+ ni->SetText(text);
+ ni->SetTime(Anope::CurTime);
+ ni->SetWho(source.GetNick());
+
+ source.Reply(msgs[MSG_ADDED]);
+ Log(LOG_ADMIN, source, this) << "to add a news item";
+ }
+
+ void DoDel(CommandSource &source, const std::vector<Anope::string> &params, NewsType ntype, const char **msgs)
+ {
+ const Anope::string &text = params.size() > 1 ? params[1] : "";
+ std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(newsitem);
+
+ if (text.empty())
+ {
+ this->OnSyntaxError(source, "DEL");
+ return;
+ }
+
+ if (list.empty())
+ {
+ source.Reply(msgs[MSG_LIST_NONE]);
+ return;
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ if (!text.equals_ci("ALL"))
+ {
+ try
+ {
+ unsigned num = convertTo<unsigned>(text);
+ if (num > 0 && num <= list.size())
+ {
+ list[num - 1]->Delete();
+ source.Reply(msgs[MSG_DELETED], num);
+ Log(LOG_ADMIN, source, this) << "to delete a news item";
+ return;
+ }
+ }
+ catch (const ConvertException &) { }
+
+ source.Reply(msgs[MSG_DEL_NOT_FOUND], text.c_str());
+ }
+ else
+ {
+ for (NewsItem *n : list)
+ n->Delete();
+ source.Reply(msgs[MSG_DELETED_ALL]);
+ Log(LOG_ADMIN, source, this) << "to delete all news items";
+ }
+ }
+
+ void DoNews(CommandSource &source, const std::vector<Anope::string> &params, NewsType ntype)
+ {
+ const Anope::string &cmd = params[0];
+
+ const char **msgs = findmsgs(ntype);
+ if (!msgs)
+ throw CoreException("news: Invalid type to do_news()");
+
+ if (cmd.equals_ci("LIST"))
+ return this->DoList(source, ntype, msgs);
+ else if (cmd.equals_ci("ADD"))
+ return this->DoAdd(source, params, ntype, msgs);
+ else if (cmd.equals_ci("DEL"))
+ return this->DoDel(source, params, ntype, msgs);
+ else
+ this->OnSyntaxError(source, "");
+ }
+ public:
+ NewsBase(Module *creator, const Anope::string &newstype) : Command(creator, newstype, 1, 2)
+ {
+ this->SetSyntax(_("ADD \037text\037"));
+ this->SetSyntax(_("DEL {\037num\037 | ALL}"));
+ this->SetSyntax("LIST");
+ }
+
+ virtual void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_abstract;
+
+ virtual bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_abstract;
+};
+
+class CommandOSLogonNews : public NewsBase
+{
+ public:
+ CommandOSLogonNews(Module *creator) : NewsBase(creator, "operserv/logonnews")
+ {
+ this->SetDesc(_("Define messages to be shown to users at logon"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ return this->DoNews(source, params, NEWS_LOGON);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Edits or displays the list of logon news messages. When a user connects to the network, these messages will be sent to them."
+ " However, no more than \002{0}\002 messages will be sent in order to avoid flooding the user."
+ " If there are more news messages, only the most recent will be sent."),
+ Config->GetModule(this->owner)->Get<unsigned>("newscount", "3"));
+ return true;
+ }
+};
+
+class CommandOSOperNews : public NewsBase
+{
+ public:
+ CommandOSOperNews(Module *creator) : NewsBase(creator, "operserv/opernews")
+ {
+ this->SetDesc(_("Define messages to be shown to users who oper"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ return this->DoNews(source, params, NEWS_OPER);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Edits or displays the list of oper news messages."
+ " When a user opers up (with the /OPER command), these messages will be sent to them."
+ " However, no more than \002{0}\002 messages will be sent in order to avoid flooding the user."
+ " If there are more news messages, only the most recent will be sent."),
+ Config->GetModule(this->owner)->Get<unsigned>("newscount", "3"));
+ return true;
+ }
+};
+
+class CommandOSRandomNews : public NewsBase
+{
+ public:
+ CommandOSRandomNews(Module *creator) : NewsBase(creator, "operserv/randomnews")
+ {
+ this->SetDesc(_("Define messages to be randomly shown to users at logon"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ return this->DoNews(source, params, NEWS_RANDOM);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Edits or displays the list of random news messages. When a user connects to the network, one (and only one) of the random news will be randomly chosen and sent to them."));
+ return true;
+ }
+};
+
+class OSNews : public Module
+ , public EventHook<Event::UserModeSet>
+ , public EventHook<Event::UserConnect>
+{
+ NewsItemType newsitemtype;
+
+ CommandOSLogonNews commandoslogonnews;
+ CommandOSOperNews commandosopernews;
+ CommandOSRandomNews commandosrandomnews;
+
+ Anope::string oper_announcer, announcer;
+ unsigned news_count;
+ unsigned cur_rand_news = 0;
+
+ void DisplayNews(User *u, NewsType Type)
+ {
+ std::vector<NewsItem *> list = Serialize::GetObjects<NewsItem *>(newsitem);
+ if (list.empty())
+ return;
+
+ ServiceBot *bi = NULL;
+ if (Type == NEWS_OPER)
+ bi = ServiceBot::Find(Config->GetModule(this)->Get<Anope::string>("oper_announcer", "OperServ"), true);
+ else
+ bi = ServiceBot::Find(Config->GetModule(this)->Get<Anope::string>("announcer", "Global"), true);
+ if (bi == NULL)
+ return;
+
+ Anope::string msg;
+ if (Type == NEWS_LOGON)
+ msg = _("[\002Logon News\002 - {0}] {1}");
+ else if (Type == NEWS_OPER)
+ msg = _("[\002Oper News\002 - {0}] {1}");
+ else if (Type == NEWS_RANDOM)
+ msg = _("[\002Random News\002 - {0}] {1]");
+ else
+ return;
+
+ unsigned int randnews = 0;
+ for (NewsItem *n : list)
+ if (n->GetNewsType() == NEWS_RANDOM)
+ ++randnews;
+
+ /* Reset to head of list to get first random news value */
+ if (Type == NEWS_RANDOM && cur_rand_news >= randnews)
+ cur_rand_news = 0;
+
+ unsigned i = 0, displayed = 0;
+ for (NewsItem *n : list)
+ {
+ if (n->GetNewsType() != Type)
+ continue;
+
+ if (Type == NEWS_RANDOM && i++ != cur_rand_news)
+ continue;
+
+ u->SendMessage(bi, msg.c_str(), Anope::strftime(n->GetTime(), u->Account(), true), n->GetText());
+
+ ++displayed;
+
+ if (Type == NEWS_RANDOM)
+ {
+ ++cur_rand_news;
+ break;
+ }
+
+ if (displayed >= news_count)
+ break;
+ }
+ }
+
+ public:
+ OSNews(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , newsitemtype(this)
+ , commandoslogonnews(this)
+ , commandosopernews(this)
+ , commandosrandomnews(this)
+ {
+ }
+
+ void OnReload(Configuration::Conf *conf) override
+ {
+ oper_announcer = conf->GetModule(this)->Get<Anope::string>("oper_announcer", "OperServ");
+ announcer = conf->GetModule(this)->Get<Anope::string>("announcer", "Global");
+ news_count = conf->GetModule(this)->Get<unsigned>("newscount", "3");
+ }
+
+ void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override
+ {
+ if (mname == "OPER")
+ DisplayNews(u, NEWS_OPER);
+ }
+
+ void OnUserConnect(User *user, bool &) override
+ {
+ if (user->Quitting() || !user->server->IsSynced())
+ return;
+
+ DisplayNews(user, NEWS_LOGON);
+ DisplayNews(user, NEWS_RANDOM);
+ }
+};
+
+MODULE_INIT(OSNews)
diff --git a/modules/operserv/noop.cpp b/modules/operserv/noop.cpp
new file mode 100644
index 000000000..a12bef6a2
--- /dev/null
+++ b/modules/operserv/noop.cpp
@@ -0,0 +1,98 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSNOOP : public Command
+{
+ public:
+ CommandOSNOOP(Module *creator) : Command(creator, "operserv/noop", 2, 2)
+ {
+ this->SetDesc(_("Remove all operators from a server remotely"));
+ this->SetSyntax(_("SET \037server\037"));
+ this->SetSyntax(_("REVOKE \037server\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &cmd = params[0];
+ const Anope::string &server = params[1];
+
+ Server *s = Server::Find(server, true);
+ if (s == NULL)
+ source.Reply(_("Server \002{0}\002 does not exist."), server);
+ else if (s == Me || s->IsJuped() || s->IsULined())
+ source.Reply(_("You can not NOOP Services."));
+ else if (cmd.equals_ci("SET"))
+ {
+ /* Remove the O:lines */
+ IRCD->SendSVSNOOP(s, true);
+ s->Extend<Anope::string>("noop", source.GetNick());
+
+ Log(LOG_ADMIN, source, this) << "SET on " << s->GetName();
+ source.Reply(_("All operators from \002{0}\002 have been removed."), s->GetName());
+
+ Anope::string reason = "NOOP command used by " + source.GetNick();
+ /* Kill all the IRCops of the server */
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ {
+ User *u2 = it->second;
+
+ if (u2->server == s && u2->HasMode("OPER"))
+ u2->Kill(*source.service, reason);
+ }
+ }
+ else if (cmd.equals_ci("REVOKE"))
+ {
+ s->ShrinkOK<Anope::string>("noop");
+ IRCD->SendSVSNOOP(s, false);
+ Log(LOG_ADMIN, source, this) << "REVOKE on " << s->GetName();
+ source.Reply(_("All O:lines of \002{0}\002 have been reset."), s->GetName());
+ }
+ else
+ this->OnSyntaxError(source, "");
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("\002{0} SET\002 kills all operators from the given \002server\002 and prevents operators from opering up on the given server."
+ " \002{0} REVOKE\002 removes this restriction."));
+ return true;
+ }
+};
+
+class OSNOOP : public Module
+ , public EventHook<Event::UserModeSet>
+{
+ CommandOSNOOP commandosnoop;
+ ExtensibleItem<Anope::string> noop;
+
+ public:
+ OSNOOP(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosnoop(this)
+ , noop(this, "noop")
+ {
+
+ }
+
+ void OnUserModeSet(const MessageSource &, User *u, const Anope::string &mname) override
+ {
+ Anope::string *setter;
+ if (mname == "OPER" && (setter = noop.Get(u->server)))
+ {
+ Anope::string reason = "NOOP command used by " + *setter;
+ ServiceBot *OperServ = Config->GetClient("OperServ");
+ u->Kill(OperServ, reason);
+ }
+ }
+};
+
+MODULE_INIT(OSNOOP)
diff --git a/modules/operserv/oline.cpp b/modules/operserv/oline.cpp
new file mode 100644
index 000000000..34c13a4a3
--- /dev/null
+++ b/modules/operserv/oline.cpp
@@ -0,0 +1,74 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSOLine : public Command
+{
+ public:
+ CommandOSOLine(Module *creator) : Command(creator, "operserv/oline", 2, 2)
+ {
+ this->SetDesc(_("Give Operflags to a certain user"));
+ this->SetSyntax(_("\037nick\037 \037flags\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &nick = params[0];
+ const Anope::string &flag = params[1];
+ User *u2 = NULL;
+
+ /* let's check whether the user is online */
+ if (!(u2 = User::Find(nick, true)))
+ source.Reply(_("\002{0}\002 isn't currently online."), nick);
+ else if (u2 && flag[0] == '+')
+ {
+ IRCD->SendSVSO(source.service, nick, flag);
+ u2->SetMode(source.service, "OPER");
+ u2->SendMessage(*source.service, _("You are now an IRC Operator."));
+ source.Reply(_("Operflags \002{0}\002 have been added for \002{1}\002."), flag, nick);
+ Log(LOG_ADMIN, source, this) << "for " << nick;
+ }
+ else if (u2 && flag[0] == '-')
+ {
+ IRCD->SendSVSO(source.service, nick, flag);
+ source.Reply(_("Operflags \002{0}\002 have been removed from \002{1}\002."), flag, nick);
+ Log(LOG_ADMIN, source, this) << "for " << nick;
+ }
+ else
+ this->OnSyntaxError(source, "");
+
+ return;
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Allows Services Operators to give Operflags to any user. Flags have to be prefixed with a \"+\" or a \"-\". To remove all flags simply type a \"-\" instead of any flags."));
+ return true;
+ }
+};
+
+class OSOLine : public Module
+{
+ CommandOSOLine commandosoline;
+
+ public:
+ OSOLine(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosoline(this)
+ {
+
+ if (!IRCD || !IRCD->CanSVSO)
+ throw ModuleException("Your IRCd does not support OMODE.");
+
+ }
+};
+
+MODULE_INIT(OSOLine)
diff --git a/modules/operserv/oper.cpp b/modules/operserv/oper.cpp
new file mode 100644
index 000000000..923137013
--- /dev/null
+++ b/modules/operserv/oper.cpp
@@ -0,0 +1,241 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSOper : public Command
+{
+ bool HasPrivs(CommandSource &source, OperType *ot) const
+ {
+ std::list<Anope::string> commands = ot->GetCommands(), privs = ot->GetPrivs();
+
+ for (std::list<Anope::string>::iterator it = commands.begin(); it != commands.end(); ++it)
+ if (!source.HasCommand(*it))
+ return false;
+
+ for (std::list<Anope::string>::iterator it = privs.begin(); it != privs.end(); ++it)
+ if (!source.HasPriv(*it))
+ return false;
+
+ return true;
+ }
+
+ public:
+ CommandOSOper(Module *creator) : Command(creator, "operserv/oper", 1, 3)
+ {
+ this->SetDesc(_("View and change Services Operators"));
+ this->SetSyntax(_("ADD \037oper\037 \037type\037"));
+ this->SetSyntax(_("DEL \037oper\037"));
+ this->SetSyntax(_("INFO [\037type\037]"));
+ this->SetSyntax("LIST");
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &subcommand = params[0];
+
+ if (subcommand.equals_ci("ADD") && params.size() > 2)
+ {
+ const Anope::string &oper = params[1];
+ const Anope::string &otype = params[2];
+
+ if (!source.HasPriv("operserv/oper/modify"))
+ {
+ source.Reply(_("Access denied. You do not have the operator privilege \002{0}\002."), "operserv/oper/modify");
+ return;
+ }
+
+ NickServ::Nick *na = NickServ::FindNick(oper);
+ if (na == NULL)
+ {
+ source.Reply(_("\002{0}\002 isn't currently online."), oper);
+ return;
+ }
+
+ OperType *ot = OperType::Find(otype);
+ if (ot == NULL)
+ {
+ source.Reply(_("Oper type \002{0}\002 has not been configured."), otype);
+ return;
+ }
+
+ if (!HasPrivs(source, ot))
+ {
+ source.Reply(_("Access denied."));
+ return;
+ }
+
+ if (na->GetAccount()->o)
+ {
+ na->GetAccount()->o->Delete();
+ na->GetAccount()->o = nullptr;
+ }
+
+ Oper *o = operblock.Create();
+ o->SetName(na->GetAccount()->GetDisplay());
+ o->SetType(ot);
+ o->SetRequireOper(true);
+
+ na->GetAccount()->o = o;
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ Log(LOG_ADMIN, source, this) << "ADD " << na->GetNick() << " as type " << ot->GetName();
+ source.Reply("\002{0}\002 (\002{1}\002) added to the \002{2}\002 list.", na->GetNick(), na->GetAccount()->GetDisplay(), ot->GetName());
+ }
+ else if (subcommand.equals_ci("DEL") && params.size() > 1)
+ {
+ const Anope::string &oper = params[1];
+
+ if (!source.HasPriv("operserv/oper/modify"))
+ {
+ source.Reply(_("Access denied. You do not have the operator privilege \002{0}\002."), "operserv/oper/modify");
+ return;
+ }
+
+ NickServ::Nick *na = NickServ::FindNick(oper);
+ if (na == NULL)
+ {
+ source.Reply(_("\002{0}\002 isn't registered."), oper);
+ return;
+ }
+
+ if (!na->GetAccount() || !na->GetAccount()->o)
+ {
+ source.Reply(_("Nick \002{0}\002 is not a Services Operator."), oper);
+ return;
+ }
+
+ if (!HasPrivs(source, na->GetAccount()->o->GetType()))
+ {
+ source.Reply(_("Access denied."));
+ return;
+ }
+
+ na->GetAccount()->o->Delete();
+ na->GetAccount()->o = NULL;
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+
+ Log(LOG_ADMIN, source, this) << "DEL " << na->GetNick();
+ source.Reply(_("Oper privileges removed from \002{0}\002 (\002{1}\002)."), na->GetNick(), na->GetAccount()->GetDisplay());
+ }
+ else if (subcommand.equals_ci("LIST"))
+ {
+ source.Reply(_("Name Type"));
+ for (NickServ::Account *nc : NickServ::service->GetAccountList())
+ {
+ if (!nc->o)
+ continue;
+
+ source.Reply(Anope::printf("%-8s %s", nc->o->GetName().c_str(), nc->o->GetType()->GetName().c_str()));
+ if (nc->o->conf)
+ source.Reply(_(" This oper is configured in the configuration file."));
+ for (User *u : nc->users)
+ source.Reply(_(" \002{0}\002 is online using this oper block."), u->nick);
+ }
+ }
+ else if (subcommand.equals_ci("INFO"))
+ {
+ if (params.size() < 2)
+ {
+ source.Reply(_("Available opertypes:"));
+ for (unsigned i = 0; i < Config->MyOperTypes.size(); ++i)
+ {
+ OperType *ot = Config->MyOperTypes[i];
+ source.Reply("%s", ot->GetName().c_str());
+ }
+ return;
+ }
+
+ Anope::string fulltype = params[1];
+ if (params.size() > 2)
+ fulltype += " " + params[2];
+ OperType *ot = OperType::Find(fulltype);
+ if (ot == NULL)
+ {
+ source.Reply(_("Oper type \002{0}\002 has not been configured."), fulltype);
+ return;
+ }
+
+ if (ot->GetCommands().empty())
+ source.Reply(_("Opertype \002{0}\002 has no allowed commands."), ot->GetName());
+ else
+ {
+ source.Reply(_("Available commands for \002{0}\002:"), ot->GetName());
+ Anope::string buf;
+ std::list<Anope::string> cmds = ot->GetCommands();
+ for (std::list<Anope::string>::const_iterator it = cmds.begin(), it_end = cmds.end(); it != it_end; ++it)
+ {
+ buf += *it + " ";
+ if (buf.length() > 400)
+ {
+ source.Reply("%s", buf.c_str());
+ buf.clear();
+ }
+ }
+ if (!buf.empty())
+ {
+ source.Reply("%s", buf.c_str());
+ buf.clear();
+ }
+ }
+ if (ot->GetPrivs().empty())
+ source.Reply(_("Opertype \002{0}\002 has no allowed privileges."), ot->GetName());
+ else
+ {
+ source.Reply(_("Available privileges for \002{0}\002:"), ot->GetName());
+ Anope::string buf;
+ std::list<Anope::string> privs = ot->GetPrivs();
+ for (std::list<Anope::string>::const_iterator it = privs.begin(), it_end = privs.end(); it != it_end; ++it)
+ {
+ buf += *it + " ";
+ if (buf.length() > 400)
+ {
+ source.Reply("%s", buf.c_str());
+ buf.clear();
+ }
+ }
+ if (!buf.empty())
+ {
+ source.Reply("%s", buf.c_str());
+ buf.clear();
+ }
+ }
+ if (!ot->modes.empty())
+ source.Reply(_("Opertype \002{0}\002 receives modes \002{1}\002 once identified."), ot->GetName(), ot->modes);
+ }
+ else
+ this->OnSyntaxError(source, subcommand);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Allows you to change and view Services Operators.\n"
+ " Note that operators removed by this command but are still set in the configuration file are not permanently affected by this."));
+ return true;
+ }
+};
+
+class OSOper : public Module
+{
+ CommandOSOper commandosoper;
+
+ public:
+ OSOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosoper(this)
+ {
+ }
+};
+
+MODULE_INIT(OSOper)
diff --git a/modules/operserv/reload.cpp b/modules/operserv/reload.cpp
new file mode 100644
index 000000000..217194e18
--- /dev/null
+++ b/modules/operserv/reload.cpp
@@ -0,0 +1,62 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSReload : public Command
+{
+ public:
+ CommandOSReload(Module *creator) : Command(creator, "operserv/reload", 0, 0)
+ {
+ this->SetDesc(_("Reload services' configuration file"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ try
+ {
+ Log(LOG_ADMIN, source, this);
+
+ Configuration::Conf *new_config = new Configuration::Conf();
+ Configuration::Conf *old = Config;
+ Config = new_config;
+ Config->Post(old);
+ delete old;
+
+ source.Reply(_("Services' configuration has been reloaded."));
+ }
+ catch (const ConfigException &ex)
+ {
+ Log(this->owner) << "Error reloading configuration file: " << ex.GetReason();
+ source.Reply(_("Error reloading configuration file: {0}"), ex.GetReason());
+ }
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Causes Services to reload the configuration file."));
+ return true;
+ }
+};
+
+class OSReload : public Module
+{
+ CommandOSReload commandosreload;
+
+ public:
+ OSReload(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosreload(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSReload)
diff --git a/modules/operserv/session.cpp b/modules/operserv/session.cpp
new file mode 100644
index 000000000..997914360
--- /dev/null
+++ b/modules/operserv/session.cpp
@@ -0,0 +1,768 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+#include "modules/os_session.h"
+
+namespace
+{
+ /* The default session limit */
+ unsigned session_limit;
+ /* How many times to kill before adding an AKILL */
+ unsigned max_session_kill;
+ /* How long session akills should last */
+ time_t session_autokill_expiry;
+ /* Reason to use for session kills */
+ Anope::string sle_reason;
+ /* Optional second reason */
+ Anope::string sle_detailsloc;
+
+ /* Max limit that can be used for exceptions */
+ unsigned max_exception_limit;
+ /* How long before exceptions expire by default */
+ time_t exception_expiry;
+
+ /* Number of bits to use when comparing session IPs */
+ unsigned ipv4_cidr;
+ unsigned ipv6_cidr;
+
+ EventHandlers<Event::Exception> *events;
+}
+
+class ExceptionImpl : public Exception
+{
+ public:
+ ExceptionImpl(Serialize::TypeBase *type) : Exception(type) { }
+ ExceptionImpl(Serialize::TypeBase *type, Serialize::ID id) : Exception(type, id) { }
+
+ Anope::string GetMask() override;
+ void SetMask(const Anope::string &) override;
+
+ unsigned int GetLimit() override;
+ void SetLimit(unsigned int) override;
+
+ Anope::string GetWho() override;
+ void SetWho(const Anope::string &) override;
+
+ Anope::string GetReason() override;
+ void SetReason(const Anope::string &) override;
+
+ time_t GetTime() override;
+ void SetTime(const time_t &) override;
+
+ time_t GetExpires() override;
+ void SetExpires(const time_t &) override;
+};
+
+class ExceptionType : public Serialize::Type<ExceptionImpl>
+{
+ public:
+ Serialize::Field<ExceptionImpl, Anope::string> mask, who, reason;
+ Serialize::Field<ExceptionImpl, unsigned int> limit;
+ Serialize::Field<ExceptionImpl, time_t> time, expires;
+
+ ExceptionType(Module *me) : Serialize::Type<ExceptionImpl>(me, "Exception")
+ , mask(this, "mask")
+ , who(this, "who")
+ , reason(this, "reason")
+ , limit(this, "limit")
+ , time(this, "time")
+ , expires(this, "expires")
+ {
+ }
+};
+
+Anope::string ExceptionImpl::GetMask()
+{
+ return Get(&ExceptionType::mask);
+}
+
+void ExceptionImpl::SetMask(const Anope::string &m)
+{
+ Set(&ExceptionType::mask, m);
+}
+
+unsigned int ExceptionImpl::GetLimit()
+{
+ return Get(&ExceptionType::limit);
+}
+
+void ExceptionImpl::SetLimit(unsigned int l)
+{
+ Set(&ExceptionType::limit, l);
+}
+
+Anope::string ExceptionImpl::GetWho()
+{
+ return Get(&ExceptionType::who);
+}
+
+void ExceptionImpl::SetWho(const Anope::string &w)
+{
+ Set(&ExceptionType::who, w);
+}
+
+Anope::string ExceptionImpl::GetReason()
+{
+ return Get(&ExceptionType::reason);
+}
+
+void ExceptionImpl::SetReason(const Anope::string &r)
+{
+ Set(&ExceptionType::reason, r);
+}
+
+time_t ExceptionImpl::GetTime()
+{
+ return Get(&ExceptionType::time);
+}
+
+void ExceptionImpl::SetTime(const time_t &t)
+{
+ Set(&ExceptionType::time, t);
+}
+
+time_t ExceptionImpl::GetExpires()
+{
+ return Get(&ExceptionType::expires);
+}
+
+void ExceptionImpl::SetExpires(const time_t &e)
+{
+ Set(&ExceptionType::expires, e);
+}
+
+class MySessionService : public SessionService
+{
+ SessionMap Sessions;
+
+ public:
+ MySessionService(Module *m) : SessionService(m) { }
+
+ Exception *FindException(User *u) override
+ {
+ for (Exception *e : Serialize::GetObjects<Exception *>(exception))
+ {
+ if (Anope::Match(u->host, e->GetMask()) || Anope::Match(u->ip.addr(), e->GetMask()))
+ return e;
+
+ if (cidr(e->GetMask()).match(u->ip))
+ return e;
+ }
+ return nullptr;
+ }
+
+ Exception *FindException(const Anope::string &host) override
+ {
+ for (Exception *e : Serialize::GetObjects<Exception *>(exception))
+ {
+ if (Anope::Match(host, e->GetMask()))
+ return e;
+
+ if (cidr(e->GetMask()).match(sockaddrs(host)))
+ return e;
+ }
+
+ return nullptr;
+ }
+
+ void DelSession(Session *s)
+ {
+ this->Sessions.erase(s->addr);
+ }
+
+ Session *FindSession(const Anope::string &ip) override
+ {
+ cidr c(ip, ip.find(':') != Anope::string::npos ? ipv6_cidr : ipv4_cidr);
+ if (!c.valid())
+ return NULL;
+ SessionMap::iterator it = this->Sessions.find(c);
+ if (it != this->Sessions.end())
+ return it->second;
+ return NULL;
+ }
+
+ SessionMap::iterator FindSessionIterator(const sockaddrs &ip)
+ {
+ cidr c(ip, ip.ipv6() ? ipv6_cidr : ipv4_cidr);
+ if (!c.valid())
+ return this->Sessions.end();
+ return this->Sessions.find(c);
+ }
+
+ Session* &FindOrCreateSession(const cidr &ip)
+ {
+ return this->Sessions[ip];
+ }
+
+ SessionMap &GetSessions() override
+ {
+ return this->Sessions;
+ }
+};
+
+class CommandOSSession : public Command
+{
+ private:
+ void DoList(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ Anope::string param = params[1];
+
+ unsigned mincount = 0;
+ try
+ {
+ mincount = convertTo<unsigned>(param);
+ }
+ catch (const ConvertException &) { }
+
+ if (mincount <= 1)
+ {
+ source.Reply(_("Invalid threshold value. It must be a valid integer greater than 1."));
+ return;
+ }
+
+ ListFormatter list(source.GetAccount());
+ list.AddColumn(_("Session")).AddColumn(_("Host"));
+
+ for (SessionService::SessionMap::iterator it = session_service->GetSessions().begin(), it_end = session_service->GetSessions().end(); it != it_end; ++it)
+ {
+ Session *session = it->second;
+
+ if (session->count >= mincount)
+ {
+ ListFormatter::ListEntry entry;
+ entry["Session"] = stringify(session->count);
+ entry["Host"] = session->addr.mask();
+ list.AddEntry(entry);
+ }
+ }
+
+ source.Reply(_("Hosts with at least \002{0}\002 sessions:"), mincount);
+
+ std::vector<Anope::string> replies;
+ list.Process(replies);
+
+ for (unsigned i = 0; i < replies.size(); ++i)
+ source.Reply(replies[i]);
+ }
+
+ void DoView(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ Anope::string param = params[1];
+ Session *session = session_service->FindSession(param);
+
+ Exception *e = session_service->FindException(param);
+ Anope::string entry = "no entry";
+ unsigned limit = session_limit;
+ if (e)
+ {
+ if (!e->GetLimit())
+ limit = 0;
+ else if (e->GetLimit() > limit)
+ limit = e->GetLimit();
+ entry = e->GetMask();
+ }
+
+ if (!session)
+ source.Reply(_("\002{0}\002 not found on the session list, but has a limit of \002{1}\002 because it matches entry: \002{2}\002."), param, limit, entry);
+ else
+ source.Reply(_("The host \002{0}\002 currently has \002{1}\002 sessions with a limit of \002{2}\002 because it matches entry: \002{3}\002."), session->addr.mask(), session->count, limit, entry);
+ }
+
+ public:
+ CommandOSSession(Module *creator) : Command(creator, "operserv/session", 2, 2)
+ {
+ this->SetDesc(_("View the list of host sessions"));
+ this->SetSyntax(_("LIST \037threshold\037"));
+ this->SetSyntax(_("VIEW \037host\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &cmd = params[0];
+
+ Log(LOG_ADMIN, source, this) << cmd << " " << params[1];
+
+ if (!session_limit)
+ source.Reply(_("Session limiting is disabled."));
+ else if (cmd.equals_ci("LIST"))
+ this->DoList(source, params);
+ else if (cmd.equals_ci("VIEW"))
+ this->DoView(source, params);
+ else
+ this->OnSyntaxError(source, "");
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Allows Services Operators to view the session list.\n"
+ "\n"
+ "\002{0} LIST\002 lists hosts with at least \037threshold\037 sessions. The threshold must be a number greater than 1.\n"
+ "\n"
+ "\002{0} VIEW\002 displays detailed information about a specific host - including the current session count and session limit.\n"
+ "\n"
+ "See the \002EXCEPTION\002 help for more information about session limiting and how to set session limits specific to certain hosts and groups thereof."), // XXX
+ source.command);
+ return true;
+ }
+};
+
+class CommandOSException : public Command
+{
+ static void DoDel(CommandSource &source, Exception *e)
+ {
+ (*events)(&Event::Exception::OnExceptionDel, source, e);
+ e->Delete();
+ }
+
+ void DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ Anope::string mask, expiry, limitstr;
+ unsigned last_param = 3;
+
+ mask = params.size() > 1 ? params[1] : "";
+ if (!mask.empty() && mask[0] == '+')
+ {
+ expiry = mask;
+ mask = params.size() > 2 ? params[2] : "";
+ last_param = 4;
+ }
+
+ limitstr = params.size() > last_param - 1 ? params[last_param - 1] : "";
+
+ if (params.size() <= last_param)
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ Anope::string reason = params[last_param];
+ if (last_param == 3 && params.size() > 4)
+ reason += " " + params[4];
+ if (reason.empty())
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ time_t expires = !expiry.empty() ? Anope::DoTime(expiry) : exception_expiry;
+ if (expires < 0)
+ {
+ source.Reply(_("Invalid expiry time \002{0}\002."), expiry);
+ return;
+ }
+ else if (expires > 0)
+ expires += Anope::CurTime;
+
+ unsigned limit = -1;
+ try
+ {
+ limit = convertTo<unsigned>(limitstr);
+ }
+ catch (const ConvertException &) { }
+
+ if (limit > max_exception_limit)
+ {
+ source.Reply(_("Invalid session limit. It must be a valid integer greater than or equal to zero and less than \002{0}\002."), max_exception_limit);
+ return;
+ }
+ else
+ {
+ if (mask.find('!') != Anope::string::npos || mask.find('@') != Anope::string::npos)
+ {
+ source.Reply(_("Invalid hostmask. Only real hostmasks are valid, as exceptions are not matched against nicks or usernames."));
+ return;
+ }
+
+ for (Exception *e : Serialize::GetObjects<Exception *>(exception))
+ if (e->GetMask().equals_ci(mask))
+ {
+ if (e->GetLimit() != limit)
+ {
+ e->SetLimit(limit);
+ source.Reply(_("Exception for \002{0}\002 has been updated to \002{1}\002."), mask, e->GetLimit());
+ }
+ else
+ source.Reply(_("\002{0}\002 already exists on the session-limit exception list."), mask);
+ return;
+ }
+
+ Exception *e = exception.Create();
+ e->SetMask(mask);
+ e->SetLimit(limit);
+ e->SetReason(reason);
+ e->SetTime(Anope::CurTime);
+ e->SetWho(source.GetNick());
+ e->SetExpires(expires);
+
+ EventReturn MOD_RESULT;
+ MOD_RESULT = (*events)(&Event::Exception::OnExceptionAdd, e);
+ if (MOD_RESULT == EVENT_STOP)
+ return;
+
+ Log(LOG_ADMIN, source, this) << "to set the session limit for " << mask << " to " << limit;
+ source.Reply(_("Session limit for \002{0}\002 set to \002{1}\002."), mask, limit);
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ }
+ }
+
+ void DoDel(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string &mask = params.size() > 1 ? params[1] : "";
+
+ if (mask.empty())
+ {
+ this->OnSyntaxError(source, "DEL");
+ return;
+ }
+
+ if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
+ {
+ unsigned int deleted = 0;
+
+ NumberList(mask, true,
+ [&](unsigned int number)
+ {
+ std::vector<Exception *> exceptions = Serialize::GetObjects<Exception *>(exception);
+ if (!number || number > exceptions.size())
+ return;
+
+ Exception *e = exceptions[number - 1];
+
+ Log(LOG_ADMIN, source, this) << "to remove the session limit exception for " << e->GetMask();
+
+ ++deleted;
+ DoDel(source, e);
+ },
+ [&]()
+ {
+ if (!deleted)
+ source.Reply(_("No matching entries on session-limit exception list."));
+ else if (deleted == 1)
+ source.Reply(_("Deleted \0021\002 entry from session-limit exception list."));
+ else
+ source.Reply(_("Deleted \002{0}\002 entries from session-limit exception list."), deleted);
+ });
+ }
+ else
+ {
+ bool found = false;
+ for (Exception *e : Serialize::GetObjects<Exception *>(exception))
+ if (mask.equals_ci(e->GetMask()))
+ {
+ Log(LOG_ADMIN, source, this) << "to remove the session limit exception for " << mask;
+ DoDel(source, e);
+ source.Reply(_("\002{0}\002 deleted from session-limit exception list."), mask);
+ found = true;
+ break;
+ }
+ if (!found)
+ source.Reply(_("\002{0}\002 not found on session-limit exception list."), mask);
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ }
+
+ void ProcessList(CommandSource &source, const std::vector<Anope::string> &params, ListFormatter &list)
+ {
+ const Anope::string &mask = params.size() > 1 ? params[1] : "";
+ std::vector<Exception *> exceptions = Serialize::GetObjects<Exception *>(exception);
+
+ if (exceptions.empty())
+ {
+ source.Reply(_("The session exception list is empty."));
+ return;
+ }
+
+ if (!mask.empty() && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
+ {
+ NumberList(mask, false,
+ [&](unsigned int number)
+ {
+ if (!number || number > exceptions.size())
+ return;
+
+ Exception *e = exceptions[number - 1];
+
+ ListFormatter::ListEntry entry;
+ entry["Number"] = stringify(number);
+ entry["Mask"] = e->GetMask();
+ entry["By"] = e->GetWho();
+ entry["Created"] = Anope::strftime(e->GetTime(), NULL, true);
+ entry["Expires"] = Anope::Expires(e->GetExpires(), source.GetAccount());
+ entry["Limit"] = stringify(e->GetLimit());
+ entry["Reason"] = e->GetReason();
+ list.AddEntry(entry);
+ },
+ []{});
+ }
+ else
+ {
+ unsigned int i = 0;
+ for (Exception *e : exceptions)
+ {
+ if (mask.empty() || Anope::Match(e->GetMask(), mask))
+ {
+ ListFormatter::ListEntry entry;
+ entry["Number"] = stringify(++i);
+ entry["Mask"] = e->GetMask();
+ entry["By"] = e->GetWho();
+ entry["Created"] = Anope::strftime(e->GetTime(), NULL, true);
+ entry["Expires"] = Anope::Expires(e->GetExpires(), source.GetAccount());
+ entry["Limit"] = stringify(e->GetLimit());
+ entry["Reason"] = e->GetReason();
+ list.AddEntry(entry);
+ }
+ }
+ }
+
+ if (list.IsEmpty())
+ {
+ source.Reply(_("No matching entries on session-limit exception list."));
+ return;
+ }
+
+ source.Reply(_("Session-limit exception list:"));
+
+ std::vector<Anope::string> replies;
+ list.Process(replies);
+
+ for (const Anope::string &r : replies)
+ source.Reply(r);
+ }
+
+ void DoList(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ ListFormatter list(source.GetAccount());
+ list.AddColumn(_("Number")).AddColumn(_("Limit")).AddColumn(_("Mask"));
+
+ this->ProcessList(source, params, list);
+ }
+
+ void DoView(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ ListFormatter list(source.GetAccount());
+ list.AddColumn(_("Number")).AddColumn(_("Mask")).AddColumn(_("By")).AddColumn(_("Created")).AddColumn(_("Expires")).AddColumn(_("Limit")).AddColumn(_("Reason"));
+
+ this->ProcessList(source, params, list);
+ }
+
+ public:
+ CommandOSException(Module *creator) : Command(creator, "operserv/exception", 1, 5)
+ {
+ this->SetDesc(_("Modify the session-limit exception list"));
+ this->SetSyntax(_("ADD [\037+expiry\037] \037mask\037 \037limit\037 \037reason\037"));
+ this->SetSyntax(_("DEL {\037mask\037 | \037entry-num\037 | \037list\037}"));
+ this->SetSyntax(_("LIST [\037mask\037 | \037list\037]"));
+ this->SetSyntax(_("VIEW [\037mask\037 | \037list\037]"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &cmd = params[0];
+
+ if (!session_limit)
+ source.Reply(_("Session limiting is disabled."));
+ else if (cmd.equals_ci("ADD"))
+ return this->DoAdd(source, params);
+ else if (cmd.equals_ci("DEL"))
+ return this->DoDel(source, params);
+ else if (cmd.equals_ci("LIST"))
+ return this->DoList(source, params);
+ else if (cmd.equals_ci("VIEW"))
+ return this->DoView(source, params);
+ else
+ this->OnSyntaxError(source, "");
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ if (subcommand.equals_ci("ADD"))
+ source.Reply(_("\002{0} ADD\002 adds the given hostmask to the exception list."
+ " Note that \002nick!user@host\002 and \002user@host\002 masks are invalid!\n"
+ " Only real host masks, such as \002box.host.dom\002 and \002*.host.dom\002, are allowed because sessions limiting does not take nickname or user names into account."
+ " \037limit\037 must be a number greater than or equal to zero."
+ " This determines how many sessions this host may carry at a time."
+ " A value of zero means the host has an unlimited session limit."
+ " If more than one entry matches a client, the first matching enty will be used."),
+ source.command);
+ else
+ source.Reply(_("Allows you to manipulate the list of hosts that have specific session limits - allowing certain machines, such as shell servers, to carry more than the default number of clients at a time."
+ " Once a host reaches its session limit, all clients attempting to connect from that host will be killed."
+ " Before the user is killed, they are notified, of a source of help regarding session limiting. The content of this notice is a config setting.\n"
+ "\n"
+ "\002{0} ADD\002 adds the given host mask to the exception list.\n"
+ "\002{msg}{service} {help} {command} ADD\002 for more information.\n"
+ "\n"
+ "\002{0} DEL\002 removes the given mask from the exception list.\n"
+ "\n"
+ "\002{0} LIST\002 and \002{0} VIEW\002 show all current sessions if the optional mask is given, the list is limited to those sessions matching the mask."
+ " The difference is that \002{0} VIEW\002 is more verbose, displaying the name of the person who added the exception, its session limit, reason, host mask and the expiry date and time.\n"));
+ return true;
+ }
+};
+
+class OSSession : public Module
+ , public EventHook<Event::UserConnect>
+ , public EventHook<Event::UserQuit>
+ , public EventHook<Event::ExpireTick>
+{
+ MySessionService ss;
+ CommandOSSession commandossession;
+ CommandOSException commandosexception;
+ ServiceReference<XLineManager> akills;
+ EventHandlers<Event::Exception> exceptionevents;
+ ExceptionType etype;
+
+ public:
+ OSSession(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::UserConnect>(EventHook<Event::UserConnect>::Priority::FIRST)
+ , EventHook<Event::UserQuit>(EventHook<Event::UserQuit>::Priority::FIRST)
+ , EventHook<Event::ExpireTick>(EventHook<Event::ExpireTick>::Priority::FIRST)
+ , ss(this)
+ , commandossession(this)
+ , commandosexception(this)
+ , akills("XLineManager", "xlinemanager/sgline")
+ , exceptionevents(this)
+ , etype(this)
+ {
+ this->SetPermanent(true);
+
+ events = &exceptionevents;
+ }
+
+ void OnReload(Configuration::Conf *conf) override
+ {
+ Configuration::Block *block = Config->GetModule(this);
+
+ session_limit = block->Get<int>("defaultsessionlimit");
+ max_session_kill = block->Get<int>("maxsessionkill");
+ session_autokill_expiry = block->Get<time_t>("sessionautokillexpiry");
+ sle_reason = block->Get<Anope::string>("sessionlimitexceeded");
+ sle_detailsloc = block->Get<Anope::string>("sessionlimitdetailsloc");
+
+ max_exception_limit = block->Get<int>("maxsessionlimit");
+ exception_expiry = block->Get<time_t>("exceptionexpiry");
+
+ ipv4_cidr = block->Get<unsigned>("session_ipv4_cidr", "32");
+ ipv6_cidr = block->Get<unsigned>("session_ipv6_cidr", "128");
+
+ if (ipv4_cidr > 32 || ipv6_cidr > 128)
+ throw ConfigException(this->name + ": session CIDR value out of range");
+ }
+
+ void OnUserConnect(User *u, bool &exempt) override
+ {
+ if (u->Quitting() || !session_limit || exempt || !u->server || u->server->IsULined())
+ return;
+
+ cidr u_ip(u->ip, u->ip.ipv6() ? ipv6_cidr : ipv4_cidr);
+ if (!u_ip.valid())
+ return;
+
+ Session* &session = this->ss.FindOrCreateSession(u_ip);
+
+ if (session)
+ {
+ bool kill = false;
+ if (session->count >= session_limit)
+ {
+ kill = true;
+ Exception *e = this->ss.FindException(u);
+ if (e)
+ {
+ kill = false;
+ if (e->GetLimit() && session->count >= e->GetLimit())
+ kill = true;
+ }
+ }
+
+ ++session->count;
+
+ if (kill && !exempt)
+ {
+ ServiceBot *OperServ = Config->GetClient("OperServ");
+ if (OperServ)
+ {
+ if (!sle_reason.empty())
+ {
+ Anope::string message = sle_reason.replace_all_cs("%IP%", u->ip.addr());
+ u->SendMessage(OperServ, message);
+ }
+ if (!sle_detailsloc.empty())
+ u->SendMessage(OperServ, sle_detailsloc);
+ }
+
+ ++session->hits;
+
+ const Anope::string &akillmask = "*@" + session->addr.mask();
+ if (max_session_kill && session->hits >= max_session_kill && akills && !akills->HasEntry(akillmask))
+ {
+ XLine *x = new XLine(akillmask, OperServ ? OperServ->nick : "", Anope::CurTime + session_autokill_expiry, "Session limit exceeded", XLineManager::GenerateUID());
+ akills->AddXLine(x);
+ akills->Send(NULL, x);
+ Log(OperServ, "akill/session") << "Added a temporary AKILL for \002" << akillmask << "\002 due to excessive connections";
+ }
+ else
+ {
+ u->Kill(OperServ, "Session limit exceeded");
+ }
+ }
+ }
+ else
+ {
+ session = new Session(u->ip, u->ip.ipv6() ? ipv6_cidr : ipv4_cidr);
+ }
+ }
+
+ void OnUserQuit(User *u, const Anope::string &msg) override
+ {
+ if (!session_limit || !u->server || u->server->IsULined())
+ return;
+
+ SessionService::SessionMap &sessions = this->ss.GetSessions();
+ SessionService::SessionMap::iterator sit = this->ss.FindSessionIterator(u->ip);
+
+ if (sit == sessions.end())
+ return;
+
+ Session *session = sit->second;
+
+ if (session->count > 1)
+ {
+ --session->count;
+ return;
+ }
+
+ delete session;
+ sessions.erase(sit);
+ }
+
+ void OnExpireTick() override
+ {
+ if (Anope::NoExpire)
+ return;
+
+ for (Exception *e : Serialize::GetObjects<Exception *>(exception))
+ {
+ if (!e->GetExpires() || e->GetExpires() > Anope::CurTime)
+ continue;
+
+ ServiceBot *OperServ = Config->GetClient("OperServ");
+ Log(OperServ, "expire/exception") << "Session exception for " << e->GetMask() << " has expired.";
+ e->Delete();
+ }
+ }
+};
+
+MODULE_INIT(OSSession)
diff --git a/modules/operserv/set.cpp b/modules/operserv/set.cpp
new file mode 100644
index 000000000..45515fa4b
--- /dev/null
+++ b/modules/operserv/set.cpp
@@ -0,0 +1,243 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSSet : public Command
+{
+ private:
+ void DoList(CommandSource &source)
+ {
+ Log(LOG_ADMIN, source, this) << "LIST";
+
+ Anope::string index;
+
+ index = Anope::ReadOnly ? _("%s is enabled") : _("%s is disabled");
+ source.Reply(index.c_str(), "READONLY");
+ index = Anope::Debug ? _("%s is enabled") : _("%s is disabled");
+ source.Reply(index.c_str(), "DEBUG");
+ index = Anope::NoExpire ? _("%s is enabled") : _("%s is disabled");
+ source.Reply(index.c_str(), "NOEXPIRE");
+
+ return;
+ }
+
+ void DoSetReadOnly(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string &setting = params.size() > 1 ? params[1] : "";
+
+ if (setting.empty())
+ {
+ this->OnSyntaxError(source, "READONLY");
+ return;
+ }
+
+ if (setting.equals_ci("ON"))
+ {
+ Anope::ReadOnly = true;
+ Log(LOG_ADMIN, source, this) << "READONLY ON";
+ source.Reply(_("Services are now in \002read-only\002 mode."));
+ }
+ else if (setting.equals_ci("OFF"))
+ {
+ Anope::ReadOnly = false;
+ Log(LOG_ADMIN, source, this) << "READONLY OFF";
+ source.Reply(_("Services are now in \002read-write\002 mode."));
+ }
+ else
+ source.Reply(_("Setting for READONLY must be \002ON\002 or \002OFF\002."));
+ }
+
+ void DoSetSuperAdmin(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string &setting = params.size() > 1 ? params[1] : "";
+
+ if (!source.GetUser())
+ return;
+
+ if (setting.empty())
+ {
+ this->OnSyntaxError(source, "SUPERADMIN");
+ return;
+ }
+
+ /**
+ * Allow the user to turn super admin on/off
+ *
+ * Rob
+ **/
+ bool super_admin = Config->GetModule(this->owner)->Get<bool>("superadmin");
+ if (!super_admin)
+ source.Reply(_("Super admin can not be set because it is not enabled in the configuration."));
+ else if (setting.equals_ci("ON"))
+ {
+ source.GetUser()->super_admin = true;
+ source.Reply(_("You are now a super admin."));
+ Log(LOG_ADMIN, source, this) << "SUPERADMIN ON";
+ }
+ else if (setting.equals_ci("OFF"))
+ {
+ source.GetUser()->super_admin = false;
+ source.Reply(_("You are no longer a super admin."));
+ Log(LOG_ADMIN, source, this) << "SUPERADMIN OFF";
+ }
+ else
+ source.Reply(_("Setting for super admin must be \002ON\002 or \002OFF\002."));
+ }
+
+ void DoSetDebug(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string &setting = params.size() > 1 ? params[1] : "";
+
+ if (setting.empty())
+ {
+ this->OnSyntaxError(source, "DEBUG");
+ return;
+ }
+
+ if (setting.equals_ci("ON"))
+ {
+ Anope::Debug = 1;
+ Log(LOG_ADMIN, source, this) << "DEBUG ON";
+ source.Reply(_("Services are now in \002debug\002 mode."));
+ }
+ else if (setting.equals_ci("OFF") || setting == "0")
+ {
+ Log(LOG_ADMIN, source, this) << "DEBUG OFF";
+ Anope::Debug = 0;
+ source.Reply(_("Services are now in \002non-debug\002 mode."));
+ }
+ else
+ {
+ try
+ {
+ Anope::Debug = convertTo<int>(setting);
+ Log(LOG_ADMIN, source, this) << "DEBUG " << Anope::Debug;
+ source.Reply(_("Services are now in \002debug\002 mode (level %d)."), Anope::Debug);
+ return;
+ }
+ catch (const ConvertException &) { }
+
+ source.Reply(_("Setting for DEBUG must be \002ON\002, \002OFF\002, or a positive number."));
+ }
+
+ return;
+ }
+
+ void DoSetNoExpire(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ const Anope::string &setting = params.size() > 1 ? params[1] : "";
+
+ if (setting.empty())
+ {
+ this->OnSyntaxError(source, "NOEXPIRE");
+ return;
+ }
+
+ if (setting.equals_ci("ON"))
+ {
+ Anope::NoExpire = true;
+ Log(LOG_ADMIN, source, this) << "NOEXPIRE ON";
+ source.Reply(_("Services are now in \002no expire\002 mode."));
+ }
+ else if (setting.equals_ci("OFF"))
+ {
+ Anope::NoExpire = false;
+ Log(LOG_ADMIN, source, this) << "NOEXPIRE OFF";
+ source.Reply(_("Services are now in \002expire\002 mode."));
+ }
+ else
+ source.Reply(_("Setting for NOEXPIRE must be \002ON\002 or \002OFF\002."));
+ }
+ public:
+ CommandOSSet(Module *creator) : Command(creator, "operserv/set", 1, 2)
+ {
+ this->SetDesc(_("Set various global Services options"));
+ this->SetSyntax(_("\037option\037 \037setting\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &option = params[0];
+
+ if (option.equals_ci("LIST"))
+ return this->DoList(source);
+ else if (option.equals_ci("READONLY"))
+ return this->DoSetReadOnly(source, params);
+ else if (option.equals_ci("DEBUG"))
+ return this->DoSetDebug(source, params);
+ else if (option.equals_ci("NOEXPIRE"))
+ return this->DoSetNoExpire(source, params);
+ else if (option.equals_ci("SUPERADMIN"))
+ return this->DoSetSuperAdmin(source, params);
+ else
+ this->OnSyntaxError(source, "");
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ if (subcommand.empty())
+ {
+ source.Reply(_("Sets various global Services options. Option names currently defined are:\n"
+ " READONLY Set read-only or read-write mode\n"
+ " DEBUG Activate or deactivate debug mode\n"
+ " NOEXPIRE Activate or deactivate no expire mode\n"
+ " SUPERADMIN Activate or deactivate super admin mode\n"
+ " LIST List the options"));
+ }
+ else if (subcommand.equals_ci("LIST"))
+ //source.Reply(_("Syntax: \002LIST\002\n"
+ // " \n"
+ source.Reply(("Display the various {0} settings."), source.service->nick);
+ else if (subcommand.equals_ci("READONLY"))
+ //source.Reply(_("Syntax: \002READONLY {ON | OFF}\002\n"
+ // " \n"
+ source.Reply(_("Sets read-only mode on or off. In read-only mode, norma users will not be allowed to modify any Services data, including channel and nickname access lists, etc."
+ "Services Operators will still be able to do most tasks, but should understand any changes they do may not be permanent.\n"
+ "\n"
+ "This option is equivalent to the command-line option \002--readonly\002."));
+ else if (subcommand.equals_ci("DEBUG"))
+ //source.Reply(_("Syntax: \002DEBUG {ON | OFF}\002\n"
+ // " \n"
+ source.Reply(_("Sets debug mode on or off.\n"
+ "\n"
+ "This option is equivalent to the command-line option \002--debug\002."));
+ else if (subcommand.equals_ci("NOEXPIRE"))
+ //source.Reply(_("Syntax: \002NOEXPIRE {ON | OFF}\002\n"
+ // " \n"
+ source.Reply(_("Sets no expire mode on or off. In no expire mode, nicks, channels, akills and exceptions won't expire until the option is unset.\n"
+ "\n"
+ "This option is equivalent to the command-line option \002--noexpire\002."));
+ else if (subcommand.equals_ci("SUPERADMIN"))
+ //source.Reply(_("Syntax: \002SUPERADMIN {ON | OFF}\002\n"
+ // " \n"
+ source.Reply(_("Setting this will grant you extra privileges, such as the ability to be \"founder\" on all channels."
+ "\n"
+ "This option is \002not\002 persistent, and should only be used when needed, and set back to OFF when no longer needed."));
+ else
+ return false;
+
+ return true;
+ }
+};
+
+class OSSet : public Module
+{
+ CommandOSSet commandosset;
+
+ public:
+ OSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosset(this)
+ {
+ }
+};
+
+MODULE_INIT(OSSet)
diff --git a/modules/operserv/shutdown.cpp b/modules/operserv/shutdown.cpp
new file mode 100644
index 000000000..642be5d84
--- /dev/null
+++ b/modules/operserv/shutdown.cpp
@@ -0,0 +1,101 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSQuit : public Command
+{
+ public:
+ CommandOSQuit(Module *creator) : Command(creator, "operserv/quit", 0, 0)
+ {
+ this->SetDesc(_("Terminate Services without saving"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ Log(LOG_ADMIN, source, this);
+ Anope::QuitReason = source.command + " command received from " + source.GetNick();
+ Anope::Quitting = true;
+ return;
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Causes Services to do an immediate shutdown; databases may \002not\002 saved."
+ " If you are using a real time database such as SQL or Redis, this command is not useful."
+ " This command should not be used unless damage to the in-memory copies of the databases is feared and they should not be saved."));
+ return true;
+ }
+};
+
+class CommandOSRestart : public Command
+{
+ public:
+ CommandOSRestart(Module *creator) : Command(creator, "operserv/restart", 0, 0)
+ {
+ this->SetDesc(_("Save databases and restart Services"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ Log(LOG_ADMIN, source, this);
+ Anope::QuitReason = source.command + " command received from " + source.GetNick();
+ Anope::Quitting = Anope::Restarting = true;
+ Anope::SaveDatabases();
+ return;
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Causes Services to restart."));
+ return true;
+ }
+};
+
+class CommandOSShutdown : public Command
+{
+ public:
+ CommandOSShutdown(Module *creator) : Command(creator, "operserv/shutdown", 0, 0)
+ {
+ this->SetDesc(_("Terminate services with save"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ Log(LOG_ADMIN, source, this);
+ Anope::QuitReason = source.command + " command received from " + source.GetNick();
+ Anope::Quitting = true;
+ Anope::SaveDatabases();
+ return;
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Causes Services to shut down"));
+ return true;
+ }
+};
+
+class OSShutdown : public Module
+{
+ CommandOSQuit commandosquit;
+ CommandOSRestart commandosrestart;
+ CommandOSShutdown commandosshutdown;
+
+ public:
+ OSShutdown(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
+ commandosquit(this), commandosrestart(this), commandosshutdown(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSShutdown)
diff --git a/modules/operserv/stats.cpp b/modules/operserv/stats.cpp
new file mode 100644
index 000000000..6e74303ce
--- /dev/null
+++ b/modules/operserv/stats.cpp
@@ -0,0 +1,271 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+#include "modules/os_session.h"
+
+#if 0
+struct Stats : Serialize::Object
+{
+ static Stats *me;
+
+ Stats() : Serialize::Object("Stats")
+ {
+ me = this;
+ }
+
+ void Serialize(Serialize::Data &data) const override
+ {
+ data["maxusercnt"] << MaxUserCount;
+ data["maxusertime"] << MaxUserTime;
+ }
+
+ static Serializable* Unserialize(Serializable *obj, Serialize::Data &data)
+ {
+ data["maxusercnt"] >> MaxUserCount;
+ data["maxusertime"] >> MaxUserTime;
+ return me;
+ }
+};
+
+Stats *Stats::me;
+
+/**
+ * Count servers connected to server s
+ * @param s The server to start counting from
+ * @return Amount of servers connected to server s
+ **/
+static int stats_count_servers(Server *s)
+{
+ if (!s)
+ return 0;
+
+ int count = 1;
+
+ if (!s->GetLinks().empty())
+ for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i)
+ count += stats_count_servers(s->GetLinks()[i]);
+
+ return count;
+}
+
+class CommandOSStats : public Command
+{
+ ServiceReference<XLineManager> akills, snlines, sqlines;
+ private:
+ void DoStatsAkill(CommandSource &source)
+ {
+ int timeout;
+ if (akills)
+ {
+ /* AKILLs */
+ source.Reply(_("Current number of AKILLs: \002{0}\002"), akills->GetCount());
+ timeout = Config->GetModule("operserv")->Get<time_t>("autokillexpiry", "30d") + 59;
+ if (timeout >= 172800)
+ source.Reply(_("Default AKILL expiry time: \002{0} days\002"), timeout / 86400);
+ else if (timeout >= 86400)
+ source.Reply(_("Default AKILL expiry time: \0021 day\002"));
+ else if (timeout >= 7200)
+ source.Reply(_("Default AKILL expiry time: \002{0} hours\002"), timeout / 3600);
+ else if (timeout >= 3600)
+ source.Reply(_("Default AKILL expiry time: \0021 hour\002"));
+ else if (timeout >= 120)
+ source.Reply(_("Default AKILL expiry time: \002{0} minutes\002"), timeout / 60);
+ else if (timeout >= 60)
+ source.Reply(_("Default AKILL expiry time: \0021 minute\002"));
+ else
+ source.Reply(_("Default AKILL expiry time: \002No expiration\002"));
+ }
+ if (snlines)
+ {
+ /* SNLINEs */
+ source.Reply(_("Current number of SNLINEs: \002{0}\002"), snlines->GetCount());
+ timeout = Config->GetModule("operserv")->Get<time_t>("snlineexpiry", "30d") + 59;
+ if (timeout >= 172800)
+ source.Reply(_("Default SNLINE expiry time: \002{0} days\002"), timeout / 86400);
+ else if (timeout >= 86400)
+ source.Reply(_("Default SNLINE expiry time: \0021 day\002"));
+ else if (timeout >= 7200)
+ source.Reply(_("Default SNLINE expiry time: \002{0} hours\002"), timeout / 3600);
+ else if (timeout >= 3600)
+ source.Reply(_("Default SNLINE expiry time: \0021 hour\002"));
+ else if (timeout >= 120)
+ source.Reply(_("Default SNLINE expiry time: \002{0} minutes\002"), timeout / 60);
+ else if (timeout >= 60)
+ source.Reply(_("Default SNLINE expiry time: \0021 minute\002"));
+ else
+ source.Reply(_("Default SNLINE expiry time: \002No expiration\002"));
+ }
+ if (sqlines)
+ {
+ /* SQLINEs */
+ source.Reply(_("Current number of SQLINEs: \002{0}\002"), sqlines->GetCount());
+ timeout = Config->GetModule("operserv")->Get<time_t>("sglineexpiry", "30d") + 59;
+ if (timeout >= 172800)
+ source.Reply(_("Default SQLINE expiry time: \002{0} days\002"), timeout / 86400);
+ else if (timeout >= 86400)
+ source.Reply(_("Default SQLINE expiry time: \0021 day\002"));
+ else if (timeout >= 7200)
+ source.Reply(_("Default SQLINE expiry time: \002{0} hours\002"), timeout / 3600);
+ else if (timeout >= 3600)
+ source.Reply(_("Default SQLINE expiry time: \0021 hour\002"));
+ else if (timeout >= 120)
+ source.Reply(_("Default SQLINE expiry time: \002{0} minutes\002"), timeout / 60);
+ else if (timeout >= 60)
+ source.Reply(_("Default SQLINE expiry time: \0021 minute\002"));
+ else
+ source.Reply(_("Default SQLINE expiry time: \002No expiration\002"));
+ }
+ }
+
+ void DoStatsReset(CommandSource &source)
+ {
+ MaxUserCount = UserListByNick.size();
+ source.Reply(_("Statistics reset."));
+ return;
+ }
+
+ void DoStatsUptime(CommandSource &source)
+ {
+ time_t uptime = Anope::CurTime - Anope::StartTime;
+ source.Reply(_("Current users: \002{0}\002 (\002{1}\002 ops)"), UserListByNick.size(), OperCount);
+ source.Reply(_("Maximum users: \002{0}\002 ({1})"), MaxUserCount, Anope::strftime(MaxUserTime, source.GetAccount()));
+ source.Reply(_("Services up \002{0}\002."), Anope::Duration(uptime, source.GetAccount()));
+ }
+
+ void DoStatsUplink(CommandSource &source)
+ {
+ Anope::string buf;
+ for (std::set<Anope::string>::iterator it = Servers::Capab.begin(); it != Servers::Capab.end(); ++it)
+ buf += " " + *it;
+ if (!buf.empty())
+ buf.erase(buf.begin());
+
+ source.Reply(_("Uplink server: \002{0}\002"), Me->GetLinks().front()->GetName());
+ source.Reply(_("Uplink capab: {0}"), buf);
+ source.Reply(_("Servers found: {0}"), stats_count_servers(Me->GetLinks().front()));
+ }
+
+ template<typename T> void GetHashStats(const T& map, size_t& entries, size_t& buckets, size_t& max_chain)
+ {
+ entries = map.size(), buckets = map.bucket_count(), max_chain = 0;
+ for (size_t i = 0; i < buckets; ++i)
+ if (map.bucket_size(i) > max_chain)
+ max_chain = map.bucket_size(i);
+ }
+
+ void DoStatsHash(CommandSource &source)
+ {
+ size_t entries, buckets, max_chain;
+
+ GetHashStats(UserListByNick, entries, buckets, max_chain);
+ source.Reply(_("Users (nick): {0} entries, {1} buckets, longest chain is {2}"), entries, buckets, max_chain);
+
+ if (!UserListByUID.empty())
+ {
+ GetHashStats(UserListByUID, entries, buckets, max_chain);
+ source.Reply(_("Users (uid): {0} entries, {1} buckets, longest chain is {2}"), entries, buckets, max_chain);
+ }
+
+ GetHashStats(ChannelList, entries, buckets, max_chain);
+ source.Reply(_("Channels: {0} entries, {1} buckets, longest chain is {2}"), entries, buckets, max_chain);
+
+ GetHashStats(ChanServ::service->GetChannels(), entries, buckets, max_chain);
+ source.Reply(_("Registered channels: {0} entries, {1} buckets, longest chain is {2}"), entries, buckets, max_chain);
+
+ GetHashStats(NickServ::service->GetNickMap(), entries, buckets, max_chain);
+ source.Reply(_("Registered nicknames: {0} entries, {1} buckets, longest chain is {2}"), entries, buckets, max_chain);
+
+ GetHashStats(NickServ::service->GetAccountMap(), entries, buckets, max_chain);
+ source.Reply(_("Registered nick groups: {0} entries, {1} buckets, longest chain is {2}"), entries, buckets, max_chain);
+
+ if (session_service)
+ {
+ GetHashStats(session_service->GetSessions(), entries, buckets, max_chain);
+ source.Reply(_("Sessions: {0} entries, {1} buckets, longest chain is {2}"), entries, buckets, max_chain);
+ }
+ }
+
+ public:
+ CommandOSStats(Module *creator) : Command(creator, "operserv/stats", 0, 1),
+ akills("XLineManager", "xlinemanager/sgline"), snlines("XLineManager", "xlinemanager/snline"), sqlines("XLineManager", "xlinemanager/sqline")
+ {
+ this->SetDesc(_("Show status of Services and network"));
+ this->SetSyntax("[AKILL | HASH | UPLINK | UPTIME | ALL | RESET]");
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ Anope::string extra = !params.empty() ? params[0] : "";
+
+ Log(LOG_ADMIN, source, this) << extra;
+
+ if (extra.equals_ci("RESET"))
+ return this->DoStatsReset(source);
+
+ if (extra.equals_ci("ALL") || extra.equals_ci("AKILL"))
+ this->DoStatsAkill(source);
+
+ if (extra.equals_ci("ALL") || extra.equals_ci("HASH"))
+ this->DoStatsHash(source);
+
+ if (extra.equals_ci("ALL") || extra.equals_ci("UPLINK"))
+ this->DoStatsUplink(source);
+
+ if (extra.empty() || extra.equals_ci("ALL") || extra.equals_ci("UPTIME"))
+ this->DoStatsUptime(source);
+
+ if (!extra.empty() && !extra.equals_ci("ALL") && !extra.equals_ci("AKILL") && !extra.equals_ci("HASH") && !extra.equals_ci("UPLINK") && !extra.equals_ci("UPTIME"))
+ source.Reply(_("Unknown STATS option: \002{0}\002"), extra);
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Without any option, shows the current number of users online, and the highest number of users online since Services was started, and the length of time Services has been running.\n"
+ "\n"
+ "With the \002AKILL\002 option, displays the current size of the AKILL list and the current default expiry time.\n"
+ "\n"
+ "The \002RESET\002 option currently resets the maximum user count to the number of users currently present on the network.\n"
+ "\n"
+ "The \002UPLINK\002 option displays information about the current server Anope uses as an uplink to the network.\n"
+ "\n"
+ "The \002HASH\002 option displays information about the hash maps.\n"
+ "\n"
+ "The \002ALL\002 option displays all of the above statistics."));
+ return true;
+ }
+};
+
+class OSStats : public Module
+{
+ CommandOSStats commandosstats;
+ //Serialize::TypeBase stats_type;
+ Stats stats_saver;
+
+ public:
+ OSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosstats(this)
+// , stats_type("Stats", Stats::Unserialize)
+ {
+
+ }
+
+#if 0
+ void OnUserConnect(User *u, bool &exempt) override
+ {
+ if (UserListByNick.size() == MaxUserCount && Anope::CurTime == MaxUserTime)
+ stats_saver.QueueUpdate();
+ }
+#endif
+};
+
+MODULE_INIT(OSStats)
+#endif
diff --git a/modules/operserv/svs.cpp b/modules/operserv/svs.cpp
new file mode 100644
index 000000000..35c3136a8
--- /dev/null
+++ b/modules/operserv/svs.cpp
@@ -0,0 +1,171 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSSVSNick : public Command
+{
+ public:
+ CommandOSSVSNick(Module *creator) : Command(creator, "operserv/svsnick", 2, 2)
+ {
+ this->SetDesc(_("Forcefully change a user's nickname"));
+ this->SetSyntax(_("\037nick\037 \037newnick\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &nick = params[0];
+ Anope::string newnick = params[1];
+ User *u2;
+
+ if (!IRCD->CanSVSNick)
+ {
+ source.Reply(_("Your IRCd does not support SVSNICK."));
+ return;
+ }
+
+ /* Truncate long nicknames to nicklen characters */
+ unsigned nicklen = Config->GetBlock("networkinfo")->Get<unsigned>("nicklen");
+ if (newnick.length() > nicklen)
+ {
+ source.Reply(_("Nick \002{0}\002 was truncated to \002{1}\002 characters."), newnick, nicklen);
+ newnick = params[1].substr(0, nicklen);
+ }
+
+ /* Check for valid characters */
+ if (!IRCD->IsNickValid(newnick))
+ {
+ source.Reply(_("Nick \002{0}\002 is an illegal nickname and cannot be used."), newnick);
+ return;
+ }
+
+ /* Check for a nick in use or a forbidden/suspended nick */
+ if (!(u2 = User::Find(nick, true)))
+ source.Reply(_("\002{0}\002 isn't currently online."), nick);
+ else if (!nick.equals_ci(newnick) && User::Find(newnick))
+ source.Reply(_("\002{0}\002 is currently in use."), newnick);
+ else
+ {
+ source.Reply(_("\002{0}\002 is now being changed to \002{1}\002."), nick, newnick);
+ Log(LOG_ADMIN, source, this) << "to change " << nick << " to " << newnick;
+ IRCD->SendForceNickChange(u2, newnick, Anope::CurTime);
+ }
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Forcefully changes a user's nickname from \037nick\037 to \037newnick\037."));
+ return true;
+ }
+};
+
+class CommandOSSVSJoin : public Command
+{
+ public:
+ CommandOSSVSJoin(Module *creator) : Command(creator, "operserv/svsjoin", 2, 2)
+ {
+ this->SetDesc(_("Forcefully join a user to a channel"));
+ this->SetSyntax(_("\037user\037 \037channel\037"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ if (!IRCD->CanSVSJoin)
+ {
+ source.Reply(_("Your IRCd does not support SVSJOIN."));
+ return;
+ }
+
+ User *target = User::Find(params[0], true);
+ Channel *c = Channel::Find(params[1]);
+ if (target == NULL)
+ source.Reply(_("\002{0}\002 isn't currently online."), params[0]);
+ else if (source.GetUser() != target && (target->IsProtected() || target->server == Me))
+ source.Reply(_("Access denied."));
+ else if (!c && !IRCD->IsChannelValid(params[1]))
+ source.Reply(_("\002{0}\002 isn't a valid channel."), params[1]);
+ else if (c && c->FindUser(target))
+ source.Reply(_("\002{0}\002 is already in \002{1}\002."), target->nick, c->name);
+ else
+ {
+ IRCD->SendSVSJoin(*source.service, target, params[1], "");
+ Log(LOG_ADMIN, source, this) << "to force " << target->nick << " to join " << params[1];
+ source.Reply(_("\002{0}\002 has been joined to \002{1}\002."), target->nick, params[1]);
+ }
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Forcefully join \037user\037 to \037channel\037."));
+ return true;
+ }
+};
+
+class CommandOSSVSPart : public Command
+{
+ public:
+ CommandOSSVSPart(Module *creator) : Command(creator, "operserv/svspart", 2, 3)
+ {
+ this->SetDesc(_("Forcefully part a user from a channel"));
+ this->SetSyntax(_("\037nick\037 \037channel\037 [\037reason\037]"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ if (!IRCD->CanSVSJoin)
+ {
+ source.Reply(_("Your IRCd does not support SVSPART."));
+ return;
+ }
+
+ User *target = User::Find(params[0], true);
+ Channel *c = Channel::Find(params[1]);
+ const Anope::string &reason = params.size() > 2 ? params[2] : "";
+ if (target == NULL)
+ source.Reply(_("\002{0}\002 isn't currently online."), params[0]);
+ else if (source.GetUser() != target && (target->IsProtected() || target->server == Me))
+ source.Reply(_("Access denied."));
+ else if (!c)
+ source.Reply(_("Channel \002{0}\002 doesn't exist."), params[1]);
+ else if (!c->FindUser(target))
+ source.Reply(_("\002{0}\002 is not in \002{1}\002."), target->nick, c->name);
+ else
+ {
+ IRCD->SendSVSPart(*source.service, target, params[1], reason);
+ if (!reason.empty())
+ Log(LOG_ADMIN, source, this) << "to force " << target->nick << " to part " << c->name << " with reason " << reason;
+ else
+ Log(LOG_ADMIN, source, this) << "to force " << target->nick << " to part " << c->name;
+ source.Reply(_("\002{0}\002 has been parted from \002{1}\002."), target->nick, c->name);
+ }
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Forcefully part \037user\037 from \037channel\037."));
+ return true;
+ }
+};
+
+class OSSVS : public Module
+{
+ CommandOSSVSNick commandossvsnick;
+ CommandOSSVSJoin commandossvsjoin;
+ CommandOSSVSPart commandossvspart;
+
+ public:
+ OSSVS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
+ commandossvsnick(this), commandossvsjoin(this), commandossvspart(this)
+ {
+ }
+};
+
+MODULE_INIT(OSSVS)
diff --git a/modules/operserv/sxline.cpp b/modules/operserv/sxline.cpp
new file mode 100644
index 000000000..3465faae7
--- /dev/null
+++ b/modules/operserv/sxline.cpp
@@ -0,0 +1,673 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSSXLineBase : public Command
+{
+ private:
+ virtual XLineManager* xlm() anope_abstract;
+
+ virtual void OnAdd(CommandSource &source, const std::vector<Anope::string> &params) anope_abstract;
+
+ void OnDel(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ if (!this->xlm() || this->xlm()->GetXLines().empty())
+ {
+ source.Reply(_("{0} list is empty."), source.command);
+ return;
+ }
+
+ const Anope::string &mask = params.size() > 1 ? params[1] : "";
+
+ if (mask.empty())
+ {
+ this->OnSyntaxError(source, "DEL");
+ return;
+ }
+
+ if (isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
+ {
+ unsigned int deleted = 0;
+
+ NumberList(mask, true,
+ [&](unsigned int number)
+ {
+ XLine *x = this->xlm()->GetEntry(number - 1);
+
+ if (!x)
+ return;
+
+ Log(LOG_ADMIN, source, this) << "to remove " << x->GetMask() << " from the list";
+
+ ++deleted;
+ x->Delete();
+ },
+ [&]()
+ {
+ if (!deleted)
+ source.Reply(_("No matching entries on the {0} list."), source.command);
+ else if (deleted == 1)
+ source.Reply(_("Deleted \0021\002 entry from the {0} list."), source.command);
+ else
+ source.Reply(_("Deleted \002{0}\002 entries from the {1} list."), deleted, source.command);
+ });
+ }
+ else
+ {
+ XLine *x = this->xlm()->HasEntry(mask);
+
+ if (!x)
+ {
+ source.Reply(_("\002{0}\002 not found on the {1] list."), mask, source.command);
+ return;
+ }
+
+ Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, this->xlm());
+
+ x->Delete();
+ source.Reply(_("\002{0}\002 deleted from the {1} list."), mask, source.command);
+ Log(LOG_ADMIN, source, this) << "to remove " << mask << " from the list";
+ }
+
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ }
+
+ void ProcessList(CommandSource &source, const std::vector<Anope::string> &params, ListFormatter &list)
+ {
+ if (!this->xlm() || this->xlm()->GetXLines().empty())
+ {
+ source.Reply(_("{0} list is empty."), source.command);
+ return;
+ }
+
+ const Anope::string &mask = params.size() > 1 ? params[1] : "";
+
+ if (!mask.empty() && isdigit(mask[0]) && mask.find_first_not_of("1234567890,-") == Anope::string::npos)
+ {
+ NumberList(mask, false,
+ [&](unsigned int number)
+ {
+ XLine *x = this->xlm()->GetEntry(number - 1);
+
+ if (!x)
+ return;
+
+ ListFormatter::ListEntry entry;
+ entry["Number"] = stringify(number);
+ entry["Mask"] = x->GetMask();
+ entry["By"] = x->GetBy();
+ entry["Created"] = Anope::strftime(x->GetCreated(), NULL, true);
+ entry["Expires"] = Anope::Expires(x->GetExpires(), source.nc);
+ entry["Reason"] = x->GetReason();
+ list.AddEntry(entry);
+ },
+ []{});
+ }
+ else
+ {
+ unsigned int i = 0;
+ for (XLine *x : this->xlm()->GetXLines())
+ {
+ if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->id || Anope::Match(x->GetMask(), mask, false, true))
+ {
+ ListFormatter::ListEntry entry;
+ entry["Number"] = stringify(i + 1);
+ entry["Mask"] = x->GetMask();
+ entry["By"] = x->GetBy();
+ entry["Created"] = Anope::strftime(x->GetCreated(), NULL, true);
+ entry["Expires"] = Anope::Expires(x->GetExpires(), source.nc);
+ entry["Reason"] = x->GetReason();
+ list.AddEntry(entry);
+ }
+ }
+ }
+
+ if (list.IsEmpty())
+ source.Reply(_("No matching entries on the {0} list."), source.command);
+ else
+ {
+ source.Reply(_("{0} list:"), source.command);
+
+ std::vector<Anope::string> replies;
+ list.Process(replies);
+
+ for (unsigned i = 0; i < replies.size(); ++i)
+ source.Reply(replies[i]);
+ }
+ }
+
+ void OnList(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ ListFormatter list(source.GetAccount());
+ list.AddColumn(_("Number")).AddColumn(_("Mask")).AddColumn(_("Reason"));
+
+ this->ProcessList(source, params, list);
+ }
+
+ void OnView(CommandSource &source, const std::vector<Anope::string> &params)
+ {
+ ListFormatter list(source.GetAccount());
+ list.AddColumn(_("Number")).AddColumn(_("Mask")).AddColumn(_("By")).AddColumn(_("Created")).AddColumn(_("Expires")).AddColumn(_("Reason"));
+ this->ProcessList(source, params, list);
+ }
+
+ void OnClear(CommandSource &source)
+ {
+ Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, nullptr, this->xlm());
+
+ for (XLine *x : this->xlm()->GetXLines())
+ x->Delete();
+
+ Log(LOG_ADMIN, source, this) << "to CLEAR the list";
+ source.Reply(_("The {0} list has been cleared."), source.command);
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ }
+ public:
+ CommandOSSXLineBase(Module *creator, const Anope::string &cmd) : Command(creator, cmd, 1, 4)
+ {
+ }
+
+ const Anope::string GetDesc(CommandSource &source) const override
+ {
+ return Anope::printf(Language::Translate(source.GetAccount(), _("Manipulate the %s list")), source.command.upper().c_str());
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ const Anope::string &cmd = params[0];
+
+ if (cmd.equals_ci("ADD"))
+ return this->OnAdd(source, params);
+ else if (cmd.equals_ci("DEL"))
+ return this->OnDel(source, params);
+ else if (cmd.equals_ci("LIST"))
+ return this->OnList(source, params);
+ else if (cmd.equals_ci("VIEW"))
+ return this->OnView(source, params);
+ else if (cmd.equals_ci("CLEAR"))
+ return this->OnClear(source);
+ else
+ this->OnSyntaxError(source, "");
+ }
+
+ virtual bool OnHelp(CommandSource &source, const Anope::string &subcommand) = 0;
+};
+
+class CommandOSSNLine : public CommandOSSXLineBase
+{
+ XLineManager *xlm()
+ {
+ return this->snlines;
+ }
+
+ void OnAdd(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ if (!this->xlm())
+ return;
+
+ unsigned last_param = 2;
+ Anope::string param, expiry;
+
+ param = params.size() > 1 ? params[1] : "";
+ if (!param.empty() && param[0] == '+')
+ {
+ expiry = param;
+ param = params.size() > 2 ? params[2] : "";
+ last_param = 3;
+ }
+
+ time_t expires = !expiry.empty() ? Anope::DoTime(expiry) : Config->GetModule("operserv")->Get<time_t>("snlineexpiry", "30d");
+ /* If the expiry given does not contain a final letter, it's in days,
+ * said the doc. Ah well.
+ */
+ if (!expiry.empty() && isdigit(expiry[expiry.length() - 1]))
+ expires *= 86400;
+ /* Do not allow less than a minute expiry time */
+ if (expires && expires < 60)
+ {
+ source.Reply(_("Invalid expiry time \002{0}\002."), expiry);
+ return;
+ }
+ else if (expires > 0)
+ expires += Anope::CurTime;
+
+ if (param.empty())
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ Anope::string rest = param;
+ if (params.size() > last_param)
+ rest += " " + params[last_param];
+
+ if (rest.find(':') == Anope::string::npos)
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ sepstream sep(rest, ':');
+ Anope::string mask;
+ sep.GetToken(mask);
+ Anope::string reason = sep.GetRemaining();
+
+ if (mask.empty() || reason.empty())
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ if (mask[0] == '/' && mask[mask.length() - 1] == '/')
+ {
+ if (!Config->regex_flags)
+ {
+ source.Reply(_("Regex is disabled."));
+ return;
+ }
+
+ Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
+ try
+ {
+ std::regex(stripped_mask.str(), Config->regex_flags);
+ }
+ catch (const std::regex_error &ex)
+ {
+ source.Reply(ex.what());
+ return;
+ }
+ }
+
+ /* Clean up the last character of the mask if it is a space
+ * See bug #761
+ */
+ unsigned masklen = mask.length();
+ if (mask[masklen - 1] == ' ')
+ mask.erase(masklen - 1);
+
+ if (Config->GetModule("operserv")->Get<bool>("addakiller", "yes") && !source.GetNick().empty())
+ reason = "[" + source.GetNick() + "] " + reason;
+
+ if (!this->xlm()->CanAdd(source, mask, expires, reason))
+ return;
+ else if (mask.find_first_not_of("/.*?") == Anope::string::npos)
+ {
+ source.Reply(_("\002{0}\002 coverage is too wide; please use a more specific mask."), mask);
+ return;
+ }
+
+ XLine *x = new XLine(mask, source.GetNick(), expires, reason);
+ if (Config->GetModule("operserv")->Get<bool>("akillids"))
+ x->SetID(XLineManager::GenerateUID());
+
+ unsigned int affected = 0;
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (this->xlm()->Check(it->second, x))
+ ++affected;
+ float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
+
+ if (percent > 95)
+ {
+ source.Reply(_("\002{0}\002 coverage is too wide; please use a more specific mask."), mask);
+ Log(LOG_ADMIN, source, this) << "tried to " << source.command << " " << percent << "% of the network (" << affected << " users)";
+ delete x;
+ return;
+ }
+
+ EventReturn MOD_RESULT;
+ MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, this->xlm());
+ if (MOD_RESULT == EVENT_STOP)
+ {
+ delete x;
+ return;
+ }
+
+ this->xlm()->AddXLine(x);
+
+ if (Config->GetModule("operserv")->Get<bool>("killonsnline", "yes"))
+ {
+ Anope::string rreason = "G-Lined: " + reason;
+
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ {
+ User *user = it->second;
+
+ if (!user->HasMode("OPER") && user->server != Me && this->xlm()->Check(user, x))
+ user->Kill(Me, rreason);
+ }
+
+ this->xlm()->Send(NULL, x);
+ }
+
+ source.Reply(_("\002{0}\002 added to the {1} list."), mask, source.command);
+ Log(LOG_ADMIN, source, this) << "on " << mask << " (" << reason << "), expires in " << (expires ? Anope::Duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]";
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ }
+
+ ServiceReference<XLineManager> snlines;
+ public:
+ CommandOSSNLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/snline"), snlines("XLineManager", "xlinemanager/snline")
+ {
+ this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037:\037reason\037"));
+ this->SetSyntax(_("DEL {\037mask\037 | \037entry-num\037 | \037list\037 | \037id\037}"));
+ this->SetSyntax(_("LIST [\037mask\037 | \037list\037 | \037id\037]"));
+ this->SetSyntax(_("VIEW [\037mask\037 | \037list\037 | \037id\037]"));
+ this->SetSyntax("CLEAR");
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ if (subcommand.equals_ci("ADD"))
+ {
+ source.Reply(_("\002{0} ADD\002 adds the given \037mask\037 to the {0} list for the given \037reason\037."
+ " \037expiry\037 is specified as an integer followed by one of \037d\037 (days), \037h\037 (hours), or \037m\037 (minutes)."
+ " If a unit specifier is not included, the default is days, so \037+30\037 by itself means 30 days."
+ " To add a {0} which does not expire, use \037+0\037."
+ " The default {0} expiry time is \002{1}\002."
+ " Because the real name may contain spaces, the separator between it and the reason is a \002colon\002."),
+ source.command, Anope::Duration(Config->GetModule("operserv")->Get<time_t>("snlineexpiry", "30d"), source.GetAccount()));
+
+ const Anope::string &regexengine = Config->GetBlock("options")->Get<Anope::string>("regexengine");
+ if (!regexengine.empty())
+ {
+ source.Reply(" ");
+ source.Reply(_("Regex matches are also supported using the {0} engine. Enclose your mask in // if this is desired."), regexengine);
+ }
+ }
+ else if (subcommand.equals_ci("DEL"))
+ source.Reply(_("The \002{0} DEL\002 command removes the given \037mask\037 from the {0} list if it is present."
+ " If a list of entry numbers is given, those entries are deleted."));
+ else if (subcommand.equals_ci("LIST") || subcommand.equals_ci("VIEW"))
+ source.Reply(_("The \002{0} LIST\002 and \002{0} VIEW\002 commands displays the {0} list.\n"
+ "If a wildcard \037mask\037 is given, only those entries matching the \037mask\037 are displayed."
+ " If a list of entry numbers is given, only those entries are shown."
+ " \002VIEW\002 is similar to \002LIST\002 but also shows who created the {0}, when it was created, and when it expires.\n"
+ "\n"
+ "Example:\n"
+ "\n"
+ " {0} LIST 2-5,7-9\n"
+ " Lists {0} entries numbered 2 through 5 and 7 through 9.\n"),
+ source.command);
+ else if (subcommand.equals_ci("CLEAR"))
+ source.Reply(_("\002{0} CLEAR\002 removes all entries from the {0} list."),
+ source.command);
+ else
+ {
+ CommandInfo *help = source.service->FindCommand("generic/help");
+
+ source.Reply(_("Allows you to manipulate the {0} list."
+ " If a user attempts to use a realname that matches a {0} mask, services will kill the user."
+ "\n"
+ "The \002ADD\002 command adds \037mask\037 to the {0} list.\n"
+ "\002{msg}{service} {help} {command} ADD\002 for more information.\n"
+ "\n"
+ "The \002DEL\002 command removes \037mask\037 from the {0} list.\n"
+ "\002{msg}{service} {help} {command} DEL\002 for more information.\n"
+ "\n"
+ "The \002LIST\002 and \002VIEW\002 commands both show the {0} list, but \002VIEW\002 also shows who created the {0} entry, when it was created, and when it expires.\n"
+ "\002{msg}{service} {help} {command} [LIST | VIEW]\002 for more information.\n"
+ "\n"
+ "The \002CLEAR\002 command clears th auto kill list."
+ "\002{msg}{service} {help} {command} CLEAR\002 for more information.\n"),
+ "msg"_kw = Config->StrictPrivmsg, "service"_kw = source.service->nick, "help"_kw = help->cname, "command"_kw = source.command);
+ }
+ return true;
+ }
+};
+
+class CommandOSSQLine : public CommandOSSXLineBase
+{
+ XLineManager *xlm()
+ {
+ return this->sqlines;
+ }
+
+ void OnAdd(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ if (!this->xlm())
+ return;
+
+ unsigned last_param = 2;
+ Anope::string expiry, mask;
+
+ mask = params.size() > 1 ? params[1] : "";
+ if (!mask.empty() && mask[0] == '+')
+ {
+ expiry = mask;
+ mask = params.size() > 2 ? params[2] : "";
+ last_param = 3;
+ }
+
+ time_t expires = !expiry.empty() ? Anope::DoTime(expiry) : Config->GetModule("operserv")->Get<time_t>("sqlineexpiry", "30d");
+ /* If the expiry given does not contain a final letter, it's in days,
+ * said the doc. Ah well.
+ */
+ if (!expiry.empty() && isdigit(expiry[expiry.length() - 1]))
+ expires *= 86400;
+ /* Do not allow less than a minute expiry time */
+ if (expires && expires < 60)
+ {
+ source.Reply(_("Invalid expiry time \002{0}\002."), expiry);
+ return;
+ }
+ else if (expires > 0)
+ expires += Anope::CurTime;
+
+ if (params.size() <= last_param)
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ Anope::string reason = params[last_param];
+ if (last_param == 2 && params.size() > 3)
+ reason += " " + params[3];
+
+ if (mask.empty() || reason.empty())
+ {
+ this->OnSyntaxError(source, "ADD");
+ return;
+ }
+
+ if (mask[0] == '/' && mask[mask.length() - 1] == '/')
+ {
+ if (!Config->regex_flags)
+ {
+ source.Reply(_("Regex is disabled."));
+ return;
+ }
+
+ Anope::string stripped_mask = mask.substr(1, mask.length() - 2);
+ try
+ {
+ std::regex(stripped_mask.str(), Config->regex_flags);
+ }
+ catch (const std::regex_error &ex)
+ {
+ source.Reply(ex.what());
+ return;
+ }
+ }
+
+ if (Config->GetModule("operserv")->Get<bool>("addakiller", "yes") && !source.GetNick().empty())
+ reason = "[" + source.GetNick() + "] " + reason;
+
+ if (!this->sqlines->CanAdd(source, mask, expires, reason))
+ return;
+ else if (mask.find_first_not_of("./?*") == Anope::string::npos)
+ {
+ source.Reply(_("\002{0}\002 coverage is too wide; please use a more specific mask."), mask);
+ return;
+ }
+
+ XLine *x = new XLine(mask, source.GetNick(), expires, reason);
+ if (Config->GetModule("operserv")->Get<bool>("akillids"))
+ x->SetID(XLineManager::GenerateUID());
+
+ unsigned int affected = 0;
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ if (this->xlm()->Check(it->second, x))
+ ++affected;
+ float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0;
+
+ if (percent > 95)
+ {
+ source.Reply(_("\002{0}\002 coverage is too wide; please use a more specific mask."), mask);
+ Log(LOG_ADMIN, source, this) << "tried to SQLine " << percent << "% of the network (" << affected << " users)";
+ delete x;
+ return;
+ }
+
+ EventReturn MOD_RESULT;
+ MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, this->xlm());
+ if (MOD_RESULT == EVENT_STOP)
+ {
+ delete x;
+ return;
+ }
+
+ this->xlm()->AddXLine(x);
+
+ if (Config->GetModule("operserv")->Get<bool>("killonsqline", "yes"))
+ {
+ Anope::string rreason = "Q-Lined: " + reason;
+
+ if (mask[0] == '#')
+ {
+ for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit)
+ {
+ Channel *c = cit->second;
+
+ if (!Anope::Match(c->name, mask, false, true))
+ continue;
+
+ std::vector<User *> users;
+ for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it)
+ {
+ ChanUserContainer *uc = it->second;
+ User *user = uc->user;
+
+ if (!user->HasMode("OPER") && user->server != Me)
+ users.push_back(user);
+ }
+
+ for (unsigned i = 0; i < users.size(); ++i)
+ c->Kick(NULL, users[i], "%s", reason.c_str());
+ }
+ }
+ else
+ {
+ for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
+ {
+ User *user = it->second;
+
+ if (!user->HasMode("OPER") && user->server != Me && this->xlm()->Check(user, x))
+ user->Kill(Me, rreason);
+ }
+ }
+
+ this->xlm()->Send(NULL, x);
+ }
+
+ source.Reply(_("\002{0}\002 added to the {1} list."), mask, source.command);
+ Log(LOG_ADMIN, source, this) << "on " << mask << " (" << reason << "), expires in " << (expires ? Anope::Duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]";
+ if (Anope::ReadOnly)
+ source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
+ }
+
+ ServiceReference<XLineManager> sqlines;
+ public:
+ CommandOSSQLine(Module *creator) : CommandOSSXLineBase(creator, "operserv/sqline"), sqlines("XLineManager", "xlinemanager/sqline")
+ {
+ this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037 \037reason\037"));
+ this->SetSyntax(_("DEL {\037mask\037 | \037entry-num\037 | \037list\037 | \037id\037}"));
+ this->SetSyntax(_("LIST [\037mask\037 | \037list\037 | \037id\037]"));
+ this->SetSyntax(_("VIEW [\037mask\037 | \037list\037 | \037id\037]"));
+ this->SetSyntax("CLEAR");
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ if (subcommand.equals_ci("ADD"))
+ {
+ source.Reply(_("\002{0} ADD\002 adds the given \037mask\037 to the {0} list for the given \037reason\037."
+ " \037expiry\037 is specified as an integer followed by one of \037d\037 (days), \037h\037 (hours), or \037m\037 (minutes)."
+ " If a unit specifier is not included, the default is days, so \037+30\037 by itself means 30 days."
+ " To add a {0} which does not expire, use \037+0\037."
+ " The default {0} expiry time is \002{1}\002."),
+ source.command, Anope::Duration(Config->GetModule("operserv")->Get<time_t>("sqlineexpiry", "30d"), source.GetAccount()));
+
+ const Anope::string &regexengine = Config->GetBlock("options")->Get<Anope::string>("regexengine");
+ if (!regexengine.empty())
+ {
+ source.Reply(" ");
+ source.Reply(_("Regex matches are also supported using the {0} engine. Enclose your mask in // if this is desired."), regexengine);
+ }
+ }
+ else if (subcommand.equals_ci("DEL"))
+ source.Reply(_("The \002{0} DEL\002 command removes the given \037mask\037 from the {0} list if it is present."
+ " If a list of entry numbers is given, those entries are deleted."));
+ else if (subcommand.equals_ci("LIST") || subcommand.equals_ci("VIEW"))
+ source.Reply(_("The \002{0} LIST\002 and \002{0} VIEW\002 commands displays the {0} list.\n"
+ "If a wildcard \037mask\037 is given, only those entries matching the \037mask\037 are displayed."
+ " If a list of entry numbers is given, only those entries are shown."
+ " \002VIEW\002 is similar to \002LIST\002 but also shows who created the {0}, when it was created, and when it expires.\n"
+ "\n"
+ "Example:\n"
+ "\n"
+ " {0} LIST 2-5,7-9\n"
+ " Lists {0} entries numbered 2 through 5 and 7 through 9.\n"),
+ source.command);
+ else if (subcommand.equals_ci("CLEAR"))
+ source.Reply(_("\002{0} CLEAR\002 removes all entries from the {0} list."),
+ source.command);
+ else
+ {
+ CommandInfo *help = source.service->FindCommand("generic/help");
+
+ source.Reply(_("Allows you to manipulate the {0} list."
+ " If a user attempts to use a nickname that matches a {0} mask, services will force the user off of the nickname."
+ " If the first character of the mask is a #, services will prevent the use of matching channels."
+ "\n"
+ "The \002ADD\002 command adds \037mask\037 to the {0} list.\n"
+ "\002{msg}{service} {help} {command} ADD\002 for more information.\n"
+ "\n"
+ "The \002DEL\002 command removes \037mask\037 from the {0} list.\n"
+ "\002{msg}{service} {help} {command} DEL\002 for more information.\n"
+ "\n"
+ "The \002LIST\002 and \002VIEW\002 commands both show the {0} list, but \002VIEW\002 also shows who created the {0} entry, when it was created, and when it expires.\n"
+ "\002{msg}{service} {help} {command} [LIST | VIEW]\002 for more information.\n"
+ "\n"
+ "The \002CLEAR\002 command clears th auto kill list."
+ "\002{msg}{service} {help} {command} CLEAR\002 for more information.\n"),
+ "msg"_kw = Config->StrictPrivmsg, "service"_kw = source.service->nick, "help"_kw = help->cname, "command"_kw = source.command);
+ }
+ return true;
+ }
+};
+
+class OSSXLine : public Module
+{
+ CommandOSSNLine commandossnline;
+ CommandOSSQLine commandossqline;
+
+ public:
+ OSSXLine(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
+ commandossnline(this), commandossqline(this)
+ {
+ }
+};
+
+MODULE_INIT(OSSXLine)
diff --git a/modules/operserv/update.cpp b/modules/operserv/update.cpp
new file mode 100644
index 000000000..8ff39fb69
--- /dev/null
+++ b/modules/operserv/update.cpp
@@ -0,0 +1,49 @@
+/* OperServ core functions
+ *
+ * (C) 2003-2014 Anope Team
+ * Contact us at team@anope.org
+ *
+ * Please read COPYING and README for further details.
+ *
+ * Based on the original code of Epona by Lara.
+ * Based on the original code of Services by Andy Church.
+ */
+
+#include "module.h"
+
+class CommandOSUpdate : public Command
+{
+ public:
+ CommandOSUpdate(Module *creator) : Command(creator, "operserv/update", 0, 0)
+ {
+ this->SetDesc(_("Force the Services databases to be updated immediately"));
+ }
+
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
+ {
+ Log(LOG_ADMIN, source, this);
+ source.Reply(_("Updating databases."));
+ Anope::SaveDatabases();
+ return;
+ }
+
+ bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
+ {
+ source.Reply(_("Causes Services to update all database files."));
+ return true;
+ }
+};
+
+class OSUpdate : public Module
+{
+ CommandOSUpdate commandosupdate;
+
+ public:
+ OSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , commandosupdate(this)
+ {
+
+ }
+};
+
+MODULE_INIT(OSUpdate)