summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2018-07-23 12:19:34 +0100
committerKatolaZ <katolaz@freaknet.org>2018-07-23 12:19:34 +0100
commit1df435313418065be6eb6ab2f7aaf47b9a3876e6 (patch)
tree5aff5356ae8039dbea9607832c3be347bdbde083
parentfe87591ab64d343b6634a8aaae397ec1acb4d88c (diff)
added further checks0.2
-rw-r--r--TODO2
-rwxr-xr-xgosher52
2 files changed, 33 insertions, 21 deletions
diff --git a/TODO b/TODO
index 3d53072..51eba8e 100644
--- a/TODO
+++ b/TODO
@@ -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)
-
diff --git a/gosher b/gosher
index 668a2db..31e9abf 100755
--- a/gosher
+++ b/gosher
@@ -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
-
######################
##