Module: BotAway

Defined in:
lib/bot-away.rb,
lib/bot-away/version.rb,
lib/bot-away/middleware.rb,
lib/bot-away/param_parser.rb

Defined Under Namespace

Modules: TestCase, Version Classes: Middleware, ParamParser, Railtie, Spinner

Constant Summary collapse

VERSION =
BotAway::Version::STRING

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dump_paramsObject

Returns the value of attribute dump_params.



15
16
17
# File 'lib/bot-away.rb', line 15

def dump_params
  @dump_params
end

.obfuscate_honeypot_warning_messages=(value) ⇒ Object (writeonly)

Sets the attribute obfuscate_honeypot_warning_messages

Parameters:

  • value

    the value to set the attribute obfuscate_honeypot_warning_messages to.



16
17
18
# File 'lib/bot-away.rb', line 16

def obfuscate_honeypot_warning_messages=(value)
  @obfuscate_honeypot_warning_messages = value
end

.show_honeypotsObject

Returns the value of attribute show_honeypots.



15
16
17
# File 'lib/bot-away.rb', line 15

def show_honeypots
  @show_honeypots
end

Class Method Details

.disabled_for(options = {}) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/bot-away.rb', line 83

def disabled_for(options = {})
  @disabled_for ||= []
  if !options.empty?
    @disabled_for << options.stringify_keys
  end
  @disabled_for
end

.disabled_for?(options) ⇒ Boolean

Returns true if the given options match the options set via #disabled_for, or if the Rails run mode matches any run modes set via #disabled_for.

Returns:

  • (Boolean)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bot-away.rb', line 60

def disabled_for?(options)
  return false if @disabled_for.nil? || options.empty?
  options = options.stringify_keys
  @disabled_for.each do |set|
    if set.key?('mode')
      next unless ENV['RAILS_ENV'] == set['mode'].to_s
      return true if set.keys.length == 1
      # if there are more keys, then it looks something like:
      #   disabled_for :mode => 'development', :controller => 'tests'
      # and that means we need to check the next few conditions.
    end
    
    if set.key?('controller') && set.key?('action')
      return true if set['controller'] == options['controller'] && set['action'] == options['action']
    elsif set.key?('controller') && !set.key?('action')
      return true if set['controller'] == options['controller']
    elsif set.key?('action')
      return true if set['action'] == options['action']
    end
  end
  false
end

.excluded?(options) ⇒ Boolean

options include:

:controller
:action
:object_name
:method_name

excluded? will also check the current Rails run mode against disabled_for

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
# File 'lib/bot-away.rb', line 37

def excluded?(options)
  options = options.stringify_keys
  nonparams = options.stringify_keys
  nonparams.delete 'object_name'
  nonparams.delete 'method_name'
  (options['object_name'] && options['method_name'] &&
          unfiltered_params_include?(options['object_name'], options['method_name'])) || disabled_for?(nonparams)
end

.obfuscate_honeypot_warning_messages?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/bot-away.rb', line 18

def obfuscate_honeypot_warning_messages?
  !!@obfuscate_honeypot_warning_messages
end

.reset!Object



91
92
93
94
95
96
97
# File 'lib/bot-away.rb', line 91

def reset!
  self.show_honeypots = false
  self.dump_params = false
  self.obfuscate_honeypot_warning_messages = true
  self.unfiltered_params.clear
  self.disabled_for.clear
end

.unfiltered_params(*keys) ⇒ Object Also known as: accepts_unfiltered_params



22
23
24
25
26
# File 'lib/bot-away.rb', line 22

def unfiltered_params(*keys)
  unfiltered_params = instance_variable_get("@unfiltered_params") || instance_variable_set("@unfiltered_params", [])
  unfiltered_params.concat keys.flatten.collect { |k| k.to_s }
  unfiltered_params
end

.unfiltered_params_include?(object_name, method_name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/bot-away.rb', line 46

def unfiltered_params_include?(object_name, method_name)
  unfiltered_params.collect! { |u| u.to_s }
  if (object_name &&
          (unfiltered_params.include?(object_name.to_s) ||
                  unfiltered_params.include?("#{object_name}[#{method_name}]")) ||
      unfiltered_params.include?(method_name.to_s))
    true
  else
    false
  end
end