2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2020 satmd <satmd@users.noreply.github.com>
5 * Copyright (C) 2017 B00mX0r <b00mx0r@aureus.pw>
6 * Copyright (C) 2017 Adam <Adam@anope.org>
7 * Copyright (C) 2016 Sheogorath <sheogorath@shivering-isles.com>
8 * Copyright (C) 2013, 2017, 2020 Sadie Powell <sadie@witchery.services>
9 * Copyright (C) 2013 Daniel Vassdal <shutter@canternet.org>
10 * Copyright (C) 2012-2015 Attila Molnar <attilamolnar@hush.com>
11 * Copyright (C) 2012 Shawn Smith <ShawnSmith0828@gmail.com>
12 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
13 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
14 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
15 * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
16 * Copyright (C) 2007-2008 Dennis Friis <peavey@inspircd.org>
17 * Copyright (C) 2004, 2006, 2008, 2010 Craig Edwards <brain@inspircd.org>
19 * This file is part of InspIRCd. InspIRCd is free software: you can
20 * redistribute it and/or modify it under the terms of the GNU General Public
21 * License as published by the Free Software Foundation, version 2.
23 * This program is distributed in the hope that it will be useful, but WITHOUT
24 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
25 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
28 * You should have received a copy of the GNU General Public License
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 #include "modules/invite.h"
36 class Override : public SimpleUserModeHandler
39 Override(Module* Creator) : SimpleUserModeHandler(Creator, "override", 'O')
42 if (!ServerInstance->Config->ConfValue("override")->getBool("enableumode"))
43 DisableAutoRegister();
47 class ModuleOverride : public Module
53 ChanModeReference topiclock;
54 ChanModeReference inviteonly;
55 ChanModeReference key;
56 ChanModeReference limit;
59 static bool IsOverride(unsigned int userlevel, const Modes::ChangeList::List& list)
61 for (Modes::ChangeList::List::const_iterator i = list.begin(); i != list.end(); ++i)
63 ModeHandler* mh = i->mh;
64 if (mh->GetLevelRequired(i->adding) > userlevel)
70 ModResult HandleJoinOverride(LocalUser* user, Channel* chan, const std::string& keygiven, const char* bypasswhat, const char* mode)
72 if (RequireKey && keygiven != "override")
74 // Can't join normally -- must use a special key to bypass restrictions
75 user->WriteNotice("*** You may not join normally. You must join with a key of 'override' to oper override.");
76 return MOD_RES_PASSTHRU;
80 chan->WriteRemoteNotice(InspIRCd::Format("%s used oper override to bypass %s", user->nick.c_str(), bypasswhat));
81 ServerInstance->SNO->WriteGlobalSno('v', user->nick+" used oper override to bypass " + mode + " on " + chan->name);
89 , topiclock(this, "topiclock")
90 , inviteonly(this, "inviteonly")
92 , limit(this, "limit")
97 void init() CXX11_OVERRIDE
99 ServerInstance->SNO->EnableSnomask('v', "OVERRIDE");
100 UmodeEnabled = ServerInstance->Config->ConfValue("override")->getBool("enableumode");
103 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
105 // re-read our config options
106 ConfigTag* tag = ServerInstance->Config->ConfValue("override");
107 NoisyOverride = tag->getBool("noisy");
108 RequireKey = tag->getBool("requirekey");
111 void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE
116 bool CanOverride(User* source, const char* token)
118 // If we require oper override umode (+O) but it is not set
119 if (UmodeEnabled && !source->IsModeSet(ou))
122 std::string tokenlist = source->oper->getConfig("override");
123 // its defined or * is set, return its value as a boolean for if the token is set
124 return ((tokenlist.find(token, 0) != std::string::npos) || (tokenlist.find("*", 0) != std::string::npos));
128 ModResult OnPreTopicChange(User *source, Channel *channel, const std::string &topic) CXX11_OVERRIDE
130 if (IS_LOCAL(source) && source->IsOper() && CanOverride(source, "TOPIC"))
132 if (!channel->HasUser(source) || (channel->IsModeSet(topiclock) && channel->GetPrefixValue(source) < HALFOP_VALUE))
134 ServerInstance->SNO->WriteGlobalSno('v',source->nick+" used oper override to change a topic on "+channel->name);
138 return MOD_RES_ALLOW;
141 return MOD_RES_PASSTHRU;
144 ModResult OnUserPreKick(User* source, Membership* memb, const std::string &reason) CXX11_OVERRIDE
146 if (source->IsOper() && CanOverride(source,"KICK"))
148 // If the kicker's status is less than the target's, or the kicker's status is less than or equal to voice
149 if ((memb->chan->GetPrefixValue(source) < memb->getRank()) || (memb->chan->GetPrefixValue(source) <= VOICE_VALUE) ||
150 (memb->chan->GetPrefixValue(source) == HALFOP_VALUE && memb->getRank() == HALFOP_VALUE))
152 ServerInstance->SNO->WriteGlobalSno('v',source->nick+" used oper override to kick "+memb->user->nick+" on "+memb->chan->name+" ("+reason+")");
153 return MOD_RES_ALLOW;
156 return MOD_RES_PASSTHRU;
159 ModResult OnPreMode(User* source, User* dest, Channel* channel, Modes::ChangeList& modes) CXX11_OVERRIDE
162 return MOD_RES_PASSTHRU;
163 if (!source->IsOper() || !IS_LOCAL(source))
164 return MOD_RES_PASSTHRU;
166 const Modes::ChangeList::List& list = modes.getlist();
167 unsigned int mode = channel->GetPrefixValue(source);
169 if (!IsOverride(mode, list))
170 return MOD_RES_PASSTHRU;
172 if (CanOverride(source, "MODE"))
174 std::string msg = source->nick + " used oper override to set modes on " + channel->name + ": ";
176 // Construct a MODE string in the old format for sending it as a snotice
179 for (Modes::ChangeList::List::const_iterator i = list.begin(); i != list.end(); ++i)
181 const Modes::Change& item = *i;
182 if (!item.param.empty())
183 params.append(1, ' ').append(item.param);
185 char wanted_pm = (item.adding ? '+' : '-');
192 msg += item.mh->GetModeChar();
195 ServerInstance->SNO->WriteGlobalSno('v',msg);
196 return MOD_RES_ALLOW;
198 return MOD_RES_PASSTHRU;
201 ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE
207 if (chan->IsModeSet(inviteonly) && (CanOverride(user,"INVITE")))
209 if (!invapi->IsInvited(user, chan))
210 return HandleJoinOverride(user, chan, keygiven, "invite-only", "+i");
211 return MOD_RES_ALLOW;
214 if (chan->IsModeSet(key) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter(key))
215 return HandleJoinOverride(user, chan, keygiven, "the channel key", "+k");
217 if (chan->IsModeSet(limit) && (chan->GetUserCounter() >= ConvToNum<size_t>(chan->GetModeParameter(limit))) && (CanOverride(user,"LIMIT")))
218 return HandleJoinOverride(user, chan, keygiven, "the channel limit", "+l");
220 if (chan->IsBanned(user) && CanOverride(user,"BANWALK"))
221 return HandleJoinOverride(user, chan, keygiven, "channel ban", "channel ban");
224 return MOD_RES_PASSTHRU;
227 Version GetVersion() CXX11_OVERRIDE
229 return Version("Allows server operators to be given privileges that allow them to ignore various channel-level restrictions.",VF_VENDOR);
233 MODULE_INIT(ModuleOverride)