]> git.ipfire.org Git - oddments/ddns.git/blobdiff - ddns/system.py
Add class to raise configuration errors.
[oddments/ddns.git] / ddns / system.py
index 6840b7d656d398a8ef1dded2c8babfd1a34be01c..e4e5731a2b8dd20fb298936d9c8a86ddc6f35ca3 100644 (file)
@@ -1,4 +1,23 @@
 #!/usr/bin/python
+###############################################################################
+#                                                                             #
+# ddns - A dynamic DNS client for IPFire                                      #
+# Copyright (C) 2012 IPFire development team                                  #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
 
 import re
 import urllib2
@@ -29,11 +48,27 @@ class DDNSSystem(object):
                proxy = self.core.settings.get("proxy")
 
                # Strip http:// at the beginning.
-               if proxy.startswith("http://"):
+               if proxy and proxy.startswith("http://"):
                        proxy = proxy[7:]
 
                return proxy
 
+       def guess_external_ipv6_address(self):
+               """
+                       Sends a request to an external web server
+                       to determine the current default IP address.
+               """
+               response = self.send_request("http://checkip6.dns.lightningwirelabs.com")
+
+               if not response.code == 200:
+                       return
+
+               match = re.search(r"^Your IP address is: (.*)$", response.read())
+               if match is None:
+                       return
+
+               return match.group(1)
+
        def guess_external_ipv4_address(self):
                """
                        Sends a request to the internet to determine
@@ -41,10 +76,10 @@ class DDNSSystem(object):
 
                        XXX does not work for IPv6.
                """
-               response = self.send_request("http://checkip.dyndns.org/")
+               response = self.send_request("http://checkip4.dns.lightningwirelabs.com")
 
                if response.code == 200:
-                       match = re.search(r"Current IP Address: (\d+.\d+.\d+.\d+)", response.read())
+                       match = re.search(r"Your IP address is: (\d+.\d+.\d+.\d+)", response.read())
                        if match is None:
                                return
 
@@ -91,14 +126,17 @@ class DDNSSystem(object):
        def get_address(self, proto):
                assert proto in ("ipv6", "ipv4")
 
-               if proto == "ipv4":
-                       # Check if the external IP address should be guessed from
-                       # a remote server.
-                       guess_ip = self.core.settings.get("guess_external_ip", "")
+               # Check if the external IP address should be guessed from
+               # a remote server.
+               guess_ip = self.core.settings.get("guess_external_ip", "true")
+
+               # If the external IP address should be used, we just do
+               # that.
+               if guess_ip in ("true", "yes", "1"):
+                       if proto == "ipv6":
+                               return self.guess_external_ipv6_address()
 
-                       # If the external IP address should be used, we just do
-                       # that.
-                       if guess_ip in ("true", "yes", "1"):
+                       elif proto == "ipv4":
                                return self.guess_external_ipv4_address()
 
                # XXX TODO