Class: Sqreen::Actions::RedirectIp

Inherits:
Base
  • Object
show all
Extended by:
IpRangeIndexedActionClass
Defined in:
lib/sqreen/actions/redirect_ip.rb

Overview

Block a list of IP address ranges by forcefully redirecting the user to a specific URL.

Instance Attribute Summary collapse

Attributes inherited from Base

#expiry, #id, #send_response

Instance Method Summary collapse

Methods included from IpRangeIndexedActionClass

new_index

Methods inherited from Base

get_type_class, inherited, known_subclasses, known_types, new_index, #run

Constructor Details

#initialize(id, opts, params = {}) ⇒ RedirectIp

Returns a new instance of RedirectIp.



21
22
23
24
25
# File 'lib/sqreen/actions/redirect_ip.rb', line 21

def initialize(id, opts, params = {})
  super(id, opts)
  @redirect_url = params['url']
  raise "no url provided for action #{id}" unless @redirect_url
end

Instance Attribute Details

#redirect_urlObject (readonly)

Returns the value of attribute redirect_url.



19
20
21
# File 'lib/sqreen/actions/redirect_ip.rb', line 19

def redirect_url
  @redirect_url
end

Instance Method Details

#do_run(client_ip) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/sqreen/actions/redirect_ip.rb', line 27

def do_run(client_ip)
  Sqreen.log.debug "Will request redirect for client with IP #{client_ip} " \
    "(action: #{id})."
  {
    :status => :skip,
    :new_return_value => [303, { 'Location' => @redirect_url }, ['']],
    :skip_rem_cbs => true,
  }
end

#event_properties(client_ip) ⇒ Object



37
38
39
# File 'lib/sqreen/actions/redirect_ip.rb', line 37

def event_properties(client_ip)
  { 'ip_address' => client_ip, 'url' => @redirect_url }
end