Compare commits

...

3 Commits

Author SHA1 Message Date
R4SAS 7413bad322
[gha] update used actions 2 years ago
R4SAS ee11c06eda
add `output` option to README (#40) 2 years ago
R4SAS a7d62df966
add get --output option for decoded data (#40) 2 years ago
  1. 6
      .github/workflows/binary.yml
  2. 1
      README.md
  3. 3
      README.rst
  4. 25
      pbincli/actions.py
  5. 2
      pbincli/cli.py
  6. 11
      pbincli/utils.py

6
.github/workflows/binary.yml

@ -7,9 +7,9 @@ jobs:
name: Binary for windows name: Binary for windows
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Setup python 3.8 - name: Setup python 3.8
uses: actions/setup-python@v2 uses: actions/setup-python@v4
with: with:
python-version: 3.8 python-version: 3.8
- name: Build executable with pyinstaller - name: Build executable with pyinstaller
@ -18,7 +18,7 @@ jobs:
pip install . pip install .
pip install pyinstaller pywin32-ctypes pip install pyinstaller pywin32-ctypes
pyinstaller pbincli.spec pyinstaller pbincli.spec
- uses: actions/upload-artifact@v2 - uses: actions/upload-artifact@v3
with: with:
name: pbincli-windows name: pbincli-windows
path: dist/* path: dist/*

1
README.md

@ -54,6 +54,7 @@ proxy=http://127.0.0.1:3128
| short_user | None | Used only in `yourls` | | short_user | None | Used only in `yourls` |
| short_pass | None | Used only in `yourls` | | short_pass | None | Used only in `yourls` |
| short_token | None | Used only in `yourls` | | short_token | None | Used only in `yourls` |
| output | None | Path to the directory where the received data will be saved |
| no_check_certificate | False | True / False | | no_check_certificate | False | True / False |
| no_insecure_warning | False | True / False | | no_insecure_warning | False | True / False |
| compression | zlib | zlib / none | | compression | zlib | zlib / none |

3
README.rst

@ -104,6 +104,9 @@ List of OPTIONS available
* - short_token * - short_token
- None - None
- Used only in ``yourls`` - Used only in ``yourls``
* - output
- None
- Path to the directory where the received data will be saved
* - no_check_certificate * - no_check_certificate
- False - False
- True / False - True / False

25
pbincli/actions.py

@ -3,7 +3,7 @@ from urllib.parse import parse_qsl
from pbincli.api import Shortener from pbincli.api import Shortener
from pbincli.format import Paste from pbincli.format import Paste
from pbincli.utils import PBinCLIError, check_writable, json_encode, uri_validator, validate_url_ending from pbincli.utils import PBinCLIError, check_writable, json_encode, uri_validator, validate_url_ending, validate_path_ending
def signal_handler(sig, frame): def signal_handler(sig, frame):
@ -166,21 +166,30 @@ def get(args, api_client, settings=None):
if len(text): if len(text):
if args.debug: print("{}\n".format(text.decode())) if args.debug: print("{}\n".format(text.decode()))
filename = "paste-" + pasteid + ".txt" if settings['output']:
print("Found text in paste. Saving it to {}".format(filename)) paste_path = validate_path_ending(settings['output']) + "paste-" + pasteid + ".txt"
else:
paste_path = "paste-" + pasteid + ".txt"
print("Found text in paste. Saving it to {}".format(paste_path))
check_writable(filename) check_writable(paste_path)
with open(filename, "wb") as f: with open(paste_path, "wb") as f:
f.write(text) f.write(text)
f.close() f.close()
attachment, attachment_name = paste.getAttachment() attachment, attachment_name = paste.getAttachment()
if attachment: if attachment:
print("Found file, attached to paste. Saving it to {}\n".format(attachment_name)) if settings['output']:
attachment_path = validate_path_ending(settings['output']) + attachment_name
else:
attachment_path = attachment_name
print("Found file, attached to paste. Saving it to {}\n".format(attachment_path))
check_writable(attachment_name) check_writable(attachment_path)
with open(attachment_name, "wb") as f: with open(attachment_path, "wb") as f:
f.write(attachment) f.write(attachment)
f.close() f.close()

2
pbincli/cli.py

@ -81,6 +81,7 @@ def main():
get_parser = subparsers.add_parser("get", description="Get data from PrivateBin instance") get_parser = subparsers.add_parser("get", description="Get data from PrivateBin instance")
get_parser.add_argument("pasteinfo", help="\"PasteID#Passphrase\" or full URL") get_parser.add_argument("pasteinfo", help="\"PasteID#Passphrase\" or full URL")
get_parser.add_argument("-p", "--password", help="Password for decrypting paste") get_parser.add_argument("-p", "--password", help="Password for decrypting paste")
get_parser.add_argument("-o", "--output", default=argparse.SUPPRESS, help="Path to directory where decoded paste data will be saved")
## Connection options ## Connection options
get_parser.add_argument("-s", "--server", default=argparse.SUPPRESS, help="Instance URL (default: https://paste.i2pd.xyz/, ignored if URL used in pasteinfo)") get_parser.add_argument("-s", "--server", default=argparse.SUPPRESS, help="Instance URL (default: https://paste.i2pd.xyz/, ignored if URL used in pasteinfo)")
get_parser.add_argument("-x", "--proxy", default=argparse.SUPPRESS, help="Proxy server address (default: None)") get_parser.add_argument("-x", "--proxy", default=argparse.SUPPRESS, help="Proxy server address (default: None)")
@ -124,6 +125,7 @@ def main():
'short_user': None, 'short_user': None,
'short_pass': None, 'short_pass': None,
'short_token': None, 'short_token': None,
'output': None,
'no_check_certificate': False, 'no_check_certificate': False,
'no_insecure_warning': False, 'no_insecure_warning': False,
'compression': None 'compression': None

11
pbincli/utils.py

@ -1,4 +1,5 @@
import json, ntpath, os, sys import json, ntpath, os, sys
from platform import system
class PBinCLIException(Exception): class PBinCLIException(Exception):
pass pass
@ -35,6 +36,16 @@ def validate_url_ending(s):
s = s + "/" s = s + "/"
return s return s
def validate_path_ending(s):
if system() == 'Windows':
slash = '\\'
else:
slash = '/'
if not s.endswith(slash):
s = s + slash
return s
def uri_validator(x): def uri_validator(x):
from urllib.parse import urlsplit from urllib.parse import urlsplit
try: try:

Loading…
Cancel
Save