module Unbind

Constants

Commands
VERSION

Attributes

config[R]
geoip[R]

Public Class Methods

clear_config() click to toggle source
# File lib/unbind.rb, line 54
def clear_config
  @config = {}
end
init_geoip() click to toggle source
# File lib/unbind.rb, line 63
def init_geoip
  if @config[:geoip_dat]
    begin
      require 'geoip'
      @geoip = GeoIP.new(@config[:geoip_dat])
    rescue LoadError
    end
  end
end
load_config(config) click to toggle source
# File lib/unbind.rb, line 18
def load_config config
  clear_config

  files = File.directory?(config) ? Dir["#{config}/**/*.conf"] : Dir[config]
  raise "No files could be found (search path: #{config})" if files.empty?
  files.each { |f| raise "File '#{f}' could not be loaded" unless load_file(f) }

  prepare_config

  true
end
load_file(f) click to toggle source

private

# File lib/unbind.rb, line 44
def load_file f
  load_string(File.read(File.expand_path(f)))
end
load_string(s) click to toggle source
# File lib/unbind.rb, line 48
def load_string s
  data = YAML.load(s)
  raise "config data should be a hash" unless data.is_a? Hash
  @config.merge!(data) and true
end
master(*) click to toggle source
# File lib/unbind.rb, line 30
def master(*)
  views.map { |v| v.master }.join("\n")
end
policies() click to toggle source
# File lib/unbind.rb, line 85
def policies
  @policies ||= @config[:zones].reduce([]) { |a, (name, config)| a + (config[:policies] || []) }.map { |policy_name|
    Unbind::Policy.const_get(policy_name.camelize)
  }
end
prepare_config() click to toggle source
# File lib/unbind.rb, line 58
def prepare_config
  symbolize_config
  init_geoip
end
slave(*) click to toggle source
# File lib/unbind.rb, line 34
def slave(*)
  views.map { |v| v.slave }.join("\n")
end
symbolize_config() click to toggle source
# File lib/unbind.rb, line 73
def symbolize_config
  @config.symbolize_keys!

  @config[:views] ||= {}
  @config[:zones] ||= {}

  @config[:zones].each do |k, v|
    v.symbolize_keys!
    v[:data].symbolize_keys!
  end
end
views() click to toggle source
# File lib/unbind.rb, line 95
def views
  @views ||= @config[:views].map { |name, clients| Unbind::View.new(name, {clients: clients, zones: zones}) }
end
zone(zone_names) click to toggle source
# File lib/unbind.rb, line 38
def zone zone_names
  zone_names.map { |z| Unbind::Zone.new(z, @config[:zones][z]).generate }.join("\n")
end
zones() click to toggle source
# File lib/unbind.rb, line 91
def zones
  @zones ||= @config[:zones].map { |name, config| Unbind::Zone.new(name, config) }
end