forked from r4sas/PBinCLI
add "mirrors" option to provide urls for mirrors links (closes #33)
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
parent
6c9a5c95b6
commit
5589ba0437
@ -1,5 +1,5 @@
|
||||
from pbincli.format import Paste
|
||||
from pbincli.utils import PBinCLIError
|
||||
from pbincli.utils import PBinCLIError, validate_url
|
||||
import signal
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
@ -58,6 +58,7 @@ def send(args, api_client, settings=None):
|
||||
discussion = args.discus,
|
||||
expiration = args.expire)
|
||||
|
||||
if args.verbose: print("Sending request to server…")
|
||||
request = paste.getJSON()
|
||||
|
||||
if args.debug: print("Passphrase:\t{}\nRequest:\t{}".format(paste.getHash(), request))
|
||||
@ -74,13 +75,34 @@ def send(args, api_client, settings=None):
|
||||
if not result['status']: # return code is zero
|
||||
passphrase = paste.getHash()
|
||||
|
||||
print("Paste uploaded!\nPasteID:\t{}\nPassword:\t{}\nDelete token:\t{}\n\nLink:\t\t{}?{}#{}".format(
|
||||
# Paste information
|
||||
print("Paste uploaded!\nPasteID:\t{}\nPassword:\t{}\nDelete token:\t{}".format(
|
||||
result['id'],
|
||||
passphrase,
|
||||
result['deletetoken'],
|
||||
result['deletetoken']))
|
||||
|
||||
# Paste link
|
||||
print("\nLink:\t\t{}?{}#{}".format(
|
||||
settings['server'],
|
||||
result['id'],
|
||||
passphrase))
|
||||
|
||||
# Paste deletion link
|
||||
print("Delete Link:\t{}?pasteid={}&deletetoken={}".format(
|
||||
settings['server'],
|
||||
result['id'],
|
||||
result['deletetoken']))
|
||||
|
||||
# Print links to mirrors if present
|
||||
if settings['mirrors']:
|
||||
print("\nMirrors:")
|
||||
list = settings['mirrors'].split(',')
|
||||
for x in list:
|
||||
print("\t\t{}?{}#{}".format(
|
||||
validate_url(x),
|
||||
result['id'],
|
||||
passphrase))
|
||||
|
||||
elif result['status']: # return code is other then zero
|
||||
PBinCLIError("Something went wrong…\nError:\t\t{}".format(result['message']))
|
||||
else: # or here no status field in response or it is empty
|
||||
|
@ -5,8 +5,11 @@ import pbincli.actions
|
||||
from pbincli.api import PrivateBin
|
||||
from pbincli.utils import PBinCLIException, PBinCLIError, validate_url
|
||||
|
||||
CONFIG_PATHS = [os.path.join(".", "pbincli.conf", ),
|
||||
os.path.join(os.getenv("HOME") or "~", ".config", "pbincli", "pbincli.conf") ]
|
||||
CONFIG_PATHS = [
|
||||
os.path.join(".", "pbincli.conf", ),
|
||||
os.path.join(os.getenv("HOME") or "~", ".config", "pbincli", "pbincli.conf"),
|
||||
os.path.join(os.getenv("APPDATA"), "pbincli", "pbincli.conf"),
|
||||
]
|
||||
|
||||
def read_config(filename):
|
||||
"""Read config variables from a file"""
|
||||
@ -56,6 +59,7 @@ def main():
|
||||
send_parser.add_argument("--no-insecure-warning", default=False, action="store_true",
|
||||
help="suppress InsecureRequestWarning (only with --no-check-certificate)")
|
||||
##
|
||||
send_parser.add_argument("-L", "--mirrors", default=argparse.SUPPRESS, help="Comma-separated list of mirrors of service with scheme (default: None)")
|
||||
send_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="enable verbose output")
|
||||
send_parser.add_argument("-d", "--debug", default=False, action="store_true", help="enable debug output")
|
||||
send_parser.add_argument("--dry", default=False, action="store_true", help="invoke dry run")
|
||||
@ -97,6 +101,7 @@ def main():
|
||||
|
||||
CONFIG = {
|
||||
'server': 'https://paste.i2pd.xyz/',
|
||||
'mirrors': None, # real example for paste.i2pd.xyz: 'http://privatebin.ygg/,http://privatebin.i2p/'
|
||||
'proxy': None,
|
||||
'short_api': None,
|
||||
'short_url': None,
|
||||
|
@ -254,6 +254,7 @@ class Paste:
|
||||
self._discussion = discussion
|
||||
self._expiration = expiration
|
||||
|
||||
if self._debug: print("[Enc] Starting encyptor…")
|
||||
if self._version == 2: self._encryptV2()
|
||||
else: self._encryptV1()
|
||||
|
||||
@ -261,10 +262,13 @@ class Paste:
|
||||
def _encryptV2(self):
|
||||
from pbincli.utils import json_encode
|
||||
|
||||
if self._debug: print("[Enc] Preparing IV, Salt…")
|
||||
iv = get_random_bytes(int(self._tag_bits / 8))
|
||||
salt = get_random_bytes(self._salt_bytes)
|
||||
if self._debug: print("[Enc] Deriving Key…")
|
||||
key = self.__deriveKey(salt)
|
||||
|
||||
if self._debug: print("[Enc] Preparing aData and message…")
|
||||
# prepare encryption authenticated data and message
|
||||
adata = [
|
||||
[
|
||||
@ -286,6 +290,7 @@ class Paste:
|
||||
cipher_message['attachment'] = self._attachment
|
||||
cipher_message['attachment_name'] = self._attachment_name
|
||||
|
||||
if self._debug: print("[Enc] Encrypting message…")
|
||||
cipher = self.__initializeCipher(key, iv, adata, int(self._tag_bits /8 ))
|
||||
ciphertext, tag = cipher.encrypt_and_digest(self.__compress(json_encode(cipher_message)))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user