Print a human-readable summary of a zone.

master
Philippe Pittoli 2023-05-08 04:01:33 +02:00
parent 9449ba336f
commit fe48c1412d
3 changed files with 45 additions and 9 deletions

View File

@ -100,7 +100,15 @@ class Actions
domains.each do |domain|
begin
pp! domain
pp! @dnsmanagerd.user_zone_get domain
response = @dnsmanagerd.user_zone_get domain
case response
when DNSManager::Response::Zone
pp! response.zone
puts response.zone
else
puts "Didn't get the zone"
pp! response
end
rescue e
puts "error for user_zone_get: #{e.message}"
end

View File

@ -46,6 +46,10 @@ class DNSManager::Storage::Zone
def get_errors : Array(Error)
[] of Error
end
def to_s(io : IO)
io << "#{@name} #{@ttl} IN #{@rrtype.upcase} #{@target}\n"
end
end
class SOA < ResourceRecord
@ -63,6 +67,15 @@ class DNSManager::Storage::Zone
@rrtype = "soa"
end
def to_s(io : IO)
io << "#{name} #{ttl} #{target} #{@rrtype.upcase} (#{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)\n"
end
def get_errors : Array(Error)
errors = [] of Error
@ -209,6 +222,10 @@ class DNSManager::Storage::Zone
@rrtype = "mx"
end
def to_s(io : IO)
io << "#{@name} #{@ttl} IN #{@rrtype.upcase} #{@priority} #{@target}\n"
end
def get_errors : Array(Error)
errors = [] of Error
@ -220,8 +237,11 @@ class DNSManager::Storage::Zone
errors << "MX invalid ttl: #{@ttl}, shouldn't be less than #{Zone.ttl_limit_min}"
end
unless Zone.is_domain_valid? @target
errors << "MX invalid target (domain): #{@target}"
# MX target can either be a subdomain or a FQDN.
unless Zone.is_subdomain_valid? @target
unless Zone.is_domain_valid? @target
errors << "MX invalid target (domain): #{@target}"
end
end
errors
@ -256,7 +276,10 @@ class DNSManager::Storage::Zone
end
def to_s(io : IO)
io << "TEST"
io << "domain: #{@domain}\n"
@resources.each do |rr|
io << rr
end
end
def get_errors? : Array(Error)?
@ -350,7 +373,7 @@ class DNSManager::Storage::Zone
false
end
rescue e
Baguette::Log.warning "wrong IPv4 address: #{address}"
Baguette::Log.warning "wrong IPv6 address: #{address}"
false
end

View File

@ -19,17 +19,22 @@ zone = DSZ.new domain
# Add some values.
#
zone.resources << DSZ::A.new "www", 600.to_u32, "10.0.0.1"
zone.resources << DSZ::A.new "www2", 600.to_u32, "10.0.0.2"
zone.resources << 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
"john\\.doe.#{domain}" # admin email address
zone.resources << DSZ::A.new "www", 600.to_u32, "10.0.0.1"
zone.resources << DSZ::A.new "www2", 600.to_u32, "10.0.0.2"
zone.resources << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns1.some-example.com."
zone.resources << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns0.some-example.com."
zone.resources << DSZ::A.new "mail", 300.to_u32, "10.0.0.10"
zone.resources << DSZ::CNAME.new "mail2", 600.to_u32, "www"
zone.resources << DSZ::MX.new "mail", 300.to_u32, "mail", 10
zone.resources << DSZ::MX.new "mail", 300.to_u32, "mail2", 5
File.write("#{domain}.json", zone.to_json)