From 891be61722962251a3a3a8f0e74c8b281a365f0a Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Sat, 24 Feb 2024 07:30:16 +0100 Subject: [PATCH] Provide bind9 file format export of domain zones. --- src/storage/zone.cr | 48 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/storage/zone.cr b/src/storage/zone.cr index 4e7f1c9..2b5cbb8 100644 --- a/src/storage/zone.cr +++ b/src/storage/zone.cr @@ -56,7 +56,12 @@ class DNSManager::Storage::Zone end 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 @@ -81,7 +86,8 @@ class DNSManager::Storage::Zone end 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" % refresh } ; refresh\n" io << "\t\t#{ "%10d" % retry } ; retry\n" @@ -90,6 +96,16 @@ class DNSManager::Storage::Zone io << "\t)\n" 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) errors = [] of Error @@ -237,7 +253,12 @@ class DNSManager::Storage::Zone end 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 def get_errors : Array(Error) @@ -287,6 +308,20 @@ class DNSManager::Storage::Zone errors 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 def <<(rr : ResourceRecord) @@ -302,6 +337,13 @@ class DNSManager::Storage::Zone 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)? errors = [] of Error unless Zone.is_domain_valid? @domain