2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2019 linuxdaemon <linuxdaemon.irc@gmail.com>
5 * Copyright (C) 2013, 2017-2020 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012-2014 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2012, 2018 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
10 * Copyright (C) 2006 Oliver Lupton <om@inspircd.org>
11 * Copyright (C) 2005-2006, 2008-2010 Craig Edwards <brain@inspircd.org>
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 #include "modules/exemption.h"
34 RPL_ENDOFSPAMFILTER = 940,
38 class ChanFilter : public ListModeBase
43 ChanFilter(Module* Creator)
44 : ListModeBase(Creator, "filter", 'g', "End of channel spamfilter list", RPL_SPAMFILTER, RPL_ENDOFSPAMFILTER, false)
49 bool ValidateParam(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE
51 if (word.length() > maxlen)
53 user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Word is too long for the spamfilter list."));
61 class ModuleChanFilter : public Module
63 CheckExemption::EventProvider exemptionprov;
68 ChanFilter::ListItem* Match(User* user, Channel* chan, const std::string& text)
70 ModResult res = CheckExemption::Call(exemptionprov, user, chan, "filter");
71 if (!IS_LOCAL(user) || res == MOD_RES_ALLOW)
74 ListModeBase::ModeList* list = cf.GetList(chan);
78 for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); i++)
80 if (InspIRCd::Match(text, i->mask))
95 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
97 ConfigTag* tag = ServerInstance->Config->ConfValue("chanfilter");
98 hidemask = tag->getBool("hidemask");
99 cf.maxlen = tag->getUInt("maxlen", 35, 10, ModeParser::MODE_PARAM_MAX);
100 notifyuser = tag->getBool("notifyuser", true);
104 void OnUserPart(Membership* memb, std::string& partmessage, CUList& except_list) CXX11_OVERRIDE
109 User* user = memb->user;
110 Channel* chan = memb->chan;
111 ChanFilter::ListItem* match = Match(user, chan, partmessage);
115 // Match() checks the user is local, we can assume from here
116 LocalUser* luser = IS_LOCAL(user);
118 std::string oldreason(partmessage);
119 partmessage = "Reason filtered";
123 ClientProtocol::Messages::Part partmsg(memb, oldreason);
124 ClientProtocol::Event ev(ServerInstance->GetRFCEvents().part, partmsg);
127 // Don't send the user the changed message
128 except_list.insert(user);
133 user->WriteNumeric(Numerics::CannotSendTo(chan, "Your part message contained a banned phrase and was blocked."));
135 user->WriteNumeric(Numerics::CannotSendTo(chan, InspIRCd::Format("Your part message contained a banned phrase (%s) and was blocked.",
136 match->mask.c_str())));
139 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
141 if (target.type != MessageTarget::TYPE_CHANNEL)
142 return MOD_RES_PASSTHRU;
144 Channel* chan = target.Get<Channel>();
145 ChanFilter::ListItem* match = Match(user, chan, details.text);
150 details.echo_original = true;
155 user->WriteNumeric(Numerics::CannotSendTo(chan, "Your message to this channel contained a banned phrase and was blocked."));
157 user->WriteNumeric(Numerics::CannotSendTo(chan, InspIRCd::Format("Your message to this channel contained a banned phrase (%s) and was blocked.",
158 match->mask.c_str())));
162 return MOD_RES_PASSTHRU;
165 Version GetVersion() CXX11_OVERRIDE
167 // We don't send any link data if the length is 35 for compatibility with the 2.0 branch.
168 std::string maxfilterlen;
170 maxfilterlen.assign(ConvToStr(cf.maxlen));
172 return Version("Adds channel mode g (filter) which allows channel operators to define glob patterns for inappropriate phrases that are not allowed to be used in the channel.", VF_VENDOR, maxfilterlen);
176 MODULE_INIT(ModuleChanFilter)