diff options
| author | Adam <Adam@anope.org> | 2015-12-14 16:52:24 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2015-12-14 16:52:24 -0500 |
| commit | 6302f980fe6dad83aab7d2dc1046dadea5ffd939 (patch) | |
| tree | 4c27d33f55fc32ce34827977932dac4b3e5ceedd /modules/hostserv | |
| parent | 64dac60071fab652745a6e7a06cf6b7bdbbd3625 (diff) | |
New source tree structure for modules. From commands/cs_access => chanserv/access etc.
Diffstat (limited to 'modules/hostserv')
| -rw-r--r-- | modules/hostserv/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | modules/hostserv/del.cpp | 109 | ||||
| -rw-r--r-- | modules/hostserv/group.cpp | 117 | ||||
| -rw-r--r-- | modules/hostserv/list.cpp | 159 | ||||
| -rw-r--r-- | modules/hostserv/main/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | modules/hostserv/main/hostserv.cpp | 135 | ||||
| -rw-r--r-- | modules/hostserv/off.cpp | 60 | ||||
| -rw-r--r-- | modules/hostserv/on.cpp | 70 | ||||
| -rw-r--r-- | modules/hostserv/request.cpp | 414 | ||||
| -rw-r--r-- | modules/hostserv/set.cpp | 216 |
10 files changed, 1282 insertions, 0 deletions
diff --git a/modules/hostserv/CMakeLists.txt b/modules/hostserv/CMakeLists.txt new file mode 100644 index 000000000..cd225a94d --- /dev/null +++ b/modules/hostserv/CMakeLists.txt @@ -0,0 +1 @@ +build_modules(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/hostserv/del.cpp b/modules/hostserv/del.cpp new file mode 100644 index 000000000..b45c10a61 --- /dev/null +++ b/modules/hostserv/del.cpp @@ -0,0 +1,109 @@ +/* HostServ 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/hs_del.h" + +class CommandHSDel : public Command +{ + EventHandlers<Event::DeleteVhost> &OnDeleteVhost; + + public: + CommandHSDel(Module *creator, EventHandlers<Event::DeleteVhost> &onDeleteVhost) : Command(creator, "hostserv/del", 1, 1), OnDeleteVhost(onDeleteVhost) + { + this->SetDesc(_("Delete the vhost of another user")); + this->SetSyntax(_("\037user\037")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + if (Anope::ReadOnly) + source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); + + const Anope::string &nick = params[0]; + NickServ::Nick *na = NickServ::FindNick(nick); + if (!na) + { + source.Reply(_("\002{0}\002 isn't registered."), nick); + return; + } + + Log(LOG_ADMIN, source, this) << "for user " << na->GetNick(); + this->OnDeleteVhost(&Event::DeleteVhost::OnDeleteVhost, na); + na->RemoveVhost(); + source.Reply(_("Vhost for \002{0}\002 has been removed."), na->GetNick()); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Removes the vhost of \037user\037.")); + return true; + } +}; + +class CommandHSDelAll : public Command +{ + EventHandlers<Event::DeleteVhost> &ondeletevhost; + + public: + CommandHSDelAll(Module *creator, EventHandlers<Event::DeleteVhost> &event) : Command(creator, "hostserv/delall", 1, 1), ondeletevhost(event) + { + this->SetDesc(_("Delete the vhost for all nicks in a group")); + this->SetSyntax(_("\037group\037")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + if (Anope::ReadOnly) + source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); + + const Anope::string &nick = params[0]; + NickServ::Nick *na = NickServ::FindNick(nick); + if (!na) + { + source.Reply(_("\002{0}\002 isn't registered."), nick); + return; + } + + this->ondeletevhost(&Event::DeleteVhost::OnDeleteVhost, na); + + NickServ::Account *nc = na->GetAccount(); + for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>(NickServ::nick)) + na2->RemoveVhost(); + Log(LOG_ADMIN, source, this) << "for all nicks in group " << nc->GetDisplay(); + source.Reply(_("Vhosts for group \002{0}\002 have been removed."), nc->GetDisplay()); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Removes the vhost of all nicks in the group \037group\037.")); + return true; + } +}; + +class HSDel : public Module +{ + CommandHSDel commandhsdel; + CommandHSDelAll commandhsdelall; + EventHandlers<Event::DeleteVhost> ondeletevhost; + + public: + HSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhsdel(this, ondeletevhost) + , commandhsdelall(this, ondeletevhost) + , ondeletevhost(this) + { + if (!IRCD || !IRCD->CanSetVHost) + throw ModuleException("Your IRCd does not support vhosts"); + } +}; + +MODULE_INIT(HSDel) diff --git a/modules/hostserv/group.cpp b/modules/hostserv/group.cpp new file mode 100644 index 000000000..c3971fdea --- /dev/null +++ b/modules/hostserv/group.cpp @@ -0,0 +1,117 @@ +/* HostServ 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/ns_group.h" + +class CommandHSGroup : public Command +{ + bool setting; + + public: + void Sync(NickServ::Nick *na) + { + if (setting) + return; + + if (!na || !na->HasVhost()) + return; + + setting = true; + for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick)) + { + nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); + Event::OnSetVhost(&Event::SetVhost::OnSetVhost, nick); + } + setting = false; + } + + CommandHSGroup(Module *creator) : Command(creator, "hostserv/group", 0, 0), setting(false) + { + this->SetDesc(_("Syncs the vhost for all nicks in a group")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + if (Anope::ReadOnly) + { + source.Reply(_("Services are in read-only mode.")); + return; + } + + NickServ::Nick *na = NickServ::FindNick(source.GetNick()); + if (!na || na->GetAccount() != source.GetAccount()) + { + source.Reply(_("Access denied.")); + return; + } + + if (!na->HasVhost()) + { + source.Reply(_("There is no vhost assigned to this nickname.")); + return; + } + + this->Sync(na); + if (!na->GetVhostIdent().empty()) + source.Reply(_("All vhosts in the group \002{0}\002 have been set to \002{1}\002@\002{2}\002."), source.nc->GetDisplay(), na->GetVhostIdent(), na->GetVhostHost()); + else + source.Reply(_("All vhosts in the group \002{0}\002 have been set to \002{1}\002."), source.nc->GetDisplay(), na->GetVhostHost()); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Sets the vhost of all nicks in your group to the vhost of your current nick.")); + return true; + } +}; + +class HSGroup : public Module + , public EventHook<Event::SetVhost> + , public EventHook<Event::NickGroup> +{ + CommandHSGroup commandhsgroup; + bool syncongroup; + bool synconset; + + public: + HSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhsgroup(this) + { + if (!IRCD || !IRCD->CanSetVHost) + throw ModuleException("Your IRCd does not support vhosts"); + } + + void OnSetVhost(NickServ::Nick *na) override + { + if (!synconset) + return; + + commandhsgroup.Sync(na); + } + + void OnNickGroup(User *u, NickServ::Nick *na) override + { + if (!syncongroup) + return; + + commandhsgroup.Sync(na); + } + + void OnReload(Configuration::Conf *conf) override + { + Configuration::Block *block = conf->GetModule(this); + syncongroup = block->Get<bool>("syncongroup"); + synconset = block->Get<bool>("synconset"); + } +}; + +MODULE_INIT(HSGroup) diff --git a/modules/hostserv/list.cpp b/modules/hostserv/list.cpp new file mode 100644 index 000000000..738f9f1bd --- /dev/null +++ b/modules/hostserv/list.cpp @@ -0,0 +1,159 @@ +/* HostServ 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 CommandHSList : public Command +{ + public: + CommandHSList(Module *creator) : Command(creator, "hostserv/list", 0, 1) + { + this->SetDesc(_("Displays one or more vhost entries")); + this->SetSyntax(_("[\037key\037|\037#X-Y\037]")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + const Anope::string &key = !params.empty() ? params[0] : ""; + int from = 0, to = 0, counter = 1; + + /** + * Do a check for a range here, then in the next loop + * we'll only display what has been requested.. + **/ + if (!key.empty() && key[0] == '#') + { + size_t tmp = key.find('-'); + if (tmp == Anope::string::npos || tmp == key.length() || tmp == 1) + { + source.Reply(_("Incorrect range specified. The correct syntax is \002#\037from\037-\037to\037\002.")); + return; + } + for (unsigned i = 1, end = key.length(); i < end; ++i) + { + if (!isdigit(key[i]) && i != tmp) + { + source.Reply(_("Incorrect range specified. The correct syntax is \002#\037from\037-\037to\037\002.")); + return; + } + try + { + from = convertTo<int>(key.substr(1, tmp - 1)); + to = convertTo<int>(key.substr(tmp + 1)); + } + catch (const ConvertException &) { } + } + } + + unsigned display_counter = 0, listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax", "50"); + ListFormatter list(source.GetAccount()); + list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Creator")).AddColumn(_("Created")); + + for (NickServ::Nick *na : NickServ::service->GetNickList()) + { + if (!na->HasVhost()) + continue; + + if (!key.empty() && key[0] != '#') + { + if ((Anope::Match(na->GetNick(), key) || Anope::Match(na->GetVhostHost(), key)) && display_counter < listmax) + { + ++display_counter; + + ListFormatter::ListEntry entry; + entry["Number"] = stringify(display_counter); + entry["Nick"] = na->GetNick(); + if (!na->GetVhostIdent().empty()) + entry["Vhost"] = na->GetVhostIdent() + "@" + na->GetVhostHost(); + else + entry["Vhost"] = na->GetVhostHost(); + entry["Creator"] = na->GetVhostCreator(); + entry["Created"] = Anope::strftime(na->GetVhostCreated(), NULL, true); + list.AddEntry(entry); + } + } + else + { + /** + * List the host if its in the display range, and not more + * than NSListMax records have been displayed... + **/ + if (((counter >= from && counter <= to) || (!from && !to)) && display_counter < listmax) + { + ++display_counter; + ListFormatter::ListEntry entry; + entry["Number"] = stringify(display_counter); + entry["Nick"] = na->GetNick(); + if (!na->GetVhostIdent().empty()) + entry["Vhost"] = na->GetVhostIdent() + "@" + na->GetVhostHost(); + else + entry["Vhost"] = na->GetVhostHost(); + entry["Creator"] = na->GetVhostCreator(); + entry["Created"] = Anope::strftime(na->GetVhostCreated(), NULL, true); + list.AddEntry(entry); + } + } + ++counter; + } + + if (!display_counter) + { + source.Reply(_("No records to display.")); + return; + } + + if (!key.empty()) + source.Reply(_("Displayed records matching key \002{0}\002 (count: \002{1}\002)."), key, display_counter); + else + { + if (from) + source.Reply(_("Displayed records from \002{0}\002 to \002{1}\002."), from, to); + else + source.Reply(_("Displayed all records (count: \002{0}\002)."), display_counter); + } + + std::vector<Anope::string> replies; + list.Process(replies); + + for (unsigned i = 0; i < replies.size(); ++i) + source.Reply(replies[i]); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Lists all vhosts. If \037key\037 is specified, only entries whose nick or vhost match the pattern given in \037key\037 are displayed." + "If a \037#X-Y\037 style is used, only entries between the range of \002X\002 and \002Y\002 will be displayed.\n" + "\n" + "Examples:\n" + " {0} Rob*\n" + " Lists all entries with the nick or vhost beginning with \"Rob\"\n" + "\n" + " {0} #1-3\n" + " Lists the first three entries."), + source.command); + return true; + } +}; + +class HSList : public Module +{ + CommandHSList commandhslist; + + public: + HSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhslist(this) + { + if (!IRCD || !IRCD->CanSetVHost) + throw ModuleException("Your IRCd does not support vhosts"); + } +}; + +MODULE_INIT(HSList) diff --git a/modules/hostserv/main/CMakeLists.txt b/modules/hostserv/main/CMakeLists.txt new file mode 100644 index 000000000..781f0ef1f --- /dev/null +++ b/modules/hostserv/main/CMakeLists.txt @@ -0,0 +1 @@ +build_subdir(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/modules/hostserv/main/hostserv.cpp b/modules/hostserv/main/hostserv.cpp new file mode 100644 index 000000000..285ea893b --- /dev/null +++ b/modules/hostserv/main/hostserv.cpp @@ -0,0 +1,135 @@ +/* HostServ 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/ns_update.h" +#include "modules/hs_del.h" +#include "modules/help.h" + +class HostServCore : public Module + , public EventHook<Event::UserLogin> + , public EventHook<Event::NickUpdate> + , public EventHook<Event::Help> + , public EventHook<Event::SetVhost> + , public EventHook<Event::DeleteVhost> +{ + Reference<ServiceBot> HostServ; + + public: + HostServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + { + if (!IRCD || !IRCD->CanSetVHost) + throw ModuleException("Your IRCd does not support vhosts"); + } + + void OnReload(Configuration::Conf *conf) override + { + const Anope::string &hsnick = conf->GetModule(this)->Get<Anope::string>("client"); + + if (hsnick.empty()) + throw ConfigException(Module::name + ": <client> must be defined"); + + ServiceBot *bi = ServiceBot::Find(hsnick, true); + if (!bi) + throw ConfigException(Module::name + ": no bot named " + hsnick); + + HostServ = bi; + } + + void OnUserLogin(User *u) override + { + if (!IRCD->CanSetVHost) + return; + + NickServ::Nick *na = NickServ::FindNick(u->nick); + if (!na || na->GetAccount() != u->Account() || !na->HasVhost()) + na = NickServ::FindNick(u->Account()->GetDisplay()); + if (!na || !na->HasVhost()) + return; + + if (u->vhost.empty() || !u->vhost.equals_cs(na->GetVhostHost()) || (!na->GetVhostIdent().empty() && !u->GetVIdent().equals_cs(na->GetVhostIdent()))) + { + IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost()); + + u->vhost = na->GetVhostHost(); + u->UpdateHost(); + + if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty()) + u->SetVIdent(na->GetVhostIdent()); + + if (HostServ) + { + if (!na->GetVhostIdent().empty()) + u->SendMessage(*HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str()); + else + u->SendMessage(*HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str()); + } + } + } + + void OnNickUpdate(User *u) override + { + this->OnUserLogin(u); + } + + EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + if (!params.empty() || source.c || source.service != *HostServ) + return EVENT_CONTINUE; + source.Reply(_("%s commands:"), HostServ->nick.c_str()); + return EVENT_CONTINUE; + } + + void OnPostHelp(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + } + + void OnSetVhost(NickServ::Nick *na) override + { + if (Config->GetModule(this)->Get<bool>("activate_on_set")) + { + User *u = User::Find(na->GetNick()); + + if (u && u->Account() == na->GetAccount()) + { + IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost()); + + u->vhost = na->GetVhostHost(); + u->UpdateHost(); + + if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty()) + u->SetVIdent(na->GetVhostIdent()); + + if (HostServ) + { + if (!na->GetVhostIdent().empty()) + u->SendMessage(*HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str()); + else + u->SendMessage(*HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str()); + } + } + } + } + + void OnDeleteVhost(NickServ::Nick *na) override + { + if (Config->GetModule(this)->Get<bool>("activate_on_set")) + { + User *u = User::Find(na->GetNick()); + + if (u && u->Account() == na->GetAccount()) + IRCD->SendVhostDel(u); + } + } +}; + +MODULE_INIT(HostServCore) + diff --git a/modules/hostserv/off.cpp b/modules/hostserv/off.cpp new file mode 100644 index 000000000..8f3c7e3da --- /dev/null +++ b/modules/hostserv/off.cpp @@ -0,0 +1,60 @@ +/* HostServ 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 CommandHSOff : public Command +{ + public: + CommandHSOff(Module *creator) : Command(creator, "hostserv/off", 0, 0) + { + this->SetDesc(_("Deactivates your assigned vhost")); + this->RequireUser(true); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + User *u = source.GetUser(); + NickServ::Nick *na = NickServ::FindNick(u->nick); + + if (!na || !na->HasVhost() || na->GetAccount() != source.GetAccount()) + { + source.Reply(_("There is no vhost assigned to this nickname.")); + return; + } + + u->vhost.clear(); + IRCD->SendVhostDel(u); + Log(LOG_COMMAND, source, this) << "to disable their vhost"; + source.Reply(_("Your vhost was removed and the normal cloaking restored.")); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Deactivates your vhost.")); + return true; + } +}; + +class HSOff : public Module +{ + CommandHSOff commandhsoff; + + public: + HSOff(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhsoff(this) + { + if (!IRCD || !IRCD->CanSetVHost) + throw ModuleException("Your IRCd does not support vhosts"); + } +}; + +MODULE_INIT(HSOff) diff --git a/modules/hostserv/on.cpp b/modules/hostserv/on.cpp new file mode 100644 index 000000000..409d56ac5 --- /dev/null +++ b/modules/hostserv/on.cpp @@ -0,0 +1,70 @@ +/* HostServ 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 CommandHSOn : public Command +{ + public: + CommandHSOn(Module *creator) : Command(creator, "hostserv/on", 0, 0) + { + this->SetDesc(_("Activates your assigned vhost")); + this->RequireUser(true); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + if (!IRCD->CanSetVHost) + return; // HostServ wouldn't even be loaded at this point + + User *u = source.GetUser(); + NickServ::Nick *na = NickServ::FindNick(u->nick); + + if (!na || !na->HasVhost() || na->GetAccount() != u->Account()) + { + source.Reply(_("There is no vhost assigned to this nickname.")); + return; + } + + if (!na->GetVhostIdent().empty()) + source.Reply(_("Your vhost of \002{0}\002@\002{1}\002 is now activated."), na->GetVhostIdent(), na->GetVhostHost()); + else + source.Reply(_("Your vhost of \002{0}\002 is now activated."), na->GetVhostHost()); + + Log(LOG_COMMAND, source, this) << "to enable their vhost of " << (!na->GetVhostIdent().empty() ? na->GetVhostIdent() + "@" : "") << na->GetVhostHost(); + IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost()); + u->vhost = na->GetVhostHost(); + if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty()) + u->SetVIdent(na->GetVhostIdent()); + u->UpdateHost(); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Activates your vhost.")); + return true; + } +}; + +class HSOn : public Module +{ + CommandHSOn commandhson; + + public: + HSOn(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , commandhson(this) + { + if (!IRCD || !IRCD->CanSetVHost) + throw ModuleException("Your IRCd does not support vhosts"); + } +}; + +MODULE_INIT(HSOn) diff --git a/modules/hostserv/request.cpp b/modules/hostserv/request.cpp new file mode 100644 index 000000000..8a064a84c --- /dev/null +++ b/modules/hostserv/request.cpp @@ -0,0 +1,414 @@ +/* + * + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +#include "module.h" +#include "modules/memoserv.h" + +static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost); + +class HostRequest : public Serialize::Object +{ + public: + HostRequest(Serialize::TypeBase *type) : Serialize::Object(type) { } + HostRequest(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { } + + NickServ::Nick *GetNick(); + void SetNick(NickServ::Nick *na); + + Anope::string GetIdent(); + void SetIdent(const Anope::string &i); + + Anope::string GetHost(); + void SetHost(const Anope::string &h); + + time_t GetTime(); + void SetTime(const time_t &t); +}; + +class HostRequestType : public Serialize::Type<HostRequest> +{ + public: + Serialize::ObjectField<HostRequest, NickServ::Nick *> na; + Serialize::Field<HostRequest, Anope::string> ident, host; + Serialize::Field<HostRequest, time_t> time; + + HostRequestType(Module *me) : Serialize::Type<HostRequest>(me, "HostRequest") + , na(this, "na", true) + , ident(this, "ident") + , host(this, "host") + , time(this, "time") + { + } +}; + +NickServ::Nick *HostRequest::GetNick() +{ + return Get(&HostRequestType::na); +} + +void HostRequest::SetNick(NickServ::Nick *na) +{ + Set(&HostRequestType::na, na); +} + +Anope::string HostRequest::GetIdent() +{ + return Get(&HostRequestType::ident); +} + +void HostRequest::SetIdent(const Anope::string &i) +{ + Set(&HostRequestType::ident, i); +} + +Anope::string HostRequest::GetHost() +{ + return Get(&HostRequestType::host); +} + +void HostRequest::SetHost(const Anope::string &h) +{ + Set(&HostRequestType::host, h); +} + +time_t HostRequest::GetTime() +{ + return Get(&HostRequestType::time); +} + +void HostRequest::SetTime(const time_t &t) +{ + Set(&HostRequestType::time, t); +} + +static Serialize::TypeReference<HostRequest> hostrequest("HostRequest"); + +class CommandHSRequest : public Command +{ + public: + CommandHSRequest(Module *creator) : Command(creator, "hostserv/request", 1, 1) + { + this->SetDesc(_("Request a vHost for your nick")); + this->SetSyntax(_("vhost")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + if (Anope::ReadOnly) + { + source.Reply(_("Services are in read-only mode.")); + return; + } + + User *u = source.GetUser(); + NickServ::Nick *na = NickServ::FindNick(source.GetNick()); + if (!na || na->GetAccount() != source.GetAccount()) + { + source.Reply(_("Access denied.")); //XXX with nonickownership this should be allowed. + return; + } + + if (source.GetAccount()->HasFieldS("UNCONFIRMED")) + { + source.Reply(_("You must confirm your account before you may request a vhost.")); + return; + } + + Anope::string rawhostmask = params[0]; + + Anope::string user, host; + size_t a = rawhostmask.find('@'); + + if (a == Anope::string::npos) + host = rawhostmask; + else + { + user = rawhostmask.substr(0, a); + host = rawhostmask.substr(a + 1); + } + + if (host.empty()) + { + this->OnSyntaxError(source, ""); + return; + } + + if (!user.empty()) + { + if (user.length() > Config->GetBlock("networkinfo")->Get<unsigned>("userlen")) + { + source.Reply(_("The username \002{0}\002 is too long, please use a username shorter than %d characters."), Config->GetBlock("networkinfo")->Get<unsigned>("userlen")); + return; + } + + if (!IRCD->CanSetVIdent) + { + source.Reply(_("Vhosts may not contain a username.")); + return; + } + + if (!IRCD->IsIdentValid(user)) + { + source.Reply(_("The requested username is not valid.")); + return; + } + } + + if (host.length() > Config->GetBlock("networkinfo")->Get<unsigned>("hostlen")) + { + source.Reply(_("The requested vhost is too long, please use a hostname no longer than {0} characters."), Config->GetBlock("networkinfo")->Get<unsigned>("hostlen")); + return; + } + + if (!IRCD->IsHostValid(host)) + { + source.Reply(_("The requested hostname is not valid.")); + return; + } + + time_t send_delay = Config->GetModule("memoserv")->Get<time_t>("senddelay"); + if (Config->GetModule(this->owner)->Get<bool>("memooper") && send_delay > 0 && u && u->lastmemosend + send_delay > Anope::CurTime) + { + source.Reply(_("Please wait %d seconds before requesting a new vHost."), send_delay); + u->lastmemosend = Anope::CurTime; + return; + } + + HostRequest *req = hostrequest.Create(); + req->SetNick(na); + req->SetIdent(user); + req->SetHost(host); + req->SetTime(Anope::CurTime); + + source.Reply(_("Your vhost has been requested.")); + req_send_memos(owner, source, user, host); + Log(LOG_COMMAND, source, this) << "to request new vhost " << (!user.empty() ? user + "@" : "") << host; + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Request the given \036vhost\037 to be actived for your nick by the network administrators. Please be patient while your request is being considered.")); + return true; + } +}; + +class CommandHSActivate : public Command +{ + public: + CommandHSActivate(Module *creator) : Command(creator, "hostserv/activate", 1, 1) + { + this->SetDesc(_("Approve the requested vHost of a user")); + this->SetSyntax(_("\037user\037")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + if (Anope::ReadOnly) + { + source.Reply(_("Services are in read-only mode.")); + return; + } + + const Anope::string &nick = params[0]; + NickServ::Nick *na = NickServ::FindNick(nick); + + if (!na) + { + source.Reply(_("\002{0}\002 isn't registered."), nick); + return; + } + + HostRequest *req = na->GetExt<HostRequest>("hostrequest"); + if (!req) + { + source.Reply(_("\002{0}\002 does not have a pending vhost request."), na->GetNick()); + return; + } + + na->SetVhost(req->GetIdent(), req->GetHost(), source.GetNick(), req->GetTime()); + Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na); + + if (Config->GetModule(this->owner)->Get<bool>("memouser") && MemoServ::service) + MemoServ::service->Send(source.service->nick, na->GetNick(), _("[auto memo] Your requested vHost has been approved."), true); + + source.Reply(_("Vhost for \002{0}\002 has been activated."), na->GetNick()); + Log(LOG_COMMAND, source, this) << "for " << na->GetNick() << " for vhost " << (!req->GetIdent().empty() ? req->GetIdent() + "@" : "") << req->GetHost(); + req->Delete(); + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Activate the requested vhost for the given user.")); + if (Config->GetModule(this->owner)->Get<bool>("memouser")) + source.Reply(_("A memo informing the user will also be sent.")); + + return true; + } +}; + +class CommandHSReject : public Command +{ + public: + CommandHSReject(Module *creator) : Command(creator, "hostserv/reject", 1, 2) + { + this->SetDesc(_("Reject the requested vHost of a user")); + this->SetSyntax(_("\037user\037 [\037reason\037]")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + if (Anope::ReadOnly) + { + source.Reply(_("Services are in read-only mode.")); + return; + } + + const Anope::string &nick = params[0]; + const Anope::string &reason = params.size() > 1 ? params[1] : ""; + + NickServ::Nick *na = NickServ::FindNick(nick); + if (!na) + { + source.Reply(_("\002{0}\002 isn't registered."), nick); + return; + } + + HostRequest *req = na->GetExt<HostRequest>("hostrequest"); + if (!req) + { + source.Reply(_("\002{0}\002 does not have a pending vhost request."), na->GetNick()); + return; + } + + req->Delete(); + + if (Config->GetModule(this->owner)->Get<bool>("memouser") && MemoServ::service) + { + Anope::string message; + if (!reason.empty()) + message = Anope::printf(_("[auto memo] Your requested vHost has been rejected. Reason: %s"), reason.c_str()); + else + message = _("[auto memo] Your requested vHost has been rejected."); + + MemoServ::service->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true); + } + + source.Reply(_("Vhost for \002{0}\002 has been rejected."), na->GetNick()); + Log(LOG_COMMAND, source, this) << "to reject vhost for " << nick << " (" << (!reason.empty() ? reason : "no reason") << ")"; + } + + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override + { + source.Reply(_("Reject the requested vhost for the given user.")); + if (Config->GetModule(this->owner)->Get<bool>("memouser")) + source.Reply(_("A memo informing the user will also be sent, which includes the reason for the rejection if supplied.")); + + return true; + } +}; + +class CommandHSWaiting : public Command +{ + public: + CommandHSWaiting(Module *creator) : Command(creator, "hostserv/waiting", 0, 0) + { + this->SetDesc(_("Retrieves the vhost requests")); + } + + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override + { + unsigned counter = 0; + unsigned display_coun |
