class WebConsole::Whitelist

Whitelist of allowed networks that can access Web Console.

Networks are represented by standard IPAddr and can be either IPv4 or IPv6 networks.

Constants

ALWAYS_WHITELISTED_NETWORKS

IPv4 and IPv6 localhost should be always whitelisted.

Public Class Methods

new(networks = nil) click to toggle source
# File lib/web_console/whitelist.rb, line 12
def initialize(networks = nil)
  @networks = normalize_networks(networks).map(&method(:coerce_network_to_ipaddr)).uniq
end

Public Instance Methods

include?(network) click to toggle source
# File lib/web_console/whitelist.rb, line 16
def include?(network)
  @networks.any? { |whitelist| whitelist.include?(network.to_s) }
end
to_s() click to toggle source
# File lib/web_console/whitelist.rb, line 20
def to_s
  @networks.map(&method(:human_readable_ipaddr)).join(', ')
end

Private Instance Methods

coerce_network_to_ipaddr(network) click to toggle source
# File lib/web_console/whitelist.rb, line 30
def coerce_network_to_ipaddr(network)
  if network.is_a?(IPAddr)
    network
  else
    IPAddr.new(network)
  end
end
human_readable_ipaddr(ipaddr) click to toggle source
# File lib/web_console/whitelist.rb, line 38
def human_readable_ipaddr(ipaddr)
  ipaddr.to_range.to_s.split('..').uniq.join('/')
end
normalize_networks(networks) click to toggle source
# File lib/web_console/whitelist.rb, line 26
def normalize_networks(networks)
  Array(networks).concat(ALWAYS_WHITELISTED_NETWORKS)
end