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