added further checks

master 0.2
KatolaZ 6 years ago
parent fe87591ab6
commit 1df4353134
  1. 2
      TODO
  2. 52
      gosher

@ -1,5 +1,5 @@
- use getopt
- add chroot and privilege drop
- allow on-the-fly creation of gopherfle from a folder (set it active
through an option)

@ -43,7 +43,7 @@ NETCAT="nc.openbsd"
### use named pipes (Does *not* work with original netcat!!!!!)
STYLE='pipe'
OPREFIX=/tmp/outf_
### prefix of the input FIFO
IPREFIX=/tmp/inf_
DEBUG=
@ -63,6 +63,8 @@ cleanup(){
}
MYNAME=$(basename $0)
MYDIR=$(dirname $(realpath $0))
NETCAT=$(which $NETCAT)
if [ -z "${MYNAME#gosher}" ]; then
## we are called as gosher -- launch the server
@ -70,28 +72,38 @@ if [ -z "${MYNAME#gosher}" ]; then
PORT=${1:-70}
GOPHERDIR=${2:-"./"}
trap cleanup 0 HUP INT TRAP TERM QUIT
INF=${IPREFIX}$$
[ "$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
[ ! -f "${NETCAT}" -o ! -x "${NETCAT}" ] && {
echo "Wrong NETCAT -- Exiting" >&2
exit 2
}
echo "Error!!! wrong STYLE specified!!!" >&2
exit 1
if [ -f "${MYDIR}/gosher_serve" -o -h "${MYDIR}/gosher_serve" ]; then
GOSHER_SERVE="${MYDIR}/gosher_serve"
trap cleanup 0 HUP INT TRAP TERM QUIT
INF=${IPREFIX}$$
[ "$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 "${GOSHERSERVE} ${GOPHERDIR}"
done
exit 0
}
echo "Wrong STYLE specified -- Exiting" >&2
exit 2
else
echo "Cannot find gosher_serve -- Exiting">&2
exit 3
fi
fi
######################
##

Loading…
Cancel
Save