Project

General

Profile

« Previous | Next » 

Revision 8fcaacd6

Added by Marc Dequènes over 13 years ago

  • ID 8fcaacd6b9f666dcfb94138e296b2c320fe9799f

[evol] work on cyborg server protocol and API #7 (refs #31)

View differences:

lib/cyborghood/services/dns.rb
require 'fileutils'
# ensure we can find the needed programs (should be handled somewhere else)
ENV['PATH'] = (ENV['PATH'].split(":") + ["/sbin", "/usr/sbin", "/usr/local/sbin"]).uniq.join(":")
module CyborgHood
module Services
class DNS
def initialize
@config = Config.instance
@zone_files_pattern = @config.dns.master_zone_pattern.gsub("#ZONE#", "*")
@zone_files_regex = Regexp.new("^" + @config.dns.master_zone_pattern.gsub("#ZONE#", "(.*)") + "$")
end
def zones(zone = nil)
if zone.nil?
Dir.glob(@zone_files_pattern).collect do |file|
$1 if file =~ @zone_files_regex
end
else
Zone.new(zone)
end
end
end
class Zone
attr_reader :zone
attr_accessor :content
......
@content = nil
@filename = @config.dns.master_zone_pattern.gsub("#ZONE#", @zone)
# ensure we can find the needed programs (should be handled somewhere else)
ENV['PATH'] = (ENV['PATH'].split(":") + ["/sbin", "/usr/sbin", "/usr/local/sbin"]).uniq.join(":")
end
def read_zone
......
end
def serial
case @config.dns.nameserver || :bind
when :bind
case @config.dns.software
when 'bind'
output = []
begin
IO.popen("named-checkzone -i none '#{@zone}' #{@filename}") do |fp|
output << fp.gets.chomp! until fp.eof?
end
rescue
raise CyberError.new(:unrecoverable, "services/dns", "zone serial for '#{@zone}' could not be found")
raise CyberError.new(:unrecoverable, "services/dns", "zone serial for '#{@zone}' could not be found (I/O error)")
end
raise CyberError.new(:unrecoverable, "services/dns", "zone serial for '#{@zone}' could not be found (#{output.first})") unless $?.success?
if $? == 0
serial = nil
......
else
nil
end
else
# TODO: should be checked at startup time
raise CyberError.new(:unrecoverable, "services/dns", "erroneous configuration: unknown nameserver")
end
end
def check_zone_file(filename)
case @config.dns.nameserver || :bind
when :bind
case @config.dns.software
when 'bind'
output = []
begin
IO.popen("named-checkzone '#{@zone}' #{filename}") do |fp|
......
else
return {:ok => false, :errors => messages}.to_ostruct
end
else
# TODO: should be checked at startup time
raise CyberError.new(:unrecoverable, "services/dns", "erroneous configuration: unknown nameserver")
end
end

Also available in: Unified diff