|
|
|
@ -26,6 +26,9 @@ NETCAT=netcat |
|
|
|
|
OPREFIX=/tmp/outf_ |
|
|
|
|
IPREFIX=/tmp/inf_ |
|
|
|
|
|
|
|
|
|
DEBUG= |
|
|
|
|
##DEBUG=yes |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## function |
|
|
|
|
cleanup(){ |
|
|
|
@ -43,17 +46,17 @@ if [ -z "${MYNAME#gosher}" ]; then |
|
|
|
|
PORT=${1:-70} |
|
|
|
|
GOPHERDIR=${2:-"./"} |
|
|
|
|
|
|
|
|
|
trap cleanup 0 HUP INT TRAP TERM QUIT |
|
|
|
|
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 & |
|
|
|
|
while [ 1 -eq 1 ]; do |
|
|
|
|
./gosher_serve ${GOPHERDIR} <$INF >$OUTF & |
|
|
|
|
${NETCAT} -vv -l -p ${PORT} >$INF <$OUTF |
|
|
|
|
ret=$? |
|
|
|
|
done |
|
|
|
|
exit 0 |
|
|
|
|
exit 0 |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -67,17 +70,16 @@ fi |
|
|
|
|
## function |
|
|
|
|
invalid_selector(){ |
|
|
|
|
sel="$1" |
|
|
|
|
echo "iInvalid selector: \"$sel\"" |
|
|
|
|
echo "3Error: Invalid selector: \"$sel\"" |
|
|
|
|
echo "." |
|
|
|
|
exit 1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
## function |
|
|
|
|
serve_selector(){ |
|
|
|
|
sel="$1" |
|
|
|
|
sel="$1" |
|
|
|
|
|
|
|
|
|
cat "${sel}" |
|
|
|
|
echo "." |
|
|
|
|
exit 0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -90,7 +92,7 @@ serve_index(){ |
|
|
|
|
' |
|
|
|
|
while read line; do |
|
|
|
|
rline=$(echo $line | sed -r -e 's/\r//g') |
|
|
|
|
case $rline in |
|
|
|
|
case $rline in |
|
|
|
|
'['*) |
|
|
|
|
echo $rline | sed -r -e 's/\[//g;s/\]//g;s/\|/\t/g;s/\t//;s/$/\r/g' |
|
|
|
|
;; |
|
|
|
@ -101,6 +103,7 @@ serve_index(){ |
|
|
|
|
echo $line |
|
|
|
|
esac |
|
|
|
|
done < $IDX |
|
|
|
|
printf ".\r\n" |
|
|
|
|
exit 0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -112,31 +115,33 @@ read selector |
|
|
|
|
|
|
|
|
|
selector=$(echo $selector | sed -r 's:\r::g' ) |
|
|
|
|
|
|
|
|
|
echo "iGOPHERDIR: ${GOPHERDIR}" |
|
|
|
|
echo "iselector: \"${selector}\"" |
|
|
|
|
[ -n "$DEBUG" ] && { |
|
|
|
|
echo "iGOPHERDIR: ${GOPHERDIR}" |
|
|
|
|
echo "iselector: \"${selector}\"" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
case $selector in |
|
|
|
|
/*|"") |
|
|
|
|
RP1=$(realpath "${GOPHERDIR}"/"${selector}" || "") |
|
|
|
|
RP2=$(realpath "${GOPHERDIR}")"${selector}" |
|
|
|
|
echo "iRP1: ${RP1}" |
|
|
|
|
echo "iRP2: ${RP2}" |
|
|
|
|
#echo "." |
|
|
|
|
RP2=$(realpath $(realpath "${GOPHERDIR}")"${selector}") |
|
|
|
|
[ -n "$DEBUG" ] && { |
|
|
|
|
echo "iRP1: ${RP1}" |
|
|
|
|
echo "iRP2: ${RP2}" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if [ "${RP1}" = "${RP2}" ]; then |
|
|
|
|
if [ -f "${RP1}" ]; then |
|
|
|
|
if [ "${RP1}" = "${RP2}" ]; then |
|
|
|
|
if [ -f "${RP1}" ]; then |
|
|
|
|
serve_selector "${RP1}" |
|
|
|
|
elif [ -d "${RP1}" ]; then |
|
|
|
|
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" |
|
|
|
|
fi |
|
|
|
|
invalid_selector "$selector" |
|
|
|
|
;; |
|
|
|
|
*) |
|
|
|
|
[ -f "${GOPHERDIR}/gophermap" ] && cat "${GOPHERDIR}/gophermap" && echo "." && exit 0 |
|
|
|
|
[ -f "${GOPHERDIR}/gophermap" ] && serve_selector "${GOPHERDIR}/gophermap" |
|
|
|
|
[ -f "${GOPHERDIR}/index.gph" ] && serve_index "${GOPHERDIR}/index.gph" |
|
|
|
|
invalid_selector "/" |
|
|
|
|
;; |
|
|
|
|
esac |
|
|
|
|