diff options
Diffstat (limited to 'gosher')
-rwxr-xr-x | gosher | 75 |
1 files changed, 57 insertions, 18 deletions
@@ -10,9 +10,9 @@ ## If PORT is not specified, the default is 70. If GOPHERDIR is not ## specified, "./" is assumed ## -## +## ## (c) 2018 Vincenzo 'KatolaZ' Nicosia <katolaz@freaknet.org> -## +## ## ###################### @@ -22,25 +22,49 @@ ## server... ## -NETCAT=netcat +## +## NETCAT: the netcat command to use, and any additional option +## +### Original netcat +##NETCAT="nc.traditional" +## +### ncat (from nmap) +##NETCAT="ncat" +## +### Openbsd netcat +NETCAT="nc.openbsd" + +## +## STYLE: The way in which netcat will talk to gosher_serve +## +### fork with "-c" (Does *not* work with OpenBSD netcat!!!!!) +#STYLE='fork' +## +### use named pipes (Does *not* work with original netcat!!!!!) +STYLE='pipe' + OPREFIX=/tmp/outf_ IPREFIX=/tmp/inf_ -##DEBUG= -DEBUG=yes +DEBUG= +#DEBUG=yes + + +[ -n "$DEBUG" ] && { + set -e + set -x +} ## function cleanup(){ - [ -p "${OPREFIX}$$" ] && rm -f ${OPREFIX}$$ - [ -p "${IPREFIX}$$" ] && rm -f ${IPREFIX}$$ + [ -n "$INF" ] && [ -p "$INF" ] && rm -f ${INF} exit 1 - } MYNAME=$(basename $0) -if [ -z "${MYNAME#gosher}" ]; then +if [ -z "${MYNAME#gosher}" ]; then ## we are called as gosher -- launch the server PORT=${1:-70} @@ -48,15 +72,23 @@ if [ -z "${MYNAME#gosher}" ]; then trap cleanup 0 HUP INT TRAP TERM QUIT - OUTF=${OPREFIX}$$ INF=${IPREFIX}$$ - mkfifo -m 600 $OUTF $INF - while [ 1 -eq 1 ]; do - ./gosher_serve ${GOPHERDIR} <$INF >$OUTF & - ${NETCAT} -vv -l -p ${PORT} >$INF <$OUTF - ret=$? - done - exit 0 + [ "$STYLE" = "pipe" ] && { + mkfifo -m 600 $INF + while [ 1 -eq 1 ]; do + ./gosher_serve ${GOPHERDIR} <$INF | ${NETCAT} -vvvvv -l -p ${PORT} >$INF + done + rm -f $INF + exit 0 + } + [ "$STYLE" = 'fork' ] && { + while [ 1 -eq 1 ]; do + ${NETCAT} -vv -l -p $PORT -c "~/gosher_serve ${GOPHERDIR}" + done + exit 0 + } + echo "Error!!! wrong STYLE specified!!!" >&2 + exit 1 fi @@ -71,7 +103,9 @@ fi invalid_selector(){ sel="$1" echo "3Error: Invalid selector: \"$sel\"" - echo "." + printf ".\r\n" + exec 1>&- + exec 2>&- exit 1 } @@ -80,6 +114,9 @@ serve_selector(){ sel="$1" cat "${sel}" + echo "$0: selector $sel served -- exiting " >&2 + exec 1>&- + exec 2>&- exit 0 } @@ -104,6 +141,8 @@ serve_index(){ esac done < $IDX printf ".\r\n" + exec 1>&- + exec 2>&- exit 0 } |