diff --git a/README.md b/README.md index 8414acc..d3bdcfc 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ $ pip install -r requirements.txt Usage ----- -Edit `self.server = 'http://paste.r4sas.i2p/'` in `pbincli/transports.py` to your server. +Edit variables `server`, `proxies` and `useproxy` in `pbincli/settings.py` to your values. Run inside `venv` command: diff --git a/pbincli.py b/pbincli.py index ac4dfa5..6ca225f 100755 --- a/pbincli.py +++ b/pbincli.py @@ -6,6 +6,7 @@ import argparse import pbincli.actions from pbincli.utils import PBinCLIException + def main(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(title="actions", help="List of commands") @@ -54,5 +55,6 @@ def main(): else: parser.print_help() + if __name__ == "__main__": main() diff --git a/pbincli/actions.py b/pbincli/actions.py index cec9ac1..567aef3 100644 --- a/pbincli/actions.py +++ b/pbincli/actions.py @@ -1,11 +1,13 @@ import json, hashlib, ntpath, os, sys import pbincli.actions, pbincli.sjcl_simple +import pbincli.settings from base64 import b64encode, b64decode from mimetypes import guess_type from pbincli.transports import privatebin from pbincli.utils import PBinCLIException, check_readable, check_writable, json_load_byteified +pbincli.settings.init() def path_leaf(path): head, tail = ntpath.split(path) @@ -21,6 +23,9 @@ def send(args): print("Nothing to send!") sys.exit(1) + """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)) @@ -34,8 +39,9 @@ def send(args): if args.debug: print("Password:\t{}".format(password)) + """Encrypting text (comment)""" cipher = pbincli.sjcl_simple.encrypt(password, text, salt) - request = {'data':json.dumps(cipher, ensure_ascii=False).replace(' ',''),'expire':args.expire,'formatter':args.format,'burnafterreading':int(args.burn),'opendiscussion':int(args.discus)} + request['data'] = json.dumps(cipher, ensure_ascii=False).replace(' ','') """If we set FILE variable""" if args.file: @@ -57,7 +63,8 @@ def send(args): if args.debug: print("Request:\t{}".format(request)) - result, server = privatebin().post(request) + server = pbincli.settings.server + result = privatebin().post(request) if args.debug: print("Response:\t{}\n".format(result.decode("UTF-8"))) diff --git a/pbincli/settings.py b/pbincli/settings.py new file mode 100644 index 0000000..cc2f1e2 --- /dev/null +++ b/pbincli/settings.py @@ -0,0 +1,13 @@ +def init(): + global server, proxies, useproxy + + """Edit that variables""" + server = "https://privatebin.net/" + proxies = {'http': 'http://127.0.0.1:4444'} + useproxy = False + + """ There is nothing more to do :D """ + + """if you set useproxy to false, we clean proxies variable""" + if useproxy == False: + proxies = {} diff --git a/pbincli/transports.py b/pbincli/transports.py index 5901797..c32c76b 100644 --- a/pbincli/transports.py +++ b/pbincli/transports.py @@ -1,25 +1,25 @@ import requests - +import pbincli.settings class privatebin(object): def __init__(self): - self.proxies = {'http': 'http://127.0.0.1:4444'} - self.server = 'http://paste.r4sas.i2p/' + self.server = pbincli.settings.server + self.proxies = pbincli.settings.proxies self.headers = {'X-Requested-With': 'JSONHttpRequest'} def post(self, request): - r = requests.post(url=self.server, headers=self.headers, proxies=self.proxies, data=request) - return r.text, self.server + r = requests.post(url = self.server, headers = self.headers, proxies = self.proxies, data = request) + return r.text def get(self, request): url = self.server + "?" + request - r = requests.get(url=url, headers=self.headers, proxies=self.proxies) + r = requests.get(url = url, headers = self.headers, proxies = self.proxies) return r.text def delete(self, pasteid, token): request = {'pasteid':pasteid,'deletetoken':token} - r = requests.post(url=self.server, headers=self.headers, proxies=self.proxies, data=request) + r = requests.post(url = self.server, headers = self.headers, proxies = self.proxies, data = request) return r.text