2013-01-02 15:49:27 +01:00
|
|
|
module ProjectHoneypot::Rack
|
|
|
|
class Forbidden
|
2012-12-21 16:13:03 +01:00
|
|
|
def initialize(app, options={})
|
|
|
|
@app = app
|
|
|
|
|
|
|
|
raise ArgumentError, 'Must specify an API key' unless options[:api_key]
|
|
|
|
ProjectHoneypot.api_key = options[:api_key]
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
request = ::Rack::Request.new(env)
|
|
|
|
url = ProjectHoneypot.lookup(request.ip)
|
|
|
|
|
2013-01-02 15:49:27 +01:00
|
|
|
if url.safe?
|
|
|
|
@app.call(request.env)
|
|
|
|
else
|
|
|
|
[403, {"Content-Type" => "text/html"}, ["Forbidden"]]
|
|
|
|
end
|
2012-12-21 16:13:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|