2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2009 Uli Schlachter <psychon@znc.in>
6 * Copyright (C) 2007-2009 Robin Burchell <robin+git@viroteck.net>
7 * Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
8 * Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
9 * Copyright (C) 2008 Geoff Bricker <geoff.bricker@gmail.com>
10 * Copyright (C) 2004-2006 Craig Edwards <craigedwards@brainbox.cc>
11 * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 class ModuleOverride : public Module
33 ChanModeReference topiclock;
34 ChanModeReference inviteonly;
35 ChanModeReference key;
36 ChanModeReference limit;
40 : topiclock(this, "topiclock")
41 , inviteonly(this, "inviteonly")
43 , limit(this, "limit")
47 void init() CXX11_OVERRIDE
49 // read our config options (main config file)
51 ServerInstance->SNO->EnableSnomask('v', "OVERRIDE");
52 Implementation eventlist[] = { I_OnRehash, I_OnPreMode, I_On005Numeric, I_OnUserPreJoin, I_OnUserPreKick, I_OnPreTopicChange };
53 ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation));
56 void OnRehash(User* user) CXX11_OVERRIDE
58 // re-read our config options on a rehash
59 ConfigTag* tag = ServerInstance->Config->ConfValue("override");
60 NoisyOverride = tag->getBool("noisy");
61 RequireKey = tag->getBool("requirekey");
64 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
69 bool CanOverride(User* source, const char* token)
71 std::string tokenlist = source->oper->getConfig("override");
73 // its defined or * is set, return its value as a boolean for if the token is set
74 return ((tokenlist.find(token, 0) != std::string::npos) || (tokenlist.find("*", 0) != std::string::npos));
78 ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic) CXX11_OVERRIDE
80 if (IS_LOCAL(source) && source->IsOper() && CanOverride(source, "TOPIC"))
82 if (!channel->HasUser(source) || (channel->IsModeSet(topiclock) && channel->GetPrefixValue(source) < HALFOP_VALUE))
84 ServerInstance->SNO->WriteGlobalSno('v',source->nick+" used oper override to change a topic on "+channel->name);
91 return MOD_RES_PASSTHRU;
94 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason) CXX11_OVERRIDE
96 if (source->IsOper() && CanOverride(source,"KICK"))
98 // If the kicker's status is less than the target's, or the kicker's status is less than or equal to voice
99 if ((memb->chan->GetPrefixValue(source) < memb->getRank()) || (memb->chan->GetPrefixValue(source) <= VOICE_VALUE))
101 ServerInstance->SNO->WriteGlobalSno('v',source->nick+" used oper override to kick "+memb->user->nick+" on "+memb->chan->name+" ("+reason+")");
102 return MOD_RES_ALLOW;
105 return MOD_RES_PASSTHRU;
108 ModResult OnPreMode(User* source,User* dest,Channel* channel, const std::vector<std::string>& parameters) CXX11_OVERRIDE
110 if (!source || !channel)
111 return MOD_RES_PASSTHRU;
112 if (!source->IsOper() || !IS_LOCAL(source))
113 return MOD_RES_PASSTHRU;
115 unsigned int mode = channel->GetPrefixValue(source);
117 if (mode < HALFOP_VALUE && CanOverride(source, "MODE"))
119 std::string msg = source->nick+" overriding modes:";
120 for(unsigned int i=0; i < parameters.size(); i++)
121 msg += " " + parameters[i];
122 ServerInstance->SNO->WriteGlobalSno('v',msg);
123 return MOD_RES_ALLOW;
125 return MOD_RES_PASSTHRU;
128 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
134 if (chan->IsModeSet(inviteonly) && (CanOverride(user,"INVITE")))
136 if (!IS_LOCAL(user)->IsInvited(chan))
138 if (RequireKey && keygiven != "override")
140 // Can't join normally -- must use a special key to bypass restrictions
141 user->WriteNotice("*** You may not join normally. You must join with a key of 'override' to oper override.");
142 return MOD_RES_PASSTHRU;
146 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass invite-only", cname.c_str(), user->nick.c_str());
147 ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +i on " + cname);
149 return MOD_RES_ALLOW;
152 if (chan->IsModeSet(key) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter(key))
154 if (RequireKey && keygiven != "override")
156 // Can't join normally -- must use a special key to bypass restrictions
157 user->WriteNotice("*** You may not join normally. You must join with a key of 'override' to oper override.");
158 return MOD_RES_PASSTHRU;
162 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel key", cname.c_str(), user->nick.c_str());
163 ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +k on " + cname);
164 return MOD_RES_ALLOW;
167 if (chan->IsModeSet(limit) && (chan->GetUserCounter() >= ConvToInt(chan->GetModeParameter(limit))) && (CanOverride(user,"LIMIT")))
169 if (RequireKey && keygiven != "override")
171 // Can't join normally -- must use a special key to bypass restrictions
172 user->WriteNotice("*** You may not join normally. You must join with a key of 'override' to oper override.");
173 return MOD_RES_PASSTHRU;
177 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass the channel limit", cname.c_str(), user->nick.c_str());
178 ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass +l on " + cname);
179 return MOD_RES_ALLOW;
182 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
184 if (RequireKey && keygiven != "override")
186 // Can't join normally -- must use a special key to bypass restrictions
187 user->WriteNotice("*** You may not join normally. You must join with a key of 'override' to oper override.");
188 return MOD_RES_PASSTHRU;
192 chan->WriteChannelWithServ(ServerInstance->Config->ServerName, "NOTICE %s :%s used oper override to bypass channel ban", cname.c_str(), user->nick.c_str());
193 ServerInstance->SNO->WriteGlobalSno('v',"%s used oper override to bypass channel ban on %s", user->nick.c_str(), cname.c_str());
194 return MOD_RES_ALLOW;
198 return MOD_RES_PASSTHRU;
201 Version GetVersion() CXX11_OVERRIDE
203 return Version("Provides support for allowing opers to override certain things",VF_VENDOR);
207 MODULE_INIT(ModuleOverride)