Make domainparts configureable

This commit is contained in:
Sheogorath 2017-06-27 22:41:07 +02:00
parent 6acb2dcdd2
commit aa5bd1eafe
No known key found for this signature in database
GPG Key ID: 1F05CC3635CDDFFD
2 changed files with 22 additions and 6 deletions

View File

@ -481,9 +481,12 @@
# #
# There are two methods of cloaking: #
# #
# half Cloak only the "unique" portion of a host; show #
# the last 2 parts of the domain, /16 subnet of IPv4 #
# or /48 subnet of the IPv6 address. #
# half Cloak only the "unique" portion of a host; by #
# default show the last 2 parts of the domain, #
# /16 subnet of IPv4 or /48 subnet of the IPv6 #
# address. #
# To change the number of shown parts, modify the #
# domainparts option. #
# #
# full Cloak the users completely, using three slices for #
# common CIDR bans (IPv4: /16, /24; IPv6: /48, /64). #
@ -494,6 +497,7 @@
#
#<cloak mode="half"
# key="secret"
# domainparts="3"
# prefix="net-">
#-#-#-#-#-#-#-#-#-#-#-#- CLOSE MODULE #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#

View File

@ -143,6 +143,7 @@ class ModuleCloaking : public Module
std::string prefix;
std::string suffix;
std::string key;
unsigned int domainparts;
dynamic_reference<HashProvider> Hash;
ModuleCloaking() : cu(this), mode(MODE_OPAQUE), ck(this), Hash(this, "hash/md5")
@ -160,7 +161,7 @@ class ModuleCloaking : public Module
*/
std::string LastTwoDomainParts(const std::string &host)
{
int dots = 0;
unsigned int dots = 0;
std::string::size_type splitdot = host.length();
for (std::string::size_type x = host.length() - 1; x; --x)
@ -170,7 +171,7 @@ class ModuleCloaking : public Module
splitdot = x;
dots++;
}
if (dots >= 3)
if (dots >= domainparts)
break;
}
@ -314,7 +315,15 @@ class ModuleCloaking : public Module
switch (mode)
{
case MODE_HALF_CLOAK:
// Use old cloaking verification to stay compatible with 2.0
// But verify domainparts when use 3.0-only features
if (domainparts == 3)
testcloak = prefix + SegmentCloak("*", 3, 8) + suffix;
else
{
irc::sockets::sockaddrs sa;
testcloak = GenCloak(sa, "", testcloak + ConvToStr(domainparts));
}
break;
case MODE_OPAQUE:
testcloak = prefix + SegmentCloak("*", 4, 8) + suffix;
@ -331,7 +340,10 @@ class ModuleCloaking : public Module
std::string modestr = tag->getString("mode");
if (modestr == "half")
{
mode = MODE_HALF_CLOAK;
domainparts = tag->getInt("domainparts", 3, 1, 10);
}
else if (modestr == "full")
mode = MODE_OPAQUE;
else