Add rack middleware
parent
d6820f3527
commit
5a4ca4d44a
|
@ -1,6 +1,7 @@
|
||||||
require 'net/dns'
|
require 'net/dns'
|
||||||
require File.dirname(__FILE__) + "/project_honeypot/url.rb"
|
require "project_honeypot/url"
|
||||||
require File.dirname(__FILE__) + "/project_honeypot/base.rb"
|
require "project_honeypot/base"
|
||||||
|
require "project_honeypot/rack"
|
||||||
|
|
||||||
module ProjectHoneypot
|
module ProjectHoneypot
|
||||||
class << self
|
class << self
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue