securenative 0.1.24 → 0.1.30
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/Gemfile.lock +2 -2
- data/README.md +44 -30
- data/lib/securenative.rb +49 -0
- data/lib/securenative/api_manager.rb +10 -17
- data/lib/securenative/client.rb +75 -0
- data/lib/securenative/{models/client_token.rb → client_token.rb} +0 -0
- data/lib/securenative/config/configuration_builder.rb +22 -22
- data/lib/securenative/config/configuration_manager.rb +42 -43
- data/lib/securenative/context.rb +65 -0
- data/lib/securenative/{models/device.rb → device.rb} +0 -0
- data/lib/securenative/enums/api_route.rb +5 -3
- data/lib/securenative/enums/risk_level.rb +7 -5
- data/{out/production/securenative-ruby/errors/securenative_config_error.rb → lib/securenative/errors/config_error.rb} +0 -0
- data/{out/production/securenative-ruby/errors/securenative_http_error.rb → lib/securenative/errors/http_error.rb} +0 -0
- data/{out/production/securenative-ruby/errors/securenative_invalid_options_error.rb → lib/securenative/errors/invalid_options_error.rb} +0 -0
- data/lib/securenative/errors/{securenative_invalid_uri_error.rb → invalid_uri_error.rb} +0 -0
- data/lib/securenative/errors/{securenative_parse_error.rb → parse_error.rb} +0 -2
- data/{out/production/securenative-ruby/errors/securenative_sdk_Illegal_state_error.rb → lib/securenative/errors/sdk_Illegal_state_error.rb} +0 -0
- data/{out/production/securenative-ruby/errors/securenative_sdk_error.rb → lib/securenative/errors/sdk_error.rb} +0 -0
- data/lib/securenative/event_manager.rb +125 -128
- data/lib/securenative/{models/event_options.rb → event_options.rb} +3 -7
- data/lib/securenative/{enums/event_types.rb → event_types.rb} +0 -0
- data/lib/securenative/{enums/failover_strategy.rb → failover_strategy.rb} +0 -0
- data/lib/securenative/frameworks/hanami.rb +46 -0
- data/lib/securenative/frameworks/rails.rb +48 -0
- data/lib/securenative/frameworks/sinatra.rb +46 -0
- data/lib/securenative/{http/securenative_http_client.rb → http_client.rb} +7 -12
- data/lib/securenative/{http/secure_native_http_response.rb → http_response.rb} +1 -1
- data/lib/securenative/{config/securenative_options.rb → options.rb} +1 -3
- data/lib/securenative/{models/request_context.rb → request_context.rb} +0 -0
- data/lib/securenative/{models/request_options.rb → request_options.rb} +0 -0
- data/lib/securenative/{models/sdk_event.rb → sdk_event.rb} +4 -11
- data/lib/securenative/{models/user_traits.rb → user_traits.rb} +0 -0
- data/lib/securenative/utils/date_utils.rb +6 -4
- data/lib/securenative/utils/encryption_utils.rb +34 -37
- data/lib/securenative/utils/ip_utils.rb +15 -15
- data/lib/securenative/utils/{secure_native_logger.rb → log.rb} +1 -1
- data/lib/securenative/utils/request_utils.rb +55 -42
- data/lib/securenative/utils/signature_utils.rb +12 -12
- data/lib/securenative/utils/utils.rb +6 -4
- data/lib/securenative/utils/version_utils.rb +9 -7
- data/lib/securenative/{models/verify_result.rb → verify_result.rb} +0 -0
- data/lib/securenative/{errors/securenative_sdk_error.rb → version.rb} +1 -2
- data/securenative.gemspec +5 -2
- data/{out/test/securenative-ruby → spec}/spec_helper.rb +0 -0
- metadata +35 -83
- data/lib/securenative/context/hanami_context.rb +0 -44
- data/lib/securenative/context/rails_context.rb +0 -46
- data/lib/securenative/context/securenative_context.rb +0 -69
- data/lib/securenative/context/sinatra_context.rb +0 -44
- data/lib/securenative/errors/securenative_config_error.rb +0 -6
- data/lib/securenative/errors/securenative_http_error.rb +0 -6
- data/lib/securenative/errors/securenative_invalid_options_error.rb +0 -6
- data/lib/securenative/errors/securenative_sdk_Illegal_state_error.rb +0 -6
- data/lib/securenative/sdk.rb +0 -85
- data/out/production/securenative-ruby/api_manager.rb +0 -39
- data/out/production/securenative-ruby/config/configuration_builder.rb +0 -27
- data/out/production/securenative-ruby/config/configuration_manager.rb +0 -56
- data/out/production/securenative-ruby/config/securenative_options.rb +0 -23
- data/out/production/securenative-ruby/context/hanami_context.rb +0 -42
- data/out/production/securenative-ruby/context/rails_context.rb +0 -44
- data/out/production/securenative-ruby/context/securenative_context.rb +0 -67
- data/out/production/securenative-ruby/context/sinatra_context.rb +0 -42
- data/out/production/securenative-ruby/enums/api_route.rb +0 -6
- data/out/production/securenative-ruby/enums/event_types.rb +0 -23
- data/out/production/securenative-ruby/enums/failover_strategy.rb +0 -6
- data/out/production/securenative-ruby/enums/risk_level.rb +0 -7
- data/out/production/securenative-ruby/errors/securenative_invalid_uri_error.rb +0 -4
- data/out/production/securenative-ruby/errors/securenative_parse_error.rb +0 -4
- data/out/production/securenative-ruby/event_manager.rb +0 -157
- data/out/production/securenative-ruby/http/secure_native_http_response.rb +0 -12
- data/out/production/securenative-ruby/http/securenative_http_client.rb +0 -50
- data/out/production/securenative-ruby/models/client_token.rb +0 -12
- data/out/production/securenative-ruby/models/device.rb +0 -10
- data/out/production/securenative-ruby/models/event_options.rb +0 -37
- data/out/production/securenative-ruby/models/request_context.rb +0 -18
- data/out/production/securenative-ruby/models/request_options.rb +0 -12
- data/out/production/securenative-ruby/models/sdk_event.rb +0 -49
- data/out/production/securenative-ruby/models/user_traits.rb +0 -13
- data/out/production/securenative-ruby/models/verify_result.rb +0 -16
- data/out/production/securenative-ruby/securenative.rb +0 -83
- data/out/production/securenative-ruby/utils/date_utils.rb +0 -9
- data/out/production/securenative-ruby/utils/encryption_utils.rb +0 -49
- data/out/production/securenative-ruby/utils/ip_utils.rb +0 -23
- data/out/production/securenative-ruby/utils/request_utils.rb +0 -69
- data/out/production/securenative-ruby/utils/secure_native_logger.rb +0 -44
- data/out/production/securenative-ruby/utils/signature_utils.rb +0 -16
- data/out/production/securenative-ruby/utils/utils.rb +0 -9
- data/out/production/securenative-ruby/utils/version_utils.rb +0 -11
- data/out/test/securenative-ruby/spec_api_manager.rb +0 -87
- data/out/test/securenative-ruby/spec_context_builder.rb +0 -87
- data/out/test/securenative-ruby/spec_date_utils.rb +0 -13
- data/out/test/securenative-ruby/spec_encryption_utils.rb +0 -26
- data/out/test/securenative-ruby/spec_event_manager.rb +0 -93
- data/out/test/securenative-ruby/spec_ip_utils.rb +0 -41
- data/out/test/securenative-ruby/spec_request_utils.rb +0 -25
- data/out/test/securenative-ruby/spec_sdk_event.rb +0 -24
- data/out/test/securenative-ruby/spec_securenative.rb +0 -61
- data/out/test/securenative-ruby/spec_securenative_http_client.rb +0 -31
- data/out/test/securenative-ruby/spec_signature_utils.rb +0 -18
- data/out/test/securenative-ruby/spec_version_util.rb +0 -10
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SecureNative
|
4
|
+
module Frameworks
|
5
|
+
class Rails
|
6
|
+
SECURENATIVE_COOKIE = '_sn'
|
7
|
+
|
8
|
+
def self.get_client_token(request)
|
9
|
+
begin
|
10
|
+
request.cookies[SECURENATIVE_COOKIE]
|
11
|
+
rescue StandardError
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get_url(request)
|
17
|
+
begin
|
18
|
+
# Rails >= 3.x
|
19
|
+
request.fullpath
|
20
|
+
rescue StandardError
|
21
|
+
begin
|
22
|
+
# Rails < 3.x & Sinatra
|
23
|
+
request.url if url.nil?
|
24
|
+
rescue StandardError
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_method(request)
|
31
|
+
begin
|
32
|
+
request.method
|
33
|
+
rescue StandardError
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.get_headers(request)
|
39
|
+
begin
|
40
|
+
# Note: At the moment we're filtering out everything but user-agent since ruby's payload is way too big
|
41
|
+
{'user-agent' => request.env['HTTP_USER_AGENT']}
|
42
|
+
rescue StandardError
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SecureNative
|
4
|
+
module Frameworks
|
5
|
+
class Sinatra
|
6
|
+
SECURENATIVE_COOKIE = '_sn'
|
7
|
+
|
8
|
+
def self.get_client_token(request)
|
9
|
+
begin
|
10
|
+
request.env[SECURENATIVE_COOKIE]
|
11
|
+
rescue StandardError
|
12
|
+
begin
|
13
|
+
request.cookies[SECURENATIVE_COOKIE]
|
14
|
+
rescue StandardError
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.get_url(request)
|
21
|
+
begin
|
22
|
+
request.env['REQUEST_URI']
|
23
|
+
rescue StandardError
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.get_method(request)
|
29
|
+
begin
|
30
|
+
request.env['REQUEST_METHOD']
|
31
|
+
rescue StandardError
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get_headers(request)
|
37
|
+
begin
|
38
|
+
# Note: At the moment we're filtering out everything but user-agent since ruby's payload is way too big
|
39
|
+
{'user-agent' => request.env['HTTP_USER_AGENT']}
|
40
|
+
rescue StandardError
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,13 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'net/http'
|
4
|
-
require 'uri'
|
5
|
-
require 'json'
|
6
|
-
require 'securenative/utils/version_utils'
|
7
|
-
require 'securenative/utils/secure_native_logger'
|
8
|
-
|
9
3
|
module SecureNative
|
10
|
-
class
|
4
|
+
class HttpClient
|
11
5
|
AUTHORIZATION_HEADER = 'Authorization'
|
12
6
|
VERSION_HEADER = 'SN-Version'
|
13
7
|
USER_AGENT_HEADER = 'User-Agent'
|
@@ -21,10 +15,10 @@ module SecureNative
|
|
21
15
|
|
22
16
|
def _headers
|
23
17
|
{
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
CONTENT_TYPE_HEADER => CONTENT_TYPE_HEADER_VALUE,
|
19
|
+
USER_AGENT_HEADER => USER_AGENT_HEADER_VALUE,
|
20
|
+
VERSION_HEADER => SecureNative::Utils::VersionUtils.version,
|
21
|
+
AUTHORIZATION_HEADER => @options.api_key
|
28
22
|
}
|
29
23
|
end
|
30
24
|
|
@@ -33,6 +27,7 @@ module SecureNative
|
|
33
27
|
headers = _headers
|
34
28
|
|
35
29
|
client = Net::HTTP.new(uri.host, uri.port)
|
30
|
+
client.read_timeout = @options.timeout
|
36
31
|
client.use_ssl = true
|
37
32
|
client.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
38
33
|
|
@@ -43,7 +38,7 @@ module SecureNative
|
|
43
38
|
begin
|
44
39
|
res = client.request(request)
|
45
40
|
rescue StandardError => e
|
46
|
-
|
41
|
+
SecureNative::Log.error("Failed to send request; #{e}")
|
47
42
|
return res
|
48
43
|
end
|
49
44
|
res
|
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'securenative/enums/failover_strategy'
|
4
|
-
|
5
3
|
module SecureNative
|
6
|
-
class
|
4
|
+
class Options
|
7
5
|
attr_reader :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
|
8
6
|
attr_writer :api_key, :api_url, :interval, :max_events, :timeout, :auto_send, :disable, :log_level, :fail_over_strategy, :proxy_headers
|
9
7
|
|
File without changes
|
File without changes
|
@@ -1,12 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'securenative/context/securenative_context'
|
4
|
-
require 'securenative/errors/securenative_invalid_options_error'
|
5
|
-
require 'securenative/utils/encryption_utils'
|
6
|
-
require 'securenative/utils/date_utils'
|
7
|
-
require 'securenative/models/request_context'
|
8
|
-
require 'securerandom'
|
9
|
-
|
10
3
|
module SecureNative
|
11
4
|
class SDKEvent
|
12
5
|
attr_reader :context, :rid, :event_type, :user_id, :user_traits, :request, :timestamp, :properties
|
@@ -24,10 +17,10 @@ module SecureNative
|
|
24
17
|
@context = if !event_options.context.nil?
|
25
18
|
event_options.context
|
26
19
|
else
|
27
|
-
|
20
|
+
Context.default_context_builder
|
28
21
|
end
|
29
22
|
|
30
|
-
client_token = EncryptionUtils.decrypt(@context.client_token, securenative_options.api_key)
|
23
|
+
client_token = SecureNative::Utils::EncryptionUtils.decrypt(@context.client_token, securenative_options.api_key)
|
31
24
|
|
32
25
|
@rid = SecureRandom.uuid.to_str
|
33
26
|
@event_type = event_options.event
|
@@ -39,12 +32,12 @@ module SecureNative
|
|
39
32
|
url: @context.url, http_method: @context.http_method)
|
40
33
|
|
41
34
|
|
42
|
-
@timestamp = DateUtils.to_timestamp(event_options.timestamp)
|
35
|
+
@timestamp = SecureNative::Utils::DateUtils.to_timestamp(event_options.timestamp)
|
43
36
|
@properties = event_options.properties
|
44
37
|
end
|
45
38
|
|
46
39
|
def to_s
|
47
|
-
"
|
40
|
+
"context: #{@context}, rid: #{@rid}, event_type: #{@event_type}, user_id: #{@user_id},
|
48
41
|
user_traits: #{@user_traits}, request: #{@request}, timestamp: #{@timestamp}, properties: #{@properties}"
|
49
42
|
end
|
50
43
|
end
|
File without changes
|
@@ -1,11 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SecureNative
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Utils
|
5
|
+
class DateUtils
|
6
|
+
def self.to_timestamp(date)
|
7
|
+
return Time.now.utc.iso8601 if date.nil?
|
7
8
|
|
8
|
-
|
9
|
+
Time.parse(date).iso8601
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -1,50 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'openssl'
|
4
|
-
require 'digest'
|
5
|
-
require 'base64'
|
6
|
-
require 'securenative/models/client_token'
|
7
|
-
|
8
3
|
module SecureNative
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
key
|
13
|
-
else
|
14
|
-
if key.length > length
|
15
|
-
key.slice(0, length)
|
16
|
-
else
|
17
|
-
(length - key.length).times { key << '0' }
|
4
|
+
module Utils
|
5
|
+
class EncryptionUtils
|
6
|
+
def self.padding_key(key, length)
|
7
|
+
if key.length == length
|
18
8
|
key
|
9
|
+
else
|
10
|
+
if key.length > length
|
11
|
+
key.slice(0, length)
|
12
|
+
else
|
13
|
+
(length - key.length).times { key << '0' }
|
14
|
+
key
|
15
|
+
end
|
19
16
|
end
|
20
17
|
end
|
21
|
-
end
|
22
18
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
19
|
+
def self.encrypt(plain_text, secret_key)
|
20
|
+
begin
|
21
|
+
cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
22
|
+
cipher.encrypt
|
23
|
+
iv = cipher.random_iv
|
24
|
+
cipher.key = padding_key(secret_key, 32)
|
25
|
+
encrypted = cipher.update(plain_text) + cipher.final
|
26
|
+
(iv + encrypted).unpack1('H*')
|
27
|
+
rescue StandardError
|
28
|
+
''
|
29
|
+
end
|
33
30
|
end
|
34
|
-
end
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
def self.decrypt(cipher_text, secret_key)
|
33
|
+
begin
|
34
|
+
cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
35
|
+
cipher.decrypt
|
36
|
+
raw_data = [cipher_text].pack('H*')
|
37
|
+
cipher.iv = raw_data.slice(0, 16)
|
38
|
+
cipher.key = padding_key(secret_key, 32)
|
39
|
+
decrypted = JSON.parse(cipher.update(raw_data.slice(16, raw_data.length)) + cipher.final)
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
SecureNative::ClientToken.new(decrypted['cid'], decrypted['vid'], decrypted['fp'])
|
42
|
+
rescue StandardError
|
43
|
+
SecureNative::ClientToken.new('', '', '')
|
44
|
+
end
|
48
45
|
end
|
49
46
|
end
|
50
47
|
end
|
@@ -1,25 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "resolv"
|
4
|
-
|
5
3
|
module SecureNative
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
module Utils
|
5
|
+
class IpUtils
|
6
|
+
def self.ip_address?(ip_address)
|
7
|
+
return true if ip_address =~ Resolv::IPv4::Regex
|
8
|
+
return true if ip_address =~ Resolv::IPv6::Regex
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
false
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def self.valid_public_ip?(ip_address)
|
14
|
+
ip = IPAddr.new(ip_address)
|
15
|
+
return false if ip.loopback? || ip.private? || ip.link_local? || ip.untrusted? || ip.tainted?
|
17
16
|
|
18
|
-
|
19
|
-
|
17
|
+
true
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
20
|
+
def self.loop_back?(ip_address)
|
21
|
+
IPAddr.new(ip_address).loopback?
|
22
|
+
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -1,71 +1,84 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module SecureNative
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
module Utils
|
5
|
+
class RequestUtils
|
6
|
+
SECURENATIVE_COOKIE = '_sn'
|
7
|
+
SECURENATIVE_HEADER = 'x-securenative'
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
def self.get_secure_header_from_request(headers)
|
10
|
+
begin
|
11
|
+
return headers[SECURENATIVE_HEADER] unless headers.nil?
|
12
|
+
rescue StandardError
|
13
|
+
[]
|
14
|
+
end
|
12
15
|
[]
|
13
16
|
end
|
14
|
-
[]
|
15
|
-
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def self.get_client_ip_from_request(request, options = nil)
|
19
|
+
unless options.nil?
|
20
|
+
for header in options.proxy_headers do
|
21
|
+
begin
|
22
|
+
h = request.env[header]
|
23
|
+
return h.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless h.nil?
|
24
|
+
rescue NoMethodError
|
25
|
+
begin
|
26
|
+
h = request[header]
|
27
|
+
return h.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless h.nil?
|
28
|
+
rescue NoMethodError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
22
33
|
|
23
|
-
begin
|
24
|
-
x_forwarded_for = request.env['HTTP_X_FORWARDED_FOR']
|
25
|
-
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
26
|
-
rescue NoMethodError
|
27
34
|
begin
|
28
|
-
x_forwarded_for = request['HTTP_X_FORWARDED_FOR']
|
35
|
+
x_forwarded_for = request.env['HTTP_X_FORWARDED_FOR']
|
29
36
|
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
30
37
|
rescue NoMethodError
|
38
|
+
begin
|
39
|
+
x_forwarded_for = request['HTTP_X_FORWARDED_FOR']
|
40
|
+
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
41
|
+
rescue NoMethodError
|
42
|
+
end
|
31
43
|
end
|
32
|
-
end
|
33
44
|
|
34
|
-
begin
|
35
|
-
x_forwarded_for = request.env['REMOTE_ADDR']
|
36
|
-
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
37
|
-
rescue NoMethodError
|
38
45
|
begin
|
39
|
-
x_forwarded_for = request['
|
46
|
+
x_forwarded_for = request.env['HTTP_X_REAL_IP']
|
40
47
|
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
41
48
|
rescue NoMethodError
|
49
|
+
begin
|
50
|
+
x_forwarded_for = request['HTTP_X_REAL_IP']
|
51
|
+
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
52
|
+
rescue NoMethodError
|
53
|
+
end
|
42
54
|
end
|
43
|
-
end
|
44
55
|
|
45
|
-
|
46
|
-
|
56
|
+
begin
|
57
|
+
x_forwarded_for = request.env['REMOTE_ADDR']
|
58
|
+
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
59
|
+
rescue NoMethodError
|
47
60
|
begin
|
48
|
-
|
49
|
-
return
|
61
|
+
x_forwarded_for = request['REMOTE_ADDR']
|
62
|
+
return x_forwarded_for.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless x_forwarded_for.nil?
|
50
63
|
rescue NoMethodError
|
51
|
-
begin
|
52
|
-
h = request[header]
|
53
|
-
return h.scan(/\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b/)[0] unless h.nil?
|
54
|
-
rescue NoMethodError
|
55
|
-
end
|
56
64
|
end
|
57
65
|
end
|
58
|
-
end
|
59
66
|
|
60
|
-
|
61
|
-
|
67
|
+
begin
|
68
|
+
return request.ip unless request.ip.nil?
|
69
|
+
rescue NoMethodError
|
70
|
+
end
|
62
71
|
|
63
|
-
def self.get_remote_ip_from_request(request)
|
64
|
-
begin
|
65
|
-
request.remote_ip
|
66
|
-
rescue NoMethodError
|
67
72
|
''
|
68
73
|
end
|
74
|
+
|
75
|
+
def self.get_remote_ip_from_request(request)
|
76
|
+
begin
|
77
|
+
request.remote_ip
|
78
|
+
rescue NoMethodError
|
79
|
+
''
|
80
|
+
end
|
81
|
+
end
|
69
82
|
end
|
70
83
|
end
|
71
84
|
end
|