root/lib/cyborghood-mapmaker/dns/bind.rb @ e971ab5a
90197e7b | Marc Dequènes (Duck) | #--
|
|
# CyborgHood, a distributed system management software.
|
|||
364e4a96 | Marc Dequènes (Duck) | # Copyright (c) 2009-2011 Marc Dequènes (Duck) <Duck@DuckCorp.org>
|
|
90197e7b | Marc Dequènes (Duck) | #
|
|
# This program is free software: you can redistribute it and/or modify
|
|||
# it under the terms of the GNU General Public License as published by
|
|||
# the Free Software Foundation, either version 3 of the License, or
|
|||
# (at your option) any later version.
|
|||
#
|
|||
# This program is distributed in the hope that it will be useful,
|
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|||
# GNU General Public License for more details.
|
|||
#
|
|||
# You should have received a copy of the GNU General Public License
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#++
|
|||
require 'cyborghood-mapmaker/dns/base'
|
|||
module CyborgHood
|
|||
module MapMakerLand
|
|||
class DNS < DNSBase
|
|||
def check_config
|
|||
output = []
|
|||
begin
|
|||
IO.popen("sudo named-checkconf") do |fp|
|
|||
output << fp.gets.chomp! until fp.eof?
|
|||
end
|
|||
rescue
|
|||
raise CyberError.new(:unrecoverable, "services/dns", "global configuration could not be checked (I/O error)")
|
|||
end
|
|||
if $?.success?
|
|||
return {:ok => true, :warnings => output}
|
|||
else
|
|||
return {:ok => false, :errors => output}
|
|||
end
|
|||
end
|
|||
def info
|
|||
super.merge(self.status)
|
|||
end
|
|||
def status
|
|||
output = []
|
|||
begin
|
|||
IO.popen("sudo rndc status") do |fp|
|
|||
output << fp.gets.chomp! until fp.eof?
|
|||
end
|
|||
rescue
|
|||
raise CyberError.new(:unrecoverable, "services/dns", "could not get DNS server status")
|
|||
end
|
|||
status = {}
|
|||
output.each do |line|
|
|||
line.sub!(" is ", ": ")
|
|||
key, value = line.split(": ")
|
|||
next if key.nil? or value.nil?
|
|||
key.gsub!(" ", "_")
|
|||
status[key.to_sym] = value.strip
|
|||
end
|
|||
status
|
|||
end
|
|||
end
|
|||
class DNSZoneFile < DNSZoneFileBase
|
|||
def activate
|
|||
system "sudo rndc reload '#{@name}' >/dev/null"
|
|||
raise CyberError.new(:unrecoverable, "services/dns", "zone activation failed") unless $?.success?
|
|||
end
|
|||
def check(on_disk = false)
|
|||
check_zone_file('full', on_disk = false)
|
|||
end
|
|||
protected
|
|||
def check_zone_file(check_type, on_disk = false)
|
|||
filename = on_disk ? @filename : current_filename
|
|||
output = []
|
|||
begin
|
|||
IO.popen("named-checkzone -i #{check_type} '#{@name}' #{filename}") do |fp|
|
|||
output << fp.gets.chomp! until fp.eof?
|
|||
end
|
|||
rescue
|
|||
raise CyberError.new(:unrecoverable, "services/dns", "zone '#{@name}' could not be checked (I/O error)")
|
|||
end
|
|||
serial = nil
|
|||
messages = []
|
|||
output.each do |l|
|
|||
next if l == "OK"
|
|||
if l =~ /: loaded serial (\d+)$/
|
|||
serial = $1
|
|||
next
|
|||
end
|
|||
messages << l
|
|||
end
|
|||
if $?.success?
|
|||
if serial
|
|||
return {:ok => true, :serial => serial, :warnings => messages}.to_ostruct
|
|||
else
|
|||
raise CyberError.new(:unrecoverable, "services/dns", "zone validated but no serial returned")
|
|||
end
|
|||
else
|
|||
return {:ok => false, :errors => messages}.to_ostruct
|
|||
end
|
|||
end
|
|||
end
|
|||
end # MapMakerLand
|
|||
end
|