]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_override.cpp
ea9d11c94e0662e367b1659e7f0e881060c325bc
[user/henk/code/inspircd.git] / src / modules / m_override.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2009 Uli Schlachter <psychon@znc.in>
6  *   Copyright (C) 2007-2009 Robin Burchell <robin+git@viroteck.net>
7  *   Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
8  *   Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
9  *   Copyright (C) 2008 Geoff Bricker <geoff.bricker@gmail.com>
10  *   Copyright (C) 2004-2006 Craig Edwards <craigedwards@brainbox.cc>
11  *   Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
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 /* $ModDesc: Provides support for allowing opers to override certain things. */
30
31 class ModuleOverride : public Module
32 {
33         bool RequireKey;
34         bool NoisyOverride;
35
36  public:
37
38         void init()
39         {
40                 // read our config options (main config file)
41                 OnRehash(NULL);
42                 ServerInstance->SNO->EnableSnomask('v', "OVERRIDE");
43                 Implementation eventlist[] = { I_OnRehash, I_OnPreMode, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPreTopicChange };
44                 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
45         }
46
47         void OnRehash(User* user)
48         {
49                 // re-read our config options on a rehash
50                 ConfigTag* tag = ServerInstance->Config->ConfValue("override");
51                 NoisyOverride = tag->getBool("noisy");
52                 RequireKey = tag->getBool("requirekey");
53         }
54
55         void On005Numeric(std::map<std::string, std::string>& tokens)
56         {
57                 tokens["OVERRIDE"];
58         }
59
60         bool CanOverride(User* source, const char* token)
61         {
62                 std::string tokenlist = source->oper->getConfig("override");
63
64                 // its defined or * is set, return its value as a boolean for if the token is set
65                 return ((tokenlist.find(token, 0) != std::string::npos) || (tokenlist.find("*", 0) != std::string::npos));
66         }
67
68
69         ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic)
70         {
71                 if (IS_LOCAL(source) && source->IsOper() && CanOverride(source, "TOPIC"))
72                 {
73                         if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetPrefixValue(source) < HALFOP_VALUE))
74                         {
75                                 ServerInstance->SNO->WriteGlobalSno('v',source->nick+" used oper override to change a topic on "+channel->name);
76                         }
77
78                         // Explicit allow
79                         return MOD_RES_ALLOW;
80                 }
81
82                 return MOD_RES_PASSTHRU;
83         }
84
85         ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
86         {
87                 if (source->IsOper() && CanOverride(source,"KICK"))
88                 {
89                         // If the kicker's status is less than the target's,                    or      the kicker's status is less than or equal to voice
90                         if ((memb->chan->GetPrefixValue(source) < memb->getRank()) || (memb->chan->GetPrefixValue(source) <= VOICE_VALUE))
91                         {
92                                 ServerInstance->SNO->WriteGlobalSno('v',source->nick+" used oper override to kick "+memb->user->nick+" on "+memb->chan->name+" ("+reason+")");
93                                 return MOD_RES_ALLOW;
94                         }
95                 }
96                 return MOD_RES_PASSTHRU;
97         }
98
99         ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters)
100         {
101                 if (!source || !channel)
102                         return MOD_RES_PASSTHRU;
103                 if (!source->IsOper() || !IS_LOCAL(source))
104                         return MOD_RES_PASSTHRU;
105
106                 unsigned int mode = channel->GetPrefixValue(source);
107
108                 if (mode < HALFOP_VALUE && CanOverride(source, "MODE"))
109                 {
110                         std::string msg = source->nick+" overriding modes:";
111                         for(unsigned int i=0; i < parameters.size(); i++)
112                                 msg += " " + parameters[i];
113                         ServerInstance->SNO->WriteGlobalSno('v',msg);
114                         return MOD_RES_ALLOW;
115                 }
116                 return MOD_RES_PASSTHRU;
117         }
118
119         ModResult OnUserPreJoin(User* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven)
120         {
121                 if (IS_LOCAL(user) && user->IsOper())
122                 {
123                         if (chan)
124                         {
125                                 if (chan->IsModeSet('i') && (CanOverride(user,"INVITE")))
126                                 {
127                                         irc::string x(chan->name.c_str());
128                                         if (!IS_LOCAL(user)->IsInvited(x))
129                                         {
130                                                 if (RequireKey && keygiven != "override")
131                                                 {
132                                                         // Can't join normally -- must use a special key to bypass restrictions
133                                                         user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
134                                                         return MOD_RES_PASSTHRU;
135                                                 }
136
137                                                 if (NoisyOverride)
138                                                         chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass invite-only", cname.c_str(), user->nick.c_str());
139                                                 ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +i on " + cname);
140                                         }
141                                         return MOD_RES_ALLOW;
142                                 }
143
144                                 if (chan->IsModeSet('k') && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
145                                 {
146                                         if (RequireKey && keygiven != "override")
147                                         {
148                                                 // Can't join normally -- must use a special key to bypass restrictions
149                                                 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
150                                                 return MOD_RES_PASSTHRU;
151                                         }
152
153                                         if (NoisyOverride)
154                                                 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel key", cname.c_str(), user->nick.c_str());
155                                         ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +k on " + cname);
156                                         return MOD_RES_ALLOW;
157                                 }
158
159                                 if (chan->IsModeSet('l') && (chan->GetUserCounter() >= ConvToInt(chan->GetModeParameter('l'))) && (CanOverride(user,"LIMIT")))
160                                 {
161                                         if (RequireKey && keygiven != "override")
162                                         {
163                                                 // Can't join normally -- must use a special key to bypass restrictions
164                                                 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
165                                                 return MOD_RES_PASSTHRU;
166                                         }
167
168                                         if (NoisyOverride)
169                                                 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel limit", cname.c_str(), user->nick.c_str());
170                                         ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +l on " + cname);
171                                         return MOD_RES_ALLOW;
172                                 }
173
174                                 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
175                                 {
176                                         if (RequireKey && keygiven != "override")
177                                         {
178                                                 // Can't join normally -- must use a special key to bypass restrictions
179                                                 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
180                                                 return MOD_RES_PASSTHRU;
181                                         }
182
183                                         if (NoisyOverride)
184                                                 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass channel ban", cname.c_str(), user->nick.c_str());
185                                         ServerInstance->SNO->WriteGlobalSno('v',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname.c_str());
186                                         return MOD_RES_ALLOW;
187                                 }
188                         }
189                 }
190                 return MOD_RES_PASSTHRU;
191         }
192
193         Version GetVersion()
194         {
195                 return Version("Provides support for allowing opers to override certain things",VF_VENDOR);
196         }
197 };
198
199 MODULE_INIT(ModuleOverride)