]>
git.ipfire.org Git - people/ms/ddns.git/blob - ddns/providers.py
f3230fc0d1ee5d47c79c1e379de248aa756e170d
3 # Import all possible exception types.
6 class DDNSProvider(object):
8 # A short string that uniquely identifies
12 # The full name of the provider.
15 # A weburl to the homepage of the provider.
16 # (Where to register a new account?)
19 # A list of supported protocols.
20 "protocols" : ["ipv6", "ipv4"],
25 def __init__(self
, core
, **settings
):
28 # Copy a set of default settings and
29 # update them by those from the configuration file.
30 self
.settings
= self
.DEFAULT_SETTINGS
.copy()
31 self
.settings
.update(settings
)
34 return "<DDNS Provider %s (%s)>" % (self
.name
, self
.handle
)
36 def __cmp__(self
, other
):
37 return cmp(self
.hostname
, other
.hostname
)
42 Returns the name of the provider.
44 return self
.INFO
.get("name")
49 Returns the website URL of the provider
50 or None if that is not available.
52 return self
.INFO
.get("website", None)
57 Returns the handle of this provider.
59 return self
.INFO
.get("handle")
61 def get(self
, key
, default
=None):
63 Get a setting from the settings dictionary.
65 return self
.settings
.get(key
, default
)
70 Fast access to the hostname.
72 return self
.get("hostname")
77 Fast access to the username.
79 return self
.get("username")
84 Fast access to the password.
86 return self
.get("password")
89 raise NotImplementedError
91 def send_request(self
, *args
, **kwargs
):
93 Proxy connection to the send request
96 return self
.core
.system
.send_request(*args
, **kwargs
)
98 def get_address(self
, proto
):
100 Proxy method to get the current IP address.
102 return self
.core
.system
.get_address(proto
)
105 class DDNSProviderNOIP(DDNSProvider
):
107 "handle" : "no-ip.com",
109 "website" : "http://www.no-ip.com/",
110 "protocols" : ["ipv4",]
113 # Information about the format of the HTTP request is to be found
114 # here: http://www.no-ip.com/integrate/request and
115 # here: http://www.no-ip.com/integrate/response
117 url
= "http://%(username)s:%(password)s@dynupdate.no-ip.com/nic/update?hostname=%(hostname)s&myip=%(address)s"
121 "hostname" : self
.hostname
,
122 "username" : self
.username
,
123 "password" : self
.password
,
124 "address" : self
.get_address("ipv4"),
127 # Send update to the server.
128 response
= self
.send_request(url
)
130 # Get the full response message.
131 output
= response
.read()
133 # Handle success messages.
134 if output
.startswith("good") or output
.startswith("nochg"):
137 # Handle error codes.
138 if output
== "badauth":
139 raise DDNSAuthenticationError
140 elif output
== "aduse":
142 elif output
== "911":
143 raise DDNSInternalServerError
145 # If we got here, some other update error happened.
146 raise DDNSUpdateError
149 class DDNSProviderSelfhost(DDNSProvider
):
151 "handle" : "selfhost.de",
152 "name" : "Selfhost.de",
153 "website" : "http://www.selfhost.de/",
154 "protocols" : ["ipv4",],
157 url
= "https://carol.selfhost.de/update?username=%(username)s&password=%(password)s&textmodi=1"
160 url
= self
.url
% { "username" : self
.username
, "password" : self
.password
}
162 response
= self
.send_request(url
)
164 match
= re
.search("status=20(0|4)", response
.read())
166 raise DDNSUpdateError