summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-03-16 19:57:07 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2008-03-16 19:57:07 +0000
commit56a5ace638d503099accf4e3461c53b154edaa1d (patch)
tree5eca289a074a33cbf32986f75c4bc2675debfd3e /src
parent15ca60210489e61269911c984ac173d6247e74aa (diff)
Start of GeoIP module. This is deceptively simple.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9102 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r--src/modules/extra/m_geoip.cpp79
1 files changed, 79 insertions, 0 deletions
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 <GeoIP.h>
+
+/* $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 &parameter)
+ {
+ 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)
+