Sha256: b052742d20061abc6f8184fcfe35a8c2ca32f8a84166c03cb96f0f5e64840a9a

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

# Copyright (c) 2015 Sqreen. All Rights Reserved.
# Please refer to our terms for more information: https://www.sqreen.com/terms.html

require 'sqreen/log'
require 'sqreen/exception'
require 'sqreen/actions/base'

module Sqreen
  module Actions
    # Block a list of IP address ranges by forcefully redirecting the user
    # to a specific URL.
    class RedirectIp < Base
      extend IpRangeIndexedActionClass

      self.type_name = 'redirect_ip'

      attr_reader :redirect_url

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

      def do_run(client_ip)
        Sqreen.log.info "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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sqreen-1.18.6-java lib/sqreen/actions/redirect_ip.rb
sqreen-1.18.6 lib/sqreen/actions/redirect_ip.rb
sqreen-1.18.5-java lib/sqreen/actions/redirect_ip.rb
sqreen-1.18.5 lib/sqreen/actions/redirect_ip.rb
sqreen-1.18.4-java lib/sqreen/actions/redirect_ip.rb
sqreen-1.18.4 lib/sqreen/actions/redirect_ip.rb
sqreen-1.18.3-java lib/sqreen/actions/redirect_ip.rb
sqreen-1.18.3 lib/sqreen/actions/redirect_ip.rb
sqreen-1.18.3.beta2 lib/sqreen/actions/redirect_ip.rb