Commit 9f3774a1 authored by ntome's avatar ntome

[zerobin] handle a zerobin fork called "privatebin"

parent 9f3cdcdc
...@@ -31,13 +31,13 @@ __all__ = ['ZerobinModule'] ...@@ -31,13 +31,13 @@ __all__ = ['ZerobinModule']
class ZerobinModule(Module, CapPaste): class ZerobinModule(Module, CapPaste):
NAME = 'zerobin' NAME = 'zerobin'
DESCRIPTION = u'ZeroBin/0bin encrypted pastebin' DESCRIPTION = u'ZeroBin/0bin/PrivateBin encrypted pastebin'
MAINTAINER = u'Vincent A' MAINTAINER = u'Vincent A'
EMAIL = 'dev@indigo.re' EMAIL = 'dev@indigo.re'
LICENSE = 'AGPLv3+' LICENSE = 'AGPLv3+'
VERSION = '1.4' VERSION = '1.4'
CONFIG = BackendConfig( 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), ValueBool('discussion', label='Allow paste comments (ZeroBin only)', default=False),
) )
......
...@@ -30,15 +30,23 @@ from .crypto import decrypt, encrypt ...@@ -30,15 +30,23 @@ from .crypto import decrypt, encrypt
class ReadPageZero(HTMLPage): class ReadPageZero(HTMLPage):
# for zerobin # for zerobin/privatebin
def decode_paste(self, key): def _get_dict(self):
d = json.loads(CleanText('//div[@id="cipherdata"]')(self.doc)) 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) decr = decrypt(key, subd)
return decompress(b64decode(decr), -MAX_WBITS) return decompress(b64decode(decr), -MAX_WBITS)
def get_expire(self): 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: if 'expire_date' in d:
return datetime.fromtimestamp(d['expire_date']) return datetime.fromtimestamp(d['expire_date'])
...@@ -84,7 +92,9 @@ class WritePageZero(HTMLPage): ...@@ -84,7 +92,9 @@ class WritePageZero(HTMLPage):
} }
def is_here(self): 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): def post(self, contents, max_age):
compressor = compressobj(-1, DEFLATED, -MAX_WBITS) compressor = compressobj(-1, DEFLATED, -MAX_WBITS)
...@@ -99,7 +109,10 @@ class WritePageZero(HTMLPage): ...@@ -99,7 +109,10 @@ class WritePageZero(HTMLPage):
'opendiscussion': str(int(self.browser.opendiscussion)), 'opendiscussion': str(int(self.browser.opendiscussion)),
'syntaxcoloring': '1', '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() j = response.json()
assert j['status'] == 0 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