mirror of
https://github.com/r4sas/PBinCLI
synced 2025-08-26 13:42:12 +00:00
add get --output option for decoded data (#40)
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
parent
08dbceebc6
commit
a7d62df966
@ -3,7 +3,7 @@ from urllib.parse import parse_qsl
|
||||
|
||||
from pbincli.api import Shortener
|
||||
from pbincli.format import Paste
|
||||
from pbincli.utils import PBinCLIError, check_writable, json_encode, uri_validator, validate_url_ending
|
||||
from pbincli.utils import PBinCLIError, check_writable, json_encode, uri_validator, validate_url_ending, validate_path_ending
|
||||
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
@ -166,21 +166,30 @@ def get(args, api_client, settings=None):
|
||||
|
||||
if len(text):
|
||||
if args.debug: print("{}\n".format(text.decode()))
|
||||
filename = "paste-" + pasteid + ".txt"
|
||||
print("Found text in paste. Saving it to {}".format(filename))
|
||||
if settings['output']:
|
||||
paste_path = validate_path_ending(settings['output']) + "paste-" + pasteid + ".txt"
|
||||
else:
|
||||
paste_path = "paste-" + pasteid + ".txt"
|
||||
|
||||
check_writable(filename)
|
||||
with open(filename, "wb") as f:
|
||||
print("Found text in paste. Saving it to {}".format(paste_path))
|
||||
|
||||
check_writable(paste_path)
|
||||
with open(paste_path, "wb") as f:
|
||||
f.write(text)
|
||||
f.close()
|
||||
|
||||
attachment, attachment_name = paste.getAttachment()
|
||||
|
||||
if attachment:
|
||||
print("Found file, attached to paste. Saving it to {}\n".format(attachment_name))
|
||||
if settings['output']:
|
||||
attachment_path = validate_path_ending(settings['output']) + attachment_name
|
||||
else:
|
||||
attachment_path = attachment_name
|
||||
|
||||
check_writable(attachment_name)
|
||||
with open(attachment_name, "wb") as f:
|
||||
print("Found file, attached to paste. Saving it to {}\n".format(attachment_path))
|
||||
|
||||
check_writable(attachment_path)
|
||||
with open(attachment_path, "wb") as f:
|
||||
f.write(attachment)
|
||||
f.close()
|
||||
|
||||
|
@ -81,6 +81,7 @@ def main():
|
||||
get_parser = subparsers.add_parser("get", description="Get data from PrivateBin instance")
|
||||
get_parser.add_argument("pasteinfo", help="\"PasteID#Passphrase\" or full URL")
|
||||
get_parser.add_argument("-p", "--password", help="Password for decrypting paste")
|
||||
get_parser.add_argument("-o", "--output", default=argparse.SUPPRESS, help="Path to directory where decoded paste data will be saved")
|
||||
## Connection options
|
||||
get_parser.add_argument("-s", "--server", default=argparse.SUPPRESS, help="Instance URL (default: https://paste.i2pd.xyz/, ignored if URL used in pasteinfo)")
|
||||
get_parser.add_argument("-x", "--proxy", default=argparse.SUPPRESS, help="Proxy server address (default: None)")
|
||||
@ -124,6 +125,7 @@ def main():
|
||||
'short_user': None,
|
||||
'short_pass': None,
|
||||
'short_token': None,
|
||||
'output': None,
|
||||
'no_check_certificate': False,
|
||||
'no_insecure_warning': False,
|
||||
'compression': None
|
||||
|
@ -1,4 +1,5 @@
|
||||
import json, ntpath, os, sys
|
||||
from platform import system
|
||||
|
||||
class PBinCLIException(Exception):
|
||||
pass
|
||||
@ -35,6 +36,16 @@ def validate_url_ending(s):
|
||||
s = s + "/"
|
||||
return s
|
||||
|
||||
def validate_path_ending(s):
|
||||
if system() == 'Windows':
|
||||
slash = '\\'
|
||||
else:
|
||||
slash = '/'
|
||||
|
||||
if not s.endswith(slash):
|
||||
s = s + slash
|
||||
return s
|
||||
|
||||
def uri_validator(x):
|
||||
from urllib.parse import urlsplit
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user