rails_hq_ip_whitelist 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8486ccbafd8b0e0fa4199540ecfd7d5e8c2bbe28
4
- data.tar.gz: 964eb8c9707489fb2e155ef3649ce7a142ec279d
3
+ metadata.gz: ad1edcc6fc6d4bf7a610f1e57983ceb770f6b783
4
+ data.tar.gz: 2239c99a2a552fbf19243b886e712aaa87e29a1f
5
5
  SHA512:
6
- metadata.gz: 77be7c860f617a7d0b38f926b479f4a603be0bd2b5ce0e592cae843158d15b820ed85d7d4407cf8ebd2389adda7fe8ddbfa7ad601b4d5bffa26750463eee9404
7
- data.tar.gz: 01374c7f940f26bd6450ed948ac36c0041e2b4f5542e8ce4469027621882528f14bb51b1df63baa29a396c4ec2e1734f73b4675031b431aa8cb6c81ac2dcf48c
6
+ metadata.gz: 208d3729063a0c1bbc8ce78d48d31fd4a8cbaa911d7c11191acb41a3a7548138352a3ebc499549053e4a6f3e66f6b4f89f7cd8954f864a1dc7e16512d4eb4d5f
7
+ data.tar.gz: 8b0157cc41c8ae3a2b55a792fbe3ed7457c505479416a893da5616ba7ccc852458939db894af17bd297aacdd723762de0e266c3873def2b69016b03e0a919816
@@ -3,9 +3,19 @@ module IPWhitelist
3
3
  def check_ip_whitelist
4
4
  if current_user && current_user.respond_to?(:ip_whitelist) && current_user.ip_whitelist.present?
5
5
  # Since requests can come through cloudflare, try that IP first.
6
- ip = request.headers["CF-Connecting-IP"] || request.headers["REMOTE_ADDR"]
7
- return if current_user.ip_whitelist.map(&:to_s).include?(ip)
8
- render text: "Not Authorized", status: 401
6
+ ip = IPAddr.new(request.headers["CF-Connecting-IP"] || request.headers["REMOTE_ADDR"])
7
+
8
+ return if current_user.ip_whitelist.detect{ |ip_or_range|
9
+ # Check if the IP is equal to the whitelisted IP, or is within the
10
+ # whitelisted IP range.
11
+ (ip_or_range.is_a?(IPAddr) ? ip_or_range : IPAddr.new(ip_or_range)) === ip
12
+ }
13
+
14
+ if redirect = IPWhitelist.configuration.redirect
15
+ redirect_to redirect
16
+ else
17
+ render text: "Not Authorized", status: 401
18
+ end
9
19
  end
10
20
  end
11
21
  end
@@ -1,3 +1,3 @@
1
1
  module IPWhitelist
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -1,4 +1,17 @@
1
1
  require "ip_whitelist/controller"
2
- module RailsHQIPList
2
+ module IPWhitelist
3
+ Configuration = Struct.new(:redirect)
4
+
5
+ class << self
6
+ attr_writer :configuration
7
+ end
8
+
9
+ def self.configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+
13
+ def self.configure
14
+ yield(configuration)
15
+ end
3
16
 
4
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_hq_ip_whitelist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendan Carney
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-09 00:00:00.000000000 Z
11
+ date: 2017-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails