summaryrefslogtreecommitdiff
path: root/gprsh
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2018-07-15 11:27:09 +0100
committerKatolaZ <katolaz@freaknet.org>2018-07-15 11:27:09 +0100
commitc15a524ced17da029abaa09bdb025487a3b27551 (patch)
tree6f9cde313117749a3b22babc389db04d534601fb /gprsh
parentcf2ff5ca4c8e0ce99bb86a1505585713c8de29fc (diff)
name changed to gosher
Diffstat (limited to 'gprsh')
-rwxr-xr-xgprsh121
1 files changed, 0 insertions, 121 deletions
diff --git a/gprsh b/gprsh
deleted file mode 100755
index f93cf29..0000000
--- a/gprsh
+++ /dev/null
@@ -1,121 +0,0 @@
-#!/bin/sh
-
-##
-## === gprsh ===
-##
-## gprsh is a simple gopher server in a POSIX shell script:
-##
-## $ ./gprsh [<PORT> [<GOPHERDIR>]
-##
-## If PORT is not specified, the default is 70. If GOPHERDIR is not
-## specified, "./" is assumed
-##
-##
-## (c) 2018 Vincenzo 'KatolaZ' Nicosia <katolaz@freaknet.org>
-##
-##
-
-######################
-
-##
-## If the script is called with basename "gprsh", launch the netcat
-## server...
-##
-
-MYNAME=$(basename $0)
-
-if [ -z "${MYNAME#gprsh}" ]; then
- ## we are called as gprsh -- launch the server
-
- PORT=${1:-70}
- GOPHERDIR=${2:-"./"}
-
- while [ 1 -eq 1 ]; do
- netcat -vv -k -l -p ${PORT} -c "./gprsh_serve ${GOPHERDIR}"
- ret=$?
- done
- exit 0
-fi
-
-
-######################
-
-##
-## ...otherwise, serve a request
-##
-
-
-## function
-invalid_selector(){
- sel="$1"
- echo "iInvalid selector: \"$sel\""
- echo "."
- exit 1
-}
-
-## function
-serve_selector(){
- sel="$1"
-
- cat "${sel}"
- echo "."
- exit 0
-}
-
-
-### transform a .gph file into a gophermap
-## function
-serve_index(){
- IDX=$1
- IFS='
-'
- while read line; do
- rline=$(echo $line | sed -r -e 's/\r//g')
- case $rline in
- '['*)
- echo $rline | sed -r -e 's/\[//g;s/\]//g;s/\|/\t/g;s/\t//;s/$/\r/g'
- ;;
- *)
- echo $line
- esac
- done < $IDX
- exit 0
-}
-
-
-
-GOPHERDIR=${1:-"./"}
-
-read selector
-
-selector=$(echo $selector | sed -r 's:\r::g' )
-
-echo "iGOPHERDIR: ${GOPHERDIR}"
-echo "iselector: \"${selector}\""
-
-case $selector in
- /*|"")
- RP1=$(realpath "${GOPHERDIR}"/"${selector}" || "")
- RP2=$(realpath "${GOPHERDIR}")"${selector}"
- echo "iRP1: ${RP1}"
- echo "iRP2: ${RP2}"
- #echo "."
-
- if [ "${RP1}" = "${RP2}" ]; then
- if [ -f "${RP1}" ]; then
- serve_selector "${RP1}"
- elif [ -d "${RP1}" ]; then
- [ -f "${RP1}/gophermap" ] && serve_selector "${RP1}/gophermap"
- [ -f "${RP1}/index.gph" ] && serve_index "${RP1}/index.gph"
- else
- echo "3Err Unable to find file ${selector}"
- fi
- fi
- invalid_selector "$selector"
- ;;
- *)
- [ -f "${GOPHERDIR}/gophermap" ] && cat "${GOPHERDIR}/gophermap" && echo "." && exit 0
- invalid_selector "/"
- ;;
-esac
-