about summary refs log tree commit diff stats
path: root/adapter
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-12-10 11:47:11 +0100
committerbptato <nincsnevem662@gmail.com>2023-12-10 15:08:53 +0100
commit2dec7483045c9e5696182db7b4ad842491b6c2b2 (patch)
treeeb4173f62684a6334a75254c88a3b0d840284ea7 /adapter
parente5a0fd6af4296f76987530a9566eb019307fa8bf (diff)
downloadchawan-2dec7483045c9e5696182db7b4ad842491b6c2b2.tar.gz
Enable finger protocol by default
* Add a default urimethodmap that points finger: to cha-finger
* Install cha-finger to /usr/local/libexec/cha/cgi-bin by default
* cha-finger: use ALL_PROXY if given, die if curl is not installed
Diffstat (limited to 'adapter')
-rwxr-xr-xadapter/finger/cha-finger49
1 files changed, 49 insertions, 0 deletions
diff --git a/adapter/finger/cha-finger b/adapter/finger/cha-finger
new file mode 100755
index 00000000..ea40e0ab
--- /dev/null
+++ b/adapter/finger/cha-finger
@@ -0,0 +1,49 @@
+#!/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: /cgi-bin/cha-finger?%s
+#
+# Note: the Chawan default configuration already does this, so normally you
+# don't need to do anything to use the finger protocol.
+
+die() {
+	echo "$1"
+	exit 1
+}
+
+if test -z "$QUERY_STRING"
+then	die "URL expected"
+fi
+type curl >/dev/null || \
+	die "curl must be installed on your computer to use finger."
+URL="$(printf '%s\n' "$QUERY_STRING" | \
+	sed 's/^finger:\/\///;s/^\([^[]\/:]\|\[[^]:]*\]\):79/\1/')"
+
+printf 'Content-Type: text/plain\r\n\r\n'
+
+if printf '%s\n' "$URL" | grep -q '^\([^[]/]*\)\|\(\[[^]]*\]\):[0-9]'
+then	die "Invalid port"
+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" | if test -n "$ALL_PROXY"
+then	curl -x "$ALL_PROXY" -- "telnet://$HOST:79"
+else	curl -- "telnet://$HOST:79"
+fi 2>/dev/null