rails_hq_ip_whitelist 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ip_whitelist/controller.rb +13 -3
- data/lib/ip_whitelist/version.rb +1 -1
- data/lib/rails_hq_ip_whitelist.rb +14 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad1edcc6fc6d4bf7a610f1e57983ceb770f6b783
|
4
|
+
data.tar.gz: 2239c99a2a552fbf19243b886e712aaa87e29a1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
8
|
-
|
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
|
data/lib/ip_whitelist/version.rb
CHANGED
@@ -1,4 +1,17 @@
|
|
1
1
|
require "ip_whitelist/controller"
|
2
|
-
module
|
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.
|
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-
|
11
|
+
date: 2017-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|