about summary refs log tree commit diff stats
path: root/bonus
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-11-14 19:21:30 +0100
committerbptato <nincsnevem662@gmail.com>2023-11-14 19:23:56 +0100
commitf054f85b722127001f5e2aadb4d578ac92e910ef (patch)
tree1e89bf19837719819d45525acc29706753ce5798 /bonus
parent41a508fbfa2a01fc20b46e075cd6b610f37cc378 (diff)
downloadchawan-f054f85b722127001f5e2aadb4d578ac92e910ef.tar.gz
bonus: add finger adapter
sort of based on lynx's finger URL parsing, except it's dumber
Diffstat (limited to 'bonus')
-rwxr-xr-xbonus/finger/cha-finger44
1 files changed, 44 insertions, 0 deletions
diff --git a/bonus/finger/cha-finger b/bonus/finger/cha-finger
new file mode 100755
index 00000000..7adf231b
--- /dev/null
+++ b/bonus/finger/cha-finger
@@ -0,0 +1,44 @@
+#!/bin/sh
+# Finger protocol adapter for Chawan. Requires curl.
+# (It also works with w3m.)
+#
+# Usage: put this script in your cgi-bin folder, then add the following line to
+# your urimethodmap:
+#
+# finger: file:/cgi-bin/cha-finger?%s
+
+decode() {
+	# URL-decode the string passed as the first parameter
+	printf '%s\n' "$1" | \
+		sed 's/+/ /g;s/%/\\x/g' | \
+		xargs -0 printf "%b"
+}
+
+printf 'Content-Type: text/plain\r\n\r\n'
+if test -z "$QUERY_STRING"
+then	echo "URL expected"
+	exit 1
+fi
+
+URL="$(decode "$QUERY_STRING" | sed 's/^finger:\/\///;s/^\([^/]*\):73/\1/')"
+
+if printf '%s\n' "$URL" | grep -q '^[^/]*:[0-9]'
+then	echo "Invalid port"
+	exit 1
+fi
+
+case "$URL" in
+*@*)	USER="$(printf '%s\n' "$URL" | sed 's/@.*//')"
+	HOST="$(printf '%s\n' "$URL" | \
+		tail -c +$((${#USER} + 2)) | \
+		sed 's/\/.*//')"
+	;;
+*/w*)	HOST="$(printf '%s\n' "$URL" | sed 's/\/.*//')"
+	USER="/w $(printf '%s\n' "$URL" | tail -c +$((${#HOST} + 4)))"
+	;;
+*)	HOST="$(printf '%s\n' "$URL" | sed 's/\/.*//')"
+	USER="$(printf '%s\n' "$URL" | tail -c +$((${#HOST} + 2)))"
+	;;
+esac
+
+printf '%s\r\n' "$USER" | curl -- "telnet://$HOST:79" 2>/dev/null