Sha256: dc5c05c3105c0caededbd90e2e6125e12ddc3d5b272bbcd485a46537a472a73a

Contents?: true

Size: 1.14 KB

Versions: 38

Compression:

Stored size: 1.14 KB

Contents

# 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

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
dyndnsd-3.10.0 lib/dyndnsd/generator/bind.rb
dyndnsd-3.9.2 lib/dyndnsd/generator/bind.rb
dyndnsd-3.9.1 lib/dyndnsd/generator/bind.rb
dyndnsd-3.9.0 lib/dyndnsd/generator/bind.rb
dyndnsd-3.8.2 lib/dyndnsd/generator/bind.rb
dyndnsd-3.8.1 lib/dyndnsd/generator/bind.rb
dyndnsd-3.8.0 lib/dyndnsd/generator/bind.rb
dyndnsd-3.7.3 lib/dyndnsd/generator/bind.rb
dyndnsd-3.7.2 lib/dyndnsd/generator/bind.rb
dyndnsd-3.7.1 lib/dyndnsd/generator/bind.rb
dyndnsd-3.7.0 lib/dyndnsd/generator/bind.rb
dyndnsd-3.6.2 lib/dyndnsd/generator/bind.rb
dyndnsd-3.6.1 lib/dyndnsd/generator/bind.rb
dyndnsd-3.6.0 lib/dyndnsd/generator/bind.rb
dyndnsd-3.5.3 lib/dyndnsd/generator/bind.rb
dyndnsd-3.5.2 lib/dyndnsd/generator/bind.rb
dyndnsd-3.5.1 lib/dyndnsd/generator/bind.rb
dyndnsd-3.5.0 lib/dyndnsd/generator/bind.rb
dyndnsd-3.4.8 lib/dyndnsd/generator/bind.rb
dyndnsd-3.4.7 lib/dyndnsd/generator/bind.rb