1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "m_override.h"
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('G', "GODMODE");
38 if (!ServerInstance->Modules->PublishFeature("Override", this))
40 throw ModuleException("m_override: Unable to publish feature 'Override'");
42 OverriddenMode = OverOther = false;
43 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
44 Implementation eventlist[] = { I_OnRehash, I_OnAccessCheck, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPostCommand, I_OnLocalTopicChange, I_OnRequest };
45 ServerInstance->Modules->Attach(eventlist, this, 8);
48 virtual void OnRehash(User* user, const std::string ¶meter)
50 // on a rehash we delete our classes for good measure and create them again.
51 ConfigReader* Conf = new ConfigReader(ServerInstance);
53 // re-read our config options on a rehash
54 NoisyOverride = Conf->ReadFlag("override", "noisy", 0);
55 RequireKey = Conf->ReadFlag("override", "requirekey", 0);
59 for (int j =0; j < Conf->Enumerate("type"); j++)
61 std::string typen = Conf->ReadValue("type","name",j);
62 std::string tokenlist = Conf->ReadValue("type","override",j);
63 overrides[typen] = tokenlist;
70 virtual void OnPostCommand(const std::string &command, const std::vector<std::string> ¶meters, User *user, CmdResult result, const std::string &original_line)
74 if ((irc::string(command.c_str()) == "MODE") && (result == CMD_SUCCESS) && !ServerInstance->Modes->GetLastParse().empty())
76 std::string msg = std::string(user->nick)+" overriding modes: "+ServerInstance->Modes->GetLastParse()+" [Detail: ";
78 msg += ConvToStr(OverOps)+" op"+(OverOps != 1 ? "s" : "")+", ";
80 msg += ConvToStr(OverDeops)+" deop"+(OverDeops != 1 ? "s" : "")+", ";
82 msg += ConvToStr(OverVoices)+" voice"+(OverVoices != 1 ? "s" : "")+", ";
84 msg += ConvToStr(OverDevoices)+" devoice"+(OverDevoices != 1 ? "s" : "")+", ";
86 msg += ConvToStr(OverHalfops)+" halfop"+(OverHalfops != 1 ? "s" : "")+", ";
88 msg += ConvToStr(OverDehalfops)+" dehalfop"+(OverDehalfops != 1 ? "s" : "")+", ";
91 msg.replace(msg.length()-2, 2, 1, ']');
92 ServerInstance->SNO->WriteToSnoMask('G',msg);
95 OverriddenMode = OverOther = false;
96 OverOps = OverDeops = OverVoices = OverDevoices = OverHalfops = OverDehalfops = 0;
100 virtual void On005Numeric(std::string &output)
102 output.append(" OVERRIDE");
105 virtual bool CanOverride(User* source, const char* token)
107 // checks to see if the oper's type has <type:override>
108 override_t::iterator j = overrides.find(source->oper);
110 if (j != overrides.end())
112 // its defined or * is set, return its value as a boolean for if the token is set
113 return ((j->second.find(token, 0) != std::string::npos) || (j->second.find("*", 0) != std::string::npos));
116 // its not defined at all, count as false
121 virtual int OnLocalTopicChange(User *source, Channel *channel, const std::string &topic)
123 if (IS_OPER(source) && CanOverride(source, "TOPIC"))
125 if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetStatus(source) < STATUS_HOP))
127 ServerInstance->SNO->WriteToSnoMask('G',std::string(source->nick)+" used oper override to change a topic on "+std::string(channel->name));
137 virtual int OnUserPreKick(User* source, User* user, Channel* chan, const std::string &reason)
139 if (IS_OPER(source) && CanOverride(source,"KICK"))
141 // If the kicker's status is less than the target's, or the kicker's status is less than or equal to voice
142 if ((chan->GetStatus(source) < chan->GetStatus(user)) || (chan->GetStatus(source) <= STATUS_VOICE))
144 ServerInstance->SNO->WriteToSnoMask('G',std::string(source->nick)+" used oper override to kick "+std::string(user->nick)+" on "+std::string(chan->name)+" ("+reason+")");
146 /* Returning -1 explicitly allows the kick */
152 virtual int OnAccessCheck(User* source,User* dest,Channel* channel,int access_type)
154 if (!IS_OPER(source))
156 if (!source || !channel)
159 int mode = STATUS_NORMAL;
160 if (channel->HasUser(source))
161 mode = channel->GetStatus(source);
162 bool over_this = false;
167 if (mode < STATUS_OP && CanOverride(source,"MODEDEOP"))
174 if (mode < STATUS_OP && CanOverride(source,"MODEOP"))
181 if (mode < STATUS_HOP && CanOverride(source,"MODEVOICE"))
188 if (mode < STATUS_HOP && CanOverride(source,"MODEDEVOICE"))
195 if (mode < STATUS_OP && CanOverride(source,"MODEHALFOP"))
202 if (mode < STATUS_OP && CanOverride(source,"MODEDEHALFOP"))
208 case AC_GENERAL_MODE:
210 std::string modes = ServerInstance->Modes->GetLastParse();
211 bool ohv_only = (modes.find_first_not_of("+-ohv") == std::string::npos);
213 if (mode < STATUS_HOP && (ohv_only || CanOverride(source,"OTHERMODE")))
225 OverriddenMode = true;
234 virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
236 if (IS_LOCAL(user) && IS_OPER(user))
240 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
242 irc::string x(chan->name.c_str());
243 if (!user->IsInvited(x))
245 if (RequireKey && keygiven != "override")
247 // Can't join normally -- must use a special key to bypass restrictions
248 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
253 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
254 ServerInstance->SNO->WriteToSnoMask('G', user->nick+" used oper override to bypass +i on "+std::string(cname));
259 if ((chan->modes[CM_KEY]) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
261 if (RequireKey && keygiven != "override")
263 // Can't join normally -- must use a special key to bypass restrictions
264 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
269 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
270 ServerInstance->SNO->WriteToSnoMask('G', user->nick+" used oper override to bypass +k on "+std::string(cname));
274 if ((chan->modes[CM_LIMIT]) && (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str())) && (CanOverride(user,"LIMIT")))
276 if (RequireKey && keygiven != "override")
278 // Can't join normally -- must use a special key to bypass restrictions
279 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
284 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
285 ServerInstance->SNO->WriteToSnoMask('G', user->nick+" used oper override to bypass +l on "+std::string(cname));
289 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
291 if (RequireKey && keygiven != "override")
293 // Can't join normally -- must use a special key to bypass restrictions
294 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
299 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str());
300 ServerInstance->SNO->WriteToSnoMask('G',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
308 virtual const char* OnRequest(Request* request)
310 if(strcmp(OVRREQID, request->GetId()) == 0)
312 OVRrequest* req = static_cast<OVRrequest*>(request);
313 return this->CanOverride(req->requser,req->reqtoken.c_str()) ? "yes":"";
318 virtual ~ModuleOverride()
320 ServerInstance->Modules->UnpublishFeature("Override");
321 ServerInstance->SNO->DisableSnomask('G');
324 virtual Version GetVersion()
326 return Version("$Id$",VF_VENDOR,API_VERSION);
330 MODULE_INIT(ModuleOverride)