From 56a5ace638d503099accf4e3461c53b154edaa1d Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 16 Mar 2008 19:57:07 +0000 Subject: Start of GeoIP module. This is deceptively simple. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9102 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules/extra/m_geoip.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/modules/extra/m_geoip.cpp (limited to 'src') diff --git a/src/modules/extra/m_geoip.cpp b/src/modules/extra/m_geoip.cpp new file mode 100644 index 000000000..57a08ed84 --- /dev/null +++ b/src/modules/extra/m_geoip.cpp @@ -0,0 +1,79 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2008 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + +#include "inspircd.h" +#include "xline.h" + +#include + +/* $ModDesc: Provides a way to restrict users by country using GeoIP lookup */ +/* $LinkerFlags: -lGeoIP */ + +class ModuleGeoIP : public Module +{ + GeoIP * gi; + + public: + ModuleGeoIP(InspIRCd *Me) : Module(Me) + { + ReadConf(); + Implementation eventlist[] = { I_OnRehash, I_OnUserRegister }; + ServerInstance->Modules->Attach(eventlist, this, 2); + + gi = GeoIP_new(GEOIP_STANDARD); + } + + virtual ~ModuleGeoIP() + { + } + + virtual Version GetVersion() + { + return Version(1, 2, 0, 0, VF_VENDOR, API_VERSION); + } + + virtual void ReadConf() + { + ConfigReader *MyConf = new ConfigReader(ServerInstance); + delete MyConf; + } + + virtual void OnRehash(User* user, const std::string ¶meter) + { + ReadConf(); + } + + virtual int OnUserRegister(User* user) + { + /* only do lookups on local users */ + if (IS_LOCAL(user)) + { + const char* c = GeoIP_country_code_by_addr(gi, user->GetIPString()); + if (c) + { + std::string country(c); + ServerInstance->Logs->Log("m_geoip", DEBUG, "*** Country: %s", country.c_str()); + } + else + { + ServerInstance->Logs->Log("m_geoip", DEBUG, "*** No country for %s!", user->GetIPString()); + } + } + + /* don't do anything with this hot potato */ + return 0; + } +}; + +MODULE_INIT(ModuleGeoIP) + -- cgit v1.2.3