1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
19 /* $ModDesc: Provides a way to restrict users by country using GeoIP lookup */
20 /* $LinkerFlags: -lGeoIP */
22 class ModuleGeoIP : public Module
28 std::map<std::string, std::string> GeoBans;
32 ModuleGeoIP(InspIRCd *Me) : Module(Me)
35 Implementation eventlist[] = { I_OnRehash, I_OnUserRegister };
36 ServerInstance->Modules->Attach(eventlist, this, 2);
38 gi = GeoIP_new(GEOIP_STANDARD);
41 virtual ~ModuleGeoIP()
45 virtual Version GetVersion()
47 return Version(1, 2, 0, 0, VF_VENDOR, API_VERSION);
50 virtual void OnRehash(User* user, const std::string ¶meter)
54 ConfigReader conf(ServerInstance);
56 banunknown = conf.ReadFlag("geoip", "banunknown", 0);
58 for (int i = 0; i < conf.Enumerate("geoban"); ++i)
60 std::string countrycode = conf.ReadValue("geoban", "country", i);
61 std::string reason = conf.ReadValue("geoban", "reason", i);
62 GeoBans[countrycode] = reason;
66 virtual int OnUserRegister(User* user)
68 /* only do lookups on local users */
71 const char* c = GeoIP_country_code_by_addr(gi, user->GetIPString());
74 std::map<std::string, std::string>::iterator x = GeoBans.find(c);
75 if (x != GeoBans.end())
76 User::QuitUser(ServerInstance, user, x->second);
81 User::QuitUser(ServerInstance, user, "Could not identify your country of origin. Access denied.");
88 MODULE_INIT(ModuleGeoIP)