]> gitweb.michael.orlitzky.com - untangle-https-backup.git/blobdiff - src/untangle/untangle.py
untangle.py: add support for v13.1 download URLs.
[untangle-https-backup.git] / src / untangle / untangle.py
index c66cd67b45dbbe56c67d3ed8d1654d2e7cb7f5fd..82b29c445da89dda7decf2ccd2a5825223535c67 100644 (file)
@@ -18,12 +18,12 @@ class Untangle:
         self.host = s['host']
         self.username = s.get('username', 'admin')
         self.password = s['password']
-        self.version = int(s.get('version', '12'))
+        self.version = s.get('version', '13.1')
         self.base_url = 'https://' + self.host + '/' # This never changes
 
         # Sanity check the numerical version.
-        if self.version not in [9, 10, 11, 12]:
-            msg =  'Invalid version "' + str(self.version) + '" '
+        if self.version not in ['9', '10', '11', '12', '13', '13.1']:
+            msg =  'Invalid version "' + self.version + '" '
             msg += 'in section "' + s.name + '"'
             raise configparser.ParsingError(msg)
 
@@ -76,11 +76,14 @@ class Untangle:
         Version-agnostic get-me-a-backup method. Dispatches to the
         actual implementation based on ``self.version``.
         """
-        if self.version == 9:
+        if self.version == '9':
             return self.get_backup_v9()
-        elif self.version in [10, 11, 12]:
-            # The procedure for v11 or v12 is the same as for v10.
+        elif self.version in ['10', '11', '12', '13']:
+            # The procedure for v11, v12, or v13 is the same as for v10.
             return self.get_backup_v10()
+        elif self.version == '13.1':
+            # But the minor update v13.1 moved the backup URL.
+            return self.get_backup_v13_1()
 
 
     def get_backup_v9(self):
@@ -112,3 +115,18 @@ class Untangle:
         post_data = urllib.parse.urlencode(post_vars).encode('ascii')
         with self.opener.open(url, post_data) as response:
             return response.read()
+
+
+    def get_backup_v13_1(self):
+        """
+        Retrieve a backup from Untangle version 13.1. This
+        differs from v13 (and v12, and v11,...) by only one word
+        in the URL: "webui" becomes "admin".
+
+        Returns the binary HTTPS response (i.e. the file).
+        """
+        url = self.base_url + '/admin/download'
+        post_vars = {'type': 'backup'}
+        post_data = urllib.parse.urlencode(post_vars).encode('ascii')
+        with self.opener.open(url, post_data) as response:
+            return response.read()