|
|
@ -1,4 +1,5 @@ |
|
|
|
import requests |
|
|
|
import requests |
|
|
|
|
|
|
|
from pbincli.utils import PBinCLIError |
|
|
|
|
|
|
|
|
|
|
|
class PrivateBin: |
|
|
|
class PrivateBin: |
|
|
|
def __init__(self, settings=None): |
|
|
|
def __init__(self, settings=None): |
|
|
@ -27,8 +28,7 @@ class PrivateBin: |
|
|
|
try: |
|
|
|
try: |
|
|
|
return result.json() |
|
|
|
return result.json() |
|
|
|
except ValueError: |
|
|
|
except ValueError: |
|
|
|
print("ERROR: Unable parse response as json. Received (size = {}):\n{}".format(len(result.text), result.text)) |
|
|
|
PBinCLIError("Unable parse response as json. Received (size = {}):\n{}".format(len(result.text), result.text)) |
|
|
|
exit(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get(self, request): |
|
|
|
def get(self, request): |
|
|
@ -56,11 +56,9 @@ class PrivateBin: |
|
|
|
if not result['status']: |
|
|
|
if not result['status']: |
|
|
|
print("Paste successfully deleted!") |
|
|
|
print("Paste successfully deleted!") |
|
|
|
elif result['status']: |
|
|
|
elif result['status']: |
|
|
|
print("Something went wrong...\nError:\t\t{}".format(result['message'])) |
|
|
|
PBinCLIError("Something went wrong...\nError:\t\t{}".format(result['message'])) |
|
|
|
exit(1) |
|
|
|
|
|
|
|
else: |
|
|
|
else: |
|
|
|
print("Something went wrong...\nError: Empty response.") |
|
|
|
PBinCLIError("Something went wrong...\nError: Empty response.") |
|
|
|
exit(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getVersion(self): |
|
|
|
def getVersion(self): |
|
|
@ -74,9 +72,24 @@ class PrivateBin: |
|
|
|
else 1 |
|
|
|
else 1 |
|
|
|
|
|
|
|
|
|
|
|
class Shortener: |
|
|
|
class Shortener: |
|
|
|
def __init__(self, settings=None): |
|
|
|
"""Some parts of this class was taken from |
|
|
|
self.server = settings['server'] |
|
|
|
python-yourls (https://github.com/tflink/python-yourls/) library |
|
|
|
self.headers = {'X-Requested-With': 'JSONHttpRequest'} |
|
|
|
""" |
|
|
|
|
|
|
|
def __init__(self, apiurl, username=None, password=None, token=None, settings=None): |
|
|
|
|
|
|
|
# we checking which service is used, because some services doesn't require |
|
|
|
|
|
|
|
# any authentication, or have only one domain on which it working |
|
|
|
|
|
|
|
if settings['api'] == 'yourls': |
|
|
|
|
|
|
|
if not apiurl: |
|
|
|
|
|
|
|
PBinCLIError("YOURLS: An API URL is required") |
|
|
|
|
|
|
|
self.apiurl = apiurl |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not username or not password: |
|
|
|
|
|
|
|
if not self.token: |
|
|
|
|
|
|
|
PBinCLIError("YOURLS: username and password or token are required") |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
self.auth_args = {'signature': token} |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
self.auth_args = {'username': self.username, 'password': self.password} |
|
|
|
|
|
|
|
|
|
|
|
if settings['proxy']: |
|
|
|
if settings['proxy']: |
|
|
|
self.proxy = {settings['proxy'].split('://')[0]: settings['proxy']} |
|
|
|
self.proxy = {settings['proxy'].split('://')[0]: settings['proxy']} |
|
|
@ -90,3 +103,33 @@ class Shortener: |
|
|
|
self.session = requests.Session() |
|
|
|
self.session = requests.Session() |
|
|
|
self.session.verify = settings['nocheckcert'] |
|
|
|
self.session.verify = settings['nocheckcert'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def yourls(self, url): |
|
|
|
|
|
|
|
data_format = 'json' |
|
|
|
|
|
|
|
args = {'action': 'shorturl', 'format': data_format, 'url': url} |
|
|
|
|
|
|
|
reqest = dict(args.items() + self.auth_args.items()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = self.session.post( |
|
|
|
|
|
|
|
url = self.apiurl, |
|
|
|
|
|
|
|
proxies = self.proxy, |
|
|
|
|
|
|
|
data = request) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
result.json() |
|
|
|
|
|
|
|
if result['status'] == 'fail' and result['code'] == 'error:keyword': |
|
|
|
|
|
|
|
PBinCLIError("YOURLS: Received error from API: {}".format(result['message'])) |
|
|
|
|
|
|
|
if not 'shorturl' in result: |
|
|
|
|
|
|
|
PBinCLIError("YOURLS: Unknown error: {}".format(result['message'])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Paste short URL: {}".format(result['shorturl'])) |
|
|
|
|
|
|
|
except ValueError: |
|
|
|
|
|
|
|
PBinCLIError("YOURLS: Unable parse response. Received (size = {}):\n{}".format(len(result.text), result.text)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clck(self, url): |
|
|
|
|
|
|
|
# from urllib.parse import quote_plus |
|
|
|
|
|
|
|
request = {'url': url} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = self.session.post( |
|
|
|
|
|
|
|
url = "https://clck.ru/--", |
|
|
|
|
|
|
|
proxies = self.proxy, |
|
|
|
|
|
|
|
data = request) |
|
|
|
|
|
|
|
print("Paste short URL: {}".format(result)) |
|
|
|