summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/conf/helpop-full.conf.example5
-rw-r--r--include/modules/shun.h70
-rw-r--r--src/modules/m_filter.cpp62
-rw-r--r--src/modules/m_shun.cpp40
4 files changed, 122 insertions, 55 deletions
diff --git a/docs/conf/helpop-full.conf.example b/docs/conf/helpop-full.conf.example
index 883ec9b16..3e8360e55 100644
--- a/docs/conf/helpop-full.conf.example
+++ b/docs/conf/helpop-full.conf.example
@@ -434,11 +434,11 @@ reason parameter is optional, and if not provided defaults to
'Please use this server/port instead' (the default given in various
numeric lists)">
-<helpop key="filter" value="/FILTER <filter-definition> [<action> <flags> [<gline-duration>] :<reason>]
+<helpop key="filter" value="/FILTER <filter-definition> [<action> <flags> [<duration>] :<reason>]
This command will add a filter when more than one parameter is given,
for messages of the types specified by the flags, with the given
-filter definition, action, gline duration (when the action is 'gline')
+filter definition, action, duration (when the action is 'gline' or 'shun'),
and reason.
The filter will take effect when a message of any type specified by
@@ -454,6 +454,7 @@ Block Blocks message and informs +s IRCops of the blocked message
Silent Blocks message, but does not notify IRCops
Kill Kills the user
Gline Glines the user for the specified duration
+Shun Shuns the user for the specified duration (requires the shun module)
Valid FILTER Flags
------------------
diff --git a/include/modules/shun.h b/include/modules/shun.h
new file mode 100644
index 000000000..f2bc4eea5
--- /dev/null
+++ b/include/modules/shun.h
@@ -0,0 +1,70 @@
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2017 Dylan Frank <b00mx0r@aureus.pw>
+ *
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+#include "xline.h"
+
+/** Shun class
+ */
+class CoreExport Shun : public XLine
+{
+ public:
+ /** Create a Shun.
+ * @param s_time The set time
+ * @param d The duration of the xline
+ * @param src The sender of the xline
+ * @param re The reason of the xline
+ * @param shunmask Mask to match
+ */
+ Shun(time_t s_time, long d, const std::string& src, const std::string& re, const std::string& shunmask)
+ : XLine(s_time, d, src, re, "SHUN")
+ , matchtext(shunmask)
+ {
+ }
+
+ bool Matches(User* u) CXX11_OVERRIDE
+ {
+ LocalUser* lu = IS_LOCAL(u);
+ if (lu && lu->exempt)
+ return false;
+
+ if (InspIRCd::Match(u->GetFullHost(), matchtext) || InspIRCd::Match(u->GetFullRealHost(), matchtext) || InspIRCd::Match(u->nick+"!"+u->ident+"@"+u->GetIPString(), matchtext))
+ return true;
+
+ if (InspIRCd::MatchCIDR(u->GetIPString(), matchtext, ascii_case_insensitive_map))
+ return true;
+
+ return false;
+ }
+
+ bool Matches(const std::string& str) CXX11_OVERRIDE
+ {
+ return (matchtext == str);
+ }
+
+ const std::string& Displayable() CXX11_OVERRIDE
+ {
+ return matchtext;
+ }
+
+ private:
+ /** Matching mask **/
+ std::string matchtext;
+};
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp
index a672bc9f6..7f5be3639 100644
--- a/src/modules/m_filter.cpp
+++ b/src/modules/m_filter.cpp
@@ -24,6 +24,7 @@
#include "xline.h"
#include "modules/regex.h"
#include "modules/server.h"
+#include "modules/shun.h"
enum FilterFlags
{
@@ -39,6 +40,7 @@ enum FilterAction
FA_BLOCK,
FA_SILENT,
FA_KILL,
+ FA_SHUN,
FA_NONE
};
@@ -49,7 +51,7 @@ class FilterResult
std::string freeform;
std::string reason;
FilterAction action;
- long gline_time;
+ long duration;
bool flag_no_opers;
bool flag_part_message;
@@ -59,7 +61,10 @@ class FilterResult
bool flag_strip_color;
FilterResult(dynamic_reference<RegexFactory>& RegexEngine, const std::string& free, const std::string& rea, FilterAction act, long gt, const std::string& fla)
- : freeform(free), reason(rea), action(act), gline_time(gt)
+ : freeform(free)
+ , reason(rea)
+ , action(act)
+ , duration(gt)
{
if (!RegexEngine)
throw ModuleException("Regex module implementing '"+RegexEngine.GetProvider()+"' is not loaded!");
@@ -145,7 +150,7 @@ class CommandFilter : public Command
: Command(f, "FILTER", 1, 5)
{
flags_needed = 'o';
- this->syntax = "<filter-definition> <action> <flags> [<gline-duration>] :<reason>";
+ this->syntax = "<filter-definition> <action> <flags> [<duration>] :<reason>";
}
CmdResult Handle(const std::vector<std::string>& , User* ) CXX11_OVERRIDE;
@@ -228,11 +233,14 @@ CmdResult CommandFilter::Handle(const std::vector<std::string> &parameters, User
if (!ModuleFilter::StringToFilterAction(parameters[1], type))
{
- user->WriteNotice("*** Invalid filter type '" + parameters[1] + "'. Supported types are 'gline', 'none', 'block', 'silent' and 'kill'.");
+ if (ServerInstance->XLines->GetFactory("SHUN"))
+ user->WriteNotice("*** Invalid filter type '" + parameters[1] + "'. Supported types are 'gline', 'none', 'block', 'silent', 'kill', and 'shun'.");
+ else
+ user->WriteNotice("*** Invalid filter type '" + parameters[1] + "'. Supported types are 'gline', 'none', 'block', 'silent', and 'kill'.");
return CMD_FAILURE;
}
- if (type == FA_GLINE)
+ if (type == FA_GLINE || type == FA_SHUN)
{
if (parameters.size() >= 5)
{
@@ -241,7 +249,7 @@ CmdResult CommandFilter::Handle(const std::vector<std::string> &parameters, User
}
else
{
- user->WriteNotice("*** Not enough parameters: When setting a gline type filter, a gline duration must be specified as the third parameter.");
+ user->WriteNotice("*** Not enough parameters: When setting a gline or shun type filter, a duration must be specified as the third parameter.");
return CMD_FAILURE;
}
}
@@ -363,9 +371,20 @@ ModResult ModuleFilter::OnUserPreMessage(User* user, void* dest, int target_type
ServerInstance->SNO->WriteGlobalSno('a', "FILTER: " + user->nick + " had their message filtered and was killed, target was " + target + ": " + f->reason);
ServerInstance->Users->QuitUser(user, "Filtered: " + f->reason);
}
+ else if (f->action == FA_SHUN && (ServerInstance->XLines->GetFactory("SHUN")))
+ {
+ Shun* sh = new Shun(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), user->GetIPString());
+ ServerInstance->SNO->WriteGlobalSno('a', "FILTER: " + user->nick + " had their message filtered and was shunned, target was " + target + ": " + f->reason);
+ if (ServerInstance->XLines->AddLine(sh, NULL))
+ {
+ ServerInstance->XLines->ApplyLines();
+ }
+ else
+ delete sh;
+ }
else if (f->action == FA_GLINE)
{
- GLine* gl = new GLine(ServerInstance->Time(), f->gline_time, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), "*", user->GetIPString());
+ GLine* gl = new GLine(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), "*", user->GetIPString());
ServerInstance->SNO->WriteGlobalSno('a', "FILTER: " + user->nick + " had their message filtered and was G-Lined, target was " + target + ": " + f->reason);
if (ServerInstance->XLines->AddLine(gl,NULL))
{
@@ -439,7 +458,7 @@ ModResult ModuleFilter::OnPreCommand(std::string &command, std::vector<std::stri
if (f->action == FA_GLINE)
{
/* Note: We gline *@IP so that if their host doesnt resolve the gline still applies. */
- GLine* gl = new GLine(ServerInstance->Time(), f->gline_time, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), "*", user->GetIPString());
+ GLine* gl = new GLine(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), "*", user->GetIPString());
ServerInstance->SNO->WriteGlobalSno('a', "FILTER: " + user->nick + " had their " + command + " message filtered and was G-Lined: " + f->reason);
if (ServerInstance->XLines->AddLine(gl,NULL))
{
@@ -448,6 +467,18 @@ ModResult ModuleFilter::OnPreCommand(std::string &command, std::vector<std::stri
else
delete gl;
}
+ else if (f->action == FA_SHUN && (ServerInstance->XLines->GetFactory("SHUN")))
+ {
+ /* Note: We shun *!*@IP so that if their host doesnt resolve the shun still applies. */
+ Shun* sh = new Shun(ServerInstance->Time(), f->duration, ServerInstance->Config->ServerName.c_str(), f->reason.c_str(), user->GetIPString());
+ ServerInstance->SNO->WriteGlobalSno('a', "FILTER: " + user->nick + " had their " + command + " message filtered and was shunned: " + f->reason);
+ if (ServerInstance->XLines->AddLine(sh, NULL))
+ {
+ ServerInstance->XLines->ApplyLines();
+ }
+ else
+ delete sh;
+ }
return MOD_RES_DENY;
}
}
@@ -521,7 +552,7 @@ std::string ModuleFilter::EncodeFilter(FilterResult* filter)
if (*n == ' ')
*n = '\7';
- stream << x << " " << FilterActionToString(filter->action) << " " << filter->GetFlags() << " " << filter->gline_time << " :" << filter->reason;
+ stream << x << " " << FilterActionToString(filter->action) << " " << filter->GetFlags() << " " << filter->duration << " :" << filter->reason;
return stream.str();
}
@@ -541,7 +572,7 @@ FilterResult ModuleFilter::DecodeFilter(const std::string &data)
if (c != 0)
throw ModuleException("Invalid flag: '" + std::string(1, c) + "'");
- tokens.GetToken(res.gline_time);
+ tokens.GetToken(res.duration);
tokens.GetToken(res.reason);
/* Hax to allow spaces in the freeform without changing the design of the irc protocol */
@@ -567,7 +598,7 @@ void ModuleFilter::OnDecodeMetaData(Extensible* target, const std::string &extna
try
{
FilterResult data = DecodeFilter(extdata);
- this->AddFilter(data.freeform, data.action, data.reason, data.gline_time, data.GetFlags());
+ this->AddFilter(data.freeform, data.action, data.reason, data.duration, data.GetFlags());
}
catch (ModuleException& e)
{
@@ -647,6 +678,8 @@ bool ModuleFilter::StringToFilterAction(const std::string& str, FilterAction& fa
fa = FA_SILENT;
else if (stdalgo::string::equalsci(str, "kill"))
fa = FA_KILL;
+ else if (stdalgo::string::equalsci(str, "shun") && (ServerInstance->XLines->GetFactory("SHUN")))
+ fa = FA_SHUN;
else if (stdalgo::string::equalsci(str, "none"))
fa = FA_NONE;
else
@@ -663,6 +696,7 @@ std::string ModuleFilter::FilterActionToString(FilterAction fa)
case FA_BLOCK: return "block";
case FA_SILENT: return "silent";
case FA_KILL: return "kill";
+ case FA_SHUN: return "shun";
default: return "none";
}
}
@@ -678,7 +712,7 @@ void ModuleFilter::ReadFilters()
std::string reason = i->second->getString("reason");
std::string action = i->second->getString("action");
std::string flgs = i->second->getString("flags");
- unsigned long gline_time = i->second->getDuration("duration", 10*60, 1);
+ unsigned long duration = i->second->getDuration("duration", 10*60, 1);
if (flgs.empty())
flgs = "*";
@@ -688,7 +722,7 @@ void ModuleFilter::ReadFilters()
try
{
- filters.push_back(FilterResult(RegexEngine, pattern, reason, fa, gline_time, flgs));
+ filters.push_back(FilterResult(RegexEngine, pattern, reason, fa, duration, flgs));
ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "Regular expression %s loaded.", pattern.c_str());
}
catch (ModuleException &e)
@@ -704,7 +738,7 @@ ModResult ModuleFilter::OnStats(Stats::Context& stats)
{
for (std::vector<FilterResult>::iterator i = filters.begin(); i != filters.end(); i++)
{
- stats.AddRow(223, RegexEngine.GetProvider()+":"+i->freeform+" "+i->GetFlags()+" "+FilterActionToString(i->action)+" "+ConvToStr(i->gline_time)+" :"+i->reason);
+ stats.AddRow(223, RegexEngine.GetProvider()+":"+i->freeform+" "+i->GetFlags()+" "+FilterActionToString(i->action)+" "+ConvToStr(i->duration)+" :"+i->reason);
}
for (ExemptTargetSet::const_iterator i = exemptedchans.begin(); i != exemptedchans.end(); ++i)
{
diff --git a/src/modules/m_shun.cpp b/src/modules/m_shun.cpp
index d68f58dd4..5b0b42cae 100644
--- a/src/modules/m_shun.cpp
+++ b/src/modules/m_shun.cpp
@@ -22,46 +22,8 @@
#include "inspircd.h"
#include "xline.h"
+#include "modules/shun.h"
-class Shun : public XLine
-{
-public:
- std::string matchtext;
-
- Shun(time_t s_time, long d, const std::string& src, const std::string& re, const std::string& shunmask)
- : XLine(s_time, d, src, re, "SHUN")
- , matchtext(shunmask)
- {
- }
-
- bool Matches(User* u) CXX11_OVERRIDE
- {
- // E: overrides shun
- LocalUser* lu = IS_LOCAL(u);
- if (lu && lu->exempt)
- return false;
-
- if (InspIRCd::Match(u->GetFullHost(), matchtext) || InspIRCd::Match(u->GetFullRealHost(), matchtext) || InspIRCd::Match(u->nick+"!"+u->ident+"@"+u->GetIPString(), matchtext))
- return true;
-
- if (InspIRCd::MatchCIDR(u->GetIPString(), matchtext, ascii_case_insensitive_map))
- return true;
-
- return false;
- }
-
- bool Matches(const std::string& s) CXX11_OVERRIDE
- {
- if (matchtext == s)
- return true;
- return false;
- }
-
- const std::string& Displayable() CXX11_OVERRIDE
- {
- return matchtext;
- }
-};
/** An XLineFactory specialized to generate shun pointers
*/