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']
|
2013-04-27 16:12:43 +02:00
|
|
|
@additional_zone_content = config['additional_zone_content']
|
2013-04-27 14:07:14 +02:00
|
|
|
end
|
|
|
|
|
2018-01-26 16:25:15 +01:00
|
|
|
def generate(db)
|
2013-04-27 14:07:14 +02:00
|
|
|
out = []
|
|
|
|
out << "$TTL #{@ttl}"
|
2013-04-27 15:08:36 +02:00
|
|
|
out << "$ORIGIN #{@domain}."
|
2018-02-23 12:54:43 +01:00
|
|
|
out << ''
|
2018-01-26 16:25:15 +01:00
|
|
|
out << "@ IN SOA #{@dns} #{@email_addr} ( #{db['serial']} 3h 5m 1w 1h )"
|
2013-04-27 14:07:14 +02:00
|
|
|
out << "@ IN NS #{@dns}"
|
2018-02-23 12:54:43 +01:00
|
|
|
out << ''
|
2018-01-26 16:25:15 +01:00
|
|
|
db['hosts'].each do |hostname, ips|
|
2018-02-02 16:14:28 +01:00
|
|
|
ips.each do |ip|
|
2016-12-07 14:16:57 +01:00
|
|
|
ip = IPAddr.new(ip).native
|
2018-02-23 12:54:43 +01:00
|
|
|
type = ip.ipv6? ? 'AAAA' : 'A'
|
2016-12-07 14:16:57 +01:00
|
|
|
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 << ''
|
2013-04-27 16:12:43 +02:00
|
|
|
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
|