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. 18
      README.md
  3. 3
      cli
  4. 14
      pbincli/actions.py

2
LICENSE

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

18
README.md

@ -17,25 +17,33 @@ Edit variables `server`, `proxies` and `useproxy` in `pbincli/settings.py` to yo @@ -17,25 +17,33 @@ Edit variables `server`, `proxies` and `useproxy` in `pbincli/settings.py` to yo
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.
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.
It must be formated like `pasteID#passphrase`. Example:
$ ./cli get 49eeb1326cfa9491#vfeortoVWaYeJlviDdhxQBtj5e0I2kArpynrtu/tnGs=
$ ./cli get 49eeb1326cfa9491#vfeortoVWaYeJlviDdhxQBtj5e0I2kArpynrtu/tnGs=
More info you can find by typing
$ ./cli [-h] {send, get, delete}
$ ./cli [-h] {send, get, delete}
License
-------
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(): @@ -19,11 +19,12 @@ def main():
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",
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("-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("-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)
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): @@ -18,7 +18,9 @@ def path_leaf(path):
def send(args):
if args.comment:
if args.stdin:
text = args.stdin.read()
elif args.comment:
text = args.comment
elif args.file:
text = "Sending a file to you!"
@ -42,7 +44,7 @@ def send(args): @@ -42,7 +44,7 @@ def send(args):
if args.debug: print("Password:\t{}".format(password))
# 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
for k in ['salt', 'iv', 'ct']: cipher[k] = cipher[k].decode()
@ -78,7 +80,7 @@ def send(args): @@ -78,7 +80,7 @@ def send(args):
server = pbincli.settings.server
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:
result = json.loads(result)
@ -115,7 +117,7 @@ def get(args): @@ -115,7 +117,7 @@ def get(args):
print("PBinCLI error: Incorrect request")
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:
result = json.loads(result)
@ -163,7 +165,7 @@ def get(args): @@ -163,7 +165,7 @@ def get(args):
print("Burn afrer reading flag found. Deleting paste...")
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:
result = json.loads(result)
@ -196,7 +198,7 @@ def delete(args): @@ -196,7 +198,7 @@ def delete(args):
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:
result = json.loads(result)

Loading…
Cancel
Save