• Stars
    star
    460
  • Rank 91,996 (Top 2 %)
  • Language
    Rust
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A minimal file upload/pastebin service.

GitHub Release Crate Release Coverage Continuous Integration Continuous Deployment Docker Builds Documentation

Rustypaste is a minimal file upload/pastebin service.

$ echo "some text" > awesome.txt

$ curl -F "[email protected]" https://paste.site.com
https://paste.site.com/safe-toad.txt

$ curl https://paste.site.com/safe-toad.txt
some text

The public instance is available at https://rustypaste.shuttleapp.rs ๐Ÿš€

Here you can read the blog post about how it is deployed on Shuttle: https://blog.orhun.dev/blazingly-fast-file-sharing

Table of Contents

Features

  • File upload & URL shortening & upload from URL
    • supports basic HTTP authentication
    • random file names (optional)
      • pet name (e.g. capital-mosquito.txt)
      • alphanumeric string (e.g. yB84D2Dv.txt)
      • random suffix (e.g. file.MRV5as.tar.gz)
    • supports expiring links
      • auto-expiration of files (optional)
      • auto-deletion of expired files (optional)
    • supports one shot links/URLs (can only be viewed once)
    • guesses MIME types
      • supports overriding and blacklisting
      • supports forcing to download via ?download=true
    • no duplicate uploads (optional)
    • listing/deleting files
    • custom landing page
  • Single binary
  • Simple configuration
    • supports hot reloading
  • Easy to deploy
  • No database
    • filesystem is used
  • Self-hosted
    • centralization is bad!
  • Written in Rust
    • blazingly fast!

Installation

From crates.io

cargo install rustypaste

Arch Linux

pacman -S rustypaste

Alpine Linux

rustypaste is available for Alpine Edge. It can be installed via apk after enabling the community repository.

apk add rustypaste

Binary releases

See the available binaries on the releases page.

Build from source

git clone https://github.com/orhun/rustypaste.git
cd rustypaste/
cargo build --release

Feature flags

  • shuttle: enable an entry point for deploying on Shuttle
  • openssl: use distro OpenSSL (binary size is reduced ~20% in release mode)
  • rustls: use rustls (enabled as default)

To enable a feature for build, pass --features flag to cargo build command.

For example, to reuse the OpenSSL present on a distro already:

cargo build --release --no-default-features --features openssl

Testing

Unit tests
cargo test -- --test-threads 1
Test Fixtures
./fixtures/test-fixtures.sh

Usage

The standalone command line tool (rpaste) is available here.

CLI

function rpaste() {
  curl -F "file=@$1" -H "Authorization: <auth_token>" "<server_address>"
}

* consider reading authorization headers from a file. (e.g. -H @rpaste_auth)

# upload a file
$ rpaste x.txt

# paste from stdin
$ rpaste -

Expiration

$ curl -F "[email protected]" -H "expire:10min" "<server_address>"

supported units:

  • nsec, ns
  • usec, us
  • msec, ms
  • seconds, second, sec, s
  • minutes, minute, min, m
  • hours, hour, hr, h
  • days, day, d
  • weeks, week, w
  • months, month, M
  • years, year, y

One shot files

$ curl -F "[email protected]" "<server_address>"

One shot URLs

$ curl -F "oneshot_url=https://example.com" "<server_address>"

URL shortening

$ curl -F "url=https://example.com/some/long/url" "<server_address>"

Paste file from remote URL

$ curl -F "remote=https://example.com/file.png" "<server_address>"

Cleaning up expired files

Configure [paste].delete_expired_files to set an interval for deleting the expired files automatically.

On the other hand, following script can be used as cron for cleaning up the expired files manually:

#!/bin/env sh
now=$(date +%s)
find upload/ -maxdepth 2 -type f -iname "*.[0-9]*" |
while read -r filename; do
	[ "$(( ${filename##*.} / 1000 - "${now}" ))" -lt 0 ] && rm -v "${filename}"
