Class: DynDynDong::DynDNS

Inherits:
Service
  • Object
show all
Defined in:
lib/dyndyndong/services/dyndns.rb

Direct Known Subclasses

NoIp

Instance Method Summary collapse

Methods inherited from Service

each, #fetch, inherited, instances, #method_missing, services

Constructor Details

#initialize(*args) ⇒ DynDNS

Returns a new instance of DynDNS.



43
44
45
46
47
48
# File 'lib/dyndyndong/services/dyndns.rb', line 43

def initialize(*args)
  @user = nil
  @pass = nil
  @ip = getip
  super(*args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DynDynDong::Service

Instance Method Details

#alias_host(h, ip, offline = false) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/dyndyndong/services/dyndns.rb', line 83

def alias_host(h, ip, offline = false)
  return "Nothing to update." if ip == @ip

  Net::HTTP.start(update_host) {|http|
    req = Net::HTTP::Get.new('/nic/update?hostname=%s&myip=%s&offline=%s' % [
        URI.escape(h), @ip, offline?(offline)])
    req.basic_auth @user, @pass
    x = http.request(req).body.gsub(/#{Regexp.escape(@ip)}/, '').strip
    self::MSGTABLE(x)
  }
end

#host(h) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/dyndyndong/services/dyndns.rb', line 61

def host(h)
  begin
    @hosts << [h.to_s, getip(h)]
  rescue Exception => e
    STDERR.puts "Ip detection error: #{e}, skipping..."
  end
end

#MSGTABLE(x) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dyndyndong/services/dyndns.rb', line 26

def MSGTABLE(x)
  {
    'badauth'         => 'The username and password pair do not match a real user.',
    '!donator'        => 'Option available only to credited users.',
    'good'            => 'The update was successful, and the hostname is now updated.',
    'nochg'           => 'The update changed no settings, and is considered abusive.',
    'notfqdn'         => 'The hostname specified is not a fully-qualified domain name.',
    'nohost'          => 'The hostname specified does not exist in this user account.',
    'numhost'         => 'Too many hosts specified in an update.',
    'abuse'           => 'The hostname specified is blocked for update abuse.',
    'badagent'        => 'The user agent was not sent or HTTP method is not permitted.',
    'good 127.0.0.1'  => 'Request was ignored because of agent that does not follow our specifications.',
    'dnserr'          => 'DNS error encountered.',
    '911'             => 'There is a problem or scheduled maintenance on our side.'
  }[x]
end

#offline(h) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/dyndyndong/services/dyndns.rb', line 69

def offline(h)
  begin
    @hosts << [h.to_s, getip(h), true]
  rescue Exception => e
    STDERR.puts "Ip detection error: #{e}, skipping..."
  end
end

#password(p) ⇒ Object Also known as: password=



54
55
56
# File 'lib/dyndyndong/services/dyndns.rb', line 54

def password(p)
  @pass = p.to_s
end

#prefetchObject



77
78
79
80
81
# File 'lib/dyndyndong/services/dyndns.rb', line 77

def prefetch
  if !(@user and @pass)
    raise "username or password ungiven"
  end
end

#username(u) ⇒ Object Also known as: username=



50
51
52
# File 'lib/dyndyndong/services/dyndns.rb', line 50

def username(u)
  @user = u.to_s
end