/* * this module requires the GeoLiteCity Database! (42 MB) * you can download it at http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz * dont forget to uncompress the file and change the path in the following #define */ #define myGeoIPCityPath "/usr/share/GeoIP/GeoLiteCity.dat" #define OPERSONLY 1 #include "inspircd.h" #include "transport.h" #include #include /* $LinkerFlags: -lGeoIP */ class ModuleGeoIP : public Module { private: GeoIP * gi; public: ModuleGeoIP(InspIRCd *Me) : Module(Me) { Implementation eventlist[] = { I_OnWhois }; ServerInstance->Modules->Attach(eventlist, this, 1); gi = GeoIP_open(myGeoIPCityPath, GEOIP_MEMORY_CACHE); if (!gi) throw CoreException("[m_showgeoip.so] Error opening file %s. Please check the file path in the .cpp file.", myGeoIPCityPath); } ~ModuleGeoIP() { if (gi) GeoIP_delete(gi); } virtual Version GetVersion() { return Version("$Id: m_showgeoip.cpp 2009-04-26 DukePyrolator $", VF_VENDOR, API_VERSION); } virtual void OnWhois(User* user, User* dest) { GeoIPRecord *geo; if (!user->HasPrivPermission("users/auspex")) return; geo = GeoIP_record_by_addr(gi, dest->GetIPString()); if (geo) { const char* region = GeoIP_region_name_by_code(geo->country_code, geo->region); ServerInstance->SendWhoisLine( user, dest, 320, "%s %s :is connecting from: %s%s%s%s%s", user->nick.c_str(), dest->nick.c_str(), geo->city ? geo->city : "", geo->city ? ", " : "", region ? region : "", region ? ", " : "", geo->country_name ? geo->country_name : ""); GeoIPRecord_delete(geo); /* free allocated memory */ } } }; MODULE_INIT(ModuleGeoIP)