コード例 #1
0
def send(args, api_client, settings=None):
    from pbincli.api import Shortener
    if args.short:
        shortener = Shortener(settings)

    if not args.notext:
        if args.text:
            text = args.text
        elif args.stdin:
            text = args.stdin.read()
    elif not args.file:
        PBinCLIError("Nothing to send!")
    else:
        text = ""

    paste = Paste(args.debug)

    # get from server supported paste format version and update object
    version = api_client.getVersion()
    paste.setVersion(version)

    # set compression type, works only on v2 pastes
    if version == 2:
        paste.setCompression(args.compression)

    # add text in paste (if it provided)
    paste.setText(text)

    # If we set PASSWORD variable
    if args.password:
        paste.setPassword(args.password)

    # If we set FILE variable
    if args.file:
        paste.setAttachment(args.file)

    paste.encrypt(formatter=args.format,
                  burnafterreading=args.burn,
                  discussion=args.discus,
                  expiration=args.expire)

    request = paste.getJSON()

    if args.debug:
        print("Passphrase:\t{}".format(paste.getHash()))
        print("Request:\t{}".format(request))

    # If we use dry option, exit now
    if args.dry: exit(0)

    result = api_client.post(request)

    if args.debug: print("Response:\t{}\n".format(result))

    # Paste was sent. Checking for returned status code
    if not result['status']:  # return code is zero
        passphrase = paste.getHash()

        print(
            "Paste uploaded!\nPasteID:\t{}\nPassword:\t{}\nDelete token:\t{}\n\nLink:\t\t{}?{}#{}"
            .format(result['id'], passphrase, result['deletetoken'],
                    settings['server'], result['id'], passphrase))
    elif result['status']:  # return code is other then zero
        PBinCLIError("Something went wrong...\nError:\t\t{}".format(
            result['message']))
    else:  # or here no status field in response or it is empty
        PBinCLIError("Something went wrong...\nError: Empty response.")

    if args.short:
        print("\nQuerying URL shortening service...")
        shortener.getlink("{}?{}#{}".format(settings['server'], result['id'],
                                            passphrase))
コード例 #2
0
def send(args, api_client):
    if not args.notext:
        if args.text:
            text = args.text
        elif args.stdin:
            text = args.stdin.read()
    elif not args.file:
        print("Nothing to send!")
        exit(1)
    else:
        text = ""

    paste = Paste(args.debug)

    # get from server supported paste format version and update object
    version = api_client.getVersion()
    paste.setVersion(version)

    # set compression type, works only on v2 pastes
    if version == 2:
        paste.setCompression(args.compression)

    # add text in paste (if it provided)
    paste.setText(text)

    # If we set PASSWORD variable
    if args.password:
        paste.setPassword(args.password)

    # If we set FILE variable
    if args.file:
        paste.setAttachment(args.file)

    paste.encrypt(
        formatter = args.format,
        burnafterreading = args.burn,
        discussion = args.discus,
        expiration = args.expire)

    request = paste.getJSON()

    if args.debug: 
        print("Passphrase:\t{}".format(paste.getHash()))
        print("Request:\t{}".format(request))

    # If we use dry option, exit now
    if args.dry: exit(0)

    result = api_client.post(request)

    if args.debug: print("Response:\t{}\n".format(result))

    if 'status' in result and not result['status']:
        passphrase = paste.getHash()

        print("Paste uploaded!\nPasteID:\t{}\nPassword:\t{}\nDelete token:\t{}\n\nLink:\t\t{}?{}#{}".format(
            result['id'],
            passphrase,
            result['deletetoken'],
            api_client.server,
            result['id'],
            passphrase))
    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)
コード例 #3
0
def make_payload(text):
    paste = Paste()
    paste.setVersion(2)
    paste.setText(text)
    paste.encrypt(formatter='plaintext', burnafterreading=0, discussion=0, expiration='never')
    return paste.getJSON(), paste.getHash()
コード例 #4
0
def send(args, api_client, settings=None):
    from pbincli.api import Shortener
    if args.short:
        shortener = Shortener(settings)

    if not args.notext:
        if args.text:
            text = args.text
        elif args.stdin:
            print("Reading text from stdin…")
            text = args.stdin.read()
    elif not args.file:
        PBinCLIError("Nothing to send!")
    else:
        text = ""

    print("Preparing paste…")
    paste = Paste(args.debug)

    if args.verbose: print("Used server: {}".format(api_client.getServer()))

    # 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()
    paste.setVersion(version)

    if args.verbose: print("Filling paste with data…")
    # set compression type, works only on v2 pastes
    if version == 2:
        paste.setCompression(args.compression)

    # add text in paste (if it provided)
    paste.setText(text)

    # If we set PASSWORD variable
    if args.password:
        paste.setPassword(args.password)

    # If we set FILE variable
    if args.file:
        paste.setAttachment(args.file)

    if args.verbose: print("Encrypting paste…")
    paste.encrypt(formatter=args.format,
                  burnafterreading=args.burn,
                  discussion=args.discus,
                  expiration=args.expire)

    if args.verbose: print("Sending request to server…")
    request = paste.getJSON()

    if args.debug:
        print("Passphrase:\t{}\nRequest:\t{}".format(paste.getHash(), request))

    # If we use dry option, exit now
    if args.dry: exit(0)

    print("Uploading paste…")
    result = api_client.post(request)

    if args.debug: print("Response:\t{}\n".format(result))

    # Paste was sent. Checking for returned status code
    if not result['status']:  # return code is zero
        passphrase = paste.getHash()

        # Paste information
        print(
            "Paste uploaded!\nPasteID:\t{}\nPassword:\t{}\nDelete token:\t{}".
            format(result['id'], passphrase, result['deletetoken']))

        # Paste link
        print("\nLink:\t\t{}?{}#{}".format(settings['server'], result['id'],
                                           passphrase))

        # Paste deletion link
        print("Delete Link:\t{}?pasteid={}&deletetoken={}".format(
            settings['server'], result['id'], result['deletetoken']))

        # Print links to mirrors if present
        if settings['mirrors']:
            print("\nMirrors:")
            urls = settings['mirrors'].split(',')
            for x in urls:
                print("\t\t{}?{}#{}".format(validate_url_ending(x),
                                            result['id'], passphrase))

    elif result['status']:  # return code is other then zero
        PBinCLIError("Something went wrong…\nError:\t\t{}".format(
            result['message']))
    else:  # or here no status field in response or it is empty
        PBinCLIError("Something went wrong…\nError: Empty response.")

    if args.short:
        print("\nQuerying URL shortening service…")
        shortener.getlink("{}?{}#{}".format(settings['server'], result['id'],
                                            passphrase))