domain_firewall 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cc0eed6d3d5f32869ee888d441f5cd61bdf61bb1
4
+ data.tar.gz: fdebdbc79c32de0fdf09af9fe1655d489588d7c3
5
+ SHA512:
6
+ metadata.gz: 4f7640632cb9071f41dd6fbe2003e4b0e5dc65eb31555aece1142b6179a40fb821605172c313aa3d26b60c9efaff5fc92ea3aadd0632005616f42b8707eaa7ae
7
+ data.tar.gz: 67c531c92527998d5d07533d06b7f2105b7ac3eaa06f69088bd3a82c0da6f28714409a81d0ba0fc548e2ac66fda31ca9d700e56dda21ea61abe70ac4aabf8039
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in domain_white_listing.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'guard'
8
+ gem 'guard-minitest'
9
+ gem 'rack-test'
10
+ gem 'byebug'
11
+ end
@@ -0,0 +1,43 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ guard :minitest do
19
+ # with Minitest::Unit
20
+ watch(%r{^test/(.*)\/?(.*)_test\.rb$})
21
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
22
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
23
+ watch(%r{^.*.rb$}) { 'test' }
24
+
25
+ # with Minitest::Spec
26
+ # watch(%r{^spec/(.*)_spec\.rb$})
27
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
28
+ # watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
29
+
30
+ # Rails 4
31
+ # watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
32
+ # watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
33
+ # watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
34
+ # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
35
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
36
+ # watch(%r{^test/.+_test\.rb$})
37
+ # watch(%r{^test/test_helper\.rb$}) { 'test' }
38
+
39
+ # Rails < 4
40
+ # watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
41
+ # watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
42
+ # watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
43
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Dave Vallance
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # DomainFirewall
2
+
3
+ Rack middleware to allow or prevent access based on an IP Whitelist and a hostname
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'domain_firewall'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install domain_firewall
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ class CustomClass
25
+ def self.whitelist(host)
26
+ host == 'client.myapp.com' ? ['1.1.1.1'] : true
27
+ end
28
+ end
29
+
30
+ config.middleware.use(DomainFirewall::IPWhitelist, delegate: CustomClass)
31
+ ```
32
+
33
+ ## Development
34
+
35
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
36
+
37
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/retailzipline/domain_firewall.
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
46
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "domain_firewall"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'domain_firewall/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "domain_firewall"
8
+ spec.version = DomainFirewall::VERSION
9
+ spec.authors = ["Dave Vallance", "Jeremy Baker"]
10
+ spec.email = ["davevallance@gmail.com", "jhubert@gmail.com"]
11
+
12
+ spec.summary = %q{Rack middleware for whitelisting IP addresses}
13
+ spec.description = %q{Rack middleware for whitelisting IP addresses. Allows you to define a custom whitelist per domain.}
14
+ spec.homepage = "https://github.com/retailzipline/domain_firewall"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest"
25
+ end
@@ -0,0 +1,2 @@
1
+ require "domain_firewall/version"
2
+ require "domain_firewall/ip_whitelist"
@@ -0,0 +1,47 @@
1
+ module DomainFirewall
2
+ IP_RANGE = "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])+"
3
+
4
+ class IPWhitelist
5
+ def initialize(app, delegate:, url: nil)
6
+ @app = app
7
+ @delegate = delegate
8
+ @url = url
9
+ end
10
+
11
+ def call(env)
12
+ req = Rack::Request.new(env)
13
+ uri = URI(req.url)
14
+ white_list = @delegate.whitelist(uri.host)
15
+
16
+ # allow the current request if it is the same as our [url] option.
17
+ return @app.call(env) if @url && @url == req.path
18
+
19
+ matches?(req.ip, white_list) ? @app.call(env) : halt_chain_with_response
20
+ end
21
+
22
+ private
23
+
24
+ def halt_chain_with_response
25
+ response = Rack::Response.new
26
+ if @url
27
+ response.redirect(@url, 303)
28
+ else
29
+ response.status = 403
30
+ response.body = [Rack::Utils::HTTP_STATUS_CODES[403]]
31
+ end
32
+ response.finish
33
+ end
34
+
35
+ def matches?(request_ip, white_list)
36
+ return true if white_list === true
37
+ Array(white_list).any? { |ip| request_ip =~ regexp_for_ip(ip) }
38
+ end
39
+
40
+ # @param ip [String] a string representing an ip. Wildcards (*) are
41
+ # acceptable.
42
+ # @return [Regexp]
43
+ def regexp_for_ip ip
44
+ Regexp.new("\\A#{ip.gsub(".", '\\.').gsub('*', IP_RANGE)}\\z")
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module DomainFirewall
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: domain_firewall
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dave Vallance
8
+ - Jeremy Baker
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-07-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: minitest
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: Rack middleware for whitelisting IP addresses. Allows you to define a
57
+ custom whitelist per domain.
58
+ email:
59
+ - davevallance@gmail.com
60
+ - jhubert@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - Guardfile
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - domain_firewall.gemspec
75
+ - lib/domain_firewall.rb
76
+ - lib/domain_firewall/ip_whitelist.rb
77
+ - lib/domain_firewall/version.rb
78
+ homepage: https://github.com/retailzipline/domain_firewall
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.5
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Rack middleware for whitelisting IP addresses
102
+ test_files: []
103
+ has_rdoc: