Detect and ban spammers with stopforumspam.com
Add this line to your application's Gemfile:
gem 'stop_spam'
And then execute:
$ bundle
Or install it yourself as:
$ gem install stop_spam
It automatically integrates with Rails and renders the ban message for suspicious IP addresses.
But you need manually call StopSpam.process(ip)
to perform an IP address check.
unless @user = User.authenticate(params[:user])
StopSpam.process(request.ip) # possible brute-force attack
end
Sample configuration:
StopSpam.configure do |config|
config.active = Rails.env.production?
config.minimum_confidence = 1
config.whitelist = [
# ...
]
end
Enable or disable StopSpam.
StopSpam.configure do |config|
config.active = Rails.env.production?
end
Default is 86400 seconds (1 day).
StopSpam.configure do |config|
config.ban_time = 6.hours
end
Default is "StopSpam: your IP address is banned". Supports proc as well.
StopSpam.configure do |config|
config.ban_message = proc do |request|
"IP #{request.ip} is banned"
end
end
Sets the minimum confidence is greater than IP will be banned.
StopSpam.configure do |config|
config.minimum_confidence = 1
end
Sets the redis namespace.
StopSpam.configure do |config|
config.namespace = "stop:spam"
end
IP addresses that never will banned.
StopSpam.configure do |config|
config.whitelist = %w[
192.168.1.1
127.0.0.1
]
end
- Fork it ( https://github.com/dimko/stop_spam/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request