t4t

simple, consent-based webpaste
git clone git://git.girlpoison.org/t4t
Log | Files | Refs | README | LICENSE

commit 90fff06c0d5d196c7d021595858ac06094e364f3
Author: Giygas <mvk@girlpoison.org>
Date:   Sun,  2 Jun 2024 10:26:20 +0200

Initial commit

Diffstat:
ALICENSE | 7+++++++
AREADME | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amime.types | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
At4t | 31+++++++++++++++++++++++++++++++
At4t-receive | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 221 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,7 @@ +Copyright 2024 girlpoison.org + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README b/README @@ -0,0 +1,67 @@ +Intro +------ +t4t is a minimal, consent-based paste service designed to be used amongst trusted friends. +It consists of two scripts: t4t, and t4t-receive. + +t4t uploads files to T4T_HOST over ssh, which prompts t4t-receive to write the received data +to the specified file. This is accomplished through setting up your authorized_keys in a certain way; +see 'SETUP' below. + +Usage - t4t +------------ +t4t [-u user] [-h host] [-N] [files...] + +DESCRIPTION + Pipes the given files to user@host through ssh. If no files are specified, + or '-' is passed as a filename, t4t will read from stdin. + + T4T_USER and T4T_HOST define which user to connect as, and which host to + connect to. The former defaults to 't4t', and the latter has no default. + +OPTIONS + -u user + Specify which username to use when connecting over ssh. This overrides + T4T_USER. + -h host + Specify which host to connect to over ssh. This overrides T4T_HOST. + -N + Do not retain file names when uploading. This will prompt t4t to + generate one for you. + +Usage - t4t-receive +-------------------- +t4t-receive [-D] [-l limit] name + +DESCRIPTION + Writes file data from stdin to name in T4T_ROOT ($HOME/www by default). + If name does not have an extension, t4t-receive will attempt to identify + the data and pick an appropriate extension. + + After a successful write, t4t-receive prints a URL to the uploaded file, + constructed with the help of T4T_URL. + +OPTIONS + -D + If the name does not have a file extension, do not attempt to guess + one. + -l limit + Specifies the maximum file size for the incoming data. limit may + optionally be followed by a unit multiplier, much like dd. e.g. + KB, MB, GB, TB + +SETUP + Uncomment and define the variables at the start of the script. T4T_ROOT is + described above. T4T_URL defines the URL displayed in the output. + + T4T_MIMETYPES specifies which file to look for extensions in. It defaults + to '/etc/mime.types', but it is recommended to set it to the saner + mime.types provided with t4t. + + Create an account and home directory for the user account that clients + will connect to. It is recommended to choose 't4t' as the name. Ensure + that this user is able to accept incoming ssh connections, and set up the + .ssh/authorized_keys file like so: + command="$HOME/t4t-receive" ssh-rsa ...public key for user 1... + command="$HOME/t4t-receive -l 20M" ssh-rsa ...public key for user 2... + ...etc + diff --git a/mime.types b/mime.types @@ -0,0 +1,60 @@ +application/pdf pdf +application/pgp-signature sig +application/futuresplash spl +application/octet-stream class +application/postscript ps +application/x-bittorrent torrent +application/x-dvi dvi +application/x-gzip gz +application/x-ns-proxy-autoconfig pac +application/x-shockwave-flash swf +application/x-tgz tar.gz +application/x-tgz tgz +application/x-tar tar +application/zip zip +audio/mpeg mp3 +audio/x-mpegurl m3u +audio/x-ms-wma wma +audio/x-ms-wax wax +application/ogg ogg +audio/x-wav wav +image/gif gif +image/jpeg jpg +image/jpeg jpeg +image/png png +image/x-xbitmap xbm +image/x-xpixmap xpm +image/x-xwindowdump xwd +text/html html +text/html htm +text/javascript js +text/plain txt +text/xml dtd +text/xml xml +video/mpeg mpeg +video/mpeg mpg +video/quicktime mov +video/quicktime qt +video/x-msvideo avi +video/x-ms-asf asf +video/x-ms-asf asx +video/x-ms-wmv wmv +application/x-bzip bz2 +application/x-bzip-compressed-tar tbz +application/x-bzip-compressed-tar tar.bz2 +application/vnd.oasis.opendocument.text odt +application/vnd.oasis.opendocument.spreadsheet ods +application/vnd.oasis.opendocument.presentation odp +application/vnd.oasis.opendocument.graphics odg +application/vnd.oasis.opendocument.chart odc +application/vnd.oasis.opendocument.formula odf +application/vnd.oasis.opendocument.image odi +application/vnd.oasis.opendocument.text-master odm +application/vnd.oasis.opendocument.text-template ott +application/vnd.oasis.opendocument.spreadsheet-template ots +application/vnd.oasis.opendocument.presentation-template otp +application/vnd.oasis.opendocument.graphics-template otg +application/vnd.oasis.opendocument.chart-template otc +application/vnd.oasis.opendocument.formula-template otf +application/vnd.oasis.opendocument.image-template oti +application/vnd.oasis.opendocument.text-web oth diff --git a/t4t b/t4t @@ -0,0 +1,31 @@ +#!/bin/sh +PROGNAME="$(basename $0)" + +err() { echo "$PROGNAME: $*" >&2; } +usage() { err "usage: $PROGNAME [-u user] [-h host] [-N] [files...]"; } +randstring() { tr -dc 'A-Za-z0-9_\-' </dev/urandom | head -c "${1-8}"; } + +KEEPNAMES=1 +while getopts "u:h:N" OPT; do + case ${OPT} in + u) + T4T_USER="${OPTARG}";; + h) + T4T_HOST="${OPTARG}";; + N) + unset KEEPNAMES;; + *) + usage; exit 1;; + esac +done +shift $((OPTIND-1)) + +[ "$T4T_HOST" ] || { err "set T4T_HOST or pass -h"; exit 1; } + +for F in "${@:--}"; do + if [ "$F" != "-" ] && [ ! -e "$F" ]; then err "no such file '$F'"; continue; fi + if [ ! "$KEEPNAMES" ] || [ "$F" == "-" ]; then NAME="$(randstring)" + else NAME="$(basename "$F")"; fi + + cat "$F" | ssh "${T4T_USER-t4t}@$T4T_HOST" "$NAME" +done diff --git a/t4t-receive b/t4t-receive @@ -0,0 +1,56 @@ +#!/bin/bash +# Set these variables to your liking. +#T4T_ROOT="$HOME/www" +#T4T_URL="https://t4t.fun" +#T4T_MIMETYPES="$HOME/mime.types" + +PROGNAME="$(basename $0)" + +err() { echo "$PROGNAME: $*" >&2; } +usage() { err "usage: $PROGNAME [-D] [-l limit] name"; } +randstring() { tr -dc 'A-Za-z0-9_\-' </dev/urandom | head -c ${1-8}; } + +[ "$T4T_ROOT" ] && [ -d "$T4T_ROOT" ] || { err "T4T_ROOT not set or directory doesn't exist"; exit 1; } +[ "$T4T_URL" ] || { err "T4T_URL not set."; exit 1; } + +MIMEDETECT=1; +while getopts "Dl:" OPT; do + case ${OPT} in + D) + unset MIMEDETECT;; + l) + T4T_LIMIT="${OPTARG}";; + *) + usage; exit 1;; + esac +done +shift $((OPTIND-1)) + +NAME="$(tr -dc 'A-Za-z0-9_\-.' <<<"$SSH_ORIGINAL_COMMAND")" +[ "$NAME" ] || { err "no name specified"; exit 1; } +[ "$NAME" == "." ] || [ "$NAME" == ".." ] && err "illegal file name" && exit 1 +EXT="$(grep -Eo '\.[a-zA-Z0-9]+$' <<<"$NAME")" + +while test -e "$T4T_ROOT/$NAME"; do + SNAME="$(basename ${EXT:+-s$EXT} "$NAME")" + NAME="$SNAME$(randstring 1)$EXT" +done +FILE="$T4T_ROOT/$NAME" + +head -c ${T4T_LIMIT-10M} > "$FILE" +[ -e "$FILE" ] || { err "could not write file '$NAME'"; exit 1; } +if [ $(du "$FILE" | cut -f1) -eq 0 ]; then + rm "$FILE" + err "empty file discarded" + exit 1 +fi + +if [ "$MIMEDETECT" ] && [ ! "$EXT" ]; then + MIME="$(file -b --mime-type "$FILE")" + EXT=".$(cat "${T4T_MIMETYPES-/etc/mime.types}" | awk -v m="$MIME" '$1==m{print $NF}')" + [ ! "$EXT" ] && EXT=".txt" + mv "$FILE" "$FILE$EXT" || exit 1; + NAME="$(basename "$FILE")$EXT" +fi + +echo "$T4T_URL/$NAME"