Forum: Ruby on Rails Ban ips

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
bogdan.ionescu (Guest)
on 2005-12-06 12:37
(Received via mailing list)
Can someone suggest me a quick solution for banning certain ips from
accessing my pages?
Recently I've got a series of smartasses that think that swearing on
forums
is cool. Banning certain words did not really help, since they can
always
write F/U/C... you the picture

Thanks,
Bogdan
vanek (Guest)
on 2005-12-06 14:07
(Received via mailing list)
if you have access to the router, the best place to intercept a
scoundrel
is on the router's deny list. Login to the router.

if you have access to the http server, the second best thing to do is
add
the ip to the server's deny list.
	http://httpd.apache.org/docs/1.3/mod/mod_access.html

if those methods are unavailable, and you are using rails, you can add
the LoginEngine (http://rails-engines.rubyforge.org/), and then add the
following code,

login_engine.rb:
	DENY_IP = ['some.smart.ass.ip','smart.ass.2.ip']
	# do you require a login?
	LOGIN_REQUIRED = false



authenticated_system.rb:
	def deny( ip )
		DENY_IP.detect { |addr| addr == ip }
	end

     def login_required
	  if deny(@request.env["REMOTE_ADDR"])
		  redirect_to_url "http://www.google.com"
		  return false
	  elsif ! LOGIN_REQUIRED
           	return true
	  end
	  ...

     end


application.rb:
   class ApplicationController < ActionController::Base

     include LoginEngine
     before_filter :login_required

   end


I'm sure there are lots of other ways, too.
ksruby (Guest)
on 2005-12-06 21:53
(Received via mailing list)
If you run Linux, iptables is your friend.

Kent.
This topic is locked and can not be replied to.