From 3eaae0075f7e0bd94595e6486528262ad962274c Mon Sep 17 00:00:00 2001 From: cel Date: Thu, 31 Oct 2019 09:29:17 -1000 Subject: Init --- README.md | 31 ++++++++++++ gemini.filter.dpi | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 README.md create mode 100755 gemini.filter.dpi diff --git a/README.md b/README.md new file mode 100644 index 0000000..6763ad3 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# dillo-gemini + +[Gemini][] protocol plugin for [Dillo][]. + +## Screenshot + +![Dillo loading gemini://gemini.conman.org/](&Mi6TnZIOeSmIVeI0VbtY3tqvIEcoCrUas2EwwS09sl0=.sha256) + +## Install + +```sh +git clone ssb://%V0D7DtSnZyyAp1NbgOJF2ZAFMeUy9eXwyClCEKYUYAI=.sha256 dillo-gemini +cd dillo-gemini +mkdir -p ~/.dillo/dpi/gemini +ln -rs gemini.dpi ~/.dillo/dpi/gemini +test -f ~/.dillo/dpidrc || cp /etc/dillo/dpidrc ~/.dillo/dpidrc +echo 'proto.gemini=gemini/gemini.dpi' >> ~/.dillo/dpidrc +dpidc stop +``` + +## Sites to try + +- +- + +[Gemini]: https://gopher.tildeverse.org/zaibatsu.circumlunar.space/1/~solderpunk/gemini +[Dillo]: https://dillo.org/ + +## License + +FSFAP diff --git a/gemini.filter.dpi b/gemini.filter.dpi new file mode 100755 index 0000000..53932e5 --- /dev/null +++ b/gemini.filter.dpi @@ -0,0 +1,143 @@ +#!/bin/bash +# dillo-gemini +# © 2019 cel @f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519 +# Copying and distribution of this file, with or without modification, +# are permitted in any medium without royalty provided the copyright +# notice and this notice are preserved. This file is offered as-is, +# without any warranty. + +read -d '>' auth +read -d '>' cmd +case "$cmd" in + "\n" + printf "Content-type: text/plain\r\n\r\n" + echo Not found +} + +render_gemini() { + printf "Content-type: text/html\r\n\r\n
"
+	sed 's/^\(=>\s*\)\(\S*\)*\(.*\)/\1\2<\/a>\3/'
+	printf "%s" "
" +} + +send_status_msg() { + printf "" "$*" +} + +serve_status_not_supported() { + printf "\n" + printf "Content-type: text/plain\r\n\r\n" + echo Status not implemented: $1 + echo $2 +} + +serve_missing_status() { + printf "\n" + printf "Content-type: text/plain\r\n\r\n" + echo Empty status response. $2 +} + +serve_success() { + printf "\n" + type=$1 + case "$type" in + text/gemini*) render_gemini;; + *) printf "Content-type: $type\r\n\r\n"; cat;; + esac +} + +serve_redirect() { + url=$1 + send_status_msg "Redirected" + printf "\n" + printf "Content-type: text/html\r\n\r\n" + # TODO: html-escape url + cat <<-EOF + + + + Redirect to $url + + +

Redirect to $url + + + EOF +} + +serve_error() { + status=$1 + meta=$2 + send_status_msg "Request failed" + printf "\n" + printf "Content-type: text/html\r\n\r\n" + cat <<-EOF + + + + Request failed + + +

Request failed: $status

+ $meta + + + EOF +} + +serve_fail() { + meta="$1" + send_status_msg "Client certificate required" + printf "\n" + printf "Content-type: text/html\r\n\r\n" + cat <<-EOF + + + + Client certificate required + + +

Client certificate required

+

Not implemented!

+ $meta + + + EOF +} + +serve_gemini() { + url=$1 + url1=${url#gemini://} + hostname=${url1%%/*} + host=${hostname%%:*} + port=${hostname##*:} + if [ "$host" = "$port" ]; then port=1965; fi + send_status_msg "Sending request..." + printf "%s\r\n" "$url" | ncat --ssl "$host" "$port" | { + read status meta + send_status_msg "Status: $status" + meta=$(echo "$meta" | sed 's/\s*$//') + case "$status" in + 1*) serve_input "$meta";; + 2*) serve_success "$meta";; + 3*) serve_redirect "$meta";; + 4*) serve_error "$status" "$meta";; + 5*) serve_error "$meta";; + 6*) serve_client_cert_required "$meta";; + '') serve_missing_status "$meta";; + *) serve_status_not_supported "$status" "$meta";; + esac + } +} + +case "$url" in + gemini:*) serve_gemini "$url";; + *) serve_404;; +esac -- cgit v1.2.3