diff --git a/lib/project-honeypot.rb b/lib/project-honeypot.rb index 7cf376b..971f376 100644 --- a/lib/project-honeypot.rb +++ b/lib/project-honeypot.rb @@ -1,6 +1,7 @@ require 'net/dns' -require File.dirname(__FILE__) + "/project_honeypot/url.rb" -require File.dirname(__FILE__) + "/project_honeypot/base.rb" +require "project_honeypot/url" +require "project_honeypot/base" +require "project_honeypot/rack" module ProjectHoneypot class << self diff --git a/lib/project_honeypot/rack.rb b/lib/project_honeypot/rack.rb new file mode 100644 index 0000000..ee002c4 --- /dev/null +++ b/lib/project_honeypot/rack.rb @@ -0,0 +1,19 @@ +module ProjectHoneypot + class Rack + 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) + + env['PROJECT_HONEYPOT_SAFE'] = url.safe? + + @app.call(request.env) + end + end +end