From 9f3774a1e5fb6b31c50ee27ec972140665d3751f Mon Sep 17 00:00:00 2001 From: Vincent A Date: Sun, 11 Mar 2018 00:31:25 +0100 Subject: [PATCH] [zerobin] handle a zerobin fork called "privatebin" --- modules/zerobin/module.py | 4 ++-- modules/zerobin/pages.py | 25 +++++++++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/modules/zerobin/module.py b/modules/zerobin/module.py index e68903d716..a1c7bc6c0e 100644 --- a/modules/zerobin/module.py +++ b/modules/zerobin/module.py @@ -31,13 +31,13 @@ class ZerobinModule(Module, CapPaste): NAME = 'zerobin' - DESCRIPTION = u'ZeroBin/0bin encrypted pastebin' + DESCRIPTION = u'ZeroBin/0bin/PrivateBin encrypted pastebin' MAINTAINER = u'Vincent A' EMAIL = 'dev@indigo.re' LICENSE = 'AGPLv3+' VERSION = '1.4' CONFIG = BackendConfig( - Value('url', label='URL of the zerobin/0bin', regexp='https?://.*', default='https://zerobin.net'), + Value('url', label='URL of the zerobin/0bin/privatebin', regexp='https?://.*', default='https://zerobin.net'), ValueBool('discussion', label='Allow paste comments (ZeroBin only)', default=False), ) diff --git a/modules/zerobin/pages.py b/modules/zerobin/pages.py index 7ed954169b..1e3527419f 100644 --- a/modules/zerobin/pages.py +++ b/modules/zerobin/pages.py @@ -30,15 +30,23 @@ class ReadPageZero(HTMLPage): - # for zerobin - def decode_paste(self, key): + # for zerobin/privatebin + def _get_dict(self): d = json.loads(CleanText('//div[@id="cipherdata"]')(self.doc)) - subd = json.loads(d[0]['data']) + if isinstance(d, list): + # zerobin + return d[0] + else: + # privatebin + return d + + def decode_paste(self, key): + subd = json.loads(self._get_dict()['data']) decr = decrypt(key, subd) return decompress(b64decode(decr), -MAX_WBITS) def get_expire(self): - d = json.loads(CleanText('//div[@id="cipherdata"]')(self.doc))[0]['meta'] + d = self._get_dict()['meta'] if 'expire_date' in d: return datetime.fromtimestamp(d['expire_date']) @@ -84,7 +92,9 @@ class WritePageZero(HTMLPage): } def is_here(self): - return 'zerobin' in self.text and self.doc.xpath('//select[@id="pasteExpiration"]') + if not self.doc.xpath('//select[@id="pasteExpiration"]'): + return False + return 'zerobin' in self.text or 'privatebin' in self.text def post(self, contents, max_age): compressor = compressobj(-1, DEFLATED, -MAX_WBITS) @@ -99,7 +109,10 @@ def post(self, contents, max_age): 'opendiscussion': str(int(self.browser.opendiscussion)), 'syntaxcoloring': '1', } - response = self.browser.location(self.url, data=data) + headers = { + 'Accept': 'application/json', + } + response = self.browser.location(self.url, data=data, headers=headers) j = response.json() assert j['status'] == 0 -- GitLab