r4sas / PBinCLI

PrivateBin CLI on python 3
MIT License
65 stars 25 forks source link

feature request - fetch shortened url with urlshortener #19

Closed muralikodali closed 5 years ago

muralikodali commented 5 years ago

Privatebin provides urlshortener buttion. When configured with self hosted server like yourls , it will be very convenient to send urls ( as privatebin urls are very lengthy ). I request you to provide a commandline option for url shortening.

r4sas commented 5 years ago

Shortening for sending, receiving, or both?

muralikodali commented 5 years ago

On 15 September 2019 11:52:58 AM IST, R4SAS notifications@github.com wrote:

Shortening for sending, receiving, or both?

It will be a neat feature, if we get lengthy URL shortened ( shown in the terminal and copied to clipboard) before we send it to others. Not for receiving URLs. YOURLS with with an API and secret is convenient for this. -- Regards, Murali Kodali

r4sas commented 5 years ago

Latest commit adds support of URL shorteners, but currently I checked it only with clck.ru service. Please check it with YOURLS.

New switches for send command:

  -S, --short           use URL shortener
  --short-api {clckru,yourls}
                        API used by shortener service
  --short-url SHORT_URL
                        URL of shortener service API
  --short-user SHORT_USER
                        Shortener username
  --short-pass SHORT_PASS
                        Shortener password
  --short-token SHORT_TOKEN
                        Shortener token

That options also can be provided in config: https://github.com/r4sas/PBinCLI/blob/432675f2e6ea935c047b73b33c402bca8e12003a/pbincli/cli.py#L81-L85

Test output:

$ pbincli send -d -S --short-api clckru -t "test!"
Set paste version to 1
Password:       b'WLJpQMxG4QDdcQ5e7O8AY1FVDeaQf5Oyp8jzpOnmDSs='
Passphrase:     WLJpQMxG4QDdcQ5e7O8AY1FVDeaQf5Oyp8jzpOnmDSs=
Request:        {'opendiscussion': 0, 'data': b'{"adata":"","cipher":"aes","iv":"ZL8kb5vkTfUhBnyI1kUx7g==","v":1,"ts":128,"ks":128,"salt":"SKTSF9zYfog=","mode":"gcm","ct":"ybN9lHL6icU6GRtrPr49GLJhgFv7sXMYaEc/HA==","iter":10000}', 'expire': '1day', 'burnafterreading': 0, 'formatter': 'plaintext'}
Response:       {'url': '/?c42b4e37d00fcc6e', 'status': 0, 'deletetoken': '98f047414d402d5ccc668ef17e9a865a26aef226db71319449229be5cb263726', 'id': 'c42b4e37d00fcc6e'}

Paste uploaded!
PasteID:        c42b4e37d00fcc6e
Password:       WLJpQMxG4QDdcQ5e7O8AY1FVDeaQf5Oyp8jzpOnmDSs=
Delete token:   98f047414d402d5ccc668ef17e9a865a26aef226db71319449229be5cb263726

Link:           https://paste.i2pd.xyz/?c42b4e37d00fcc6e#WLJpQMxG4QDdcQ5e7O8AY1FVDeaQf5Oyp8jzpOnmDSs=
Short Link:     https://clck.ru/J98sF
muralikodali commented 5 years ago

with yourls , output is given under:

Traceback (most recent call last): File "/home/murali/.pyenv/versions/3.6.0/bin/pbincli", line 11, in load_entry_point('PBinCLI==0.2.2b1', 'console_scripts', 'pbincli')() File "/home/zenova/projects/pyenv/.pyenv/versions/3.6.0/lib/python3.6/site-packages/PBinCLI-0.2.2b1-py3.6.egg/pbincli/cli.py", line 117, in main File "/home/zenova/projects/pyenv/.pyenv/versions/3.6.0/lib/python3.6/site-packages/PBinCLI-0.2.2b1-py3.6.egg/pbincli/actions.py", line 79, in send File "/home/zenova/projects/pyenv/.pyenv/versions/3.6.0/lib/python3.6/site-packages/PBinCLI-0.2.2b1-py3.6.egg/pbincli/api.py", line 112, in getlink TypeError: unsupported operand type(s) for +: 'dict_items' and 'dict_items'

r4sas commented 5 years ago

try this: https://github.com/r4sas/PBinCLI/commit/641c55a6a21aaead586e7b585d1190446451ea70

muralikodali commented 5 years ago

After giving back full length of url, output shows like this: Traceback (most recent call last):

File "/home/murali/.pyenv/versions/3.6.0/bin/pbincli", line 11, in load_entry_point('PBinCLI==0.2.2b1', 'console_scripts', 'pbincli')() File "/home/zenova/projects/pyenv/.pyenv/versions/3.6.0/lib/python3.6/site-packages/PBinCLI-0.2.2b1-py3.6.egg/pbincli/cli.py", line 117, in main File "/home/zenova/projects/pyenv/.pyenv/versions/3.6.0/lib/python3.6/site-packages/PBinCLI-0.2.2b1-py3.6.egg/pbincli/actions.py", line 79, in send File "/home/zenova/projects/pyenv/.pyenv/versions/3.6.0/lib/python3.6/site-packages/PBinCLI-0.2.2b1-py3.6.egg/pbincli/api.py", line 120, in getlink TypeError: 'Response' object is not subscriptable

r4sas commented 5 years ago

Please try again with latest commit.

muralikodali commented 5 years ago

with any of parameters (username and password or secret token) output is: PBinCLI Error: YOURLS: No status, code and message fields in response! Received: along with json output showing keyword: "shorturl" shorturl:"full length url" and status code: 200

with all parameters of login given on commandline (username,password,secret token) output is: PBinCLI Error: YOURLS: either username and password or token are required. Otherwise set to default (None).

r4sas commented 5 years ago

@muralikodali can you send me to email r4sas@i2pd.xyz access info to your "yourls" instance with temporary user?

r4sas commented 5 years ago

@muralikodali thank you for providing credentials, now all must work as expected.

Will write ASAP documentation about YOURLS shortener support. idk, maybe make required only path to shortener without yourls-api.php part (just check and add it when initializing Shortener class)?

muralikodali commented 5 years ago

Thank you very much. It is now working nice.