mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 18:56:05 +02:00
Enable WhiteIp for checking against subnets
This commit is contained in:
parent
331ade988c
commit
a6b6a3e60a
1 changed files with 4 additions and 1 deletions
|
@ -24,7 +24,10 @@ class WhiteIp < ApplicationRecord
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def include_ip?(ip)
|
def include_ip?(ip)
|
||||||
where('ipv4 = :ip OR ipv6 = :ip', ip: ip).any?
|
ipv4 = select{ |white_ip| IPAddr.new(white_ip.ipv4, Socket::AF_INET) === IPAddr.new(ip) }
|
||||||
|
ipv6 = select{ |white_ip| IPAddr.new(white_ip.ipv6, Socket::AF_INET6) === IPAddr.new(ip) }
|
||||||
|
ids = (ipv4.pluck(:id) + ipv6.pluck(:id)).flatten.uniq
|
||||||
|
where(id: ids).any?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue