Class: RedZone::Arpa

Inherits:
Object
  • Object
show all
Defined in:
lib/redzone/arpa.rb

Overview

Arpa definition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt) ⇒ Arpa

Constructs a new MailExchange entry

Parameters:

  • opt (Hash<String, SOA>)

Options Hash (opt):

  • :name (String)

    Arpa DNS name (Required)

  • :network (String)

    IP address with network mask (Required)

  • :soa (SOA, String)

    SOA record (Required)

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
# File 'lib/redzone/arpa.rb', line 23

def initialize(opt) 
  raise ArgumentError, ':name is required' unless opt.has_key?(:name)
  raise ArgumentError, ':network is required' unless opt.has_key?(:network)
  raise ArgumentError, ':soa is required' unless opt.has_key?(:soa)
  @name     = opt[:name]
  @network  = IPAddr.new(opt[:network])
  @soa      = opt[:soa]
  @records  = []
end

Instance Attribute Details

#nameString (readonly)

Reverse DNS name

Returns:

  • (String)

    dns name



8
9
10
# File 'lib/redzone/arpa.rb', line 8

def name
  @name
end

#networkIPAddr (readonly)

Network

Returns:

  • (IPAddr)


12
13
14
# File 'lib/redzone/arpa.rb', line 12

def network
  @network
end

#recordsArray<Record> (readonly)

Get the list of PTR records

Returns:

  • (Array<Record>)

    PTR records



16
17
18
# File 'lib/redzone/arpa.rb', line 16

def records
  @records
end

Instance Method Details

#add(machine, domain) ⇒ Object

Adds a machine to the arpa network for reverse-address lookup only if the machine is in this network.

Parameters:

  • machine (Machine)
  • domain (String)

    name



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/redzone/arpa.rb', line 47

def add(machine,domain)
  fqdn   = "#{machine.name}.#{domain}."
  substr = ".#{@name}"
  if @network.ipv4? and machine.ipv4? and @network.include?(machine.ipv4)
    ip = machine.ipv4.reverse
    ip.slice!(substr)
    records   << Record.new(:name => ip, :type => "PTR", :data => fqdn, :comment => "Machine #{machine.name}")
  end
  if @network.ipv6? and machine.ipv6? and @network.include?(machine.ipv6)
    ip = machine.ipv6.ip6_arpa
    ip.slice!(substr)
    records   << Record.new(:name => ip, :type => "PTR", :data => fqdn, :comment => "Machine #{machine.name}")
  end
end

#add_record(record) ⇒ Object



62
63
64
# File 'lib/redzone/arpa.rb', line 62

def add_record(record)
  records << record
end

#write(io) ⇒ Object

Writes the Arpa to the given IO stream

Parameters:

  • io (IO)

    IO Stream



35
36
37
38
39
40
41
# File 'lib/redzone/arpa.rb', line 35

def write(io)
  io << @soa
  @records.each do |r|
    io << r
  end
  io << "\n"
end