]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_geoip.cpp
Move configuration examples to docs, remove automatic overwrite on make install
[user/henk/code/inspircd.git] / src / modules / extra / m_geoip.cpp
index 57a08ed8497acdabb3563c9cb1034d3c60a5ed2c..4632da22b41c53a47bb01f074df755b232f9a750 100644 (file)
@@ -2,8 +2,8 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
+ * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
  *            the file COPYING for details.
@@ -23,10 +23,14 @@ class ModuleGeoIP : public Module
 {
        GeoIP * gi;
 
+       bool banunknown;
+
+       std::map<std::string, std::string> GeoBans;
+
+
  public:
-       ModuleGeoIP(InspIRCd *Me) : Module(Me)
-       {
-               ReadConf();
+       ModuleGeoIP()   {
+               OnRehash(NULL);
                Implementation eventlist[] = { I_OnRehash, I_OnUserRegister };
                ServerInstance->Modules->Attach(eventlist, this, 2);
 
@@ -39,39 +43,40 @@ class ModuleGeoIP : public Module
 
        virtual Version GetVersion()
        {
-               return Version(1, 2, 0, 0, VF_VENDOR, API_VERSION);
+               return Version("Provides a way to restrict users by country using GeoIP lookup", VF_VENDOR);
        }
 
-       virtual void ReadConf()
+       virtual void OnRehash(User* user)
        {
-               ConfigReader *MyConf = new ConfigReader(ServerInstance);
-               delete MyConf;
-       }
+               GeoBans.clear();
 
-       virtual void OnRehash(User* user, const std::string &parameter)
-       {
-               ReadConf();
+               ConfigReader conf;
+
+               banunknown = conf.ReadFlag("geoip", "banunknown", 0);
+
+               for (int i = 0; i < conf.Enumerate("geoban"); ++i)
+               {
+                       std::string countrycode = conf.ReadValue("geoban", "country", i);
+                       std::string reason = conf.ReadValue("geoban", "reason", i);
+                       GeoBans[countrycode] = reason;
+               }
        }
 
-       virtual int OnUserRegister(User* user)
+       virtual ModResult OnUserRegister(LocalUser* user)
        {
-               /* only do lookups on local users */
-               if (IS_LOCAL(user))
+               const char* c = GeoIP_country_code_by_addr(gi, user->GetIPString());
+               if (c)
                {
-                       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());
-                       }
+                       std::map<std::string, std::string>::iterator x = GeoBans.find(c);
+                       if (x != GeoBans.end())
+                               ServerInstance->Users->QuitUser(user,  x->second);
                }
-
-               /* don't do anything with this hot potato */
-               return 0;
+               else
+               {
+                       if (banunknown)
+                               ServerInstance->Users->QuitUser(user, "Could not identify your country of origin. Access denied.");
+               }
+               return MOD_RES_PASSTHRU;
        }
 };