Skip to content
Browse files

Added support for GeoLiteCity DB, in place of Country DB.

Added types "city" & "region"
  • Loading branch information...
1 parent 51379d9 commit 638865f90d5312f0e31889556554efd40f82bf7b William Hetherington committed Sep 2, 2011
Showing with 68 additions and 7 deletions.
  1. +2 −2 conf/Application.xml
  2. +4 −0 conf/example-locationinfo.xml
  3. +21 −0 src/GeoIP.java
  4. +41 −5 src/GeoIPLookupService.java
View
4 conf/Application.xml
@@ -84,11 +84,11 @@
-->
- <!-- GeoIPDatabase: default location: /usr/share/GeoIP/GeoIP.dat
+ <!-- GeoIPDatabase: default location: /usr/share/GeoIP/GeoLiteCity.dat
<Property>
<Name>GeoIPDatabase</Name>
- <Value>/path/to/your/GeoIP.dat</Value>
+ <Value>/path/to/your/GeoLiteCity.dat</Value>
<Type>String</Type>
</Property>
View
4 conf/example-locationinfo.xml
@@ -12,6 +12,10 @@
<Except type="ip">192.168.0.0/255.255.0.0</Except>
<!-- Except: country = http://www.maxmind.com/app/iso3166 -->
<Except type="country">SI</Except>
+ <!-- Except: city = http://www.maxmind.com/GeoIPCity-534-Location.csv -->
+ <Except type="city">CA,BC,Coquitlam</Except>
+ <!-- Except: region = http://www.maxmind.com/regionSample.csv -->
+ <Except type="region">CA,BC</Except>
</Location>
<!-- type="regex" for regular expression paths -->
<Location path="(usa|austria|germany)/" type="regex" restrict="all">
View
21 src/GeoIP.java
@@ -3,6 +3,8 @@
Tit Petric, Monotek d.o.o., (cc) 2010, tit.petric@monotek.net
http://creativecommons.org/licenses/by-sa/3.0/
+Updated by: William Hetherington, NetroMedia, will@netromedia.com
+
*/
package com.monotek.wms.module;
@@ -149,6 +151,25 @@ public boolean allowPlayback(String streamName, String IPAddress)
break;
}
}
+ else if (exceptType.equals("region")) {
+ String countryName = exceptValue.split(",")[0];
+ String regionName = exceptValue.split(",")[1];
+ if (geoip_lookup.ValidateRegion(IPAddress, countryName, regionName)) {
+ logDebug(" > Validated region ("+exceptValue+")");
+ allowPlayback = true;
+ break;
+ }
+ }
+ else if (exceptType.equals("city")) {
+ String countryName = exceptValue.split(",")[0];
+ String regionName = exceptValue.split(",")[1];
+ String cityName = exceptValue.split(",")[2];
+ if (geoip_lookup.ValidateCity(IPAddress, countryName, regionName, cityName)) {
+ logDebug(" > Validated region ("+exceptValue+")");
+ allowPlayback = true;
+ break;
+ }
+ }
}
// reverse restrictions
if (locRestrict.equals("none")) {
View
46 src/GeoIPLookupService.java
@@ -3,9 +3,11 @@
Tit Petric, Monotek d.o.o., (cc) 2010, tit.petric@monotek.net
http://creativecommons.org/licenses/by-sa/3.0/
+Updated by: William Hetherington, NetroMedia, will@netromedia.com
+
*/
-package com.monotek.wms.module;
+package com.monotek.wms.module;
import com.maxmind.geoip.*;
@@ -34,14 +36,48 @@ public boolean GetStatus()
}
/** Validate Country code against IPAdress's country code */
- public boolean ValidateCountry(String IPAddress, String CountryCode)
+ public boolean ValidateCountry(String IPAddress, String CountryName)
+ {
+ String IPCountryName = "--";
+ try {
+ //IPCountryCode = myLookupService.getCountry(IPAddress).getCode();
+ Location myLocation = myLookupService.getLocation(IPAddress);
+ IPCountryName = myLocation.countryCode;
+ } catch (Exception e) {
+ return false;
+ }
+ return IPCountryName.equals(CountryName);
+ }
+
+ /** Validate Country & Region code */
+ public boolean ValidateRegion(String IPAddress, String CountryName, String RegionName)
+ {
+ String IPCountryName = "";
+ String IPRegionName = "";
+ try {
+ Location myLocation = myLookupService.getLocation(IPAddress);
+ IPCountryName = myLocation.countryCode;
+ IPRegionName = myLocation.region;
+ } catch (Exception e) {
+ return false;
+ }
+ return IPCountryName.equals(CountryName) && IPRegionName.equals(RegionName);
+ }
+
+ /** Validate a city */
+ public boolean ValidateCity(String IPAddress, String CountryName, String RegionName, String CityName)
{
- String IPCountryCode = "--";
+ String IPCountryName = "";
+ String IPRegionName = "";
+ String IPCityName = "";
try {
- IPCountryCode = myLookupService.getCountry(IPAddress).getCode();
+ Location myLocation = myLookupService.getLocation(IPAddress);
+ IPCountryName = myLocation.countryCode;
+ IPRegionName = myLocation.region;
+ IPCityName = myLocation.city;
} catch (Exception e) {
return false;
}
- return IPCountryCode.equals(CountryCode);
+ return IPCountryName.equals(CountryName) && IPRegionName.equals(RegionName) && IPCityName.equals(CityName);
}
}

0 comments on commit 638865f

Please sign in to comment.
Something went wrong with that request. Please try again.