summaryrefslogtreecommitdiff
path: root/drasl-heads.cgi
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2026-05-26 01:52:31 +0200
committerLizzy Fleckenstein <lizzy@vlhl.dev>2026-05-26 01:52:31 +0200
commit6a8406c5b17cf9bc170b309dc8e58cffa244307e (patch)
tree6e6bad16f593c86bd95d2868a50e1325d0da4d9e /drasl-heads.cgi
downloaddrasl-heads-main.tar.xz
Diffstat (limited to 'drasl-heads.cgi')
-rwxr-xr-xdrasl-heads.cgi31
1 files changed, 31 insertions, 0 deletions
diff --git a/drasl-heads.cgi b/drasl-heads.cgi
new file mode 100755
index 0000000..a6423b7
--- /dev/null
+++ b/drasl-heads.cgi
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+finish() {
+ echo "Status: $1"
+ echo "Content-type: $2"
+ echo
+ cat -
+ exit
+}
+
+echo "$REQUEST_URI" \
+ | sed -nE "s#$DRASL_HEADS_ROOT/([[:xdigit:]]{32})/([[:digit:]]+)#\1 \2#p" \
+ | {
+ IFS=' '
+ if ! read -r uuid size; then
+ echo "Bad Request" | finish "400 Bad Request" "text/plain"
+ fi
+
+ if test "$size" -gt 64; then
+ echo "Size Limit Exceeded" | finish "403 Forbidden" "text/plain"
+ fi
+
+ image="$(mktemp)"
+ trap 'rm $image' EXIT
+
+ if ./cache.sh ./head.sh "$uuid" "$size" 2>/dev/null > "$image"; then
+ finish "200 OK" "image/png" < "$image"
+ else
+ echo "Not Found" | finish "404 Not Found" "text/plain"
+ fi
+ }