2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2016-2018 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012-2013 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2010 Craig Edwards <brain@inspircd.org>
8 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
10 * Copyright (C) 2006-2007 Dennis Friis <peavey@inspircd.org>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 * 988 <nick> <servername> :Closed for new connections
30 * 989 <nick> <servername> :Open for new connections
39 class CommandLockserv : public Command
44 CommandLockserv(Module* Creator, std::string& lock) : Command(Creator, "LOCKSERV", 0, 1), locked(lock)
46 allow_empty_last_param = false;
50 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
54 user->WriteNotice("The server is already locked.");
58 locked = parameters.empty() ? "Server is temporarily closed. Please try again later." : parameters[0];
59 user->WriteNumeric(RPL_SERVLOCKON, user->server->GetName(), "Closed for new connections");
60 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used LOCKSERV to temporarily disallow new connections", user->nick.c_str());
65 class CommandUnlockserv : public Command
70 CommandUnlockserv(Module* Creator, std::string& lock) : Command(Creator, "UNLOCKSERV", 0), locked(lock)
75 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
79 user->WriteNotice("The server isn't locked.");
84 user->WriteNumeric(RPL_SERVLOCKOFF, user->server->GetName(), "Open for new connections");
85 ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used UNLOCKSERV to allow new connections", user->nick.c_str());
90 class ModuleLockserv : public Module
93 CommandLockserv lockcommand;
94 CommandUnlockserv unlockcommand;
97 ModuleLockserv() : lockcommand(this, locked), unlockcommand(this, locked)
101 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
103 // Emergency way to unlock
108 void OnModuleRehash(User* user, const std::string& param) CXX11_OVERRIDE
110 if (irc::equals(param, "lockserv") && !locked.empty())
114 ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
118 ServerInstance->Users->QuitUser(user, locked);
121 return MOD_RES_PASSTHRU;
124 ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
126 return !locked.empty() ? MOD_RES_DENY : MOD_RES_PASSTHRU;
129 Version GetVersion() CXX11_OVERRIDE
131 return Version("Provides the LOCKSERV and UNLOCKSERV commands to lock the server and block all incoming connections until unlocked again", VF_VENDOR);
135 MODULE_INIT(ModuleLockserv)