rails_hq_ip_whitelist 0.0.2 → 0.0.3
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 +17 -15
- data/lib/ip_whitelist/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 407076a240656e2f204961c375000886f228920b
|
4
|
+
data.tar.gz: a1d63e78384cb7a39f597632983c30869263dadf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24ae2c696e12bc60c63e11088a233ddb0e8c50d8fec24e070ad4362d628418fdc7c4f8ab5297b9b64a52aaef3ad092e6cc288b5dda731ea6bcc3c269d9825fd7
|
7
|
+
data.tar.gz: 504005d4a4fae897aa17f30151be2e630715accb8c02dcc1cb02f2ac6d1f5ebfc947428d0a08291d2cdb0f8b2df930806040ea6b6f1e4abbcf58d1c9b1cabf83
|
@@ -1,19 +1,21 @@
|
|
1
|
-
module IPWhitelist
|
2
|
-
|
3
|
-
|
4
|
-
base
|
5
|
-
|
1
|
+
module IPWhitelist
|
2
|
+
module Controller
|
3
|
+
class IPWhitelistError < StandardError; end
|
4
|
+
def self.included(base)
|
5
|
+
base.before_action :check_ip_whitelist
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
def check_ip_whitelist
|
9
|
+
if current_user && current_user.respond_to?(:ip_whitelist) && current_user.ip_whitelist.present?
|
10
|
+
# Since requests can come through cloudflare, try that IP first.
|
11
|
+
ip = request.headers["CF-Connecting-IP"] || request.headers["REMOTE_ADDR"]
|
12
|
+
return if current_user.ip_whitelist.map(&:to_s).include?(ip)
|
13
|
+
raise IPWhiteListError.new(<<-MESSAGE.squish
|
14
|
+
IP #{ip} is not in the whitelist for user #{current_user.username}.
|
15
|
+
Whitelist: #{current_user.ip_whitelist.map(&:to_s)}
|
16
|
+
MESSAGE
|
17
|
+
)
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
data/lib/ip_whitelist/version.rb
CHANGED