Browse Source

implement settings file

dependabot/add-v2-config-file
R4SAS 8 years ago
parent
commit
6a6427a134
  1. 2
      README.md
  2. 2
      pbincli.py
  3. 11
      pbincli/actions.py
  4. 13
      pbincli/settings.py
  5. 14
      pbincli/transports.py

2
README.md

@ -13,7 +13,7 @@ $ pip install -r requirements.txt
Usage 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: Run inside `venv` command:

2
pbincli.py

@ -6,6 +6,7 @@ import argparse
import pbincli.actions import pbincli.actions
from pbincli.utils import PBinCLIException from pbincli.utils import PBinCLIException
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(title="actions", help="List of commands") subparsers = parser.add_subparsers(title="actions", help="List of commands")
@ -54,5 +55,6 @@ def main():
else: else:
parser.print_help() parser.print_help()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

11
pbincli/actions.py

@ -1,11 +1,13 @@
import json, hashlib, ntpath, os, sys import json, hashlib, ntpath, os, sys
import pbincli.actions, pbincli.sjcl_simple import pbincli.actions, pbincli.sjcl_simple
import pbincli.settings
from base64 import b64encode, b64decode from base64 import b64encode, b64decode
from mimetypes import guess_type from mimetypes import guess_type
from pbincli.transports import privatebin from pbincli.transports import privatebin
from pbincli.utils import PBinCLIException, check_readable, check_writable, json_load_byteified from pbincli.utils import PBinCLIException, check_readable, check_writable, json_load_byteified
pbincli.settings.init()
def path_leaf(path): def path_leaf(path):
head, tail = ntpath.split(path) head, tail = ntpath.split(path)
@ -21,6 +23,9 @@ def send(args):
print("Nothing to send!") print("Nothing to send!")
sys.exit(1) sys.exit(1)
"""Formatting request"""
request = {'expire':args.expire,'formatter':args.format,'burnafterreading':int(args.burn),'opendiscussion':int(args.discus)}
salt = os.urandom(8) salt = os.urandom(8)
passphrase = b64encode(os.urandom(32)) passphrase = b64encode(os.urandom(32))
if args.debug: print("Passphrase:\t{}".format(passphrase)) if args.debug: print("Passphrase:\t{}".format(passphrase))
@ -34,8 +39,9 @@ def send(args):
if args.debug: print("Password:\t{}".format(password)) if args.debug: print("Password:\t{}".format(password))
"""Encrypting text (comment)"""
cipher = pbincli.sjcl_simple.encrypt(password, text, salt) 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 we set FILE variable"""
if args.file: if args.file:
@ -57,7 +63,8 @@ def send(args):
if args.debug: print("Request:\t{}".format(request)) 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"))) if args.debug: print("Response:\t{}\n".format(result.decode("UTF-8")))

13
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 = {}

14
pbincli/transports.py

@ -1,25 +1,25 @@
import requests import requests
import pbincli.settings
class privatebin(object): class privatebin(object):
def __init__(self): def __init__(self):
self.proxies = {'http': 'http://127.0.0.1:4444'} self.server = pbincli.settings.server
self.server = 'http://paste.r4sas.i2p/' self.proxies = pbincli.settings.proxies
self.headers = {'X-Requested-With': 'JSONHttpRequest'} self.headers = {'X-Requested-With': 'JSONHttpRequest'}
def post(self, request): def post(self, request):
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, self.server return r.text
def get(self, request): def get(self, request):
url = self.server + "?" + 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 return r.text
def delete(self, pasteid, token): def delete(self, pasteid, token):
request = {'pasteid':pasteid,'deletetoken':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 return r.text

Loading…
Cancel
Save