require 'ipaddr' module Rack class Restrictor PAGE_CODE = <<-EOCODE Anauthorized access

Anauthorized access

EOCODE def initialize(app, plage) @app = app @plage = IPAddr.new( plage.to_s ) p @plage end def call(env) if authorized?( env['REMOTE_ADDR'].to_s ) status, headers, body = @app.call(env) else status, headers, body = 401, {"Content-Type" => "text/html"}, PAGE_CODE end [status, headers, body] end private def authorized?( ip ) @plage.include?(IPAddr.new( ip )) end end end