1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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 class ModuleOverride : public Module
27 // read our config options (main config file)
29 ServerInstance->SNO->EnableSnomask('G', "GODMODE");
30 Implementation eventlist[] = { I_OnRehash, I_OnPreMode, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPreTopicChange };
31 ServerInstance->Modules->Attach(eventlist, this, 6);
34 void OnRehash(User* user)
36 // on a rehash we delete our classes for good measure and create them again.
39 // re-read our config options on a rehash
40 NoisyOverride = Conf.ReadFlag("override", "noisy", 0);
41 RequireKey = Conf.ReadFlag("override", "requirekey", 0);
44 void On005Numeric(std::string &output)
46 output.append(" OVERRIDE");
49 bool CanOverride(User* source, const char* token)
51 std::string tokenlist = source->oper->getConfig("override");
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));
58 ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic)
60 if (IS_LOCAL(source) && IS_OPER(source) && CanOverride(source, "TOPIC"))
62 if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetPrefixValue(source) < HALFOP_VALUE))
64 ServerInstance->SNO->WriteGlobalSno('G',std::string(source->nick)+" used oper override to change a topic on "+std::string(channel->name));
71 return MOD_RES_PASSTHRU;
74 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason)
76 if (IS_OPER(source) && CanOverride(source,"KICK"))
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))
81 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+")");
85 return MOD_RES_PASSTHRU;
88 ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters)
91 return MOD_RES_PASSTHRU;
92 if (!source || !channel)
93 return MOD_RES_PASSTHRU;
95 unsigned int mode = 0;
96 if (channel->HasUser(source))
97 mode = channel->GetPrefixValue(source);
99 if (mode < HALFOP_VALUE && CanOverride(source, "MODE"))
101 std::string msg = std::string(source->nick)+" overriding modes:";
102 for(unsigned int i=0; i < parameters.size(); i++)
103 msg += " " + parameters[i];
104 ServerInstance->SNO->WriteGlobalSno('G',msg);
105 return MOD_RES_ALLOW;
107 return MOD_RES_PASSTHRU;
110 ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
112 if (IS_LOCAL(user) && IS_OPER(user))
116 if (chan->IsModeSet('i') && (CanOverride(user,"INVITE")))
118 irc::string x(chan->name.c_str());
119 if (!IS_LOCAL(user)->IsInvited(x))
121 if (RequireKey && keygiven != "override")
123 // Can't join normally -- must use a special key to bypass restrictions
124 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
125 return MOD_RES_PASSTHRU;
129 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
130 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +i on "+std::string(cname));
132 return MOD_RES_ALLOW;
135 if (chan->IsModeSet('k') && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
137 if (RequireKey && keygiven != "override")
139 // Can't join normally -- must use a special key to bypass restrictions
140 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
141 return MOD_RES_PASSTHRU;
145 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
146 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +k on "+std::string(cname));
147 return MOD_RES_ALLOW;
150 if (chan->IsModeSet('l') && (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str())) && (CanOverride(user,"LIMIT")))
152 if (RequireKey && keygiven != "override")
154 // Can't join normally -- must use a special key to bypass restrictions
155 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
156 return MOD_RES_PASSTHRU;
160 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
161 ServerInstance->SNO->WriteGlobalSno('G', user->nick+" used oper override to bypass +l on "+std::string(cname));
162 return MOD_RES_ALLOW;
165 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
167 if (RequireKey && keygiven != "override")
169 // Can't join normally -- must use a special key to bypass restrictions
170 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
171 return MOD_RES_PASSTHRU;
175 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str());
176 ServerInstance->SNO->WriteGlobalSno('G',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
177 return MOD_RES_ALLOW;
181 return MOD_RES_PASSTHRU;
186 ServerInstance->SNO->DisableSnomask('G');
191 return Version("Provides support for unreal-style oper-override",VF_VENDOR);
195 MODULE_INIT(ModuleOverride)