Browse Source

implement read text from stdin (closes #3)

fix debug output
dependabot/add-v2-config-file
R4SAS 7 years ago
parent
commit
4af4797812
  1. 2
      LICENSE
  2. 10
      README.md
  3. 3
      cli
  4. 14
      pbincli/actions.py

2
LICENSE

@ -1,7 +1,7 @@
DWTFYWWI LICENSE DWTFYWWI LICENSE
Version 1, January 2006 Version 1, January 2006
Copyright (C) 2006 Ævar Arnfjörð Bjarmason Copyright (C) 2017-2018 R4SAS <r4sas@i2pmail.org>
Preamble Preamble

10
README.md

@ -19,12 +19,20 @@ Run inside `venv` command:
$ ./cli send -c "Hello!" $ ./cli send -c "Hello!"
Or use stdin input to read text for paste:
$ ./cli send - <<EOF
Hello!
This is test paste!
EOF
It will send string `Hello!` to PrivateBin. It will send string `Hello!` to PrivateBin.
To send file use `--file` or `-f` with filename. Example: To send file use `--file` or `-f` with filename. Example:
$ ./cli send -c "My document" -f info.pdf $ ./cli send -c "My document" -f info.pdf
To retrieve paste from server, use `get` command with paste info. To retrieve paste from server, use `get` command with paste info.
It must be formated like `pasteID#passphrase`. Example: It must be formated like `pasteID#passphrase`. Example:
@ -38,4 +46,4 @@ More info you can find by typing
License License
------- -------
This project is licensed under the DWTFYWWI license, which can be found in the file This project is licensed under the DWTFYWWI license, which can be found in the file
LICENSE in the root of the project source code. [LICENSE](LICENSE) in the root of the project source code.

3
cli

@ -19,11 +19,12 @@ def main():
choices=["5min", "10min", "1hour", "1day", "1week", "1month", "1year", "never"], help="expiration of paste (default: 1day)") choices=["5min", "10min", "1hour", "1day", "1week", "1month", "1year", "never"], help="expiration of paste (default: 1day)")
send_parser.add_argument("-F", "--format", default="plaintext", action="store", send_parser.add_argument("-F", "--format", default="plaintext", action="store",
choices=["plaintext", "syntaxhighlighting", "markdown"], help="format of comment (default: plaintext)") choices=["plaintext", "syntaxhighlighting", "markdown"], help="format of comment (default: plaintext)")
send_parser.add_argument("-c", "--comment", help="comment in quotes") send_parser.add_argument("-c", "--comment", help="comment in quotes. Ignored if used stdin")
send_parser.add_argument("-p", "--password", help="password for encrypting paste") send_parser.add_argument("-p", "--password", help="password for encrypting paste")
send_parser.add_argument("-d", "--debug", default=False, action="store_true", help="enable debug") send_parser.add_argument("-d", "--debug", default=False, action="store_true", help="enable debug")
send_parser.add_argument("--dry", default=False, action="store_true", help="invoke dry run") send_parser.add_argument("--dry", default=False, action="store_true", help="invoke dry run")
send_parser.add_argument("-f", "--file", help="example: image.jpg or full path to file") send_parser.add_argument("-f", "--file", help="example: image.jpg or full path to file")
send_parser.add_argument("stdin", help="input paste text from stdin", nargs="?", type=argparse.FileType("r"), default=sys.stdin)
send_parser.set_defaults(func=pbincli.actions.send) send_parser.set_defaults(func=pbincli.actions.send)
get_parser = subparsers.add_parser("get", description="Get data from PrivateBin instance", usage=""" get_parser = subparsers.add_parser("get", description="Get data from PrivateBin instance", usage="""

14
pbincli/actions.py

@ -18,7 +18,9 @@ def path_leaf(path):
def send(args): def send(args):
if args.comment: if args.stdin:
text = args.stdin.read()
elif args.comment:
text = args.comment text = args.comment
elif args.file: elif args.file:
text = "Sending a file to you!" text = "Sending a file to you!"
@ -42,7 +44,7 @@ def send(args):
if args.debug: print("Password:\t{}".format(password)) if args.debug: print("Password:\t{}".format(password))
# Encrypting text (comment) # Encrypting text (comment)
cipher = SJCL().encrypt(text.encode("utf-8"), password, mode='gcm') cipher = SJCL().encrypt(text.encode("UTF-8"), password, mode='gcm')
# TODO: should be implemented in upstream # TODO: should be implemented in upstream
for k in ['salt', 'iv', 'ct']: cipher[k] = cipher[k].decode() for k in ['salt', 'iv', 'ct']: cipher[k] = cipher[k].decode()
@ -78,7 +80,7 @@ def send(args):
server = pbincli.settings.server server = pbincli.settings.server
result = privatebin().post(request) result = privatebin().post(request)
if args.debug: print("Response:\t{}\n".format(result.decode("UTF-8"))) if args.debug: print("Response:\t{}\n".format(result))
try: try:
result = json.loads(result) result = json.loads(result)
@ -115,7 +117,7 @@ def get(args):
print("PBinCLI error: Incorrect request") print("PBinCLI error: Incorrect request")
sys.exit(1) sys.exit(1)
if args.debug: print("Response:\t{}\n".format(result.decode("UTF-8"))) if args.debug: print("Response:\t{}\n".format(result))
try: try:
result = json.loads(result) result = json.loads(result)
@ -163,7 +165,7 @@ def get(args):
print("Burn afrer reading flag found. Deleting paste...") print("Burn afrer reading flag found. Deleting paste...")
result = privatebin().delete(pasteid, 'burnafterreading') result = privatebin().delete(pasteid, 'burnafterreading')
if args.debug: print("Delete response:\t{}\n".format(result.decode("UTF-8"))) if args.debug: print("Delete response:\t{}\n".format(result))
try: try:
result = json.loads(result) result = json.loads(result)
@ -196,7 +198,7 @@ def delete(args):
result = privatebin().delete(pasteid, token) result = privatebin().delete(pasteid, token)
if args.debug: print("Response:\t{}\n".format(result.decode("UTF-8"))) if args.debug: print("Response:\t{}\n".format(result))
try: try:
result = json.loads(result) result = json.loads(result)

Loading…
Cancel
Save