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('v', "OVERRIDE");
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('v',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('v',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)
90 if (!source || !channel)
91 return MOD_RES_PASSTHRU;
92 if (!IS_OPER(source) || !IS_LOCAL(source))
93 return MOD_RES_PASSTHRU;
95 unsigned int mode = channel->GetPrefixValue(source);
97 if (mode < HALFOP_VALUE && CanOverride(source, "MODE"))
99 std::string msg = std::string(source->nick)+" overriding modes:";
100 for(unsigned int i=0; i < parameters.size(); i++)
101 msg += " " + parameters[i];
102 ServerInstance->SNO->WriteGlobalSno('v',msg);
103 return MOD_RES_ALLOW;
105 return MOD_RES_PASSTHRU;
108 ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
110 if (IS_LOCAL(user) && IS_OPER(user))
114 if (chan->IsModeSet('i') && (CanOverride(user,"INVITE")))
116 irc::string x(chan->name.c_str());
117 if (!IS_LOCAL(user)->IsInvited(x))
119 if (RequireKey && keygiven != "override")
121 // Can't join normally -- must use a special key to bypass restrictions
122 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
123 return MOD_RES_PASSTHRU;
127 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass invite-only", cname, user->nick.c_str());
128 ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +i on "+std::string(cname));
130 return MOD_RES_ALLOW;
133 if (chan->IsModeSet('k') && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k'))
135 if (RequireKey && keygiven != "override")
137 // Can't join normally -- must use a special key to bypass restrictions
138 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
139 return MOD_RES_PASSTHRU;
143 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel key", cname, user->nick.c_str());
144 ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +k on "+std::string(cname));
145 return MOD_RES_ALLOW;
148 if (chan->IsModeSet('l') && (chan->GetUserCounter() >= atoi(chan->GetModeParameter('l').c_str())) && (CanOverride(user,"LIMIT")))
150 if (RequireKey && keygiven != "override")
152 // Can't join normally -- must use a special key to bypass restrictions
153 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
154 return MOD_RES_PASSTHRU;
158 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass the channel limit", cname, user->nick.c_str());
159 ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +l on "+std::string(cname));
160 return MOD_RES_ALLOW;
163 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
165 if (RequireKey && keygiven != "override")
167 // Can't join normally -- must use a special key to bypass restrictions
168 user->WriteServ("NOTICE %s :*** You may not join normally. You must join with a key of 'override' to oper override.", user->nick.c_str());
169 return MOD_RES_PASSTHRU;
173 chan->WriteChannelWithServ(ServerInstance->Config->ServerName.c_str(), "NOTICE %s :%s used oper override to bypass channel ban", cname, user->nick.c_str());
174 ServerInstance->SNO->WriteGlobalSno('v',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname);
175 return MOD_RES_ALLOW;
179 return MOD_RES_PASSTHRU;
184 return Version("Provides support for unreal-style oper-override",VF_VENDOR);
188 MODULE_INIT(ModuleOverride)