forked from r4sas/PBinCLI
little refactoring
This commit is contained in:
parent
e850b5495a
commit
d37e573d9e
@ -135,18 +135,7 @@ def get(args, api_client):
|
|||||||
|
|
||||||
if version == 1 and 'meta' in result and 'burnafterreading' in result['meta'] and result['meta']['burnafterreading']:
|
if version == 1 and 'meta' in result and 'burnafterreading' in result['meta'] and result['meta']['burnafterreading']:
|
||||||
print("Burn afrer reading flag found. Deleting paste...")
|
print("Burn afrer reading flag found. Deleting paste...")
|
||||||
result = api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':'burnafterreading'}))
|
api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':'burnafterreading'}))
|
||||||
|
|
||||||
if args.debug: print("Delete response:\t{}\n".format(result))
|
|
||||||
|
|
||||||
if 'status' in result and not result['status']:
|
|
||||||
print("Paste successfully deleted!")
|
|
||||||
elif 'status' in result and result['status']:
|
|
||||||
print("Something went wrong...\nError:\t\t{}".format(result['message']))
|
|
||||||
exit(1)
|
|
||||||
else:
|
|
||||||
print("Something went wrong...\nError: Empty response.")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
elif 'status' in result and result['status']:
|
elif 'status' in result and result['status']:
|
||||||
print("Something went wrong...\nError:\t\t{}".format(result['message']))
|
print("Something went wrong...\nError:\t\t{}".format(result['message']))
|
||||||
@ -164,15 +153,4 @@ def delete(args, api_client):
|
|||||||
|
|
||||||
if args.debug: print("PasteID:\t{}\nToken:\t\t{}".format(pasteid, token))
|
if args.debug: print("PasteID:\t{}\nToken:\t\t{}".format(pasteid, token))
|
||||||
|
|
||||||
result = api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':token}))
|
api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':token}))
|
||||||
|
|
||||||
if args.debug: print("Response:\t{}\n".format(result))
|
|
||||||
|
|
||||||
if 'status' in result and not result['status']:
|
|
||||||
print("Paste successfully deleted!")
|
|
||||||
elif 'status' in result and result['status']:
|
|
||||||
print("Something went wrong...\nError:\t\t{}".format(result['message']))
|
|
||||||
exit(1)
|
|
||||||
else:
|
|
||||||
print("Something went wrong...\nError: Empty response.")
|
|
||||||
exit(1)
|
|
||||||
|
@ -32,20 +32,27 @@ class PrivateBin:
|
|||||||
|
|
||||||
|
|
||||||
def delete(self, request):
|
def delete(self, request):
|
||||||
|
# using try as workaround for versions < 1.3 due to we cant detect
|
||||||
|
# if server used version 1.2, where auto-deletion is added
|
||||||
|
try:
|
||||||
result = requests.post(
|
result = requests.post(
|
||||||
url = self.server,
|
url = self.server,
|
||||||
headers = self.headers,
|
headers = self.headers,
|
||||||
proxies = self.proxy,
|
proxies = self.proxy,
|
||||||
data = request)
|
data = request).json()
|
||||||
|
|
||||||
# using try as workaround for versions < 1.3 due to we cant detect
|
|
||||||
# if server used version 1.2, where auto-deletion is added
|
|
||||||
try:
|
|
||||||
return result.json()
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
# unable parse response as json because it can be empty (1.2), so simulate correct answer
|
# unable parse response as json because it can be empty (1.2), so simulate correct answer
|
||||||
from json import loads as json_loads
|
from json import loads as json_loads
|
||||||
return json_loads('{"status":0}')
|
result = json_loads('{"status":0}')
|
||||||
|
|
||||||
|
if not result['status']:
|
||||||
|
print("Paste successfully deleted!")
|
||||||
|
elif result['status']:
|
||||||
|
print("Something went wrong...\nError:\t\t{}".format(result['message']))
|
||||||
|
exit(1)
|
||||||
|
else:
|
||||||
|
print("Something went wrong...\nError: Empty response.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
def getVersion(self):
|
def getVersion(self):
|
||||||
|
@ -120,6 +120,14 @@ class Paste:
|
|||||||
return cipher
|
return cipher
|
||||||
|
|
||||||
|
|
||||||
|
def __preparePassKey(self):
|
||||||
|
if self._password:
|
||||||
|
digest = sha256(self._password.encode("UTF-8")).hexdigest()
|
||||||
|
return b64encode(self._key) + digest.encode("UTF-8")
|
||||||
|
else:
|
||||||
|
return b64encode(self._key)
|
||||||
|
|
||||||
|
|
||||||
def __decompress(self, s):
|
def __decompress(self, s):
|
||||||
if self._version == 2:
|
if self._version == 2:
|
||||||
if self._compression == 'zlib':
|
if self._compression == 'zlib':
|
||||||
@ -178,11 +186,7 @@ class Paste:
|
|||||||
from hashlib import sha256
|
from hashlib import sha256
|
||||||
from sjcl import SJCL
|
from sjcl import SJCL
|
||||||
|
|
||||||
if self._password:
|
password = self.__preparePassKey()
|
||||||
digest = sha256(self._password.encode("UTF-8")).hexdigest()
|
|
||||||
password = b64encode(self._key) + digest.encode("UTF-8")
|
|
||||||
else:
|
|
||||||
password = b64encode(self._key)
|
|
||||||
|
|
||||||
cipher_text = json_decode(self._data['data'])
|
cipher_text = json_decode(self._data['data'])
|
||||||
|
|
||||||
@ -245,11 +249,7 @@ class Paste:
|
|||||||
|
|
||||||
self._data = {'expire':expiration,'formatter':formatter,'burnafterreading':int(burnafterreading),'opendiscussion':int(discussion)}
|
self._data = {'expire':expiration,'formatter':formatter,'burnafterreading':int(burnafterreading),'opendiscussion':int(discussion)}
|
||||||
|
|
||||||
if self._password:
|
password = self.__preparePassKey()
|
||||||
digest = sha256(self._password.encode("UTF-8")).hexdigest()
|
|
||||||
password = b64encode(self._key) + digest.encode("UTF-8")
|
|
||||||
else:
|
|
||||||
password = b64encode(self._key)
|
|
||||||
|
|
||||||
if self._debug: print("Password:\t{}".format(password))
|
if self._debug: print("Password:\t{}".format(password))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user