Project

General

Profile

Download (2.08 KB) Statistics
| Branch: | Tag: | Revision:
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 'dnsruby'
require 'tempfile'


module CyborgHood
module MapMakerLand
class ZoneContentBase
def initialize(name)
@name = name
end

def soa
find_rr('SOA').first
end

def serial
s = self.soa
s ? s.serial : nil
end

def signed?
not find_rr('DNSKEY').empty?
end

# methods a backend MUST implement
# - find_rr
end

class ZoneContent < ZoneContentBase
def initialize(name)
super

@reader = Dnsruby::ZoneReader.new(@name)
@zone = []
end

def content
@zone.collect{|rr| rr.to_s }.join("\n")
end

def content=(str)
begin
temp_file = Tempfile.new(@name)
temp_file.write(str)
temp_file.close
rescue
raise CyberError.new(:unrecoverable, "services/dns", "could not save temporary zone")
end

import_from_file(temp_file.path)

temp_file.close!
end

def import_from_file(file)
@zone = @reader.process_file(file) || []
end

def to_s
self.content
end

def empty?
@zone.empty?
end

def find_rr(rr_type)
@zone.select{|rr| rr.name.to_s == @name and rr.type == rr_type }
end

# TODO: methods to add/replace RRs
end
end
end