1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/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;
34 Implementation eventlist[] = { I_OnRehash, I_OnUserRegister };
35 ServerInstance->Modules->Attach(eventlist, this, 2);
37 gi = GeoIP_new(GEOIP_STANDARD);
40 virtual ~ModuleGeoIP()
44 virtual Version GetVersion()
46 return Version("Provides a way to restrict users by country using GeoIP lookup", VF_VENDOR);
49 virtual void OnRehash(User* user)
55 banunknown = conf.ReadFlag("geoip", "banunknown", 0);
57 for (int i = 0; i < conf.Enumerate("geoban"); ++i)
59 std::string countrycode = conf.ReadValue("geoban", "country", i);
60 std::string reason = conf.ReadValue("geoban", "reason", i);
61 GeoBans[countrycode] = reason;
65 virtual ModResult OnUserRegister(User* user)
67 /* only do lookups on local users */
70 const char* c = GeoIP_country_code_by_addr(gi, user->GetIPString());
73 std::map<std::string, std::string>::iterator x = GeoBans.find(c);
74 if (x != GeoBans.end())
75 ServerInstance->Users->QuitUser(user, x->second);
80 ServerInstance->Users->QuitUser(user, "Could not identify your country of origin. Access denied.");
83 return MOD_RES_PASSTHRU;
87 MODULE_INIT(ModuleGeoIP)