mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-10 02:59:01 -04:00
Implement support for banning users from channels by country code.
This commit is contained in:
parent
9ea8191a05
commit
d04db003df
@ -833,6 +833,10 @@
|
|||||||
#
|
#
|
||||||
# <connect deny="*" geoip="TR,RU">
|
# <connect deny="*" geoip="TR,RU">
|
||||||
#
|
#
|
||||||
|
# If enabled you can also ban people from channnels by country code
|
||||||
|
# using the G: extban (e.g. /mode #channel +b G:US).
|
||||||
|
# <geoip extban="yes">
|
||||||
|
#
|
||||||
# The country code must be in capitals and should be an ISO country
|
# The country code must be in capitals and should be an ISO country
|
||||||
# code such as TR, GB, or US. Unknown IPs (localhost, LAN IPs, etc)
|
# code such as TR, GB, or US. Unknown IPs (localhost, LAN IPs, etc)
|
||||||
# will be assigned the country code "UNK". Since connect classes are
|
# will be assigned the country code "UNK". Since connect classes are
|
||||||
|
@ -41,25 +41,33 @@
|
|||||||
# pragma comment(lib, "GeoIP.lib")
|
# pragma comment(lib, "GeoIP.lib")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class ModuleGeoIP : public Module
|
enum
|
||||||
{
|
{
|
||||||
LocalStringExt ext;
|
// InspIRCd-specific.
|
||||||
|
RPL_WHOISCOUNTRY = 344
|
||||||
|
};
|
||||||
|
|
||||||
|
class ModuleGeoIP : public Module, public Whois::EventListener
|
||||||
|
{
|
||||||
|
StringExtItem ext;
|
||||||
|
bool extban;
|
||||||
GeoIP* gi;
|
GeoIP* gi;
|
||||||
|
|
||||||
std::string* SetExt(LocalUser* user)
|
std::string* SetExt(User* user)
|
||||||
{
|
{
|
||||||
const char* c = GeoIP_country_code_by_addr(gi, user->GetIPString().c_str());
|
const char* c = GeoIP_country_code_by_addr(gi, user->GetIPString().c_str());
|
||||||
if (!c)
|
if (!c)
|
||||||
c = "UNK";
|
c = "UNK";
|
||||||
|
|
||||||
std::string* cc = new std::string(c);
|
ext.set(user, c);
|
||||||
ext.set(user, cc);
|
return ext.get(user);
|
||||||
return cc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModuleGeoIP()
|
ModuleGeoIP()
|
||||||
: ext("geoip_cc", ExtensionItem::EXT_USER, this)
|
: Whois::EventListener(this)
|
||||||
|
, ext("geoip_cc", ExtensionItem::EXT_USER, this)
|
||||||
|
, extban(true)
|
||||||
, gi(NULL)
|
, gi(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -87,9 +95,29 @@ class ModuleGeoIP : public Module
|
|||||||
GeoIP_delete(gi);
|
GeoIP_delete(gi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReadConfig(ConfigStatus&)
|
||||||
|
{
|
||||||
|
ConfigTag* tag = ServerInstance->Config->ConfValue("geoip");
|
||||||
|
extban = tag->getBool("extban");
|
||||||
|
}
|
||||||
|
|
||||||
Version GetVersion() CXX11_OVERRIDE
|
Version GetVersion() CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
return Version("Provides a way to assign users to connect classes by country using GeoIP lookup", VF_VENDOR);
|
return Version("Provides a way to assign users to connect classes by country using GeoIP lookup", VF_OPTCOMMON|VF_VENDOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
ModResult OnCheckBan(User *user, Channel *c, const std::string& mask)
|
||||||
|
{
|
||||||
|
if ((mask.length() > 2) && (mask[0] == 'G') && (mask[1] == ':'))
|
||||||
|
{
|
||||||
|
std::string* cc = ext.get(user);
|
||||||
|
if (!cc)
|
||||||
|
cc = SetExt(user);
|
||||||
|
|
||||||
|
if (InspIRCd::Match(*cc, mask.substr(2)))
|
||||||
|
return MOD_RES_DENY;
|
||||||
|
}
|
||||||
|
return MOD_RES_PASSTHRU;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass) CXX11_OVERRIDE
|
ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass) CXX11_OVERRIDE
|
||||||
@ -109,6 +137,19 @@ class ModuleGeoIP : public Module
|
|||||||
return MOD_RES_DENY;
|
return MOD_RES_DENY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
|
||||||
|
{
|
||||||
|
// If the extban is disabled we don't expose users location.
|
||||||
|
if (!extban)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string* cc = ext.get(whois.GetTarget());
|
||||||
|
if (!cc)
|
||||||
|
cc = SetExt(whois.GetTarget());
|
||||||
|
|
||||||
|
whois.SendLine(RPL_WHOISCOUNTRY, *cc, "is located in this country");
|
||||||
|
}
|
||||||
|
|
||||||
ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
|
ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
|
||||||
{
|
{
|
||||||
if (stats.GetSymbol() != 'G')
|
if (stats.GetSymbol() != 'G')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user