Add protect_from_suspicious_ips method

master
Guillaume DOTT 2013-01-04 14:16:44 +01:00
parent 309ddf48dd
commit 644a6005ca
2 changed files with 29 additions and 0 deletions

View File

@ -1,4 +1,7 @@
require 'project_honeypot'
require "project_honeypot_rails/version"
require "project_honeypot_rails/request_suspicious_ips_protection"
module ProjectHoneypotRails
# Your code goes here...

View File

@ -0,0 +1,26 @@
module ProjectHoneypotRails
module RequestSuspiciousIpsProtection
extend ActiveSupport::Concern
module ClassMethods
def protect_from_suspicious_ips(options = {})
prepend_before_filter :verify_ip_address, options
end
end
protected
def verify_ip_address
session[:project_honeypot_safe] ||= ::ProjectHoneypot.lookup(request.remote_ip).safe?
handle_unverified_request if !session[:project_honeypot_safe]
end
def handle_unverified_request
render :status => :forbidden, :text => "Forbidden fruit"
end
end
end
class ActionController::Base
include ProjectHoneypotRails::RequestSuspiciousIpsProtection
end