Class: DDNS

Inherits:
RExec::Daemon::Base
  • Object
show all
Defined in:
lib/ddns-server.rb

Defined Under Namespace

Classes: Attributes

Class Method Summary collapse

Class Method Details

.runObject

Attributes



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/ddns-server.rb', line 71

def self.run
  $DDNS_ATTR.gossip.start

  RubyDNS.run_server(:listen => [[:udp, $DDNS_ATTR.address, $DDNS_ATTR.port]]) do
    on(:start) do
      $stdout.sync = true
      $stderr.sync = true

      logger.level = $DDNS_ATTR.loglevel

      if $DDNS_ATTR.daemon and $DDNS_ATTR.sock
        $RDDNS_ATTR = DRb.start_service("drbunix:#{$DDNS_ATTR.sock}", $DDNS_ATTR)
      end
    end

    match($DDNS_ATTR.method(:lookup_a_record).to_proc, :A) do |transaction|
      address, timestamp, data = $DDNS_ATTR.gossip.select {|a, t, d| d == transaction.name }.sort_by{ rand }.first
      transaction.respond!(address, :ttl => $DDNS_ATTR.ttl)
    end

    match($DDNS_ATTR.method(:lookup_ptr_record).to_proc, :PTR) do |transaction|
      name = transaction.name.sub(/\.in-addr\.arpa\Z/, '').split('.').reverse.join('.')
      address, timestamp, data = $DDNS_ATTR.gossip.find {|a, t, d| a == name }
      transaction.respond!(Resolv::DNS::Name.create("#{data}."), :ttl => $DDNS_ATTR.ttl)
    end

    if $DDNS_ATTR.resolver
      otherwise do |transaction|
        transaction.passthrough!($DDNS_ATTR.resolver)
      end
    end
  end
end

.shutdownObject



105
106
107
108
109
110
111
# File 'lib/ddns-server.rb', line 105

def self.shutdown
  $DDNS_ATTR.gossip.stop

  if $DDNS_ATTR.daemon and $DDNS_ATTR.sock
    FileUtils.rm_f($DDNS_ATTR.sock)
  end
end