2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2017-2018, 2020 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
6 * Copyright (C) 2012, 2014-2016 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8 * Copyright (C) 2007-2008, 2010 Craig Edwards <brain@inspircd.org>
9 * Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
10 * Copyright (C) 2007, 2009 Robin Burchell <robin+git@viroteck.net>
11 * Copyright (C) 2007 John Brooks <special@inspircd.org>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 /** Handle /GLOADMODULE
31 class CommandGloadmodule : public Command
34 CommandGloadmodule(Module* Creator) : Command(Creator,"GLOADMODULE", 1)
37 syntax = "<modulename> [<servermask>]";
40 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
42 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
44 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
46 if (ServerInstance->Modules->Load(parameters[0].c_str()))
48 ServerInstance->SNO->WriteToSnoMask('a', "NEW MODULE '%s' GLOBALLY LOADED BY '%s'",parameters[0].c_str(), user->nick.c_str());
49 user->WriteNumeric(RPL_LOADEDMODULE, parameters[0], "Module successfully loaded.");
53 user->WriteNumeric(ERR_CANTLOADMODULE, parameters[0], ServerInstance->Modules->LastError());
57 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL LOAD BY '%s' (not loaded here)",parameters[0].c_str(), user->nick.c_str());
62 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
64 return ROUTE_BROADCAST;
68 /** Handle /GUNLOADMODULE
70 class CommandGunloadmodule : public Command
73 CommandGunloadmodule(Module* Creator) : Command(Creator,"GUNLOADMODULE", 1)
76 syntax = "<modulename> [<servermask>]";
79 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
81 if (!ServerInstance->Config->ConfValue("security")->getBool("allowcoreunload") &&
82 InspIRCd::Match(parameters[0], "core_*.so", ascii_case_insensitive_map))
84 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload core commands!");
88 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
90 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
92 Module* m = ServerInstance->Modules->Find(parameters[0]);
95 if (ServerInstance->Modules->Unload(m))
97 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBALLY UNLOADED BY '%s'",parameters[0].c_str(), user->nick.c_str());
98 user->WriteRemoteNumeric(RPL_UNLOADEDMODULE, parameters[0], "Module successfully unloaded.");
102 user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], ServerInstance->Modules->LastError());
106 user->WriteRemoteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "No such module");
109 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL UNLOAD BY '%s' (not unloaded here)",parameters[0].c_str(), user->nick.c_str());
114 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
116 return ROUTE_BROADCAST;
120 /** Handle /GRELOADMODULE
122 class CommandGreloadmodule : public Command
125 CommandGreloadmodule(Module* Creator) : Command(Creator, "GRELOADMODULE", 1)
128 syntax = "<modulename> [<servermask>]";
131 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
133 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
135 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
137 Module* m = ServerInstance->Modules->Find(parameters[0]);
140 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBALLY RELOADED BY '%s'", parameters[0].c_str(), user->nick.c_str());
141 ServerInstance->Parser.CallHandler("RELOADMODULE", parameters, user);
145 user->WriteNumeric(RPL_LOADEDMODULE, parameters[0], "Could not find module by that name");
150 ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL RELOAD BY '%s' (not reloaded here)",parameters[0].c_str(), user->nick.c_str());
155 RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
157 return ROUTE_BROADCAST;
161 class ModuleGlobalLoad : public Module
163 CommandGloadmodule cmd1;
164 CommandGunloadmodule cmd2;
165 CommandGreloadmodule cmd3;
169 : cmd1(this), cmd2(this), cmd3(this)
173 Version GetVersion() CXX11_OVERRIDE
175 return Version("Adds the /GLOADMODULE, /GRELOADMODULE, and /GUNLOADMODULE commands which allows server operators to load, reload, and unload modules on remote servers.", VF_COMMON | VF_VENDOR);
179 MODULE_INIT(ModuleGlobalLoad)