A minimal file upload/pastebin service.
Go to file
orhun b459761122
docs(readme): add README.md
2021-07-26 21:29:46 +03:00
img docs(readme): add README.md 2021-07-26 21:29:46 +03:00
src docs(project): update the library description 2021-07-26 17:38:28 +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
Cargo.lock chore(config): only support toml and yaml formats 2021-07-24 20:48:15 +03:00
Cargo.toml docs(readme): add README.md 2021-07-26 21:29:46 +03:00
Dockerfile chore(docker): add Dockerfile 2021-07-25 14:47:48 +03:00
README.md docs(readme): add README.md 2021-07-26 21:29:46 +03:00
config.toml refactor(config): create the `random` module for generating URLs 2021-07-26 15:34:23 +03:00
docker-compose.yml chore(docker): add docker-compose.yml 2021-07-25 14:48:11 +03:00

README.md

Rustypaste is a minimal file upload/pastebin service.

$ echo "some text" > awesome.txt

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

$ curl http://paste.example.com/safe-toad.txt
some text

Features

  • File upload
    • supports basic HTTP authentication
    • random file names (optional)
      • pet name (e.g. capital-mosquito.txt)
      • alphanumeric string (e.g. yB84D2Dv.txt)
    • guesses MIME types
  • Single binary
  • Easy to deploy
  • No database
    • filesystem is used
  • Self-hosted
    • centralization is bad!
  • Written in Rust
    • blazingly fast!

Usage

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 -

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=rustjerk" > .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 \
  --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;
        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

  • Support "disappearing" files
  • Support setting an expiry date for uploads
  • Write a CLI tool in Rust

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/