|
|
@ -3,7 +3,7 @@ from pbincli.utils import PBinCLIError |
|
|
|
import signal |
|
|
|
import signal |
|
|
|
|
|
|
|
|
|
|
|
def signal_handler(sig, frame): |
|
|
|
def signal_handler(sig, frame): |
|
|
|
print('Keyboard interrupt received, terminating...') |
|
|
|
print('Keyboard interrupt received, terminating…') |
|
|
|
exit(0) |
|
|
|
exit(0) |
|
|
|
|
|
|
|
|
|
|
|
signal.signal(signal.SIGINT, signal_handler) |
|
|
|
signal.signal(signal.SIGINT, signal_handler) |
|
|
@ -18,18 +18,24 @@ def send(args, api_client, settings=None): |
|
|
|
if args.text: |
|
|
|
if args.text: |
|
|
|
text = args.text |
|
|
|
text = args.text |
|
|
|
elif args.stdin: |
|
|
|
elif args.stdin: |
|
|
|
|
|
|
|
print("Reading text from stdin…") |
|
|
|
text = args.stdin.read() |
|
|
|
text = args.stdin.read() |
|
|
|
elif not args.file: |
|
|
|
elif not args.file: |
|
|
|
PBinCLIError("Nothing to send!") |
|
|
|
PBinCLIError("Nothing to send!") |
|
|
|
else: |
|
|
|
else: |
|
|
|
text = "" |
|
|
|
text = "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Preparing paste…") |
|
|
|
paste = Paste(args.debug) |
|
|
|
paste = Paste(args.debug) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if args.verbose: print("Used server: {}".format(api_client.getServer())) |
|
|
|
|
|
|
|
|
|
|
|
# get from server supported paste format version and update object |
|
|
|
# get from server supported paste format version and update object |
|
|
|
|
|
|
|
if args.verbose: print("Getting supported paste format version from server…") |
|
|
|
version = api_client.getVersion() |
|
|
|
version = api_client.getVersion() |
|
|
|
paste.setVersion(version) |
|
|
|
paste.setVersion(version) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if args.verbose: print("Filling paste with data…") |
|
|
|
# set compression type, works only on v2 pastes |
|
|
|
# set compression type, works only on v2 pastes |
|
|
|
if version == 2: |
|
|
|
if version == 2: |
|
|
|
paste.setCompression(args.compression) |
|
|
|
paste.setCompression(args.compression) |
|
|
@ -45,6 +51,7 @@ def send(args, api_client, settings=None): |
|
|
|
if args.file: |
|
|
|
if args.file: |
|
|
|
paste.setAttachment(args.file) |
|
|
|
paste.setAttachment(args.file) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if args.verbose: print("Encrypting paste…") |
|
|
|
paste.encrypt( |
|
|
|
paste.encrypt( |
|
|
|
formatter = args.format, |
|
|
|
formatter = args.format, |
|
|
|
burnafterreading = args.burn, |
|
|
|
burnafterreading = args.burn, |
|
|
@ -53,13 +60,12 @@ def send(args, api_client, settings=None): |
|
|
|
|
|
|
|
|
|
|
|
request = paste.getJSON() |
|
|
|
request = paste.getJSON() |
|
|
|
|
|
|
|
|
|
|
|
if args.debug: |
|
|
|
if args.debug: print("Passphrase:\t{}\nRequest:\t{}".format(paste.getHash(), request)) |
|
|
|
print("Passphrase:\t{}".format(paste.getHash())) |
|
|
|
|
|
|
|
print("Request:\t{}".format(request)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# If we use dry option, exit now |
|
|
|
# If we use dry option, exit now |
|
|
|
if args.dry: exit(0) |
|
|
|
if args.dry: exit(0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Uploading paste…") |
|
|
|
result = api_client.post(request) |
|
|
|
result = api_client.post(request) |
|
|
|
|
|
|
|
|
|
|
|
if args.debug: print("Response:\t{}\n".format(result)) |
|
|
|
if args.debug: print("Response:\t{}\n".format(result)) |
|
|
@ -76,12 +82,12 @@ def send(args, api_client, settings=None): |
|
|
|
result['id'], |
|
|
|
result['id'], |
|
|
|
passphrase)) |
|
|
|
passphrase)) |
|
|
|
elif result['status']: # return code is other then zero |
|
|
|
elif result['status']: # return code is other then zero |
|
|
|
PBinCLIError("Something went wrong...\nError:\t\t{}".format(result['message'])) |
|
|
|
PBinCLIError("Something went wrong…\nError:\t\t{}".format(result['message'])) |
|
|
|
else: # or here no status field in response or it is empty |
|
|
|
else: # or here no status field in response or it is empty |
|
|
|
PBinCLIError("Something went wrong...\nError: Empty response.") |
|
|
|
PBinCLIError("Something went wrong…\nError: Empty response.") |
|
|
|
|
|
|
|
|
|
|
|
if args.short: |
|
|
|
if args.short: |
|
|
|
print("\nQuerying URL shortening service...") |
|
|
|
print("\nQuerying URL shortening service…") |
|
|
|
shortener.getlink("{}?{}#{}".format( |
|
|
|
shortener.getlink("{}?{}#{}".format( |
|
|
|
settings['server'], |
|
|
|
settings['server'], |
|
|
|
result['id'], |
|
|
|
result['id'], |
|
|
@ -99,6 +105,7 @@ def get(args, api_client, settings=None): |
|
|
|
if not (pasteid and passphrase): |
|
|
|
if not (pasteid and passphrase): |
|
|
|
PBinCLIError("Incorrect request") |
|
|
|
PBinCLIError("Incorrect request") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if args.verbose: print("Used server: {}".format(api_client.getServer())) |
|
|
|
if args.debug: print("PasteID:\t{}\nPassphrase:\t{}".format(pasteid, passphrase)) |
|
|
|
if args.debug: print("PasteID:\t{}\nPassphrase:\t{}".format(pasteid, passphrase)) |
|
|
|
|
|
|
|
|
|
|
|
paste = Paste(args.debug) |
|
|
|
paste = Paste(args.debug) |
|
|
@ -107,13 +114,14 @@ def get(args, api_client, settings=None): |
|
|
|
paste.setPassword(args.password) |
|
|
|
paste.setPassword(args.password) |
|
|
|
if args.debug: print("Password:\t{}".format(args.password)) |
|
|
|
if args.debug: print("Password:\t{}".format(args.password)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if args.verbose: print("Requesting paste from server…") |
|
|
|
result = api_client.get(pasteid) |
|
|
|
result = api_client.get(pasteid) |
|
|
|
|
|
|
|
|
|
|
|
if args.debug: print("Response:\t{}\n".format(result)) |
|
|
|
if args.debug: print("Response:\t{}\n".format(result)) |
|
|
|
|
|
|
|
|
|
|
|
# Paste was received. Checking received status code |
|
|
|
# Paste was received. Checking received status code |
|
|
|
if not result['status']: # return code is zero |
|
|
|
if not result['status']: # return code is zero |
|
|
|
print("Paste received!") |
|
|
|
print("Paste received! Decoding…") |
|
|
|
|
|
|
|
|
|
|
|
version = result['v'] if 'v' in result else 1 |
|
|
|
version = result['v'] if 'v' in result else 1 |
|
|
|
paste.setVersion(version) |
|
|
|
paste.setVersion(version) |
|
|
@ -150,13 +158,13 @@ def get(args, api_client, settings=None): |
|
|
|
f.close() |
|
|
|
f.close() |
|
|
|
|
|
|
|
|
|
|
|
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…") |
|
|
|
api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':'burnafterreading'})) |
|
|
|
api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':'burnafterreading'})) |
|
|
|
|
|
|
|
|
|
|
|
elif result['status']: # return code is other then zero |
|
|
|
elif result['status']: # return code is other then zero |
|
|
|
PBinCLIError("Something went wrong...\nError:\t\t{}".format(result['message'])) |
|
|
|
PBinCLIError("Something went wrong…\nError:\t\t{}".format(result['message'])) |
|
|
|
else: # or here no status field in response or it is empty |
|
|
|
else: # or here no status field in response or it is empty |
|
|
|
PBinCLIError("Something went wrong...\nError: Empty response.") |
|
|
|
PBinCLIError("Something went wrong…\nError: Empty response.") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delete(args, api_client, settings=None): |
|
|
|
def delete(args, api_client, settings=None): |
|
|
@ -165,6 +173,8 @@ def delete(args, api_client, settings=None): |
|
|
|
pasteid = args.paste |
|
|
|
pasteid = args.paste |
|
|
|
token = args.token |
|
|
|
token = args.token |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if args.verbose: print("Used server: {}".format(api_client.getServer())) |
|
|
|
if args.debug: print("PasteID:\t{}\nToken:\t\t{}".format(pasteid, token)) |
|
|
|
if args.debug: print("PasteID:\t{}\nToken:\t\t{}".format(pasteid, token)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Requesting paste deletion…") |
|
|
|
api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':token})) |
|
|
|
api_client.delete(json_encode({'pasteid':pasteid,'deletetoken':token})) |
|
|
|