X-Git-Url: http://gitweb.michael.orlitzky.com/?p=untangle-https-backup.git;a=blobdiff_plain;f=src%2Funtangle%2Funtangle.py;fp=src%2Funtangle%2Funtangle.py;h=82b29c445da89dda7decf2ccd2a5825223535c67;hp=c66cd67b45dbbe56c67d3ed8d1654d2e7cb7f5fd;hb=037581d3b61d0026cb197a78e67c314b0156c09d;hpb=d49dfbf5c33aea4a11a07e5dc7bd36fe5a0d056e 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()