Coder Social home page Coder Social logo

wantguns / bin Goto Github PK

View Code? Open in Web Editor NEW
182.0 4.0 18.0 9.13 MB

highly opinionated, minimal pastebin

Home Page: https://basedbin.fly.dev

License: GNU Lesser General Public License v3.0

Dockerfile 2.75% Rust 62.70% Shell 1.79% CSS 13.76% JavaScript 19.00%
pastebin file-upload rust self-hosted rocket

bin's Introduction

Bin

A minimal pastebin which also accepts binary files like Images, PDFs and ships multiple clients.

It does not require you to host a SQL server and everything is self-contained in a statically linked binary (the docker image runs on scratch !), which makes it extremely easy to deploy.

Try it out on: https://basedbin.fly.dev

Clients

Web

You can paste

  • Normal Text

  • Paste Images from clipboard:
    clipboard-paste

  • Files by drag and drop:
    drag_n_drop

CLI

cli-usage

Installation

Get the client from this repository or from my deployed paste:

curl -o pst https://bin.wantguns.dev/client
chmod +x pst

or manually copy the following at a file in your path.

#!/bin/bash

# Change the url accordingly
URL="https://basedbin.fly.dev"

FILEPATH="$1"
FILENAME=$(basename -- "$FILEPATH")
EXTENSION="${FILENAME##*.}"

RESPONSE=$(curl --data-binary @${FILEPATH:-/dev/stdin} --url $URL)
PASTELINK="$URL$RESPONSE"

[ -z "$EXTENSION" ] && \
    echo "$PASTELINK" || \
    echo "$PASTELINK.$EXTENSION"

You have the option to remove the /client description / help in the landing page. To show the /client description, run the bin binary with either BIN_CLIENT_DESC env variable or a -c flag. More on arguments later

Usage

It just works.

$ pst somefile.txt
$ cat someimage.png | pst

(Neo)Vim

Installation

  1. Install the CLI client
  2. Append this to your init.vim / vimrc
nnoremap <leader>p :!pst %<CR>

Usage

Use <leader> + p paste.

Server Deployment

Currently, builds for the following target triples are shipped:

  • x86_64-unknown-linux-gnu (amd64)
  • aarch64-unknown-linux-gnu (arm64)

The builds shipped are statically linked, so you don't even need a libc to run the binary !
The docker manifest labelled wantguns/bin:latest includes the images for both amd64 and arm64 images.

Docker

$ docker run -p 6162:6162 wantguns/bin

Docker Compose

version: '3.3'
services:
  pastebin:
    image: wantguns/bin
    container_name: pastebin
    ports:
      - 127.0.0.1:6163:6163
    environment:
      - BIN_PORT=6163 # Defaults to 6162
      - BIN_LIMITS={form="16 MiB"}
      - BIN_CLIENT_DESC=placeholder
    volumes:
      - ./upload:/upload  # upload folder will have your pastes

Manual

  • Grab a copy of the binary from GH releases
    OR
  • Build on your own:
# A statically linked build
$ cargo build --release
  • Execute the binary as is, no extra shenanigans needed:
$ ./bin

Usage

USAGE:
    bin [OPTIONS]

OPTIONS:
    -a, --address <ADDRESS>
            Address on which the webserver runs [default: 127.0.0.1]

    -b, --binary-upload-limit <BINARY_UPLOAD_LIMIT>
            Binary uploads file size limit (in MiB) [default: 100]

    -c, --client-desc
            Include client description [env: CLIENT_DESC=]

    -h, --help
            Print help information

    -p, --port <PORT>
            Port on which the webserver runs [default: 6162]

    -u, --upload <UPLOAD>
            Path to the uploads folder [default: ./upload]

    -V, --version
            Print version information

Configuration

This pastebin utilizes a custom configuration provider from Rocket. Apart from the essential arguments, you can also use environment variables, which have the highest preference in order.

Everything from the official Rocket doc is supported, just that you have to prefix the env variable with "BIN_":

BIN_PORT=6163
BIN_ADDRESS=0.0.0.0
BIN_LIMITS={form="16 MiB"}
BIN_WORKERS=8
BIN_IDENT=false
...

API

GET /<id>
Get raw pastes

GET /p/<id>
Get highlighted pastes

GET /p/<id>.<ext>

Get syntax highlighted pastes.
E.g. https://basedbin.fly.dev/p/foobaz.cpp should return a C++ syntax highlighted paste

POST /
Post binary data

Design Decisions

This pastebin:

  • does not use a database. It lacks non-essential features like password-protection / automatic deletion as a result of which, it can do completely fine with flat filesystems. As an upside (opinionated), it makes deploying it easier.
  • uses server sided highlighting, which ensures that everything stays light and snappy at the client side.
  • uses very minimal frontend because a pastebin does not need it. It focuses (or atleast tries to) on getting things done in minimum amount of clicks.

Hacking

  • If you want to ensure your pushed refs will pass CI, add the prepush script to your Git hooks:

    $ cp -a tools/prepush .git/hooks/pre-push

    Alternately, just run ./tools/prepush yourself before pushing.

  • The Cargo configuration for this project is set for statically compiled builds. You can check out the config file to know more.

  • Read the buildci to know how the project is statically compiled for two architectures.

bin's People

Contributors

