Class: Rack::Attack::Fail2Ban

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/attack/fail2ban.rb

Direct Known Subclasses

Allow2Ban

Class Method Summary collapse

Class Method Details

.banned?(discriminator) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rack/attack/fail2ban.rb', line 27

def banned?(discriminator)
  cache.read("#{key_prefix}:ban:#{discriminator}") ? true : false
end

.filter(discriminator, options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rack/attack/fail2ban.rb', line 7

def filter(discriminator, options)
  bantime   = options[:bantime]   or raise ArgumentError, "Must pass bantime option"
  findtime  = options[:findtime]  or raise ArgumentError, "Must pass findtime option"
  maxretry  = options[:maxretry]  or raise ArgumentError, "Must pass maxretry option"

  if banned?(discriminator)
    # Return true for blocklist
    true
  elsif yield
    fail!(discriminator, bantime, findtime, maxretry)
  end
end

.reset(discriminator, options) ⇒ Object



20
21
22
23
24
25
# File 'lib/rack/attack/fail2ban.rb', line 20

def reset(discriminator, options)
  findtime = options[:findtime] or raise ArgumentError, "Must pass findtime option"
  cache.reset_count("#{key_prefix}:count:#{discriminator}", findtime)
  # Clear ban flag just in case it's there
  cache.delete("#{key_prefix}:ban:#{discriminator}")
end