]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_override.cpp
4e120ced1a96bd03076fbb13c1f803e0f51c0d55
[user/henk/code/inspircd.git] / src / modules / m_override.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15
16 /* $ModDesc: Provides support for unreal-style oper-override */
17
18 class ModuleOverride : public Module
19 {
20         bool RequireKey;
21         bool NoisyOverride;
22
23  public:
24
25         ModuleOverride()
26                         {
27                 // read our config options (main config file)
28                 OnRehash(NULL);
29                 ServerInstance->SNO->EnableSnomask('v', "OVERRIDE");
30                 Implementation eventlist[] = { I_OnRehash, I_OnPreMode, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPreTopicChange };
31                 ServerInstance->Modules->Attach(eventlist, this, 6);
32         }
33
34         void OnRehash(User* user)
35         {
36                 // on a rehash we delete our classes for good measure and create them again.
37                 ConfigReader Conf;
38
39                 // re-read our config options on a rehash
40                 NoisyOverride = Conf.ReadFlag("override", "noisy", 0);
41                 RequireKey = Conf.ReadFlag("override", "requirekey", 0);
42         }
43
44         void On005Numeric(std::string &output)
45         {
46                 output.append(" OVERRIDE");
47         }
48
49         bool CanOverride(User* source, const char* token)
50         {
51                 std::string tokenlist = source->oper->getConfig("override");
52
53                 // its defined or * is set, return its value as a boolean for if the token is set
54                 return ((tokenlist.find(token, 0) != std::string::npos) || (tokenlist.find("*", 0) != std::string::npos));
55         }
56
57
58         ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic)
59         {
60                 if (IS_LOCAL(source) && IS_OPER(source) && CanOverride(source, "TOPIC"))
61                 {
62                         if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetPrefixValue(source) < HALFOP_VALUE))
63                         {
64                                 ServerInstance->SNO->WriteGlobalSno('v',std::string(source->nick)+" used oper override to change a topic on "+std::string(channel->name));
65                         }
66
67                         // Explicit allow
68                         return MOD_RES_ALLOW;
69                 }
70
71                 return MOD_RES_PASSTHRU;
72         }
73
74         ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
75         {
76                 if (IS_OPER(source) && CanOverride(source,"KICK"))
77                 {
78                         // If the kicker's status is less than the target's,                    or      the kicker's status is less than or equal to voice
79                         if ((memb->chan->GetPrefixValue(source) < memb->getRank()) || (memb->chan->GetPrefixValue(source) <= VOICE_VALUE))
80                         {
81                                 ServerInstance->SNO->WriteGlobalSno('v',std::string(source->nick)+" used oper override to kick "+std::string(memb->user->nick)+" on "+std::string(memb->chan->name)+" ("+reason+")");
82                                 return MOD_RES_ALLOW;
83                         }
84                 }
85                 return MOD_RES_PASSTHRU;
86         }
87
88         ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters)
89         {
90                 if (!source || !channel)
91                         return MOD_RES_PASSTHRU;
92                 if (!IS_OPER(source) || !IS_LOCAL(source))
93                         return MOD_RES_PASSTHRU;
94
95                 unsigned int mode = channel->GetPrefixValue(source);
96
97                 if (mode < HALFOP_VALUE && CanOverride(source, "MODE"))
98                 {
99                         std::string msg = std::string(source->nick)+" overriding modes:";
100                         for(unsigned int i=0; i < parameters.size(); i++)
101                                 msg += " " + parameters[i];
102                         ServerInstance->SNO->WriteGlobalSno('v',msg);
103                         return MOD_RES_ALLOW;
104                 }
105                 return MOD_RES_PASSTHRU;
106         }
107
108         ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
109         {
110                 if (IS_LOCAL(user) && IS_OPER(user))
111                 {
112                         if (chan)
113                         {
114                                 if (chan->IsModeSet('i') && (CanOverride(user,"INVITE")))
115                                 {
116                                         irc::string x(chan->name.c_str());
117                                         if (!IS_LOCAL(user)->IsInvited(x))
118                                         {
119                                                 if (RequireKey && keygiven != "override")
120                                                 {
121                                                         // Can't join normally -- must use a special key to bypass restrictions
122                                                         user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
123                                                         return MOD_RES_PASSTHRU;
124                                                 }
125
126                                                 if (NoisyOverride)
127                                                         chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
128                                                 ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +i on "+std::string(cname));
129                                         }
130                                         return MOD_RES_ALLOW;
131                                 }
132
133                                 if (chan->IsModeSet('k') && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
134                                 {
135                                         if (RequireKey && keygiven != "override")
136                                         {
137                                                 // Can't join normally -- must use a special key to bypass restrictions
138                                                 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
139                                                 return MOD_RES_PASSTHRU;
140                                         }
141
142                                         if (NoisyOverride)
143                                                 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
144                                         ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +k on "+std::string(cname));
145                                         return MOD_RES_ALLOW;
146                                 }
147
148                                 if (chan->IsModeSet('l') && (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str())) && (CanOverride(user,"LIMIT")))
149                                 {
150                                         if (RequireKey && keygiven != "override")
151                                         {
152                                                 // Can't join normally -- must use a special key to bypass restrictions
153                                                 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
154                                                 return MOD_RES_PASSTHRU;
155                                         }
156
157                                         if (NoisyOverride)
158                                                 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
159                                         ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +l on "+std::string(cname));
160                                         return MOD_RES_ALLOW;
161                                 }
162
163                                 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
164                                 {
165                                         if (RequireKey && keygiven != "override")
166                                         {
167                                                 // Can't join normally -- must use a special key to bypass restrictions
168                                                 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
169                                                 return MOD_RES_PASSTHRU;
170                                         }
171
172                                         if (NoisyOverride)
173                                                 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str());
174                                         ServerInstance->SNO->WriteGlobalSno('v',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
175                                         return MOD_RES_ALLOW;
176                                 }
177                         }
178                 }
179                 return MOD_RES_PASSTHRU;
180         }
181
182         Version GetVersion()
183         {
184                 return Version("Provides support for unreal-style oper-override",VF_VENDOR);
185         }
186 };
187
188 MODULE_INIT(ModuleOverride)