done

Delete file from server

Set delete_tokens array in config.toml to activate the DELETE endpoint and secure it with one (or more) auth token(s).

$ curl -H "Authorization: <auth_token>" -X DELETE "<server_address>/file.txt"

Server

To start the server:

$ rustypaste

If the configuration file is not found in the current directory, specify it via CONFIG environment variable:

$ CONFIG="$HOME/.rustypaste.toml" rustypaste

To enable basic HTTP auth, set the AUTH_TOKEN environment variable (via .env):

$ echo "AUTH_TOKEN=$(openssl rand -base64 16)" > .env
$ rustypaste

You can also set multiple auth tokens via the array field [server].auth_tokens in your config.toml.

See config.toml for configuration options.

List endpoint

Set expose_list to true in config.toml to be able to retrieve a JSON formatted list of files in your uploads directory. This will not include oneshot files, oneshot URLs, or URLs.

$ curl "http://<server_address>/list"

[{"file_name":"accepted-cicada.txt","file_size":241,"expires_at_utc":null}]

This route will require an AUTH_TOKEN if one is set.

HTML Form

It is possible to use an HTML form for uploading files. To do so, you need to update two fields in your config.toml:

  • Set the [landing_page].content_type to text/html; charset=utf-8.
  • Update the [landing_page].text field with your HTML form or point [landing_page].file to your html file.

For an example, see examples/html_form.toml

Docker

Following command can be used to run a container which is built from the Dockerfile in this repository:

$ docker run --rm -d \
  -v "$(pwd)/upload/":/app/upload \
  -v "$(pwd)/config.toml":/app/config.toml \
  --env-file "$(pwd)/.env" \
  -e "RUST_LOG=debug" \
  -p 8000:8000 \
  --name rustypaste \
  orhunp/rustypaste
  • uploaded files go into ./upload (on the host machine)
  • set the AUTH_TOKEN via -e or --env-file to enable auth

You can build this image using docker build -t rustypaste . command.

If you want to run the image using docker compose, simply run docker-compose up -d. (see docker-compose.yml)

Nginx

Example server configuration with reverse proxy:

server {
    listen 80;
    location / {
        proxy_pass                         http://localhost:8000/;
        proxy_set_header Host              $host;
        proxy_set_header X-Forwarded-For   $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        add_header X-XSS-Protection        "1; mode=block";
        add_header X-Frame-Options         "sameorigin";
        add_header X-Content-Type-Options  "nosniff";
    }
}

If you get a 413 Request Entity Too Large error during upload, set the max body size in nginx.conf:

http {
    # ...
    client_max_body_size 100M;
}

Contributing

Pull requests are welcome!

Consider submitting your ideas via issues first and check out the existing issues.

License

All code is licensed under The MIT License.

More Repositories

1

git-cliff

A highly customizable Changelog Generator that follows Conventional Commit specifications โ›ฐ๏ธ
Rust
5,800
star
2

kmon

Linux Kernel Manager and Activity Monitor ๐Ÿง๐Ÿ’ป
Rust
1,911
star
3

systeroid

A more powerful alternative to sysctl(8) with a terminal user interface ๐Ÿง
Rust
997
star
4

gpg-tui

Manage your GnuPG keys with ease! ๐Ÿ”
Rust
991
star
5

halp

A CLI tool to get help with CLI tools ๐Ÿ™
Rust
597
star
6

menyoki

Screen{shot,cast} and perform ImageOps on the command line ๐ŸŒฑ ๐Ÿž๏ธ
Rust
489
star
7

linuxwave

Generate music from the entropy of Linux ๐Ÿง๐ŸŽต
Zig
399
star
8

pkgtop

Interactive package manager and resource monitor designed for the GNU/Linux.
Go
268
star
9

runst

A dead simple notification daemon ๐Ÿฆก
Rust
234
star
10

zps

