-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
*
- * InspIRCd: (C) 2002-2007 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ * Copyright (C) 2006-2007 Dennis Friis <peavey@inspircd.org>
+ * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
*
- * This program is free but copyrighted software; see
- * the file COPYING for details.
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
*
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "inspircd.h"
-/* $ModDesc: Allows locking of the server to stop all incoming connections till unlocked again */
+#include "inspircd.h"
/** Adds numerics
* 988 <nick> <servername> :Closed for new connections
* 989 <nick> <servername> :Open for new connections
-*/
-
-
-class cmd_lockserv : public command_t
+ */
+enum
{
-private:
- bool& locked;
-
-public:
- cmd_lockserv (InspIRCd* Instance, bool &lock)
- : command_t(Instance, "LOCKSERV", 'o', 0), locked(lock)
- {
- this->source = "m_lockserv.so";
- syntax.clear();
- }
-
- CmdResult Handle (const char** parameters, int pcnt, userrec *user)
- {
- locked = true;
- user->WriteServ("988 %s %s :Closed for new connections", user->nick, user->server);
- ServerInstance->WriteOpers("*** Oper %s used LOCKSERV to temporarily close for new connections", user->nick);
- /* Dont send to the network */
- return CMD_LOCALONLY;
- }
+ // InspIRCd-specific.
+ RPL_SERVLOCKON = 988,
+ RPL_SERVLOCKOFF = 989
};
-class cmd_unlockserv : public command_t
+class CommandLockserv : public Command
{
-private:
- bool& locked;
+ std::string& locked;
-public:
- cmd_unlockserv (InspIRCd* Instance, bool &lock)
- : command_t(Instance, "UNLOCKSERV", 'o', 0), locked(lock)
+ public:
+ CommandLockserv(Module* Creator, std::string& lock) : Command(Creator, "LOCKSERV", 0, 1), locked(lock)
{
- this->source = "m_lockserv.so";
- syntax.clear();
+ allow_empty_last_param = false;
+ flags_needed = 'o';
}
- CmdResult Handle (const char** parameters, int pcnt, userrec *user)
+ CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
{
- locked = false;
- user->WriteServ("989 %s %s :Open for new connections", user->nick, user->server);
- ServerInstance->WriteOpers("*** Oper %s used UNLOCKSERV to allow for new connections", user->nick);
- /* Dont send to the network */
- return CMD_LOCALONLY;
+ if (!locked.empty())
+ {
+ user->WriteNotice("The server is already locked.");
+ return CMD_FAILURE;
+ }
+
+ locked = parameters.empty() ? "Server is temporarily closed. Please try again later." : parameters[0];
+ user->WriteNumeric(RPL_SERVLOCKON, user->server->GetName(), "Closed for new connections");
+ ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used LOCKSERV to temporarily disallow new connections", user->nick.c_str());
+ return CMD_SUCCESS;
}
};
-class ModuleLockserv : public Module
+class CommandUnlockserv : public Command
{
-private:
- bool locked;
- cmd_lockserv* lockcommand;
- cmd_unlockserv* unlockcommand;
+ std::string& locked;
- virtual void ResetLocked()
+ public:
+ CommandUnlockserv(Module* Creator, std::string& lock) : Command(Creator, "UNLOCKSERV", 0), locked(lock)
{
- locked = false;
+ flags_needed = 'o';
}
-public:
- ModuleLockserv(InspIRCd* Me) : Module(Me)
+ CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE
{
- ResetLocked();
- lockcommand = new cmd_lockserv(ServerInstance, locked);
- ServerInstance->AddCommand(lockcommand);
+ if (locked.empty())
+ {
+ user->WriteNotice("The server isn't locked.");
+ return CMD_FAILURE;
+ }
- unlockcommand = new cmd_unlockserv(ServerInstance, locked);
- ServerInstance->AddCommand(unlockcommand);
+ locked.clear();
+ user->WriteNumeric(RPL_SERVLOCKOFF, user->server->GetName(), "Open for new connections");
+ ServerInstance->SNO->WriteGlobalSno('a', "Oper %s used UNLOCKSERV to allow new connections", user->nick.c_str());
+ return CMD_SUCCESS;
}
+};
- virtual ~ModuleLockserv()
- {
- }
+class ModuleLockserv : public Module
+{
+ std::string locked;
+ CommandLockserv lockcommand;
+ CommandUnlockserv unlockcommand;
- void Implements(char* List)
+ public:
+ ModuleLockserv() : lockcommand(this, locked), unlockcommand(this, locked)
{
- List[I_OnUserRegister] = List[I_OnRehash] = List[I_OnCheckReady] = 1;
}
- virtual void OnRehash(userrec* user, const std::string ¶meter)
+ void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
{
- ResetLocked();
+ // Emergency way to unlock
+ if (!status.srcuser)
+ locked.clear();
}
- virtual int OnUserRegister(userrec* user)
+ ModResult OnUserRegister(LocalUser* user) CXX11_OVERRIDE
{
- if (locked)
+ if (!locked.empty())
{
- userrec::QuitUser(ServerInstance, user, "Server is temporarily closed. Please try again later.");
- return 1;
+ ServerInstance->Users->QuitUser(user, locked);
+ return MOD_RES_DENY;
}
- return 0;
+ return MOD_RES_PASSTHRU;
}
- virtual bool OnCheckReady(userrec* user)
+ ModResult OnCheckReady(LocalUser* user) CXX11_OVERRIDE
{
- return !locked;
+ return !locked.empty() ? MOD_RES_DENY : MOD_RES_PASSTHRU;
}
- virtual Version GetVersion()
+ Version GetVersion() CXX11_OVERRIDE
{
- return Version(1, 0, 0, 1, VF_VENDOR, API_VERSION);
+ return Version("Allows locking of the server to stop all incoming connections until unlocked again", VF_VENDOR);
}
};