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, 2008-2010 Craig Edwards <brain@inspircd.org>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "modules/exemption.h"
33 RPL_ENDOFSPAMFILTER = 940,
37 class ChanFilter : public ListModeBase
42 ChanFilter(Module* Creator)
43 : ListModeBase(Creator, "filter", 'g', "End of channel spamfilter list", RPL_SPAMFILTER, RPL_ENDOFSPAMFILTER, false)
48 bool ValidateParam(User* user, Channel* chan, std::string& word) CXX11_OVERRIDE
50 if (word.length() > maxlen)
52 user->WriteNumeric(Numerics::InvalidModeParameter(chan, this, word, "Word is too long for the spamfilter list."));
60 class ModuleChanFilter : public Module
62 CheckExemption::EventProvider exemptionprov;
67 ChanFilter::ListItem* Match(User* user, Channel* chan, const std::string& text)
69 ModResult res = CheckExemption::Call(exemptionprov, user, chan, "filter");
70 if (!IS_LOCAL(user) || res == MOD_RES_ALLOW)
73 ListModeBase::ModeList* list = cf.GetList(chan);
77 for (ListModeBase::ModeList::iterator i = list->begin(); i != list->end(); i++)
79 if (InspIRCd::Match(text, i->mask))
94 void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
96 ConfigTag* tag = ServerInstance->Config->ConfValue("chanfilter");
97 hidemask = tag->getBool("hidemask");
98 cf.maxlen = tag->getUInt("maxlen", 35, 10, ModeParser::MODE_PARAM_MAX);
99 notifyuser = tag->getBool("notifyuser", true);
103 void OnUserPart(Membership* memb, std::string& partmessage, CUList& except_list) CXX11_OVERRIDE
108 User* user = memb->user;
109 Channel* chan = memb->chan;
110 ChanFilter::ListItem* match = Match(user, chan, partmessage);
114 // Match() checks the user is local, we can assume from here
115 LocalUser* luser = IS_LOCAL(user);
117 std::string oldreason(partmessage);
118 partmessage = "Reason filtered";
122 ClientProtocol::Messages::Part partmsg(memb, oldreason);
123 ClientProtocol::Event ev(ServerInstance->GetRFCEvents().part, partmsg);
126 // Don't send the user the changed message
127 except_list.insert(user);
132 user->WriteNumeric(Numerics::CannotSendTo(chan, "Your part message contained a banned phrase and was blocked."));
134 user->WriteNumeric(Numerics::CannotSendTo(chan, InspIRCd::Format("Your part message contained a banned phrase (%s) and was blocked.",
135 match->mask.c_str())));
138 ModResult OnUserPreMessage(User* user, const MessageTarget& target, MessageDetails& details) CXX11_OVERRIDE
140 if (target.type != MessageTarget::TYPE_CHANNEL)
141 return MOD_RES_PASSTHRU;
143 Channel* chan = target.Get<Channel>();
144 ChanFilter::ListItem* match = Match(user, chan, details.text);
149 details.echo_original = true;
154 user->WriteNumeric(Numerics::CannotSendTo(chan, "Your message to this channel contained a banned phrase and was blocked."));
156 user->WriteNumeric(Numerics::CannotSendTo(chan, InspIRCd::Format("Your message to this channel contained a banned phrase (%s) and was blocked.",
157 match->mask.c_str())));
161 return MOD_RES_PASSTHRU;
164 Version GetVersion() CXX11_OVERRIDE
166 // We don't send any link data if the length is 35 for compatibility with the 2.0 branch.
167 std::string maxfilterlen;
169 maxfilterlen.assign(ConvToStr(cf.maxlen));
171 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);
175 MODULE_INIT(ModuleChanFilter)