dok4440 avatar ellotheth avatar jonasgeiler avatar noracodes avatar sinux-l5d avatar wantguns avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bin's Issues

Feature request: File uploads from mobile

I've been using bin as a personal imgur replacement, so I'm uploading mostly images and videos. It works great in a desktop browser, but I haven't figured out how to upload from my (Android) phone, because the mobile browsers I use don't support copy/paste for media files. Would it be possible to have some sort of upload mechanism for mobile?

bug: /client not available

Hello,

I just installed bin and I like it so far :D. I noticed an incoherence : the man-like page tells that you can download the client at /client, but I get the message Unable to find entity 'client' (try https://basedbin.fly.dev/client).

I installed bin with docker(-compose).

For now I just copied/pasted the client in the upload directory.

Provide Cache-Control headers

Currently, the paste content, as well as JS and CSS content, isn't sent along with a Cache-Control header; ideally, we should provide the following:

  • max-age=[large number] to make sure clients don't have to constantly re-request pastes, CSS, and JS, which change never or rarely. Perhaps a value of 1 week or so, 604800s.
  • stale-while-revalidate=[smaller number] to allow clients to re-use cached, stale content until they can revalidate that it hasn't changed. Perhaps a value of 1 day or so, 86400s.

Additionally, only for raw pastes, we should include the immutable directive so that browsers do not attempt to refresh the contents of the pastes, which are immutable and don't change.

Missing builds for v2.3.0

Hi !

I see there is new release v2.3.0 since August 18th; however I can't see any binary attached to this release, only the source code.
Would it be possible to attach them please? I'm mainly interested in the aarch64 build.

And thanks for the great work!

Password Authentication?

Hi,

I just installed this Bin via docker and I just love the functionality and gui. Is it possible to add some form of authentication? I want to run this exposed to the internet, but since my server is at home I don't want anyone to be able to paste and share. My ideal use case is: I want to share a piece of text picture, so I open my URL, put in a password, and get a sharing link. The receiver of the share link should be able to access it without a password.
That makes me unable to use authentication via nginx or similar since you would also need a pw just to open the link.

Thanks you!

It's hard to find the wanted file type in the list

When I do a paste, and want to select the file type, the ordering of the list is not intuitive: the first 10 entries or so are a mystery to me, then the rest looks like it's sorted by the extension, but that extension is never shown.

So we end up looking for a bash highlighting near the "B", but no, it's near the "S" words, between SCSS and... "Highlight non-printable".

I would suggest to either:

  • show the extension first, so that the sorting is obvious
  • provide a search field (there is already a space between "Paste" and the list, maybe it could fit there?)
  • if only the alias is shown, actually sort by the alias string (so Bourne would be in the Bs)

Also, not related but nice-to-have, applying the selected highlight to the current text would be, well, nice.

Light mode, other configs

This looks nice.

A couple of questions (or requests if not presently possible).

  1. Any chance of a "light mode" (dark mode is bad for my eyes).
  2. Can you turn off binary pastes (or does setting -b, --binary-upload-limit <BINARY_UPLOAD_LIMIT> to 0 work?
  3. Any way to not display the text when you first visit the page (at least on your demo site)?

Not deployed yet as the dark mode is a big issue for me (as visually handicapped).

Thanks.

No "raw" link

Hi,

Yesterday I sent a diff paste to a friend, with syntax highlighting; the url was something like example.com/p/SF37PK.diff . However he wanted to download the raw text, and found no obvious way of doing that...
After a while he found out that the raw version can be accessed by stripping the file extension from the URL link.

Would it be possible to add a simple "Raw" button, that links to the same URL without the extension? It looks quite straightforward.

CORS header 'Access-Control-Allow-Origin' missing

Hello, I have a problem.
I want to get use the API to get some data I uploaded inside JavaScript but the problem is that there's no 'Access-Control-Allow-Origin' header and my browser will throw an error.

feature request: tabulation key support

Hi,

Would it be possible to enhance the web client to support the key 'tab' to indent code?
At the time of writing, it selects the adress bar on my browser.

Provide Last-Modified headers (or Etag)

We should provide a Last-Modified header which pulls its value from the paste file modification time (for pastes) or from the binary's compilation date (for CSS, JS, etc). This would allow CDN caches to revalidate simply by checking the Last-Modified date without actually transferring the body of the paste - especially good for images or large files accessed periodically.

Alternately we could provide an Etag header pulling from the current Git commit hash for CSS and JS, and from a cryptographic digest of the paste file for pastes.

Doesn't accept client description

Hi,
I am using portainer and pulled the latest bin. I must say that I am pretty new to docker, so it might just be me: I can't get the exchange of the placeholder to work.

Out of desperation (I really don't know what I am doing), I tried adding the --client-desc flag and put another env-variable without the bin_ prefix:
bin
Still the greeting page is unchanged.
Any help would be appreciated.

(also: your docker compose example show port 6163 instead of 6162)

Using a different webroot for bin

I want to host the bin from myurl.com/bin, and am using caddy as a reverse proxy. The upload page loads fine while the html is fine, the js and css are requested from /assets/... instead of /bin/assets/..., but the upload form (and all other links) route as if / was the webroot. This breaks the website unless hosted on a different domain (bin.myurl.com) or on a different port.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.