#!/bin/sh # Finger protocol adapter for Chawan. Requires curl. # (It does *not* work without the environment variables MAPPED_URI_*, so no # w3m support.) # # Usage: put this script in your cgi-bin folder, then add the following line to # your urimethodmap: # # finger: /cgi-bin/cha-finger # # Note: the Chawan default configuration already does this, so normally you # don't need to do anything to use the finger protocol. # Check for errors. die() { echo "Cha-Control: ConnectionError $1 $2" exit 1 } type curl >/dev/null || \ die 1 "curl must be installed on your computer to use finger" PORT="${MAPPED_URI_PORT:-79}" test "$PORT" = 79 || die 3 "invalid port; only port 79 is supported" # Parse the URL. Roughly based on Lynx finger URL parsing, but less # sophisticated. if test -n "$MAPPED_URI_USERNAME" then USER="$MAPPED_URI_USERNAME" else case "$MAPPED_URI_PATH" in /w*) USER="/w ${MAPPED_URI_PATH#/w}" ;; *) USER="${MAPPED_URI_PATH#/}" ;; esac fi URL="telnet://$MAPPED_URI_HOST:$PORT" # Headers. printf 'Content-Type: text/plain\n' # Newline; from here on we are sending the content body. printf '\n' # Finger request, the output of which goes to stdout. printf '%s\r\n' "$USER" | if test -n "$ALL_PROXY" then curl -x "$ALL_PROXY" -- "$URL" else curl -- "$URL" fi 2>/dev/null