A small utility for listing and reaping zombie processes on GNU/Linux.
C
153
star
11

CoolModFiles

A web player that plays some cool MOD files randomly ๐ŸŽถ
JavaScript
122
star
12

kermit

A VTE-based, simple and froggy terminal emulator ๐Ÿธ
C
114
star
13

rust-tui-template

A template for bootstrapping a Rust TUI application with tui-rs & crossterm
Rust
77
star
14

dotfiles

Orhun's Arch Linux configuration files and scripts ๐Ÿ 
Shell
70
star
15

godsays

Rust port of the Terry Davis' (RIP) "god says" program
Rust
69
star
16

rtl_map

FFT-based visualizer for RTL-SDR devices. (RTL2832/DVB-T)
C
67
star
17

battleship-rs

Battleship game implemented in Rust
Rust
65
star
18

git-cliff-action

GitHub action to generate a changelog based on the Git history
Shell
65
star
19

k3pler

Android network connection blocker and packet analyzer built on top of local HTTP proxy.
Java
48
star
20

orhun

My GitHub profile README.md โญ:octocat:
41
star
21

rustypaste-cli

A CLI tool for rustypaste
Rust
36
star
22

ApkServInject

Tool for injecting (smali) services to APK files
Java
30
star
23

cargo-nocode

Cargo subcommand to easily bootstrap nocode applications. Write nothing; deploy nowhere.
Rust
29
star
24

god

Linux utility for simplifying the Git usage.
Go
25
star
25

PSAUX

Android task manager and automated background service killer.
Java
20
star
26

alpkg

Set up Alpine Linux packaging environment with a breeze! ๐Ÿ”
Shell
18
star
27

packaging-rust-for-npm

https://blog.orhun.dev/packaging-rust-for-npm/
JavaScript
17
star
28

Picasso

PIC16F877A based 5V/20MHz development board and PIC programmer
C
15
star
29

PKGBUILDs

Arch Linux packages that I maintain ๐Ÿ”ง
Shell
13
star
30

personal-blog

The source of my blog โœ๐Ÿผ
SCSS
13
star
31

dialogflowbot

Google's Dialogflow implementation on Android with additional features.
Java
11
star
32

i3-workspace-brightness

Utility to auto-adjust the brightness of i3wm workspaces
Rust
11
star
33

Black-Waves

A wavy dark theme for VSCode
10
star
34

HydropotX

Automated and Self-contained Hydroponics System ๐ŸŒฑ
Kotlin
9
star
35

advent-of-code

My Advent of Code solutions ๐Ÿข
Rust
8
star
36

Last-Commit

A VSCode extension that focuses on the last git commit
JavaScript
7
star
37

zig-http-benchmarks

Benchmarking Zig HTTP client against Rust, Go, Python and curl
Zig
6
star
38

binsider

Analyze ELF binaries like a boss (WIP)
Rust
4
star
39

orhun.github.io

Personal website
HTML
4
star
40

base16-kermit

Base16 for kermit
Mustache
3
star
41

godsings

https://melody.godsays.xyz
Python
3
star
42

parseit

A simple text file parsing library powered by regex and glob patterns
Rust
3
star
43

typewriter

Turn your keyboard into a typewriter (WIP)
Rust
2
star
44

firebox-auth-cracker

A CLI tool to brute force the authentication signature of WatchGuard's Firebox
Rust
2
star
45

playfair-rs

Playfair cipher implemented in Rust
Rust
2
star
46

rust-arch-lto

Rust + ABS + LTO = ๐Ÿคฏ (PoC)
Shell
1
star
47

abstractapi-rs

Rust API bindings for the Abstract HTTP API
Rust
1
star
48

rust-tui-example

A very simple TUI program to demonstrate on Rust Munich Meetup #8
Rust
1
star
49

ytpls

[experimental] YouTube Playlist Synchronizer backed by yt-dl & git
Rust
1
star