From 644a6005ca3e35a82954104170a8bddc7150697d Mon Sep 17 00:00:00 2001 From: Guillaume DOTT Date: Fri, 4 Jan 2013 14:16:44 +0100 Subject: [PATCH] Add protect_from_suspicious_ips method --- lib/project_honeypot_rails.rb | 3 +++ .../request_suspicious_ips_protection.rb | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 lib/project_honeypot_rails/request_suspicious_ips_protection.rb diff --git a/lib/project_honeypot_rails.rb b/lib/project_honeypot_rails.rb index addd694..638c2ce 100644 --- a/lib/project_honeypot_rails.rb +++ b/lib/project_honeypot_rails.rb @@ -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... diff --git a/lib/project_honeypot_rails/request_suspicious_ips_protection.rb b/lib/project_honeypot_rails/request_suspicious_ips_protection.rb new file mode 100644 index 0000000..17e8d83 --- /dev/null +++ b/lib/project_honeypot_rails/request_suspicious_ips_protection.rb @@ -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