Browse Source

add "mirrors" option to provide urls for mirrors links (closes #33)

Signed-off-by: R4SAS <r4sas@i2pmail.org>
gha
R4SAS 3 years ago
parent
commit
5589ba0437
Signed by untrusted user: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 28
      pbincli/actions.py
  2. 9
      pbincli/cli.py
  3. 5
      pbincli/format.py

28
pbincli/actions.py

@ -1,5 +1,5 @@
from pbincli.format import Paste from pbincli.format import Paste
from pbincli.utils import PBinCLIError from pbincli.utils import PBinCLIError, validate_url
import signal import signal
def signal_handler(sig, frame): def signal_handler(sig, frame):
@ -58,6 +58,7 @@ def send(args, api_client, settings=None):
discussion = args.discus, discussion = args.discus,
expiration = args.expire) expiration = args.expire)
if args.verbose: print("Sending request to server…")
request = paste.getJSON() request = paste.getJSON()
if args.debug: print("Passphrase:\t{}\nRequest:\t{}".format(paste.getHash(), request)) 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 if not result['status']: # return code is zero
passphrase = paste.getHash() 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'], result['id'],
passphrase, passphrase,
result['deletetoken'], result['deletetoken']))
# Paste link
print("\nLink:\t\t{}?{}#{}".format(
settings['server'], settings['server'],
result['id'], result['id'],
passphrase)) 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 elif result['status']: # return code is other then zero
PBinCLIError("Something went wrong…\nError:\t\t{}".format(result['message'])) PBinCLIError("Something went wrong…\nError:\t\t{}".format(result['message']))
else: # or here no status field in response or it is empty else: # or here no status field in response or it is empty

9
pbincli/cli.py

@ -5,8 +5,11 @@ import pbincli.actions
from pbincli.api import PrivateBin from pbincli.api import PrivateBin
from pbincli.utils import PBinCLIException, PBinCLIError, validate_url from pbincli.utils import PBinCLIException, PBinCLIError, validate_url
CONFIG_PATHS = [os.path.join(".", "pbincli.conf", ), CONFIG_PATHS = [
os.path.join(os.getenv("HOME") or "~", ".config", "pbincli", "pbincli.conf") ] 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): def read_config(filename):
"""Read config variables from a file""" """Read config variables from a file"""
@ -56,6 +59,7 @@ def main():
send_parser.add_argument("--no-insecure-warning", default=False, action="store_true", send_parser.add_argument("--no-insecure-warning", default=False, action="store_true",
help="suppress InsecureRequestWarning (only with --no-check-certificate)") 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("-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("-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") send_parser.add_argument("--dry", default=False, action="store_true", help="invoke dry run")
@ -97,6 +101,7 @@ def main():
CONFIG = { CONFIG = {
'server': 'https://paste.i2pd.xyz/', 'server': 'https://paste.i2pd.xyz/',
'mirrors': None, # real example for paste.i2pd.xyz: 'http://privatebin.ygg/,http://privatebin.i2p/'
'proxy': None, 'proxy': None,
'short_api': None, 'short_api': None,
'short_url': None, 'short_url': None,

5
pbincli/format.py

@ -254,6 +254,7 @@ class Paste:
self._discussion = discussion self._discussion = discussion
self._expiration = expiration self._expiration = expiration
if self._debug: print("[Enc] Starting encyptor…")
if self._version == 2: self._encryptV2() if self._version == 2: self._encryptV2()
else: self._encryptV1() else: self._encryptV1()
@ -261,10 +262,13 @@ class Paste:
def _encryptV2(self): def _encryptV2(self):
from pbincli.utils import json_encode from pbincli.utils import json_encode
if self._debug: print("[Enc] Preparing IV, Salt…")
iv = get_random_bytes(int(self._tag_bits / 8)) iv = get_random_bytes(int(self._tag_bits / 8))
salt = get_random_bytes(self._salt_bytes) salt = get_random_bytes(self._salt_bytes)
if self._debug: print("[Enc] Deriving Key…")
key = self.__deriveKey(salt) key = self.__deriveKey(salt)
if self._debug: print("[Enc] Preparing aData and message…")
# prepare encryption authenticated data and message # prepare encryption authenticated data and message
adata = [ adata = [
[ [
@ -286,6 +290,7 @@ class Paste:
cipher_message['attachment'] = self._attachment cipher_message['attachment'] = self._attachment
cipher_message['attachment_name'] = self._attachment_name 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 )) cipher = self.__initializeCipher(key, iv, adata, int(self._tag_bits /8 ))
ciphertext, tag = cipher.encrypt_and_digest(self.__compress(json_encode(cipher_message))) ciphertext, tag = cipher.encrypt_and_digest(self.__compress(json_encode(cipher_message)))

Loading…
Cancel
Save