1
0
mirror of https://github.com/cmur2/dyndnsd.git synced 2024-10-09 17:02:21 +02:00
dyndnsd/lib/dyndnsd/generator/bind.rb
depfu[bot] 708cd13237
gems: update rubocop to version 0.89.0
Update rubocop to version 0.89.0 (#59)

Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>
2020-08-07 08:36:49 +02:00

42 lines
1.1 KiB
Ruby

# frozen_string_literal: true
module Dyndnsd
module Generator
class Bind
# @param domain [String]
# @param updater_params [Hash{String => Object}]
def initialize(domain, updater_params)
@domain = domain
@ttl = updater_params['ttl']
@dns = updater_params['dns']
@email_addr = updater_params['email_addr']
@additional_zone_content = updater_params['additional_zone_content']
end
# @param db [Dyndnsd::Database]
# @return [String]
def generate(db)
out = []
out << "$TTL #{@ttl}"
out << "$ORIGIN #{@domain}."
out << ''
out << "@ IN SOA #{@dns} #{@email_addr} ( #{db['serial']} 3h 5m 1w 1h )"
out << "@ IN NS #{@dns}"
out << ''
db['hosts'].each do |hostname, ips|
ips.each do |ip|
ip = IPAddr.new(ip).native
type = ip.ipv6? ? 'AAAA' : 'A'
name = hostname.chomp(".#{@domain}")
out << "#{name} IN #{type} #{ip}"
end
end
out << ''
out << @additional_zone_content
out << ''
out.join("\n")
end
end
end
end