From 037581d3b61d0026cb197a78e67c314b0156c09d Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 23 Oct 2017 16:27:00 -0400 Subject: [PATCH] untangle.py: add support for v13.1 download URLs. In version 13.1 of Untangle, the backup download URL has changed. That means we need to support a new, non-integer version number "13.1". This commit changes the version parameter from an integer to a string, and adds support for two new version strings: "13" and "13.1". Since the download URL was unchanged in v13.0, the existing routines are used for that version. However, a new get_backup_v13_1() function was added for v13.1. The only difference between that function and the get_backup_v10() function is the word "webui" which has been changed to "admin". Version "13.1" is now the default version if none is specified. --- src/untangle/untangle.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/untangle/untangle.py b/src/untangle/untangle.py index c66cd67..82b29c4 100644 --- a/src/untangle/untangle.py +++ b/src/untangle/untangle.py @@ -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() -- 2.44.2