Created
July 2, 2012 12:08
-
-
Save cgallagher/3032940 to your computer and use it in GitHub Desktop.
Rack Middleware to block IP addresses to active_admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RestrictAddresses | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = Rack::Request.new(env) | |
incoming_ip_address = request.env['REMOTE_ADDR'] | |
allowed_range = ['127.0.0.1'] | |
if request.fullpath.include?("/admin") and !(allowed_range).include?(incoming_ip_address) | |
[301, {"Location" => "http://www.betapond.com"}, self] | |
else | |
@app.call(env) | |
end | |
end | |
def each(&block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment