From 809b34c57119e9c7ce325a509fa461836574fbce Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Wed, 28 Jun 2023 00:55:39 +0200 Subject: [PATCH] SOA RR update: minttl and a few syntax changes. --- Makefile | 2 ++ src/storage/zone.cr | 40 +++++++++++++++++++++++----------------- tools/write-zone-file.cr | 11 +++++------ 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 280cd99..78c2610 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,8 @@ Q ?= @ DOMAIN ?= example.com zone-file: crystal run ./tools/write-zone-file.cr -- $(DOMAIN) +zone-basic-template-file: + crystal run ./tools/write-template-zone-file.cr -- $(DOMAIN) VERBOSITY ?= 4 run-client-verbosity: diff --git a/src/storage/zone.cr b/src/storage/zone.cr index 03ea4bb..8265cf1 100644 --- a/src/storage/zone.cr +++ b/src/storage/zone.cr @@ -42,7 +42,7 @@ class DNSManager::Storage::Zone # zone class is omited, it always will be IN in our case. def initialize(@name, @ttl, @target) - @rrtype = self.class.name.downcase.gsub /dnsmanager::storage::zone::/, "" + @rrtype = self.class.name.upcase.gsub /DNSMANAGER::STORAGE::ZONE::/, "" end def get_errors : Array(Error) @@ -50,7 +50,7 @@ class DNSManager::Storage::Zone end def to_s(io : IO) - io << "(#{ "%4d" % @rrid }) #{ "%30s" % @name} #{ "%6d" % @ttl} IN #{ "%10s" % @rrtype.upcase} #{ "%30s" % @target}\n" + io << "(#{ "%4d" % @rrid }) #{ "%30s" % @name} #{ "%6d" % @ttl} IN #{ "%10s" % @rrtype } #{ "%30s" % @target}\n" end end @@ -58,23 +58,29 @@ class DNSManager::Storage::Zone # Start of Authority property mname : String # Master Name Server for the zone. property rname : String # admin email address john.doe@example.com => john\.doe.example.com - property serial : UInt64 = 0 # Number for tracking new versions of the zone (master-slaves). - property refresh : UInt64 = 86400 # #seconds before requesting new zone version (master-slave). - property retry : UInt64 = 7200 # #seconds before retry accessing new data from the master. - property expire : UInt64 = 3600000# #seconds slaves should consider master dead. + property serial : UInt64 = 0 # Number for tracking new versions of the zone (master-slaves). + property refresh : UInt64 = 86400 # #seconds before requesting new zone version (master-slave). + property retry : UInt64 = 7200 # #seconds before retry accessing new data from the master. + property expire : UInt64 = 3600000 # #seconds slaves should consider master dead. + property minttl : UInt64 = 600 # #seconds slaves should consider master dead. - def initialize(@name, @ttl, @target, - @mname, @rname, - @serial = 0.to_u64, @refresh = 86400.to_u64, @retry = 7200.to_u64, @expire = 3600000.to_u64) - @rrtype = "soa" + def initialize(@name, @ttl, @mname, @rname, + @serial = 0.to_u64, + @refresh = 86400.to_u64, + @retry = 7200.to_u64, + @expire = 3600000.to_u64, + @minttl = 600.to_u64) + @target = "" # no use + @rrtype = "SOA" end def to_s(io : IO) - io << "(#{ "%4d" % @rrid }) #{name} #{ttl} #{target} #{@rrtype.upcase} (#{mname} #{rname}\n" - io << "\t\t#{ "%10d" % serial} ; serial\n" - io << "\t\t#{ "%10d" % refresh} ; refresh\n" - io << "\t\t#{ "%10d" % retry} ; retry\n" - io << "\t\t#{ "%10d" % expire} ; expire\n" + io << "(#{ "%4d" % @rrid }) #{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" + io << "\t\t#{ "%10d" % expire } ; expire\n" + io << "\t\t#{ "%10d" % minttl } ; minttl\n" io << "\t)\n" end @@ -221,7 +227,7 @@ class DNSManager::Storage::Zone class MX < ResourceRecord property priority : UInt32 = 10 def initialize(@name, @ttl, @target, @priority = 10) - @rrtype = "mx" + @rrtype = "MX" end def to_s(io : IO) @@ -256,7 +262,7 @@ class DNSManager::Storage::Zone property priority : UInt32 = 10 property weight : UInt32 = 10 def initialize(@name, @ttl, @target, @port, @protocol = "tcp", @priority = 10, @weight = 10) - @rrtype = "srv" + @rrtype = "SRV" end def get_errors : Array(Error) diff --git a/tools/write-zone-file.cr b/tools/write-zone-file.cr index 43b0c6c..f47fc9d 100644 --- a/tools/write-zone-file.cr +++ b/tools/write-zone-file.cr @@ -21,21 +21,20 @@ zone = DSZ.new domain zone << DSZ::SOA.new "#{domain}.", # name 60.to_u32, # TTL - "IN", # target (??) "ns0.some-example.com.", # Master Name Server for the zone "john\.doe.#{domain}" # admin email address +zone << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns1.some-example.com." +zone << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns0.some-example.com." + zone << DSZ::A.new "www", 600.to_u32, "10.0.0.1" zone << DSZ::A.new "www2", 600.to_u32, "10.0.0.2" zone << DSZ::A.new "mail", 300.to_u32, "10.0.0.10" zone << DSZ::CNAME.new "mail2", 600.to_u32, "www" -zone << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns1.some-example.com." -zone << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns0.some-example.com." - -zone << DSZ::MX.new "mail", 300.to_u32, "mail", 10 -zone << DSZ::MX.new "mail", 300.to_u32, "mail2", 5 +zone << DSZ::MX.new "mail", 300.to_u32, "mail", 10 +zone << DSZ::MX.new "mail", 300.to_u32, "mail2", 5 File.write("#{domain}.json", zone.to_json)