Browse Source

Support full URL in get command

Signed-off-by: R4SAS <r4sas@i2pmail.org>
gha
R4SAS 3 years ago
parent
commit
369738ea50
  1. 12
      pbincli/actions.py
  2. 12
      pbincli/cli.py
  3. 10
      pbincli/utils.py

12
pbincli/actions.py

@ -1,5 +1,5 @@
from pbincli.format import Paste from pbincli.format import Paste
from pbincli.utils import PBinCLIError, validate_url from pbincli.utils import PBinCLIError, validate_url_ending
import signal import signal
def signal_handler(sig, frame): def signal_handler(sig, frame):
@ -99,7 +99,7 @@ def send(args, api_client, settings=None):
urls = settings['mirrors'].split(',') urls = settings['mirrors'].split(',')
for x in urls: for x in urls:
print("\t\t{}?{}#{}".format( print("\t\t{}?{}#{}".format(
validate_url(x), validate_url_ending(x),
result['id'], result['id'],
passphrase)) passphrase))
@ -117,10 +117,14 @@ def send(args, api_client, settings=None):
def get(args, api_client, settings=None): def get(args, api_client, settings=None):
from pbincli.utils import check_writable, json_encode from pbincli.utils import check_writable, json_encode, uri_validator
try: try:
pasteid, passphrase = args.pasteinfo.split("#") if uri_validator(args.pasteinfo):
api_client.server, pasteinfo = args.pasteinfo.split("?")
pasteid, passphrase = pasteinfo.split("#")
else:
pasteid, passphrase = args.pasteinfo.split("#")
except ValueError: except ValueError:
PBinCLIError("Provided info hasn't contain valid PasteID#Passphrase string") PBinCLIError("Provided info hasn't contain valid PasteID#Passphrase string")

12
pbincli/cli.py

@ -3,7 +3,7 @@ import os, sys, argparse
import pbincli.actions import pbincli.actions
from pbincli.api import PrivateBin from pbincli.api import PrivateBin
from pbincli.utils import PBinCLIException, PBinCLIError, validate_url from pbincli.utils import PBinCLIException, PBinCLIError, validate_url_ending
CONFIG_PATHS = [ CONFIG_PATHS = [
os.path.join(".", "pbincli.conf", ), os.path.join(".", "pbincli.conf", ),
@ -57,7 +57,7 @@ def main():
send_parser.add_argument("--short-pass", default=argparse.SUPPRESS, help="Shortener password") send_parser.add_argument("--short-pass", default=argparse.SUPPRESS, help="Shortener password")
send_parser.add_argument("--short-token", default=argparse.SUPPRESS, help="Shortener token") send_parser.add_argument("--short-token", default=argparse.SUPPRESS, help="Shortener token")
## Connection options ## Connection options
send_parser.add_argument("-s", "--server", default=argparse.SUPPRESS, help="PrivateBin service URL (default: https://paste.i2pd.xyz/)") send_parser.add_argument("-s", "--server", default=argparse.SUPPRESS, help="Instance URL (default: https://paste.i2pd.xyz/)")
send_parser.add_argument("-x", "--proxy", default=argparse.SUPPRESS, help="Proxy server address (default: None)") send_parser.add_argument("-x", "--proxy", default=argparse.SUPPRESS, help="Proxy server address (default: None)")
send_parser.add_argument("--no-check-certificate", default=False, action="store_true", help="disable certificate validation") send_parser.add_argument("--no-check-certificate", default=False, action="store_true", help="disable certificate validation")
send_parser.add_argument("--no-insecure-warning", default=False, action="store_true", send_parser.add_argument("--no-insecure-warning", default=False, action="store_true",
@ -72,10 +72,10 @@ def main():
# a get command # a get command
get_parser = subparsers.add_parser("get", description="Get data from PrivateBin instance") get_parser = subparsers.add_parser("get", description="Get data from PrivateBin instance")
get_parser.add_argument("pasteinfo", help="example: aabb#cccddd") 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("-p", "--password", help="password for decrypting paste")
## Connection options ## Connection options
get_parser.add_argument("-s", "--server", default=argparse.SUPPRESS, help="PrivateBin service URL (default: https://paste.i2pd.xyz/)") 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)") get_parser.add_argument("-x", "--proxy", default=argparse.SUPPRESS, help="Proxy server address (default: None)")
get_parser.add_argument("--no-check-certificate", default=False, action="store_true", help="disable certificate validation") get_parser.add_argument("--no-check-certificate", default=False, action="store_true", help="disable certificate validation")
get_parser.add_argument("--no-insecure-warning", default=False, action="store_true", get_parser.add_argument("--no-insecure-warning", default=False, action="store_true",
@ -90,7 +90,7 @@ def main():
delete_parser.add_argument("-p", "--paste", required=True, help="paste id") delete_parser.add_argument("-p", "--paste", required=True, help="paste id")
delete_parser.add_argument("-t", "--token", required=True, help="paste deletion token") delete_parser.add_argument("-t", "--token", required=True, help="paste deletion token")
## Connection options ## Connection options
delete_parser.add_argument("-s", "--server", default=argparse.SUPPRESS, help="PrivateBin service URL (default: https://paste.i2pd.xyz/)") delete_parser.add_argument("-s", "--server", default=argparse.SUPPRESS, help="Instance URL (default: https://paste.i2pd.xyz/)")
delete_parser.add_argument("-x", "--proxy", default=argparse.SUPPRESS, help="Proxy server address (default: None)") delete_parser.add_argument("-x", "--proxy", default=argparse.SUPPRESS, help="Proxy server address (default: None)")
delete_parser.add_argument("--no-check-certificate", default=False, action="store_true", help="disable certificate validation") delete_parser.add_argument("--no-check-certificate", default=False, action="store_true", help="disable certificate validation")
delete_parser.add_argument("--no-insecure-warning", default=False, action="store_true", delete_parser.add_argument("--no-insecure-warning", default=False, action="store_true",
@ -136,7 +136,7 @@ def main():
CONFIG[key] = args_var[key] CONFIG[key] = args_var[key]
# Re-validate PrivateBin instance URL # Re-validate PrivateBin instance URL
CONFIG['server'] = validate_url(CONFIG['server']) CONFIG['server'] = validate_url_ending(CONFIG['server'])
api_client = PrivateBin(CONFIG) api_client = PrivateBin(CONFIG)

10
pbincli/utils.py

@ -30,7 +30,15 @@ def json_encode(s):
return json.dumps(s, separators=(',',':')).encode() return json.dumps(s, separators=(',',':')).encode()
def validate_url(s): def validate_url_ending(s):
if not s.endswith('/'): if not s.endswith('/'):
s = s + "/" s = s + "/"
return s return s
def uri_validator(x):
from urllib.parse import urlparse
try:
result = urlparse(x)
return all([result.scheme, result.netloc])
except:
return False
Loading…
Cancel
Save