Add protect_from_suspicious_ips method
parent
309ddf48dd
commit
644a6005ca
|
@ -1,4 +1,7 @@
|
||||||
|
require 'project_honeypot'
|
||||||
|
|
||||||
require "project_honeypot_rails/version"
|
require "project_honeypot_rails/version"
|
||||||
|
require "project_honeypot_rails/request_suspicious_ips_protection"
|
||||||
|
|
||||||
module ProjectHoneypotRails
|
module ProjectHoneypotRails
|
||||||
# Your code goes here...
|
# Your code goes here...
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue