]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_globalload.cpp
71a455a34f7da7c7b62f6510210bb7b41ebc3e6d
[user/henk/code/inspircd.git] / src / modules / m_globalload.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
12  *
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.
16  *
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
20  * details.
21  *
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/>.
24  */
25
26
27 #include "inspircd.h"
28
29 /** Handle /GLOADMODULE
30  */
31 class CommandGloadmodule : public Command
32 {
33  public:
34         CommandGloadmodule(Module* Creator) : Command(Creator,"GLOADMODULE", 1)
35         {
36                 flags_needed = 'o';
37                 syntax = "<modulename> [<servermask>]";
38         }
39
40         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
41         {
42                 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
43
44                 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
45                 {
46                         if (ServerInstance->Modules->Load(parameters[0].c_str()))
47                         {
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.");
50                         }
51                         else
52                         {
53                                 user->WriteNumeric(ERR_CANTLOADMODULE, parameters[0], ServerInstance->Modules->LastError());
54                         }
55                 }
56                 else
57                         ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL LOAD BY '%s' (not loaded here)",parameters[0].c_str(), user->nick.c_str());
58
59                 return CMD_SUCCESS;
60         }
61
62         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
63         {
64                 return ROUTE_BROADCAST;
65         }
66 };
67
68 /** Handle /GUNLOADMODULE
69  */
70 class CommandGunloadmodule : public Command
71 {
72  public:
73         CommandGunloadmodule(Module* Creator) : Command(Creator,"GUNLOADMODULE", 1)
74         {
75                 flags_needed = 'o';
76                 syntax = "<modulename> [<servermask>]";
77         }
78
79         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
80         {
81                 if (!ServerInstance->Config->ConfValue("security")->getBool("allowcoreunload") &&
82                         InspIRCd::Match(parameters[0], "core_*.so", ascii_case_insensitive_map))
83                 {
84                         user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "You cannot unload core commands!");
85                         return CMD_FAILURE;
86                 }
87
88                 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
89
90                 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
91                 {
92                         Module* m = ServerInstance->Modules->Find(parameters[0]);
93                         if (m)
94                         {
95                                 if (ServerInstance->Modules->Unload(m))
96                                 {
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.");
99                                 }
100                                 else
101                                 {
102                                         user->WriteNumeric(ERR_CANTUNLOADMODULE, parameters[0], ServerInstance->Modules->LastError());
103                                 }
104                         }
105                         else
106                                 user->WriteRemoteNumeric(ERR_CANTUNLOADMODULE, parameters[0], "No such module");
107                 }
108                 else
109                         ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL UNLOAD BY '%s' (not unloaded here)",parameters[0].c_str(), user->nick.c_str());
110
111                 return CMD_SUCCESS;
112         }
113
114         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
115         {
116                 return ROUTE_BROADCAST;
117         }
118 };
119
120 /** Handle /GRELOADMODULE
121  */
122 class CommandGreloadmodule : public Command
123 {
124  public:
125         CommandGreloadmodule(Module* Creator) : Command(Creator, "GRELOADMODULE", 1)
126         {
127                 flags_needed = 'o';
128                 syntax = "<modulename> [<servermask>]";
129         }
130
131         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
132         {
133                 std::string servername = parameters.size() > 1 ? parameters[1] : "*";
134
135                 if (InspIRCd::Match(ServerInstance->Config->ServerName.c_str(), servername))
136                 {
137                         Module* m = ServerInstance->Modules->Find(parameters[0]);
138                         if (m)
139                         {
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);
142                         }
143                         else
144                         {
145                                 user->WriteNumeric(RPL_LOADEDMODULE, parameters[0], "Could not find module by that name");
146                                 return CMD_FAILURE;
147                         }
148                 }
149                 else
150                         ServerInstance->SNO->WriteToSnoMask('a', "MODULE '%s' GLOBAL RELOAD BY '%s' (not reloaded here)",parameters[0].c_str(), user->nick.c_str());
151
152                 return CMD_SUCCESS;
153         }
154
155         RouteDescriptor GetRouting(User* user, const Params& parameters) CXX11_OVERRIDE
156         {
157                 return ROUTE_BROADCAST;
158         }
159 };
160
161 class ModuleGlobalLoad : public Module
162 {
163         CommandGloadmodule cmd1;
164         CommandGunloadmodule cmd2;
165         CommandGreloadmodule cmd3;
166
167  public:
168         ModuleGlobalLoad()
169                 : cmd1(this), cmd2(this), cmd3(this)
170         {
171         }
172
173         Version GetVersion() CXX11_OVERRIDE
174         {
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);
176         }
177 };
178
179 MODULE_INIT(ModuleGlobalLoad)