Moved hostname handling into try block to avoid an unhandled exception in case of...
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 5 Mar 2014 22:05:36 +0000 (23:05 +0100)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 5 Mar 2014 22:05:36 +0000 (23:05 +0100)
cgi-bin/dyndns.py

index b89cd39..7863b79 100755 (executable)
@@ -34,11 +34,6 @@ backmx   = fields.getvalue('backmx')
 offline  = fields.getvalue('offline')
 
 
-# Strip zone
-hostname = hostname.strip()
-if hostname.endswith(ZONE):
-       hostname = hostname[:-len(ZONE)]
-
 try:
        # check username
        user_info = pwd.getpwnam(username) # returns a key error if the user does not exist
@@ -53,6 +48,11 @@ try:
        if re.match(r'[-0-9a-z]+(\.[-0-9a-z]+)*$', hostname) is None:
                raise RuntimeError('Invalid host name')
 
+       # strip zone
+       hostname = hostname.strip()
+       if hostname.endswith(ZONE):
+               hostname = hostname[:-len(ZONE)]
+
        # check IP address
        ip = ipaddr.IPAddress(myip) # throws axception if the IP address is not valid
        if isinstance(ip, ipaddr.IPv4Address):