TylerRick / rack_attack_admin

A Rack::Attack admin dashboard
MIT License
7 stars 9 forks source link

New syntax for blocklists doesn't work: undefined method `limit' for #<Rack::Attack::Blocklist:0x000055c369b07340> #3

Open Nowaker opened 4 years ago

Nowaker commented 4 years ago

Original blocklist definition:

Rack::Attack.blocklist('bot_php') do |req|
  Rack::Attack::Allow2Ban.filter(req.ip, maxretry: 5, findtime: 1.minute, bantime: 1.hour) do
    next unless req.path.end_with?('.php') || req.path.include?('wp-admin')
    req.ip
  end

New blocklist definition:

Rack::Attack.blocklist('bot_php') do |req|
  Rack::Attack.def_allow2ban('bot_php', limit: 5, period: 1.minute, bantime: 1.hour)
  Rack::Attack.allow2ban('bot_php', req.ip) do
    next unless req.path.end_with?('.php') || req.path.include?('wp-admin')
    req.ip
  end
end

Result when visiting the admin dashboard:

Showing /home/nowaker/projekty/modern/rack_attack_admin/app/views/rack_attack_admin/rack_attack/index.html.haml where line #80 raised:

undefined method `limit' for #<Rack::Attack::Blocklist:0x000055c369b07340>

Broken HAML line:

      - limit = parsed && (rule = parsed[:rule]) && rule.limit.to_i

It suggests Rack::Attack::Fail2Ban is not InstantiableFail2Ban. Why? No idea.