]> gitweb.michael.orlitzky.com - untangle-https-backup.git/blobdiff - bin/untangle-https-backup
src/untangle/untangle.py: use cleaner way of disabling verification.
[untangle-https-backup.git] / bin / untangle-https-backup
index 69e46ba0c6af76de91f61a8db725c7df4b25fd26..3abb05f257741b96fd349c650b09c8c5db23932f 100755 (executable)
@@ -8,6 +8,7 @@ import configparser
 from http.client import HTTPException
 from os import chmod
 from urllib.error import HTTPError, URLError
+from socket import timeout
 from sys import stderr
 
 from untangle.untangle import Untangle
@@ -30,8 +31,10 @@ args = parser.parse_args()
 # Default to success, change it if anything fails.
 status = EXIT_OK
 
-# Parse the configuration file...
-config = configparser.ConfigParser()
+# Parse the configuration file. In this contect "interpolation" is
+# something completely berserk, and it breaks passwords containing '%'
+# characters. So, we turn it off.
+config = configparser.ConfigParser(interpolation=None)
 config.read(args.config_file)
 
 # And loop through each section.
@@ -52,9 +55,7 @@ for section in config.sections():
         chmod(filename, 0o600)
 
     # If it didn't work, but in a predictable way (some host is down),
-    # then we report that error and keep going. At least one sort of
-    # HTTPException (BadStatusLine) is not translated by urllib into
-    # an HTTPError, so we catch HTTPExceptions too.
+    # then we report that error and keep going.
     except URLError as e:
         tpl = '{:s}: {:s} from {:s}'
         msg = tpl.format(u.name, str(e.reason), u.host)
@@ -66,9 +67,19 @@ for section in config.sections():
         print(msg, file=stderr)
         status = EXIT_BACKUPS_FAILED
     except HTTPException as e:
+        # At least one sort of HTTPException (BadStatusLine) is not
+        # translated by urllib into an HTTPError, so we catch
+        # HTTPExceptions too.
         tpl = '{:s}: HTTP exception {:s} from {:s}'
         msg = tpl.format(u.name, repr(e), u.host)
         print(msg, file=stderr)
         status = EXIT_BACKUPS_FAILED
+    except timeout as e:
+        # A socket.timeout exception occurs when something goes over
+        # the configured "timeout" limit.
+        tpl = '{:s}: socket timeout ({:s}) from {:s}'
+        msg = tpl.format(u.name, str(e), u.host)
+        print(msg, file=stderr)
+        status = EXIT_BACKUPS_FAILED
 
 exit(status)