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 * ---------------------------------------------------
17 /* $ModDesc: Provides support for unreal-style oper-override */
19 typedef std::map<std::string,std::string> override_t;
21 class ModuleOverride : public Module
28 int OverOps, OverDeops, OverVoices, OverDevoices, OverHalfops, OverDehalfops;
32 ModuleOverride(InspIRCd* Me)
35 // read our config options (main config file)
37 ServerInstance->SNO->EnableSnomask('O', "OVERRIDE");
38 OverriddenMode = false;
39 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
40 Implementation eventlist[] = { I_OnRehash, I_OnAccessCheck, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPostCommand };
41 ServerInstance->Modules->Attach(eventlist, this, 6);
44 virtual void OnRehash(User* user, const std::string ¶meter)
46 // on a rehash we delete our classes for good measure and create them again.
47 ConfigReader* Conf = new ConfigReader(ServerInstance);
49 // re-read our config options on a rehash
50 NoisyOverride = Conf->ReadFlag("override", "noisy", 0);
51 RequireKey = Conf->ReadFlag("override", "requirekey", 0);
55 for (int j =0; j < Conf->Enumerate("type"); j++)
57 std::string typen = Conf->ReadValue("type","name",j);
58 std::string tokenlist = Conf->ReadValue("type","override",j);
59 overrides[typen] = tokenlist;
66 virtual void OnPostCommand(const std::string &command, const std::vector<std::string> ¶meters, User *user, CmdResult result, const std::string &original_line)
68 if ((NoisyOverride) && (OverriddenMode) && (irc::string(command.c_str()) == "MODE") && (result == CMD_SUCCESS))
70 int Total = OverOps + OverDeops + OverVoices + OverDevoices + OverHalfops + OverDehalfops;
72 ServerInstance->SNO->WriteToSnoMask('O',std::string(user->nick)+" Overriding modes: "+ServerInstance->Modes->GetLastParse()+" "+(Total ? "[Detail: " : "")+
73 (OverOps ? ConvToStr(OverOps)+" op"+(OverOps != 1 ? "s" : "")+" " : "")+
74 (OverDeops ? ConvToStr(OverDeops)+" deop"+(OverDeops != 1 ? "s" : "")+" " : "")+
75 (OverVoices ? ConvToStr(OverVoices)+" voice"+(OverVoices != 1 ? "s" : "")+" " : "")+
76 (OverDevoices ? ConvToStr(OverDevoices)+" devoice"+(OverDevoices != 1 ? "s" : "")+" " : "")+
77 (OverHalfops ? ConvToStr(OverHalfops)+" halfop"+(OverHalfops != 1 ? "s" : "")+" " : "")+
78 (OverDehalfops ? ConvToStr(OverDehalfops)+" dehalfop"+(OverDehalfops != 1 ? "s" : "") : "")
81 OverriddenMode = false;
82 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
86 virtual void On005Numeric(std::string &output)
88 output.append(" OVERRIDE");
91 virtual bool CanOverride(User* source, const char* token)
93 // checks to see if the oper's type has <type:override>
94 override_t::iterator j = overrides.find(source->oper);
96 if (j != overrides.end())
98 // its defined or * is set, return its value as a boolean for if the token is set
99 return ((j->second.find(token, 0) != std::string::npos) || (j->second.find("*", 0) != std::string::npos));
102 // its not defined at all, count as false
106 virtual int OnUserPreKick(User* source, User* user, Channel* chan, const std::string &reason)
108 if (IS_OPER(source) && CanOverride(source,"KICK"))
110 if (((chan->GetStatus(source) == STATUS_HOP) && (chan->GetStatus(user) == STATUS_OP)) || (chan->GetStatus(source) < STATUS_VOICE))
112 ServerInstance->SNO->WriteToSnoMask('O',std::string(source->nick)+" Override-Kicked "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
114 /* Returning -1 explicitly allows the kick */
120 virtual int OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
124 if (source && channel)
126 // Fix by brain - allow the change if they arent on channel - rely on boolean short-circuit
127 // to not check the other items in the statement if they arent on the channel
128 int mode = channel->GetStatus(source);
132 if (CanOverride(source,"MODEDEOP"))
135 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
145 if (CanOverride(source,"MODEOP"))
148 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
158 if (CanOverride(source,"MODEVOICE"))
161 if ((!channel->HasUser(source)) || (mode < STATUS_HOP))
171 if (CanOverride(source,"MODEDEVOICE"))
174 if ((!channel->HasUser(source)) || (mode < STATUS_HOP))
184 if (CanOverride(source,"MODEHALFOP"))
187 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
197 if (CanOverride(source,"MODEDEHALFOP"))
200 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
211 if (CanOverride(source,"OTHERMODE"))
214 if ((!channel->HasUser(source)) || (mode < STATUS_OP))
216 OverriddenMode = true;
217 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
231 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
233 if (IS_LOCAL(user) && IS_OPER(user))
237 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
239 irc::string x(chan->name.c_str());
240 if (!user->IsInvited(x))
242 if (RequireKey && keygiven != "override")
244 // Can't join normally -- must use a special key to bypass restrictions
245 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
250 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
251 ServerInstance->SNO->WriteToSnoMask('O', user->nick+" used oper override to bypass +i on "+std::string(cname));
256 if ((chan->key.empty()) && (CanOverride(user,"KEY")) && keygiven != chan->key)
258 if (RequireKey && keygiven != "override")
260 // Can't join normally -- must use a special key to bypass restrictions
261 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
266 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
267 ServerInstance->SNO->WriteToSnoMask('O', user->nick+" used oper override to bypass +k on "+std::string(cname));
271 if ((chan->limit > 0) && (chan->GetUserCounter() >= chan->limit) && (CanOverride(user,"LIMIT")))
273 if (RequireKey && keygiven != "override")
275 // Can't join normally -- must use a special key to bypass restrictions
276 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
281 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
282 ServerInstance->SNO->WriteToSnoMask('O', user->nick+" used oper override to bypass +l on "+std::string(cname));
286 if (CanOverride(user,"BANWALK"))
288 if (chan->IsBanned(user))
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 channel ban", cname, user->nick.c_str());
299 ServerInstance->SNO->WriteToSnoMask('O',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
308 virtual ~ModuleOverride()
310 ServerInstance->SNO->DisableSnomask('O');
313 virtual Version GetVersion()
315 return Version(1,2,0,1,VF_VENDOR,API_VERSION);
319 MODULE_INIT(ModuleOverride)