Very simple firewall
Add this line to your application's Gemfile:
gem 'firewall'
And then execute:
$ bundle
Or install it yourself as:
$ gem install firewall
- Create a firewall instance
fw = Firewall::Firewall.new(false) # reject by default
- Add some rules
r = Firewall::Rule.new("192.168.1.0/24", true) # allow network
fw.add_rule(r)
- Let's check
fw.allowed?("192.168.1.15") # true
fw.allowed?("127.0.0.1") # false
Lets assume you have an object that can do some checks
class Deletest
def complex_check
true
end
end
delegate = Deletest.new
fw = Firewall::Firewall.new(false)
r = Firewall::ComplexRule.new("192.168.1.1", true, {delegate: delegate, method: :complex_check})
fw.add_rule(r)
fw.allowed?("192.168.1.1", true) # true
fw.allowed?("192.168.1.1", false) # false
or
fw = Firewall::Firewall.new(false)
r = Firewall::ComplexRule.new("192.168.1.1", true, {value: true})
fw.add_rule(r)
fw.allowed?("192.168.1.1", true) # true
fw.allowed?("192.168.1.1", false) # false
- Fork it ( https://github.com/davidterranova/firewall/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