-- Leo's gemini proxy
-- Connecting to git.thebackupbox.net:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
repo: spartanclient action: commit revision: path_from: revision_from: 4274948f6edfed7cbec15b0db9f1f8482d5bac4b: path_to: revision_to:
commit 4274948f6edfed7cbec15b0db9f1f8482d5bac4b Author: epoch <epoch@enzo.thebackupbox.net> Date: Fri Feb 18 07:26:59 2022 +0000 close enough for now diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..aad2b082fd60809a3588b9b767d0466f2b751f8b --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +PREFIX:=/usr/local + +all: + echo nothing whatever + +install: all + install -t $(PREFIX)/bin spartan-handler + install -t $(PREFIX)/bin spartan-get + install -t $(PREFIX)/bin spartan-message-handler diff --git a/README b/README new file mode 100644 index 0000000000000000000000000000000000000000..f85ca068015fb1a30dbdc17bb488ad4bbc3bd74b --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +this uses a handful of things from +git://git.thebackupbox.net/geminiclient diff --git a/spartan-get b/spartan-get new file mode 100755 index 0000000000000000000000000000000000000000..27e384df1f7a0b5865ea5474c4b96fef6c3c51fc --- /dev/null +++ b/spartan-get @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +#printf "openssl s_client isn't working right. probably libressl version is borked.\n" >&2 +#printf "because of that, we're using ncat --ssl which might break because no SNI.\n" >&2 + +if [ ! "$1" ];then + printf "usage: spartan-get spartan:uri\n" + printf ' or: spartan-get spartan-proxy:uri\n' + printf "the output is to stdout and is in raw message/spartan format.\n" + printf "any arguments after the first will be passed to openssl s_client.\n" + printf "for example, to use a client cert: spartan-get spartan:uri -key ~/epoch.key.pem -cert ~/epoch.cert.pem\n" + exit 1 +fi + +uri="$1" +shift +uri_minus_fragment="$(printf "%s\n" "$uri" | cut '-d#' -f1)" + +scheme="$(printf "%s\n" "$uri" | uricut -s)" + +host="$(printf "%s\n" "$uri" | uricut -d)" +port="$(printf "%s\n" "$uri" | uricut -P)" + +if [ "$scheme" = "spartan-proxy" ];then + uri="$(uriescape "$(uriunescape "$(printf "%s\n" "$uri" | uricut -p | cut -b2-)")")" +fi + +if [ ! "$port" ];then + port=300 +fi + +path="$(printf "%s\n" "$uri" | uricut -p)" + +content_length=0 + +printf '%s %s %s\r\n' "$host" "$path" "$content_length" \ + | ncat "$host" "$port" +#echo $? diff --git a/spartan-handler b/spartan-handler new file mode 100755 index 0000000000000000000000000000000000000000..f019776f12e31783d2357afce43cd71f34066252 --- /dev/null +++ b/spartan-handler @@ -0,0 +1,3 @@ +#!/bin/sh +export spartan_uri="$1" +spartan-get "$spartan_uri" | spartan-message-handler "$spartan_uri" diff --git a/spartan-message-handler b/spartan-message-handler new file mode 100755 index 0000000000000000000000000000000000000000..1a7ff23be32f6d5ce607ee9316b052f2bc7c392e --- /dev/null +++ b/spartan-message-handler @@ -0,0 +1,22 @@ +#!/bin/bash +### WE DO NOT KNOW WTF THE URI IS SUPPOSED TO BE. + +export spartan_uri="$1" + +read -r header meta +meta="$(printf "%s\n" "$meta" | cut '-d;' -f1 | tr -d ' \r')" +case "$header" in +2) + export gemini_uri="$1" #lie of a variable name for subprocesses to use + printf "mime-type: %s\n" "$meta" + if run_stdio_handler_by_mime_type "$meta";then + exit 0 #this worked, we're done. + else + ### it didn't work. time to save and launch a file-based handler + uristart "$(uri_write_cache)?mime-type=${meta}" + fi + ;; +*) + printf "wtf '%s'\n" "$header" + ;; +esac
-----END OF PAGE-----
-- Response ended
-- Page fetched on Sun Jun 2 12:12:43 2024