Difference between revisions of "Pb"

From ArchWiki
Jump to: navigation, search
(rm security section, add small note)
(Client: rewrite)
Line 18: Line 18:
== Client ==
== Client ==
=== curl ===
Like with most other pastebins pastes are created using HTTP post requests. You can therefore use {{pkg|curl}} to upload a file like this:
The {{Pkg|curl}} package is available in the {{Grp|base}} group.
curl -F c=@- <nowiki>https://ptpb.pw <</nowiki> ''file''
* [https://curl.haxx.se/docs/httpscripting.html#Forms_explained Forms explained]
* [https://curl.haxx.se/docs/manpage.html#-F -F/--form] This lets curl emulate a filled-in form in which a user has pressed the submit button. The {{ic|@}} sign forces the "content" part to be a file.
* [https://ptpb.pw/#post ptpb.pw POST/]
* [https://ptpb.pw/#get-f HTML form] (https://ptpb.pw/f)
{{Style|Taken verbatim from [[Pastebin]]}}
You can access the [https://ptpb.pw ptpb.pw], [http://sprunge.us/ sprunge.us] and [http://ix.io/ ix.io] pastebins using curl. For example pipe the output of a command to ptpb: {{bc|''command'' <nowiki>| curl -F c=@- https://ptpb.pw </nowiki>}} or upload a file (including images): {{bc|<nowiki>curl -F c=@- https://ptpb.pw < </nowiki>''file''}}
=== pbpst ===
=== pbpst ===

Revision as of 12:29, 21 August 2017

pb is a lightweight pastebin and URL shortener built, written in Python using Flask. The official instance is https://ptpb.pw/.

Note: A pastebin should not be used for sharing confidential or private information.


Install the nodejs-gruntAUR and pb-gitAUR packages, and enable pb.service.

To configure the server, edit the /etc/uwsgi/pb.ini file.


Like with most other pastebins pastes are created using HTTP post requests. You can therefore use curl to upload a file like this:

curl -F c=@- https://ptpb.pw < file


pbqst is a pb client written in C.

Note: Default ptpb.pw, pb instance can be configured

Install the pbpst package, or pbpst-gitAUR for the development version.

  • man pbpst
  • man pbpst_db

Pastes are created with -S, taking data from standard input by default. As such, shell pipes, here documents or here strings may be used. For example, to paste the output of the PRIMARY (selection) clipboard:

$ xclip -o | pbpst -S
Note: When taking standard input from a terminal, press Ctrl+D twice to process the data. [1]

A file can be uploaded with -Sf:

$ pbpst -Sf foo.txt

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Note how pbpst has "quiet" output by default, unlike the curl approach. This is however configurable (Discuss in Talk:Pb#)

For all of the commands above a response is received that contains an URL:

$ echo 'ArchLinux: livin’ on the edge!' | pbpst -S

In this example, https://ptpb.pw/qJrv is the URL at which the paste is available.

Managing pastes

To manage a paste, one needs its UUID. These are stored in a local database located in $XDG_CONFIG_HOME/pbpst/db.json. Since it's inconvenient to manually search through the database, a descriptive message may be attached to a paste and then searched for from command line. The example below creates a paste containing a random text and then deletes it (-R option):

$ thePaste="$(cat /dev/urandom | tr -cd [:print:] | head -c 32)"
$ echo "$thePaste"

$ echo "$thePaste" | pbpst -S -m 'A random test message' 

$ curl 'https://ptpb.pw/scrubbed'

$ pbpst -Dq test
deadbeef-dead-beef-dead-000000000000	https://ptpb.pw/scrubbed	A random test message	N/A

$ pbpst -Ru deadbeef-dead-beef-dead-000000000000
Paste deleted

$ curl 'https://ptpb.pw/scrubbed'
status: not found

$ pbpst -Dq test

Note that the paste is also removed from the local database, so -Dq can't find it.

One can't manage pastes for which one doesn't have UUID - this includes pastes that are, upon creation, matching already existing ones.

Tip: Finding pastes for a given URL

Currently pbpst can't search for pastes using their URL directly. However, the identifier from an address may be used to search the database. For an URL in form https://ptpb.pw/RAs8, the bold part (RAs8) is the identifier. It may be passed to -Dq to find matching entries:

$ pbpst -Dq RAs8
3bac4f7b-79dd-4eb4-b0d0-42b72f1c681e	https://ptpb.pw/AFUImP5F76wX_ZrottbtWiOfRAs8	-	N/A


By default pastes are created with no expiration time. They'll last as long as the service's operator let them. -x option may be used to set the number of seconds after which a paste should be removed:

$ thePaste="$(cat /dev/urandom | tr -cd [:print:] | head -c 32)"
$ echo "$thePaste"

$ echo "$thePaste" | pbpst -S -m 'A test message that expires after 60s' -x 60

$ date; curl 'https://ptpb.pw/scrubbed'
Tue Apr 12 19:11:41 CEST 2016

$ date; curl 'https://ptpb.pw/scrubbed'
Tue Apr 12 19:13:06 CEST 2016
status: not found

The expired pastes, while no longer available from the remote service, are still listed in the local database:

$ pbpst -Dq expires
deadbeef-dead-beef-dead-1111111111	https://ptpb.pw/scrubbed	A test message that expires after 60s	1460481140

To prune them -Dy should be used:

$ pbpst -Dy
$ pbpst -Dq expires

Shortening URLs

The -s option (lowercase -s) is used to create short URLs:

$ pbpst -s 'https://www.archlinux.org/'