1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-09 01:03:13 +02:00

Add /GEOIP command so it's a bit easier to debug these things.

Load geoip_classic with correct settings (for now) in modules.optional.conf.
This commit is contained in:
Bram Matthys
2021-10-30 09:56:40 +02:00
parent 2adbb42ec7
commit ed9f7cfb57
2 changed files with 65 additions and 0 deletions
+7
View File
@@ -228,3 +228,10 @@ set {
// };
//};
loadmodule "geoip_classic";
set {
geoip-classic {
ipv4-database "https://www.unrealircd.org/files/geo/classic/GeoIP.dat";
ipv6-database "https://www.unrealircd.org/files/geo/classic/GeoIPv6.dat";
}
}
+58
View File
@@ -30,6 +30,7 @@ int geoip_connect_extinfo(Client *client, NameValuePrioList **list);
int geoip_base_configtest(ConfigFile *cf, ConfigEntry *ce, int type, int *errs);
int geoip_base_configrun(ConfigFile *cf, ConfigEntry *ce, int type);
EVENT(geoip_base_set_existing_users_evt);
CMD_FUNC(cmd_geoip);
ModDataInfo *geoip_md; /* Module Data structure which we acquire */
struct geoip_base_config_s geoip_base_config;
@@ -124,6 +125,8 @@ MOD_INIT()
HookAdd(modinfo->handle, HOOKTYPE_REMOTE_CONNECT, 0, geoip_base_handshake); /* remote user */
HookAdd(modinfo->handle, HOOKTYPE_WHOIS, 0, geoip_base_whois);
CommandAdd(modinfo->handle, "GEOIP", cmd_geoip, MAXPARA, CMD_USER);
/* set defaults */
geoip_base_config.check_on_load = 1;
@@ -266,3 +269,58 @@ int geoip_base_whois(Client *client, Client *target, NameValuePrioList **list)
geo->country_name);
return 0;
}
CMD_FUNC(cmd_geoip)
{
const char *ip = NULL;
Client *target;
GeoIPResult *res;
if (!IsOper(client))
{
sendnumeric(client, ERR_NOPRIVILEGES);
return;
}
if ((parc < 2) || BadPtr(parv[1]))
{
/* Maybe some report */
return;
}
if (strchr(parv[1], '.') || strchr(parv[1], ':'))
{
ip = parv[1];
} else {
target = find_user(parv[1], NULL);
if (!target)
{
sendnumeric(client, ERR_NOSUCHNICK, parv[1]);
return;
}
ip = target->ip;
if (!ip)
{
sendnotice(client, "User %s has no known IP address", client->name); // (eg: services bot)
return;
}
}
res = geoip_lookup(ip);
sendnotice(client, "*** GEOIP information for IP %s ***", ip);
if (!res)
{
sendnotice(client, "- No information available");
return;
} else {
if (res->country_code)
sendnotice(client, "- Country code: %s", res->country_code);
if (res->country_name)
sendnotice(client, "- Country name: %s", res->country_name);
}
free_geoip_result(res);
sendnotice(client, "*** End of information ***");
}