Browse Source

adding server and proxy parameters [2]

dependabot/add-v2-config-file
R4SAS 7 years ago
parent
commit
d91fbb4da9
  1. 5
      cli
  2. 17
      pbincli/actions.py
  3. 2
      pbincli/settings.py
  4. 25
      pbincli/transports.py

5
cli

@ -19,8 +19,9 @@ def main():
choices=["5min", "10min", "1hour", "1day", "1week", "1month", "1year", "never"], help="expiration of paste (default: 1day)") 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", send_parser.add_argument("-F", "--format", default="plaintext", action="store",
choices=["plaintext", "syntaxhighlighting", "markdown"], help="format of text (default: plaintext)") choices=["plaintext", "syntaxhighlighting", "markdown"], help="format of text (default: plaintext)")
send_parser.add_argument("-S", "--server", help="Set server to work with") send_parser.add_argument("--server", help="Set server to work with")
send_parser.add_argument("-P", "--proxy", help="Proxy address (example: socks5://127.0.0.1:9050)") send_parser.add_argument("--use-proxy", default=False, action="store_true", help="Enable using of proxy")
send_parser.add_argument("--proxy", help="Proxy address (example: socks5://127.0.0.1:9050)")
send_parser.add_argument("-t", "--text", help="comment in quotes. Ignored if used stdin") send_parser.add_argument("-t", "--text", help="comment in quotes. Ignored if used stdin")
send_parser.add_argument("-p", "--password", help="password for encrypting paste") 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("-d", "--debug", default=False, action="store_true", help="enable debug")

17
pbincli/actions.py

@ -4,14 +4,13 @@ from sjcl import SJCL
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
# Initialise settings # Initialise settings
pbincli.settings.init() pbincli.settings.init()
def path_leaf(path): def path_leaf(path):
head, tail = ntpath.split(path) head, tail = ntpath.split(path)
return tail or ntpath.basename(head) return tail or ntpath.basename(head)
@ -27,6 +26,8 @@ def compress(s):
return b64encode(''.join(map(chr, b)).encode('utf-8')) return b64encode(''.join(map(chr, b)).encode('utf-8'))
def send(args): def send(args):
api = PrivateBin(args.server, args.proxy, args.use-proxy)
if args.stdin: if args.stdin:
text = args.stdin.read() text = args.stdin.read()
elif args.text: elif args.text:
@ -87,7 +88,7 @@ def send(args):
if args.dry: sys.exit(0) if args.dry: sys.exit(0)
server = pbincli.settings.server server = pbincli.settings.server
result = privatebin().post(request) result = api.post(request)
if args.debug: print("Response:\t{}\n".format(result)) if args.debug: print("Response:\t{}\n".format(result))
@ -108,6 +109,8 @@ def send(args):
def get(args): def get(args):
api = PrivateBin(args.server, args.proxy, args.use-proxy)
pasteid, passphrase = args.pasteinfo.split("#") pasteid, passphrase = args.pasteinfo.split("#")
if pasteid and passphrase: if pasteid and passphrase:
@ -121,7 +124,7 @@ def get(args):
if args.debug: print("Password:\t{}".format(password)) if args.debug: print("Password:\t{}".format(password))
result = privatebin().get(pasteid) result = api.get(pasteid)
else: else:
print("PBinCLI error: Incorrect request") print("PBinCLI error: Incorrect request")
sys.exit(1) sys.exit(1)
@ -172,7 +175,7 @@ def get(args):
if 'burnafterreading' in result['meta'] and result['meta']['burnafterreading']: if 'burnafterreading' in result['meta'] and result['meta']['burnafterreading']:
print("Burn afrer reading flag found. Deleting paste...") print("Burn afrer reading flag found. Deleting paste...")
result = privatebin().delete(pasteid, 'burnafterreading') result = api.delete(pasteid, 'burnafterreading')
if args.debug: print("Delete response:\t{}\n".format(result)) if args.debug: print("Delete response:\t{}\n".format(result))
@ -200,12 +203,14 @@ def get(args):
def delete(args): def delete(args):
api = PrivateBin(args.server, args.proxy, args.use-proxy)
pasteid = args.paste pasteid = args.paste
token = args.token token = args.token
if args.debug: print("PasteID:\t{}\nToken:\t\t{}".format(pasteid, token)) if args.debug: print("PasteID:\t{}\nToken:\t\t{}".format(pasteid, token))
result = privatebin().delete(pasteid, token) result = api.delete(pasteid, token)
if args.debug: print("Response:\t{}\n".format(result)) if args.debug: print("Response:\t{}\n".format(result))

2
pbincli/settings.py

@ -3,7 +3,7 @@ def init():
# Edit that variables # Edit that variables
server = "https://paste.i2pd.xyz/" server = "https://paste.i2pd.xyz/"
proxies = {'socks5': 'socks5://127.0.0.1:9050'} proxy = "socks5://127.0.0.1:9050"
# True/False # True/False
useproxy = False useproxy = False

25
pbincli/transports.py

@ -1,35 +1,28 @@
import requests import requests
import pbincli.settings import pbincli.settings
class privatebin(object): class PrivateBin:
def __init__(self): def __init__(self, server = pbincli.settings.server, proxy = pbincli.settings.proxy, useproxy = pbincli.settings.useproxy):
if args.server: self.server = server
self.server = args.server
else:
self.server = pbincli.settings.server
self.headers = {'X-Requested-With': 'JSONHttpRequest'} self.headers = {'X-Requested-With': 'JSONHttpRequest'}
if useproxy:
if args.proxy: self.proxy = {proxy.split('://')[0]: proxy}
self.proxies = {args.proxy.split('://')[0]: args.proxy}
elif pbincli.settings.useproxy:
self.proxies = pbincli.settings.proxies
else: else:
self.proxies = {} self.proxy = {}
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.proxy, data = request)
return r.text 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.proxy)
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.proxy, data = request)
return r.text return r.text

Loading…
Cancel
Save