2019-04-03 14:24:05 +02:00
|
|
|
class IPService
|
|
|
|
class << self
|
|
|
|
def ip_trusted?(ip)
|
|
|
|
ip_address = parse_address(ip)
|
|
|
|
|
2019-08-01 15:34:33 +02:00
|
|
|
trusted_networks.any? { |network| network.include?(ip_address) }
|
2019-04-03 14:24:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def trusted_networks
|
|
|
|
if ENV['TRUSTED_NETWORKS'].present?
|
|
|
|
ENV['TRUSTED_NETWORKS']
|
|
|
|
.split
|
2021-06-10 15:24:15 +02:00
|
|
|
.filter_map { |string| parse_address(string) }
|
|
|
|
|
2019-04-03 14:24:05 +02:00
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def parse_address(address)
|
|
|
|
begin
|
|
|
|
IPAddr.new(address)
|
|
|
|
rescue
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|