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 * ---------------------------------------------------
16 /* $ModDesc: Provides support for unreal-style oper-override */
18 typedef std::map<std::string,std::string> override_t;
20 class ModuleOverride : public Module
30 // read our config options (main config file)
32 ServerInstance->SNO->EnableSnomask('G', "GODMODE");
33 Implementation eventlist[] = { I_OnRehash, I_OnPreMode, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPreTopicChange };
34 ServerInstance->Modules->Attach(eventlist, this, 6);
37 void OnRehash(User* user)
39 // on a rehash we delete our classes for good measure and create them again.
42 // re-read our config options on a rehash
43 NoisyOverride = Conf.ReadFlag("override", "noisy", 0);
44 RequireKey = Conf.ReadFlag("override", "requirekey", 0);
48 for (int j =0; j < Conf.Enumerate("type"); j++)
50 std::string typen = Conf.ReadValue("type","name",j);
51 std::string tokenlist = Conf.ReadValue("type","override",j);
52 overrides[typen] = tokenlist;
56 void On005Numeric(std::string &output)
58 output.append(" OVERRIDE");
61 bool CanOverride(User* source, const char* token)
63 // checks to see if the oper's type has <type:override>
64 override_t::iterator j = overrides.find(source->oper->name);
66 if (j != overrides.end())
68 // its defined or * is set, return its value as a boolean for if the token is set
69 return ((j->second.find(token, 0) != std::string::npos) || (j->second.find("*", 0) != std::string::npos));
72 // its not defined at all, count as false
77 ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic)
79 if (IS_LOCAL(source) && IS_OPER(source) && CanOverride(source, "TOPIC"))
81 if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetPrefixValue(source) < HALFOP_VALUE))
83 ServerInstance->SNO->WriteGlobalSno('G',std::string(source->nick)+" used oper override to change a topic on "+std::string(channel->name));
90 return MOD_RES_PASSTHRU;
93 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
95 if (IS_OPER(source) && CanOverride(source,"KICK"))
97 // If the kicker's status is less than the target's, or the kicker's status is less than or equal to voice
98 if ((memb->chan->GetPrefixValue(source) < memb->getRank()) || (memb->chan->GetPrefixValue(source) <= VOICE_VALUE))
100 ServerInstance->SNO->WriteGlobalSno('G',std::string(source->nick)+" used oper override to kick "+std::string(memb->user->nick)+" on "+std::string(memb->chan->name)+" ("+reason+")");
101 return MOD_RES_ALLOW;
104 return MOD_RES_PASSTHRU;
107 ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters)
109 if (!IS_OPER(source))
110 return MOD_RES_PASSTHRU;
111 if (!source || !channel)
112 return MOD_RES_PASSTHRU;
114 unsigned int mode = 0;
115 if (channel->HasUser(source))
116 mode = channel->GetPrefixValue(source);
118 if (mode < HALFOP_VALUE && CanOverride(source, "MODE"))
120 std::string msg = std::string(source->nick)+" overriding modes:";
121 for(unsigned int i=0; i < parameters.size(); i++)
122 msg += " " + parameters[i];
123 ServerInstance->SNO->WriteGlobalSno('G',msg);
124 return MOD_RES_ALLOW;
126 return MOD_RES_PASSTHRU;
129 ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
131 if (IS_LOCAL(user) && IS_OPER(user))
135 if ((chan->modes[CM_INVITEONLY]) && (CanOverride(user,"INVITE")))
137 irc::string x(chan->name.c_str());
138 if (!IS_LOCAL(user)->IsInvited(x))
140 if (RequireKey && keygiven != "override")
142 // Can't join normally -- must use a special key to bypass restrictions
143 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
144 return MOD_RES_PASSTHRU;
148 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
149 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +i on "+std::string(cname));
151 return MOD_RES_ALLOW;
154 if ((chan->modes[CM_KEY]) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
156 if (RequireKey && keygiven != "override")
158 // Can't join normally -- must use a special key to bypass restrictions
159 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
160 return MOD_RES_PASSTHRU;
164 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
165 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +k on "+std::string(cname));
166 return MOD_RES_ALLOW;
169 if ((chan->modes[CM_LIMIT]) && (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str())) && (CanOverride(user,"LIMIT")))
171 if (RequireKey && keygiven != "override")
173 // Can't join normally -- must use a special key to bypass restrictions
174 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
175 return MOD_RES_PASSTHRU;
179 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
180 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +l on "+std::string(cname));
181 return MOD_RES_ALLOW;
184 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
186 if (RequireKey && keygiven != "override")
188 // Can't join normally -- must use a special key to bypass restrictions
189 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
190 return MOD_RES_PASSTHRU;
194 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str());
195 ServerInstance->SNO->WriteGlobalSno('G',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
196 return MOD_RES_ALLOW;
200 return MOD_RES_PASSTHRU;
205 ServerInstance->SNO->DisableSnomask('G');
210 return Version("Provides support for unreal-style oper-override",VF_VENDOR);
214 MODULE_INIT(ModuleOverride)