diff options
-rw-r--r-- | data/example.conf | 2 | ||||
-rw-r--r-- | docs/Changes.conf | 1 | ||||
-rw-r--r-- | modules/core/os_forbid.cpp | 2 | ||||
-rw-r--r-- | modules/core/os_oper.cpp | 221 | ||||
-rw-r--r-- | modules/core/os_staff.cpp | 80 |
5 files changed, 224 insertions, 82 deletions
diff --git a/data/example.conf b/data/example.conf index 0a4827a98..f98b8b9f5 100644 --- a/data/example.conf +++ b/data/example.conf @@ -1420,7 +1420,7 @@ operserv * * This directive is optional, but highly recommended. */ - modules = "os_help os_stats os_staff os_mode os_kick os_akill os_snline os_sqline os_szline os_chanlist os_userlist os_news os_session os_noop os_jupe os_ignore os_set os_reload os_update os_restart os_quit os_shutdown os_chankill os_svsnick os_oline os_modload os_modunload os_modreload os_modlist os_modinfo os_config os_login os_forbid" + modules = "os_help os_stats os_oper os_mode os_kick os_akill os_snline os_sqline os_szline os_chanlist os_userlist os_news os_session os_noop os_jupe os_ignore os_set os_reload os_update os_restart os_quit os_shutdown os_chankill os_svsnick os_oline os_modload os_modunload os_modreload os_modlist os_modinfo os_config os_login os_forbid" /* * If set, Services Admins will be able to use SUPERADMIN [ON|OFF] which will temporarily grant diff --git a/docs/Changes.conf b/docs/Changes.conf index 1cdf28ba9..31d42a5b2 100644 --- a/docs/Changes.conf +++ b/docs/Changes.conf @@ -11,6 +11,7 @@ operserv:modules added os_forbid ** MODIFIED CONFIGURATION DIRECTIVES ** opertype:permissions added memoserv/no-limit operserv:modules removed os_global +operserv:modules renamed os_staff to os_oper ** DELETED CONFIGURATION DIRECTIVES ** memoserv:notifyall diff --git a/modules/core/os_forbid.cpp b/modules/core/os_forbid.cpp index 26314d966..6ac4ffc0b 100644 --- a/modules/core/os_forbid.cpp +++ b/modules/core/os_forbid.cpp @@ -275,7 +275,7 @@ class OSForbid : public Module EventReturn OnPreCommand(CommandSource &source, Command *command, const std::vector<Anope::string> ¶ms) { if (source.u->HasMode(UMODE_OPER)) - return EVEMT_CONTINUE; + return EVENT_CONTINUE; else if (command->service->nick == Config->s_NickServ && command->name == "REGISTER" && params.size() > 1) { ForbidData *d = this->forbidService.FindForbid(params[1], FT_EMAIL); diff --git a/modules/core/os_oper.cpp b/modules/core/os_oper.cpp new file mode 100644 index 000000000..80a5dc4be --- /dev/null +++ b/modules/core/os_oper.cpp @@ -0,0 +1,221 @@ +/* OperServ core functions + * + * (C) 2003-2011 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 "operserv.h" + +class CommandOSOper : public Command +{ + public: + CommandOSOper() : Command("OPER", 1, 3, "operserv/oper") + { + this->SetDesc(_("View and change services operators")); + } + + CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) + { + const Anope::string &subcommand = params[0]; + + if (subcommand.equals_ci("ADD") && params.size() > 2) + { + const Anope::string &oper = params[1]; + const Anope::string &type = params[2]; + + NickAlias *na = findnick(oper); + if (na == NULL) + source.Reply(_(NICK_X_NOT_REGISTERED), oper.c_str()); + else + { + OperType *ot = OperType::Find(type); + if (ot == NULL) + source.Reply(_("Oper type \2%s\2 has not been configured."), type.c_str()); + else + { + if (na->nc->o) + delete na->nc->o; + na->nc->o = new Oper(na->nc->display, "", "", ot); + + Log(LOG_ADMIN, source.u, this) << "ADD " << na->nick << " as type " << ot->GetName(); + source.Reply("%s (%s) added to the \2%s\2 list.", na->nick.c_str(), na->nc->display.c_str(), ot->GetName().c_str()); + } + } + } + else if (subcommand.equals_ci("DEL") && params.size() > 1) + { + const Anope::string &oper = params[1]; + + NickAlias *na = findnick(oper); + if (na == NULL) + source.Reply(_(NICK_X_NOT_REGISTERED), oper.c_str()); + else if (!na->nc || !na->nc->o) + source.Reply(_("Nick \2%s\2 is not a services operator."), oper.c_str()); + else + { + delete na->nc->o; + na->nc->o = NULL; + + Log(LOG_ADMIN, source.u, this) << "DEL " << na->nick; + source.Reply(_("Oper privileges removed from %s (%s)."), na->nick.c_str(), na->nc->display.c_str()); + } + } + else if (subcommand.equals_ci("LIST")) + { + source.Reply(_("Name Type")); + for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it) + { + NickCore *nc = it->second; + + if (!nc->o) + continue; + + source.Reply(_("%-8s %s"), nc->o->name.c_str(), nc->o->ot->GetName().c_str()); + for (std::list<NickAlias *>::const_iterator it2 = nc->aliases.begin(), it2_end = nc->aliases.end(); it2 != it2_end; ++it2) + if (Oper::Find((*it2)->nick) != NULL) + source.Reply(_(" This oper is configured in the configuration file as %s"), (*it2)->nick.c_str()); + for (std::list<User *>::iterator uit = nc->Users.begin(); uit != nc->Users.end(); ++uit) + { + User *u = *uit; + source.Reply(_(" %s is online using this oper block."), u->nick.c_str()); + } + } + } + else if (subcommand.equals_ci("INFO") && params.size() > 1) + { + Anope::string fulltype = params[1]; + if (params.size() > 2) + fulltype += " " + params[2]; + OperType *ot = OperType::Find(fulltype); + if (ot == NULL) + source.Reply(_("Oper type \2%s\2 has not been configured."), fulltype.c_str()); + else + { + if (ot->GetCommands().empty()) + source.Reply(_("Opertype \2%s\2 has no allowed commands."), ot->GetName().c_str()); + else + { + source.Reply(_("Available commands for \2%s\2:"), ot->GetName().c_str()); + Anope::string buf; + for (std::list<Anope::string>::const_iterator it = ot->GetCommands().begin(), it_end = ot->GetCommands().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 \2%s\2 has no allowed privileges."), ot->GetName().c_str()); + else + { + source.Reply(_("Available privileges for \2%s\2:"), ot->GetName().c_str()); + Anope::string buf; + for (std::list<Anope::string>::const_iterator it = ot->GetPrivs().begin(), it_end = ot->GetPrivs().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(); + } + } + } + } + else + this->OnSyntaxError(source, subcommand); + + return MOD_CONT; + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) + { + source.Reply(_("Syntax: \002OPER {ADD|DEL|LIST|INFO} [\037oper\037] [\037type\037\002\n" + "\n" + "\002OPER\002 allows you to change and view services operators.\n" + "Note that operators removed by this command but are still set in\n" + "the configuration file are not permanently affected by this.")); + return true; + } + + void OnSyntaxError(CommandSource &source, const Anope::string &subcommand) + { + SyntaxError(source, "OPER", _("OPER {ADD|DEL|LIST|INFO} [\037oper\037] [\037type\037")); + } +}; + +class OSOper : public Module +{ + CommandOSOper commandosoper; + + public: + OSOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE) + { + this->SetAuthor("Anope"); + + if (!operserv) + throw ModuleException("OperServ is not loaded!"); + + Implementation i[] = { I_OnDatabaseWrite, I_OnDatabaseRead }; + ModuleManager::Attach(i, this, 2); + + this->AddCommand(operserv->Bot(), &commandosoper); + } + + void OnDatabaseWrite(void (*Write)(const Anope::string &)) + { + for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it) + { + NickCore *nc = it->second; + if (!nc->o) + continue; + bool found = false; + for (std::list<NickAlias *>::const_iterator it2 = nc->aliases.begin(), it2_end = nc->aliases.end(); it2 != it2_end; ++it2) + if (Oper::Find((*it2)->nick) != NULL) + found = true; + if (found == false) + { + Write("OPER " + nc->display + " :" + nc->o->ot->GetName()); + } + } + } + + EventReturn OnDatabaseRead(const std::vector<Anope::string> ¶ms) + { + if (params[0] == "OPER" && params.size() > 2) + { + NickCore *nc = findcore(params[1]); + if (!nc || nc->o) + return EVENT_CONTINUE; + OperType *ot = OperType::Find(params[2]); + if (ot == NULL) + return EVENT_CONTINUE; + nc->o = new Oper(nc->display, "", "", ot); + Log(LOG_NORMAL, "operserv/oper", operserv->Bot()) << "Tied oper " << nc->display << " to type " << ot->GetName(); + } + return EVENT_CONTINUE; + } +}; + +MODULE_INIT(OSOper) diff --git a/modules/core/os_staff.cpp b/modules/core/os_staff.cpp deleted file mode 100644 index 0f59d9650..000000000 --- a/modules/core/os_staff.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* OperServ core functions - * - * (C) 2003-2011 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 "operserv.h" - -class CommandOSStaff : public Command -{ - public: - CommandOSStaff() : Command("STAFF", 0, 0, "operserv/staff") - { - this->SetDesc(_("Display Services staff and online status")); - } - - CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) - { - source.Reply(_("On Level Nick")); - - for (unsigned i = 0; i < Config->Opers.size(); ++i) - { - Oper *o = Config->Opers[i]; - - NickAlias *na = findnick(o->name); - if (na) - { - NickCore *nc = na->nc; - for (std::list<User *>::iterator uit = nc->Users.begin(); uit != nc->Users.end(); ++uit) - { - User *u2 = *uit; - - if (na->nick.equals_ci(u2->nick)) - source.Reply(_(" %c %s %s"), '*', o->ot->GetName().c_str(), u2->nick.c_str()); - else - source.Reply(_(" %c %s %s [%s]"), '*', o->ot->GetName().c_str(), na->nick.c_str(), u2->nick.c_str()); - } - if (nc->Users.empty()) - source.Reply(_(" %c %s %s"), ' ', o->ot->GetName().c_str(), na->nick.c_str()); - } - } - - source.Reply(_(END_OF_ANY_LIST), "Staff"); - return MOD_CONT; - } - - bool OnHelp(CommandSource &source, const Anope::string &subcommand) - { - source.Reply(_("Syntax: \002STAFF\002\n" - "Displays all Services Staff nicks along with level\n" - "and on-line status.")); - return true; - } -}; - -class OSStaff : public Module -{ - CommandOSStaff commandosstaff; - - public: - OSStaff(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE) - { - this->SetAuthor("Anope"); - - if (!operserv) - throw ModuleException("OperServ is not loaded!"); - - this->AddCommand(operserv->Bot(), &commandosstaff); - } -}; - -MODULE_INIT(OSStaff) |