dnsmanager/tools/write-zone-file.cr

41 lines
973 B
Crystal
Raw Normal View History

2023-05-07 04:11:19 +02:00
require "json"
require "../src/storage/zone.cr"
alias DSZ = DNSManager::Storage::Zone
#
# Create a zone file.
#
if ARGV.size < 1
puts "usage: domain"
exit 0
end
domain = ARGV[0]
zone = DSZ.new domain
#
# Add some values.
#
2023-05-08 16:36:21 +02:00
zone << DSZ::SOA.new "#{domain}.", # name
2023-05-07 04:11:19 +02:00
60.to_u32, # TTL
"ns0.some-example.com.", # Master Name Server for the zone
2023-05-08 16:17:23 +02:00
"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."
2023-05-08 16:36:21 +02:00
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"
2023-05-08 16:17:23 +02:00
2023-05-08 16:36:21 +02:00
zone << DSZ::CNAME.new "mail2", 600.to_u32, "www"
2023-05-07 04:11:19 +02:00
zone << DSZ::MX.new "mail", 300.to_u32, "mail", 10
zone << DSZ::MX.new "mail", 300.to_u32, "mail2", 5
2023-05-07 04:11:19 +02:00
File.write("#{domain}.json", zone.to_json)