diff options
author | Adam <Adam@anope.org> | 2016-10-09 22:15:42 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2016-10-09 22:15:42 -0400 |
commit | 257156c10a918bf9ba4eb7ca4baf043095a5f369 (patch) | |
tree | 0a4b2569addd9cc1c83d39d992619a3115e1b8e4 | |
parent | ab749ce2a871c524c2f187635913998bbcd41a1d (diff) |
Add max vhosts configuration option
-rw-r--r-- | data/hostserv.example.conf | 5 | ||||
-rw-r--r-- | modules/hostserv/add.cpp | 7 | ||||
-rw-r--r-- | modules/hostserv/request.cpp | 16 |
3 files changed, 27 insertions, 1 deletions
diff --git a/data/hostserv.example.conf b/data/hostserv.example.conf index 928261b26..6d551e26b 100644 --- a/data/hostserv.example.conf +++ b/data/hostserv.example.conf @@ -60,6 +60,11 @@ module * If enabled, vhosts are activated on users immediately when they are set. */ activate_on_set = false + + /* + * Maximum number of vhosts that can be assigned to an account. + */ + max_vhosts = 8 } /* diff --git a/modules/hostserv/add.cpp b/modules/hostserv/add.cpp index 42f457b25..240324470 100644 --- a/modules/hostserv/add.cpp +++ b/modules/hostserv/add.cpp @@ -91,6 +91,13 @@ class CommandHSAdd : public Command return; } + unsigned int max_vhosts = Config->GetModule("hostserv/main")->Get<unsigned int>("max_vhosts"); + if (max_vhosts && max_vhosts >= na->GetAccount()->GetRefs<HostServ::VHost *>().size()) + { + source.Reply(_("\002{0}\002 already has the maximum number of vhosts allowed (\002{1}\002)."), na->GetAccount()->GetDisplay(), max_vhosts); + return; + } + Anope::string mask = (!user.empty() ? user + "@" : "") + host; Log(LOG_ADMIN, source, this) << "to add the vhost " << mask << " to " << na->GetAccount()->GetDisplay(); diff --git a/modules/hostserv/request.cpp b/modules/hostserv/request.cpp index 3cc2b1aa9..dcaed4913 100644 --- a/modules/hostserv/request.cpp +++ b/modules/hostserv/request.cpp @@ -212,6 +212,13 @@ class CommandHSRequest : public Command return; } + unsigned int max_vhosts = Config->GetModule("hostserv/main")->Get<unsigned int>("max_vhosts"); + if (max_vhosts && max_vhosts >= u->Account()->GetRefs<HostServ::VHost *>().size()) + { + source.Reply(_("You already has the maximum number of vhosts allowed (\002{0}\002)."), max_vhosts); + return; + } + HostRequest *req = u->Account()->GetRef<HostRequest *>(); if (req != nullptr) req->Delete(); // delete old request @@ -265,7 +272,14 @@ class CommandHSActivate : public Command HostRequest *req = na->GetAccount()->GetRef<HostRequest *>(); if (!req) { - source.Reply(_("\002{0}\002 does not have a pending vhost request."), na->GetNick()); + source.Reply(_("\002{0}\002 does not have a pending vhost request."), na->GetAccount()->GetDisplay()); + return; + } + + unsigned int max_vhosts = Config->GetModule("hostserv/main")->Get<unsigned int>("max_vhosts"); + if (max_vhosts && max_vhosts >= na->GetAccount()->GetRefs<HostServ::VHost *>().size()) + { + source.Reply(_("\002{0}\002 already has the maximum number of vhosts allowed (\002{1}\002)."), na->GetAccount()->GetDisplay(), max_vhosts); return; } |