Commit 9f3774a1 authored by ntome's avatar ntome

[zerobin] handle a zerobin fork called "privatebin"

parent 9f3cdcdc
......@@ -31,13 +31,13 @@ __all__ = ['ZerobinModule']
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),
)
......
......@@ -30,15 +30,23 @@ from .crypto import decrypt, encrypt
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 @@ class WritePageZero(HTMLPage):
'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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment