Class: Rack::Attack::Fail2Ban
- Inherits:
-
Object
- Object
- Rack::Attack::Fail2Ban
- Defined in:
- lib/rack/attack/fail2ban.rb
Direct Known Subclasses
Class Method Summary collapse
- .banned?(discriminator) ⇒ Boolean
- .filter(discriminator, options) ⇒ Object
- .reset(discriminator, options) ⇒ Object
Class Method Details
.banned?(discriminator) ⇒ 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, ) bantime = [:bantime] or raise ArgumentError, "Must pass bantime option" findtime = [:findtime] or raise ArgumentError, "Must pass findtime option" maxretry = [: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, ) findtime = [: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 |