diff --git a/.gitignore b/.gitignore index b6424f1..a3807e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -__pycache__ *.pyc venv/ diff --git a/README.md b/README.md index a776542..8ee187b 100644 --- a/README.md +++ b/README.md @@ -17,23 +17,23 @@ Edit variables `server`, `proxies` and `useproxy` in `pbincli/settings.py` to yo Run inside `venv` command: - $ python pbincli.py send -c "Hello!" + $ ./cli send -c "Hello!" It will send string `Hello!` to PrivateBin. To send file use `--file` or `-f` with filename. Example: - $ python pbincli.py 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: - $ python pbincli.py get 49eeb1326cfa9491#vfeortoVWaYeJlviDdhxQBtj5e0I2kArpynrtu/tnGs= + $ ./cli get 49eeb1326cfa9491#vfeortoVWaYeJlviDdhxQBtj5e0I2kArpynrtu/tnGs= More info you can find by typing - $ python pbincli.py {send,get} -h + $ ./cli [-h] {send, get, delete} License ------- diff --git a/pbincli.py b/cli similarity index 95% rename from pbincli.py rename to cli index c6580e4..9a190d3 100755 --- a/pbincli.py +++ b/cli @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#!/usr/bin/env python2.7 import os, sys, argparse import pbincli.actions from pbincli.utils import PBinCLIException @@ -22,6 +22,7 @@ def main(): send_parser.add_argument("-c", "--comment", help="comment in quotes") 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.set_defaults(func=pbincli.actions.send) diff --git a/pbincli/actions.py b/pbincli/actions.py index fc16fbe..9455642 100644 --- a/pbincli/actions.py +++ b/pbincli/actions.py @@ -7,7 +7,7 @@ from pbincli.transports import privatebin from pbincli.utils import PBinCLIException, check_readable, check_writable, json_load_byteified -""" Initialise settings """ +# Initialise settings pbincli.settings.init() @@ -25,14 +25,14 @@ def send(args): print("Nothing to send!") sys.exit(1) - """Formatting request""" + # Formatting request request = {'expire':args.expire,'formatter':args.format,'burnafterreading':int(args.burn),'opendiscussion':int(args.discus)} salt = os.urandom(8) passphrase = b64encode(os.urandom(32)) if args.debug: print("Passphrase:\t{}".format(passphrase)) - """If we set PASSWORD variable""" + # If we set PASSWORD variable if args.password: digest = hashlib.sha256(args.password.encode("UTF-8")).hexdigest() password = passphrase + digest.encode("UTF-8") @@ -41,11 +41,11 @@ def send(args): if args.debug: print("Password:\t{}".format(password)) - """Encrypting text (comment)""" + # Encrypting text (comment) cipher = pbincli.sjcl_simple.encrypt(password, text, salt) request['data'] = json.dumps(cipher, ensure_ascii=False).replace(' ','') - """If we set FILE variable""" + # If we set FILE variable if args.file: check_readable(args.file) with open(args.file, "rb") as f: @@ -65,6 +65,9 @@ def send(args): if args.debug: print("Request:\t{}".format(request)) + # If we use dry option, exit now + if args.dry: sys.exit(0) + server = pbincli.settings.server result = privatebin().post(request) diff --git a/pbincli/settings.py b/pbincli/settings.py index fa523b0..d67ecb2 100644 --- a/pbincli/settings.py +++ b/pbincli/settings.py @@ -1,15 +1,11 @@ def init(): global server, proxies, useproxy - """ Edit that variables """ + # Edit that variables server = "http://paste.r4sas.i2p/" proxies = {'http': 'http://127.0.0.1:4444'} - """ True/False """ + # True/False useproxy = True - """ There is nothing more to do :D """ - - """if you set useproxy to false, we clean proxies variable""" - if useproxy == False: - proxies = {} + # There is nothing more to do :D diff --git a/pbincli/transports.py b/pbincli/transports.py index c32c76b..eb09e80 100644 --- a/pbincli/transports.py +++ b/pbincli/transports.py @@ -4,9 +4,12 @@ import pbincli.settings class privatebin(object): def __init__(self): self.server = pbincli.settings.server - self.proxies = pbincli.settings.proxies self.headers = {'X-Requested-With': 'JSONHttpRequest'} + if pbincli.settings.useproxy: + self.proxies = pbincli.settings.proxies + else: + self.proxies = {} def post(self, request): r = requests.post(url = self.server, headers = self.headers, proxies = self.proxies, data = request) diff --git a/pbincli/utils.py b/pbincli/utils.py index f0b76bd..f8c9ae4 100644 --- a/pbincli/utils.py +++ b/pbincli/utils.py @@ -6,18 +6,18 @@ class PBinCLIException(Exception): def check_readable(f): - """Checks if path exists and readable""" + # Checks if path exists and readable if not os.path.exists(f) or not os.access(f, os.R_OK): raise PBinCLIException("Error accessing path: {}".format(f)) def check_writable(f): - """Checks if path is writable""" + # Checks if path is writable if not os.access(os.path.dirname(f) or ".", os.W_OK): raise PBinCLIException("Path is not writable: {}".format(f)) -"""http://stackoverflow.com/a/33571117""" +# http://stackoverflow.com/a/33571117 def json_load_byteified(file_handle): return _byteify( json.load(file_handle, object_hook=_byteify),