Sha256: 3edd9b02e27138c5cfbcf71d0430c1ce8f155c4ec768f328cce8cb28bda9cc36

Contents?: true

Size: 1.1 KB

Versions: 11

Compression:

Stored size: 1.1 KB

Contents

# typed: true

# 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.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

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sqreen-1.22.0-java lib/sqreen/actions/redirect_ip.rb
sqreen-1.22.0 lib/sqreen/actions/redirect_ip.rb
sqreen-1.21.1-java lib/sqreen/actions/redirect_ip.rb
sqreen-1.21.1 lib/sqreen/actions/redirect_ip.rb
sqreen-1.21.0-java lib/sqreen/actions/redirect_ip.rb
sqreen-1.21.0 lib/sqreen/actions/redirect_ip.rb
sqreen-1.20.4-java lib/sqreen/actions/redirect_ip.rb
sqreen-1.20.4 lib/sqreen/actions/redirect_ip.rb
sqreen-1.21.0.beta3-java lib/sqreen/actions/redirect_ip.rb
sqreen-1.21.0.beta3 lib/sqreen/actions/redirect_ip.rb
sqreen-1.20.4.beta1 lib/sqreen/actions/redirect_ip.rb