Giter VIP home page Giter VIP logo

proxy-blocker's Introduction

This is a library for blocking arbitrary IP addresses on arbitary controller actions.

The ProxyBlocker gem provides a method in ActionController that by the default is included in a before_filter on all requests.

The list of IPs can either be passed in a text file, or if you prefer to include it in some other format (XML,JSON, or YAML), feel free to include your own function that returns an array of IP addresses as part of the object.

Right now, we use Redis to store the IP addresses in memory, so on every request Redis is queried to see if the IP Address is listed in the list of queries.

If you don't have plans on using Redis in your stack, right now we also support (but discourage) using memory to store the array of IPs.

The gem can be configured as follows:

ProxyBlocker.congure do |config| config.block_behavior = lambda { raise Exception |} config.redis = Redis.connect("redis://blahblah.com:6739") config.list = "#{Rails.root}/config/blocked_ips.txt" end

Alternatively, you can call it without the list as a text file as follows:

ProxyBlocker.configure do |config| config.block_behavior = lambda {raise Exception } config.list_aggregator = lambda { JSON.parse("#{Rails.root}/config/blocked_ips.json")["data"]} end

The default block_behavior is raise Exception to cause a 404. If no redis is provided, we store the list in memory,and if no list is provided, we look for "#{Rails.root}"/config/blocked_ips.txt" for a list of IPs. If you would just like to use these defaults, feel free to simply call ProxyBlocker.setup!

After this configuration is done, simply use the block_ips method in the before_filter of any controller action as follows:

class PublicController < ActionController before_filter :block_ips

def home ... end

... end

If you would like this filter to be called on all actions, you can include this in the configuration as follows:

ProxyBlocker.configure do |config| config.use_on_all_controllers = true end

Thank you for using this gem!

proxy-blocker's People

Contributors

squidarth avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.