Skip to content

Instantly share code, notes, and snippets.

@yseto
Created October 5, 2015 05:02
Show Gist options
  • Save yseto/5c8b68caffa05b66777a to your computer and use it in GitHub Desktop.
Save yseto/5c8b68caffa05b66777a to your computer and use it in GitHub Desktop.
class CountryDeniedViaGeoIP
@@geoip = nil
def call(env)
if @@geoip == nil
@@geoip = GeoIP.new("/usr/share/GeoIP/GeoIPCity.dat")
end
@@geoip.record_by_addr env["REMOTE_ADDR"]
ret = [399, {}, []]
if @@geoip.country_code != "JP"
ret = [403, {'content-type' => 'text/plain'}, [ "forbidden" ]]
end
# geoip.close
return ret
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment