From 2dec7483045c9e5696182db7b4ad842491b6c2b2 Mon Sep 17 00:00:00 2001 From: bptato Date: Sun, 10 Dec 2023 11:47:11 +0100 Subject: 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 --- adapter/finger/cha-finger | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 adapter/finger/cha-finger (limited to 'adapter/finger') 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 -- cgit 1.4.1-2-gfad0