Print a human-readable summary of a zone.
This commit is contained in:
parent
9449ba336f
commit
fe48c1412d
@ -100,7 +100,15 @@ class Actions
|
|||||||
domains.each do |domain|
|
domains.each do |domain|
|
||||||
begin
|
begin
|
||||||
pp! domain
|
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
|
rescue e
|
||||||
puts "error for user_zone_get: #{e.message}"
|
puts "error for user_zone_get: #{e.message}"
|
||||||
end
|
end
|
||||||
|
@ -46,6 +46,10 @@ class DNSManager::Storage::Zone
|
|||||||
def get_errors : Array(Error)
|
def get_errors : Array(Error)
|
||||||
[] of Error
|
[] of Error
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s(io : IO)
|
||||||
|
io << "#{@name} #{@ttl} IN #{@rrtype.upcase} #{@target}\n"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class SOA < ResourceRecord
|
class SOA < ResourceRecord
|
||||||
@ -63,6 +67,15 @@ class DNSManager::Storage::Zone
|
|||||||
@rrtype = "soa"
|
@rrtype = "soa"
|
||||||
end
|
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)
|
def get_errors : Array(Error)
|
||||||
errors = [] of Error
|
errors = [] of Error
|
||||||
|
|
||||||
@ -209,6 +222,10 @@ class DNSManager::Storage::Zone
|
|||||||
@rrtype = "mx"
|
@rrtype = "mx"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def to_s(io : IO)
|
||||||
|
io << "#{@name} #{@ttl} IN #{@rrtype.upcase} #{@priority} #{@target}\n"
|
||||||
|
end
|
||||||
|
|
||||||
def get_errors : Array(Error)
|
def get_errors : Array(Error)
|
||||||
errors = [] of 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}"
|
errors << "MX invalid ttl: #{@ttl}, shouldn't be less than #{Zone.ttl_limit_min}"
|
||||||
end
|
end
|
||||||
|
|
||||||
unless Zone.is_domain_valid? @target
|
# MX target can either be a subdomain or a FQDN.
|
||||||
errors << "MX invalid target (domain): #{@target}"
|
unless Zone.is_subdomain_valid? @target
|
||||||
|
unless Zone.is_domain_valid? @target
|
||||||
|
errors << "MX invalid target (domain): #{@target}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
errors
|
errors
|
||||||
@ -256,7 +276,10 @@ class DNSManager::Storage::Zone
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s(io : IO)
|
def to_s(io : IO)
|
||||||
io << "TEST"
|
io << "domain: #{@domain}\n"
|
||||||
|
@resources.each do |rr|
|
||||||
|
io << rr
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_errors? : Array(Error)?
|
def get_errors? : Array(Error)?
|
||||||
@ -350,7 +373,7 @@ class DNSManager::Storage::Zone
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
rescue e
|
rescue e
|
||||||
Baguette::Log.warning "wrong IPv4 address: #{address}"
|
Baguette::Log.warning "wrong IPv6 address: #{address}"
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,17 +19,22 @@ zone = DSZ.new domain
|
|||||||
# Add some values.
|
# 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
|
zone.resources << DSZ::SOA.new "#{domain}.", # name
|
||||||
60.to_u32, # TTL
|
60.to_u32, # TTL
|
||||||
"IN", # target (??)
|
"IN", # target (??)
|
||||||
"ns0.some-example.com.", # Master Name Server for the zone
|
"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, "ns1.some-example.com."
|
||||||
zone.resources << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns0.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)
|
File.write("#{domain}.json", zone.to_json)
|
||||||
|
Loading…
Reference in New Issue
Block a user