Sha256: 3a06ebf2dd0a81a5391b41051cf006cf09c6b1f895143aff3ebedc1d9ae2d12a

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module Dyndnsd
  module Generator
    class Bind
      # @param domain [String]
      # @param config [Hash{String => Object}]
      def initialize(domain, config)
        @domain = domain
        @ttl = config['ttl']
        @dns = config['dns']
        @email_addr = config['email_addr']
        @additional_zone_content = config['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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dyndnsd-2.1.1 lib/dyndnsd/generator/bind.rb
dyndnsd-2.1.0 lib/dyndnsd/generator/bind.rb