A minimal file upload/pastebin service.
Go to file
Orhun Parmaksız 284481e560
Merge branch 'master' into chore/bump_actix_deps
2022-03-16 16:54:12 +03:00
.github chore(security): optimize cargo-audit workflow 2021-11-07 16:16:46 +03:00
img docs(readme): add README.md 2021-07-26 21:29:46 +03:00
src Merge branch 'master' into chore/bump_actix_deps 2022-03-16 16:54:12 +03:00
.dockerignore chore(docker): add Dockerfile 2021-07-25 14:47:48 +03:00
.env refactor(server): use .env for auth token 2021-07-24 14:10:30 +03:00
.gitignore feat(server): support file upload and serving 2021-07-23 22:52:00 +03:00
CHANGELOG.md chore(release): prepare for v0.6.5 2022-03-13 21:33:32 +03:00
Cargo.lock Merge branch 'master' into chore/bump_actix_deps 2022-03-16 00:46:58 +03:00
Cargo.toml Merge branch 'master' into chore/bump_actix_deps 2022-03-16 00:46:58 +03:00
Dockerfile chore(docker): remove Rust edition workaround from Dockerfile 2022-02-25 00:14:14 +03:00
LICENSE docs(license): update copyright years 2022-01-09 15:05:41 +03:00
README.md docs(readme): add installation instructions for Arch Linux 2022-03-13 21:13:31 +03:00
config.toml feat(config): support setting the timeout for HTTP requests 2022-03-12 00:35:54 +03:00
docker-compose.yml chore(docker): share the config file between host and container 2021-08-09 23:27:35 +03:00

README.md

Rustypaste is a minimal file upload/pastebin service.

$ echo "some text" > awesome.txt

$ curl -F "file=@awesome.txt" https://paste.site.com
https://paste.site.com/safe-toad.txt

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

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)
    • supports expiring links
    • supports one shot links (can only be viewed once)
    • guesses MIME types
      • supports overriding and blacklisting
    • no duplicate uploads (optional)
  • 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

Binary releases

See the available binaries on releases page.

Build from source

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

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 "file=@x.txt" -H "expire:10min" "<server_address>"

(supported units: ns, us, ms, sec, min, hours, days, weeks, months, years)

One shot

$ curl -F "oneshot=@x.txt" "<server_address>"

Cleaning up expired files

$ find upload/ -maxdepth 2 -type f -iname "*.[0-9]*" -exec rm -v {} \;

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>"

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

See config.toml for configuration options.

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;
}

Roadmap

Nothing here yet! 🎉

Contributing

Pull requests are welcome!

Consider submitting your ideas via issues first. Also, see the roadmap and/or run the following command to see what is needed to be done:

$ grep -nr "TODO:" src/

License

All code is licensed under The MIT License.