Provide bind9 file format export of domain zones.

This commit is contained in:
Philippe Pittoli 2024-02-24 07:30:16 +01:00
parent 8bec7eb33c
commit 891be61722

View File

@ -56,7 +56,12 @@ class DNSManager::Storage::Zone
end end
def to_s(io : IO) def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) #{ "%30s" % @name} #{ "%6d" % @ttl} IN #{ "%10s" % @rrtype } #{ "%30s" % @target}\n" io << "(#{ "%4d" % @rrid }) "
io << "#{ "%30s" % @name} #{ "%6d" % @ttl} IN #{ "%10s" % @rrtype } #{ "%30s" % @target}\n"
end
def to_bind9(io : IO)
io << "#{@name} #{@ttl} IN #{@rrtype} #{@target}\n"
end end
end end
@ -81,7 +86,8 @@ class DNSManager::Storage::Zone
end end
def to_s(io : IO) def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) #{name} #{ttl} IN SOA (#{mname} #{rname}\n" io << "(#{ "%4d" % @rrid }) "
io << "#{name} #{ttl} IN SOA (#{mname} #{rname}\n"
io << "\t\t#{ "%10d" % serial } ; serial\n" io << "\t\t#{ "%10d" % serial } ; serial\n"
io << "\t\t#{ "%10d" % refresh } ; refresh\n" io << "\t\t#{ "%10d" % refresh } ; refresh\n"
io << "\t\t#{ "%10d" % retry } ; retry\n" io << "\t\t#{ "%10d" % retry } ; retry\n"
@ -90,6 +96,16 @@ class DNSManager::Storage::Zone
io << "\t)\n" io << "\t)\n"
end end
def to_bind9(io : IO)
io << "#{name} #{ttl} IN SOA (#{mname} #{rname}\n"
io << "\t\t#{serial } ; serial\n"
io << "\t\t#{refresh} ; refresh\n"
io << "\t\t#{retry } ; retry\n"
io << "\t\t#{expire } ; expire\n"
io << "\t\t#{minttl } ; minttl\n"
io << "\t)\n"
end
def get_errors : Array(Error) def get_errors : Array(Error)
errors = [] of Error errors = [] of Error
@ -237,7 +253,12 @@ class DNSManager::Storage::Zone
end end
def to_s(io : IO) def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) #{ "%30s" % @name} #{ "%6d" % @ttl} IN MX #{ "%3d" % @priority} #{ "%30s" % @target}\n" io << "(#{ "%4d" % @rrid }) "
io << "#{ "%30s" % @name} #{ "%6d" % @ttl} IN MX #{ "%3d" % @priority} #{ "%30s" % @target}\n"
end
def to_bind9(io : IO)
io << "#{@name} #{@ttl} IN MX #{@priority} #{@target}\n"
end end
def get_errors : Array(Error) def get_errors : Array(Error)
@ -287,6 +308,20 @@ class DNSManager::Storage::Zone
errors errors
end end
def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) "
io << "#{ "%30s" % @name} "
io << "#{ "%6d" % @ttl} IN SRV "
io << "#{ "%3d" % @priority} "
io << "#{ "%3d" % @weight} "
io << "#{ "%5d" % @port} "
io << "#{ "%30s" % @target}\n"
end
def to_bind9(io : IO)
io << "#{@name} #{@ttl} IN SRV #{@priority} #{@weight} #{@port} #{@target}\n"
end
end end
def <<(rr : ResourceRecord) def <<(rr : ResourceRecord)
@ -302,6 +337,13 @@ class DNSManager::Storage::Zone
end end
end end
def to_bind9(io : IO)
io << "DOMAIN: #{@domain}\n"
@resources.each do |rr|
rr.to_bind9 io
end
end
def get_errors? : Array(Error)? def get_errors? : Array(Error)?
errors = [] of Error errors = [] of Error
unless Zone.is_domain_valid? @domain unless Zone.is_domain_valid? @domain