mirror of
https://github.com/r4sas/PBinCLI
synced 2025-01-08 22:08:00 +00:00
[wip] url shortener support (#19)
Signed-off-by: r4sas <r4sas@i2pmail.org>
This commit is contained in:
parent
7c5ba2fdbe
commit
6b6c33e545
@ -1,8 +1,8 @@
|
||||
import requests
|
||||
|
||||
class PrivateBin:
|
||||
def __init__(self, server, settings=None):
|
||||
self.server = server
|
||||
def __init__(self, settings=None):
|
||||
self.server = settings['server']
|
||||
self.headers = {'X-Requested-With': 'JSONHttpRequest'}
|
||||
|
||||
if settings['proxy']:
|
||||
@ -72,3 +72,21 @@ class PrivateBin:
|
||||
'v' in jsonldSchema['@context'] and
|
||||
'@value' in jsonldSchema['@context']['v']) \
|
||||
else 1
|
||||
|
||||
class Shortener:
|
||||
def __init__(self, settings=None):
|
||||
self.server = settings['server']
|
||||
self.headers = {'X-Requested-With': 'JSONHttpRequest'}
|
||||
|
||||
if settings['proxy']:
|
||||
self.proxy = {settings['proxy'].split('://')[0]: settings['proxy']}
|
||||
else:
|
||||
self.proxy = {}
|
||||
|
||||
if settings['noinsecurewarn']:
|
||||
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||
|
||||
self.session = requests.Session()
|
||||
self.session.verify = settings['nocheckcert']
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
import os, sys, argparse
|
||||
|
||||
import pbincli.actions
|
||||
from pbincli.api import PrivateBin
|
||||
from pbincli.api import PrivateBin, Shortener
|
||||
from pbincli.utils import PBinCLIException, validate_url
|
||||
|
||||
CONFIG_PATHS = [os.path.join(".", "pbincli.conf", ),
|
||||
@ -36,8 +36,18 @@ def main():
|
||||
send_parser.add_argument("-q", "--notext", default=False, action="store_true", help="don't send text in paste")
|
||||
send_parser.add_argument("-c", "--compression", default="zlib", action="store",
|
||||
choices=["zlib", "none"], help="set compression for paste (default: zlib). Note: works only on v2 paste format")
|
||||
# URL shortener
|
||||
send_parser.add_argument("-s", "--shorten", default=False, action="store_true", help="use URL shortener")
|
||||
send_parser.add_argument("--shorten-api", default="yourls", action="store",
|
||||
choices=["yourls"], help="select API used for selected URL shortener service")
|
||||
send_parser.add_argument("--shorten-url", help="URL of shortener service API")
|
||||
send_parser.add_argument("--shorten-user", help="Shortener username")
|
||||
send_parser.add_argument("--shorten-pass", help="Shortener password")
|
||||
send_parser.add_argument("--shorten-token", help="Shortener token")
|
||||
# Certificates check bypass
|
||||
send_parser.add_argument("--no-check-certificate", default=True, action="store_false", help="disable certificate validation")
|
||||
send_parser.add_argument("--no-insecure-warning", default=False, action="store_true", help="suppress InsecureRequestWarning (only with --no-check-certificate)")
|
||||
#
|
||||
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("stdin", help="input paste text from stdin", nargs="?", type=argparse.FileType("r"), default=sys.stdin)
|
||||
@ -78,15 +88,14 @@ def main():
|
||||
var = "PRIVATEBIN_{}".format(key.upper())
|
||||
if var in os.environ: CONFIG[key] = os.getenv(var)
|
||||
|
||||
PBIN_URL = validate_url(CONFIG["server"])
|
||||
|
||||
SETTINGS = {
|
||||
"server" : validate_url(CONFIG["server"])
|
||||
"proxy": CONFIG["proxy"],
|
||||
"nocheckcert": args.no_check_certificate,
|
||||
"noinsecurewarn": args.no_insecure_warning
|
||||
}
|
||||
|
||||
api_client = PrivateBin(PBIN_URL, settings=SETTINGS)
|
||||
api_client = PrivateBin(SETTINGS)
|
||||
|
||||
if hasattr(args, "func"):
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user