~mort/coffeepaste

Neat paste bin.

349f7ab version 1.5.1

~mort pushed to ~mort/coffeepaste git

a month ago

49ad7f4 upgrade and document highlight.js

~mort pushed to ~mort/coffeepaste git

a month ago

#Coffeepaste

Coffeepaste is a pastebin-like service intended to be used from the command line.

#Building

Build with cargo build (or cargo build --release for a release build).

#Config

The config file config.toml contains config options like data path, page URL, max file size, etc. It's compiled into the binary, so any changes requires a recompile.

#Usage

The basic usage is to do curl --upload-file <file> <URL> to upload a file, or curl --upload-file - <URL> to upload from stdin. The server will respond with a URL to your content.

The URL's extension doesn't change the content of the file, but might change the way it's presented.

#HTTP endpoints

#GET /, GET /index.html

Get the main page which provides usage information.

#GET /<ID>

Get the raw content of the file with the given ID.

#GET /<ID>.<EXT>

View the contents of the file with the given ID, but displayed in a way determined by the extension.

  • Any extension associated with an image, video or audio file is sent unmodified, but with the appropriate Content-Type header.
  • Other extensions are a bit more complex:
    • If the client doing the request doesn't advertise HTML support, the client is sent the content unmodified.
    • Otherwise, the client is sent an HTML page which adds syntax highlighting and other features, where the syntax highlighting is determined by the extension (or, if the extension is .auto, the syntax highlighting guesses the file type based on content).

#PUT /<PATH>

Upload a file to the server. The path is ignored (a random ID is generated instead), but if the path has a file extension, the returned URL will have the same file extension.

#Hosting

If you want to host your own version of Coffeepaste, I recommend running it behind something like an nginx reverse proxy. By default, it listens to 127.0.0.1:8080, which means it's only accessible from the machine it's running on. Coffeepaste has no support for HTTPS and no features for preventing abuse (such as rate limiting or blocking IP addresses), instead relying on your reverse proxy setup for that stuff.

Here's nginx's documentation on setting up a reverse proxy: https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

The basic idea boils down to:

location / {
	proxy_set_header X-Real-IP $remote_addr;
	proxy_pass http://localhost:<coffeepaste's port>;
}

You probably want to at least do something to rate limit PUT requests to prevent someone spamming your server with files. There's less documentation about that, but this is basically the gist of how I do it:

limit_req_zone $binary_remote_addr zone=put_request_by_addr:10m rate=10r/s;

server {
	...

	error_page 599 = @putrequest;
	if ($request_method = 'PUT') {
		return 599;
	}

	location / {
		proxy_pass http://localhost:8080;
		proxy_set_header X-Real-IP $remote_addr;
	}
	location @putrequest {
		limit_req zone=put_request_by_addr burst=10;
		proxy_pass http://localhost:8080;
		proxy_set_header X-Real-IP $remote_addr;
	}
}

I don't know if that's a great way to do it, but it works and seems to be the simplest solution I could find. Basically, it abuses the error page for HTTP error 599 (which is not a real status code) to let us have two different 'location' blocks, one for PUT requests and one for all other requests.

Although inadvisable, if you want to expose Coffeepaste to the internet directly, replace the 127.0.0.1 with 0.0.0.0 in the config.toml.

#Highlight.js

A highlight.js package is vendored in, in web/vendor/highlight.min.{js,css}.

In addition to the default styles, these languages are enabled: .properties, ARM assembly, AVR assembly, Apache Config, AppleScript, Augmented Backus-Naur Form, AWK, BASIC, Backus-Naur Form, Brainfuck, CMake, Cap'n Proto, CoffeeScript, D, Dart, DeviceTree, Extended Backus-Naur Form, GLSL, HTTP, Haskell, Intel X86 Assembly, Julia, LLVM IR, LaTeX, Lisp, MIPS Assembly, Nginx Config, OCaml, PostgreSQL and PL/pgSQL, Protocol Buffers, Standard ML, Scala, Scheme, Tcl, Test Anything Protocol, VHDL, Vala, Verilog, Vim Script, Webassembly.

The theme is, currently, unknown.