Class: Rack::Attack::Fail2Ban

Inherits:
Object
  • Object
show all
Includes:
InstantiableFail2Ban
Defined in:
lib/rack/attack_extensions.rb

Constant Summary

Constants included from InstantiableFail2Ban

InstantiableFail2Ban::MANDATORY_OPTIONS

Instance Attribute Summary

Attributes included from InstantiableFail2Ban

#bantime, #limit, #name, #period, #type

Class Method Summary collapse

Methods included from InstantiableFail2Ban

#initialize, #options

Methods included from InspectWithOptions

#inspect_with_options, #options

Methods included from PeriodIntrospection

#time_range

Class Method Details

.banned_ip_keysObject



251
252
253
# File 'lib/rack/attack_extensions.rb', line 251

def banned_ip_keys
  keys.grep(/(allow|fail)2ban:ban:/)
end

.full_key_prefixObject



255
256
257
# File 'lib/rack/attack_extensions.rb', line 255

def full_key_prefix
  "#{cache.prefix}:#{key_prefix}"
end

.keysObject

AKA unprefixed_keys Removes the Rack::Attack.cache.prefix, but not ‘allow2ban’



239
240
241
242
243
# File 'lib/rack/attack_extensions.rb', line 239

def keys
  prefixed_keys.map { |key|
    Rack::Attack.unprefix_key(key)
  }
end

.prefixed_keysObject



233
234
235
# File 'lib/rack/attack_extensions.rb', line 233

def prefixed_keys
  cache.store.keys.grep(/^#{cache.prefix}:(allow|fail)2ban:/)
end

.to_hObject



245
246
247
248
249
# File 'lib/rack/attack_extensions.rb', line 245

def to_h
  keys.each_with_object({}) do |k, h|
    h[k] = cache.store.read(k)
  end
end