]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operlog.cpp
Sync helpop chmodes s and p with docs
[user/henk/code/inspircd.git] / src / modules / m_operlog.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2018-2020 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012-2014 Attila Molnar <attilamolnar@hush.com>
6  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
7  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
9  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2006, 2010 Craig Edwards <brain@inspircd.org>
11  *
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.
15  *
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
19  * details.
20  *
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/>.
23  */
24
25
26 #include "inspircd.h"
27
28 class ModuleOperLog : public Module
29 {
30         bool tosnomask;
31
32  public:
33         void init() CXX11_OVERRIDE
34         {
35                 ServerInstance->SNO->EnableSnomask('r', "OPERLOG");
36         }
37
38         Version GetVersion() CXX11_OVERRIDE
39         {
40                 return Version("Allows the server administrator to make the server log when a server operator-only command is executed.", VF_VENDOR);
41         }
42
43         void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
44         {
45                 tosnomask = ServerInstance->Config->ConfValue("operlog")->getBool("tosnomask", false);
46         }
47
48         ModResult OnPreCommand(std::string& command, CommandBase::Params& parameters, LocalUser* user, bool validated) CXX11_OVERRIDE
49         {
50                 /* If the command doesnt appear to be valid, we dont want to mess with it. */
51                 if (!validated)
52                         return MOD_RES_PASSTHRU;
53
54                 if ((user->IsOper()) && (user->HasCommandPermission(command)))
55                 {
56                         Command* thiscommand = ServerInstance->Parser.GetHandler(command);
57                         if ((thiscommand) && (thiscommand->flags_needed == 'o'))
58                         {
59                                 std::string msg = "[" + user->GetFullRealHost() + "] " + command + " " + stdalgo::string::join(parameters);
60                                 if (tosnomask)
61                                         ServerInstance->SNO->WriteGlobalSno('r', msg);
62                                 else
63                                         ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, msg);
64                         }
65                 }
66
67                 return MOD_RES_PASSTHRU;
68         }
69 };
70
71 MODULE_INIT(ModuleOperLog)