From 5c89cd901a37c96d6a1b81e90eac0fb37b22c33c Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 24 Feb 2021 20:36:26 -0600 Subject: [PATCH] Initial commit --- bastord | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 bastord diff --git a/bastord b/bastord new file mode 100755 index 0000000..5f0cd49 --- /dev/null +++ b/bastord @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# BASTORD, a gemini server in bash +# by Case Duckworth +# License: ISC + +# CONFIGURATION ################################################################ +# bastord has a few ways to set variables: +# +# - set environment variables +# - use a config file (default: /etc/bastord.conf.sh) +# - pass them in as arguments, Make-style +# +# Unless I can figure out how to tell bash to source a file and /not/ clobber +# other environment variables, I can't just have the first two forms of setting +# variables. Basically, if you have a config file, use the make-style arguments +# (bastord var=value). + +: "${BASTORD_CONFIG:=/etc/bastord.conf.sh}" +[[ -r "$BASTORD_CONFIG" ]] && source "$BASTORD_CONFIG" + +: "${BASTORD_PORT:=1965}" +: "${BASTORD_ROOT:=/var/gemini}" + +# CONSTANTS #################################################################### +# +### Status codes +# These come straight from the spec, with underscores instead of spaces +SC_INPUT=10 +SC_SENSITIVE_INPUT=11 +SC_SUCCESS=20 +SC_TEMPORARY_REDIRECT=30 +SC_PERMANENT_REDIRECT=31 +SC_TEMPORARY_FAILURE=40 +SC_SERVER_UNAVAILABLE=41 +SC_CGI_ERROR=42 +SC_PROXY_ERROR=43 +SC_SLOW_DOWN=44 +SC_PERMANENT_ERROR=50 +SC_NOT_FOUND=51 +SC_GONE=52 +SC_PROXY_REQUEST_REFUSED=53 +SC_BAD_REQUEST=59 +SC_CLIENT_CERTIFICATE_REQUIRED=60 +SC_CERTIFICATE_NOT_AUTHORIZED=61 +SC_CERTIFICATE_NOT_VALID=62 + +# FUNCTIONS #################################################################### + +reply() { # reply STATUS_CODE MESSAGE + local sc="$1"; shift + printf '%d %s\r\n' "$sc" "$*" +} + +handle_request() { # handle_request REQUEST + # as per the spec, a Gemini request is a URL followed by \r\n, of a maximum + # length of 1024 bytes. + local req="$1" + + # badly-formed request + +}