diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-04-30 15:17:30 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-04-30 15:37:23 +0200 |
| commit | 8cc11c52a88ec78d175b3ec8de854916f631caab (patch) | |
| tree | 4ad0bc1664a97418d0475b0b730c54d874953348 /extras | |
Initial build
Diffstat (limited to 'extras')
| -rwxr-xr-x | extras/estampa-ssh | 26 | ||||
| -rw-r--r-- | extras/nginx.conf | 36 |
2 files changed, 62 insertions, 0 deletions
diff --git a/extras/estampa-ssh b/extras/estampa-ssh new file mode 100755 index 0000000..f1cbd08 --- /dev/null +++ b/extras/estampa-ssh @@ -0,0 +1,26 @@ +#!/bin/sh +# estampa-ssh: forced command for the upload account in ~/.ssh/authorized_keys. +# +# Usage in authorized_keys: +# command="/usr/local/bin/estampa-ssh /srv/estampa/pastes",no-pty,no-agent-forwarding,no-port-forwarding,no-X11-forwarding ssh-ed25519 AAAA... uploader +# +# On every incoming SSH session this: +# 1. prunes pastes older than one week from $1 (best-effort, never blocks), +# 2. then exec's the original scp/sftp command the client wanted to run. +# Any other command is rejected. + +set -eu + +PASTE_DIR="${1:?usage: estampa-ssh <paste-dir>}" + +estampa --run "$PASTE_DIR" >/dev/null 2>&1 || true + +case "${SSH_ORIGINAL_COMMAND:-}" in + "scp -t "*|"scp -f "*|"/usr/lib/openssh/sftp-server"|"internal-sftp") + exec $SSH_ORIGINAL_COMMAND + ;; + *) + echo "estampa-ssh: only scp/sftp uploads are allowed" >&2 + exit 1 + ;; +esac diff --git a/extras/nginx.conf b/extras/nginx.conf new file mode 100644 index 0000000..0afc365 --- /dev/null +++ b/extras/nginx.conf @@ -0,0 +1,36 @@ +# Example nginx server block for estampa. +# +# estampa speaks CGI: when invoked with no arguments it reads +# DOCUMENT_ROOT and DOCUMENT_URI from the env (both populated by +# nginx's stock fastcgi_params) and serves the file at +# $document_root$document_uri as a syntax-highlighted HTML page. +# Files that aren't valid UTF-8 return 404. +# +# Pastes live under the `root` directory below; uploading via scp +# is enough to publish a new paste, and `estampa --run` is what +# expires them (see extras/estampa-ssh). +# +# Requires fcgiwrap (or any CGI-over-FastCGI gateway). + +server { + listen 80; + server_name paste.example.com; + + # Where pastes live. Change to taste. + # If this is also the home directory of an upload account (see + # README), the dotfile guard below is what keeps .ssh/ private. + root /srv/estampa; + + # Estampa only serves top-level, non-dotfile names. These rules + # short-circuit obvious misses so the CGI doesn't even fork. + location ~ /\. { return 404; } # dotfiles (.ssh/, .bashrc, ...) + location ~ /.+/ { return 404; } # anything inside a subdirectory + + location / { + fastcgi_pass unix:/run/fcgiwrap.socket; + include fastcgi_params; + + # No wrapper script needed: estampa with no args is the CGI mode. + fastcgi_param SCRIPT_FILENAME /usr/bin/estampa; + } +} |