dyndnsd/lib/dyndnsd/generator/bind.rb

37 lines
957 B
Ruby
Raw Normal View History

2013-04-27 14:07:14 +02:00
module Dyndnsd
module Generator
class Bind
2013-04-27 15:08:36 +02:00
def initialize(domain, config)
@domain = domain
2013-04-27 14:07:14 +02:00
@ttl = config['ttl']
@dns = config['dns']
@email_addr = config['email_addr']
@additional_zone_content = config['additional_zone_content']
2013-04-27 14:07:14 +02:00
end
def generate(zone)
out = []
out << "$TTL #{@ttl}"
2013-04-27 15:08:36 +02:00
out << "$ORIGIN #{@domain}."
2018-02-23 12:54:43 +01:00
out << ''
2013-04-27 14:07:14 +02:00
out << "@ IN SOA #{@dns} #{@email_addr} ( #{zone['serial']} 3h 5m 1w 1h )"
out << "@ IN NS #{@dns}"
2018-02-23 12:54:43 +01:00
out << ''
zone['hosts'].each do |hostname, ips|
ips.each do |ip|
ip = IPAddr.new(ip).native
2018-02-23 12:54:43 +01:00
type = ip.ipv6? ? 'AAAA' : 'A'
name = hostname.chomp('.' + @domain)
out << "#{name} IN #{type} #{ip}"
end
2013-04-27 14:07:14 +02:00
end
2018-02-23 12:54:43 +01:00
out << ''
out << @additional_zone_content
2018-02-23 12:54:43 +01:00
out << ''
2013-04-27 14:07:14 +02:00
out.join("\n")
end
end
end
end