Browse Source

add latest changes from march'17

dependabot/add-v2-config-file
R4SAS 6 years ago
parent
commit
7a88bf2efc
  1. 1
      .gitignore
  2. 8
      README.md
  3. 3
      cli
  4. 13
      pbincli/actions.py
  5. 10
      pbincli/settings.py
  6. 5
      pbincli/transports.py
  7. 6
      pbincli/utils.py

1
.gitignore vendored

@ -1,3 +1,2 @@ @@ -1,3 +1,2 @@
__pycache__
*.pyc
venv/

8
README.md

@ -17,23 +17,23 @@ Edit variables `server`, `proxies` and `useproxy` in `pbincli/settings.py` to yo @@ -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
-------

3
pbincli.py → cli

@ -1,4 +1,4 @@ @@ -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(): @@ -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)

13
pbincli/actions.py

@ -7,7 +7,7 @@ from pbincli.transports import privatebin @@ -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): @@ -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): @@ -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): @@ -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)

10
pbincli/settings.py

@ -1,15 +1,11 @@ @@ -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

5
pbincli/transports.py

@ -4,9 +4,12 @@ import pbincli.settings @@ -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)

6
pbincli/utils.py

@ -6,18 +6,18 @@ class PBinCLIException(Exception): @@ -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),

Loading…
Cancel
Save