1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Provides support for unreal-style oper-override */
18 typedef std::map<std::string,std::string> override_t;
20 class ModuleOverride : public Module
27 int OverOps, OverDeops, OverVoices, OverDevoices, OverHalfops, OverDehalfops;
31 ModuleOverride(InspIRCd* Me)
34 // read our config options (main config file)
36 ServerInstance->SNO->EnableSnomask('O', "OVERRIDE");
37 OverriddenMode = false;
38 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
39 Implementation eventlist[] = { I_OnRehash, I_OnAccessCheck, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPostCommand, I_OnLocalTopicChange };
40 ServerInstance->Modules->Attach(eventlist, this, 7);
43 virtual void OnRehash(User* user, const std::string ¶meter)
45 // on a rehash we delete our classes for good measure and create them again.
46 ConfigReader* Conf = new ConfigReader(ServerInstance);
48 // re-read our config options on a rehash
49 NoisyOverride = Conf->ReadFlag("override", "noisy", 0);
50 RequireKey = Conf->ReadFlag("override", "requirekey", 0);
54 for (int j =0; j < Conf->Enumerate("type"); j++)
56 std::string typen = Conf->ReadValue("type","name",j);
57 std::string tokenlist = Conf->ReadValue("type","override",j);
58 overrides[typen] = tokenlist;
65 virtual void OnPostCommand(const std::string &command, const std::vector<std::string> ¶meters, User *user, CmdResult result, const std::string &original_line)
67 if ((NoisyOverride) && (OverriddenMode) && (irc::string(command.c_str()) == "MODE") && (result == CMD_SUCCESS))
69 int Total = OverOps + OverDeops + OverVoices + OverDevoices + OverHalfops + OverDehalfops;
71 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" Overriding modes: "+ServerInstance->Modes->GetLastParse()+" "+(Total ? "[Detail: " : "")+
72 (OverOps ? ConvToStr(OverOps)+" op"+(OverOps != 1 ? "s" : "")+" " : "")+
73 (OverDeops ? ConvToStr(OverDeops)+" deop"+(OverDeops != 1 ? "s" : "")+" " : "")+
74 (OverVoices ? ConvToStr(OverVoices)+" voice"+(OverVoices != 1 ? "s" : "")+" " : "")+
75 (OverDevoices ? ConvToStr(OverDevoices)+" devoice"+(OverDevoices != 1 ? "s" : "")+" " : "")+
76 (OverHalfops ? ConvToStr(OverHalfops)+" halfop"+(OverHalfops != 1 ? "s" : "")+" " : "")+
77 (OverDehalfops ? ConvToStr(OverDehalfops)+" dehalfop"+(OverDehalfops != 1 ? "s" : "") : "")
80 OverriddenMode = false;
81 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
85 virtual void On005Numeric(std::string &output)
87 output.append(" OVERRIDE");
90 virtual bool CanOverride(User* source, const char* token)
92 // checks to see if the oper's type has <type:override>
93 override_t::iterator j = overrides.find(source->oper);
95 if (j != overrides.end())
97 // its defined or * is set, return its value as a boolean for if the token is set
98 return ((j->second.find(token, 0) != std::string::npos) || (j->second.find("*", 0) != std::string::npos));
101 // its not defined at all, count as false
106 virtual int OnLocalTopicChange(User *source, Channel *channel, const std::string &topic)
108 if (IS_OPER(source) && CanOverride(source, "TOPIC"))
110 if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetStatus(source) < STATUS_HOP))
112 ServerInstance->SNO->WriteToSnoMask('O',std::string(source->nick)+" used oper override to change a topic on "+std::string(channel->name));
122 virtual int OnUserPreKick(User* source, User* user, Channel* chan, const std::string &reason)
124 if (IS_OPER(source) && CanOverride(source,"KICK"))
126 // If the kicker's status is less than the target's, or the kicker's status is less than or equal to voice
127 if ((chan->GetStatus(source) < chan->GetStatus(user)) || (chan->GetStatus(source) <= STATUS_VOICE))
129 ServerInstance->SNO->WriteToSnoMask('O',std::string(source->nick)+" used oper override to kick "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
131 /* Returning -1 explicitly allows the kick */
137 virtual int OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
141 if (source && channel)
143 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
144 // to not check the other items in the statement if they arent on the channel
145 int mode = channel->GetStatus(source);
149 if (CanOverride(source,"MODEDEOP"))
152 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
162 if (CanOverride(source,"MODEOP"))
165 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
175 if (CanOverride(source,"MODEVOICE"))
178 if ((!channel->HasUser(source)) || (mode < STATUS_HOP))
188 if (CanOverride(source,"MODEDEVOICE"))
191 if ((!channel->HasUser(source)) || (mode < STATUS_HOP))
201 if (CanOverride(source,"MODEHALFOP"))
204 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
214 if (CanOverride(source,"MODEDEHALFOP"))
217 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
228 if (CanOverride(source,"OTHERMODE"))
231 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
233 OverriddenMode = true;
234 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
248 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
250 if (IS_LOCAL(user) && IS_OPER(user))
254 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
256 irc::string x(chan->name.c_str());
257 if (!user->IsInvited(x))
259 if (RequireKey && keygiven != "override")
261 // Can't join normally -- must use a special key to bypass restrictions
262 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
267 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
268 ServerInstance->SNO->WriteToSnoMask('O', user->nick+" used oper override to bypass +i on "+std::string(cname));
273 if ((chan->modes[CM_KEY]) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
275 if (RequireKey && keygiven != "override")
277 // Can't join normally -- must use a special key to bypass restrictions
278 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
283 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
284 ServerInstance->SNO->WriteToSnoMask('O', user->nick+" used oper override to bypass +k on "+std::string(cname));
288 if ((chan->modes[CM_LIMIT]) && (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str())) && (CanOverride(user,"LIMIT")))
290 if (RequireKey && keygiven != "override")
292 // Can't join normally -- must use a special key to bypass restrictions
293 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
298 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
299 ServerInstance->SNO->WriteToSnoMask('O', user->nick+" used oper override to bypass +l on "+std::string(cname));
303 if (CanOverride(user,"BANWALK"))
305 if (chan->IsBanned(user))
307 if (RequireKey && keygiven != "override")
309 // Can't join normally -- must use a special key to bypass restrictions
310 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
315 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str());
316 ServerInstance->SNO->WriteToSnoMask('O',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
325 virtual ~ModuleOverride()
327 ServerInstance->SNO->DisableSnomask('O');
330 virtual Version GetVersion()
332 return Version(1,2,0,1,VF_VENDOR,API_VERSION);
336 MODULE_INIT(ModuleOverride)