fix on nc invocation and several fixes on regexp

master
Hiltjo Posthuma 7 years ago committed by KatolaZ
parent 3ed2653b14
commit e86c8c70ad
  1. 27
      gosher
  2. 45
      gosher.8

@ -45,8 +45,8 @@
### ncat (from nmap)
##NETCAT="ncat"
##
### Openbsd netcat
NETCAT="nc.openbsd"
### OpenBSD netcat
NETCAT="nc"
##
## STYLE: The way in which netcat will talk to gosher_serve
@ -65,8 +65,7 @@ DEBUG=
[ -n "$DEBUG" ] && {
set -e
set -x
set -e -x
}
@ -77,7 +76,7 @@ cleanup(){
}
MYNAME=$(basename "$0")
MYDIR=$(dirname "$(realpath "$0")")
MYDIR=$(dirname "$(readlink -f "$0")")
NETCAT=$(which "$NETCAT")
if [ -z "${MYNAME#gosher}" ]; then
@ -103,7 +102,7 @@ if [ -z "${MYNAME#gosher}" ]; then
# shellcheck disable=SC2094
${GOSHER_SERVE} "${GOPHERDIR}" \
"${HOSTNAME}" "${PORT}" <"$INF" |\
${NETCAT} -vvvvv -l -p "${PORT}" >"$INF"
${NETCAT} -vvvvv -l "${HOSTNAME}" "${PORT}" >"$INF"
done
rm -f $INF
exit 0
@ -164,13 +163,13 @@ serve_index(){
echo "[$(date +%Y-%m-%d\ %H:%M:%S)|GPH|${IDX}|\"\"]" >&2
while read -r line; do
rline=$(echo "$line" | sed -r -e 's/\r//g')
rline=$(echo "$line" | tr -d '\r')
case "$rline" in
'['*)
echo "$rline" | sed -r -e 's/\[//g;s/\]//g;s/\|/\t/g;s/\t//;s/$/\r/g'
echo "$rline" | sed -r -e 's/\[//g;s/\]//g;s/\|/ /g;s/ //;s/$/\r/g'
;;
t*)
echo "$rline" | cut -c 2-
echo "$rline" | cut -c 2-
;;
*)
echo "$line"
@ -240,7 +239,7 @@ PORT=${3:-"70"}
read -r selector
selector=$(echo "$selector" | sed -r 's:\$.*::g;s:\r::g' )
selector=$(echo "$selector" | tr -d '\r' )
[ -n "$DEBUG" ] && {
echo "iGOPHERDIR: ${GOPHERDIR}"
@ -258,10 +257,10 @@ case $selector in
script_name=$(echo "$selector" | cut -d "?" -f 1)
query_string=$(echo "$selector" | cut -d "?" -f 2)
[ "${script_name}" = "${query_string}" ] && query_string=""
RP1=$(realpath "${GOPHERDIR}""${script_name}" || "")
RP1=$(readlink -f "${GOPHERDIR}""${script_name}" || "")
# shellcheck disable=SC2181
[ $? -eq 0 ] || invalid_selector "${selector}"
RP2=$(realpath "${GOPHERDIR}")"${script_name}"
RP2=$(readlink -f "${GOPHERDIR}")"${script_name}"
RP2=$(echo "${RP2}" | sed -r 's/\/+/\//g')
# shellcheck disable=SC2181
[ $? -eq 0 ] || invalid_selector "${selector}"
@ -279,10 +278,10 @@ case $selector in
;;
/?*|"")
## it's a regular selector
RP1=$(realpath "${GOPHERDIR}"/"${selector}" || "")
RP1=$(readlink -f "${GOPHERDIR}"/"${selector}" || "")
# shellcheck disable=SC2181
[ $? -eq 0 ] || invalid_selector "$selector"
RP2=$(realpath "${GOPHERDIR}")"${selector}"
RP2=$(readlink -f "${GOPHERDIR}")"${selector}"
# shellcheck disable=SC2181
[ $? -eq 0 ] || invalid_selector "$selector"
[ -n "$DEBUG" ] && {

@ -9,20 +9,17 @@
.Nm gosher
.Op Ar GOPHERDIR Op Ar HOSTNAME Op Ar PORT
.Sh DESCRIPTION
.Pp
.Ic gosher
.Nm
is a server for the Gopher protocol (RFC 1436) in a POSIX shell
script.
.Pp
Gopher is a textual protocol for information exchange over the Internet,
that provides a unified hierarchical menu-based interface. The Gopher
protocol has assigned port 70 by IANA.
that provides a unified hierarchical menu-based interface.
The Gopher protocol has assigned port 70 by IANA.
.Pp
.Ic gosher
.Nm
uses
.Em netcat(1)
.Xr nc 1
to listen for incoming connections on the specified
.Ar HOSTNAME
(defaults to 'localhost' if not specified) and
@ -32,33 +29,21 @@ to listen for incoming connections on the specified
is not specified) and makes available all the files under the folder
.Ar GOPHERDIR
(defaults to the current directory if not specified).
.\" This next request is for sections 1, 6, 7 & 8 only
.\".Sh ENVIRONMENT
.\".Sh EXAMPLES
.\" This next request is for sections 1, 6, 7 & 8 only
.\" (command return values (to shell) and
.\" fprintf/stderr type diagnostics)
.\" .Sh DIAGNOSTICS
.Sh SEE ALSO
lynx(1), gopher(1), sacc(1), clic(1)
.\" .Sh CONFORMING TO
.\" .Sh HISTORY
.Xr clic 1 ,
.Xr gopher 1 ,
.Xr lynx 1 ,
.Xr sacc 1 ,
.Sh AUTHORS
.Ic gosher
.Nm
is Free Software, distributed under the terms of the GNU
General Public License (GPL), version 3 of the License.
.Pp
.Ic gosher
.Nm
is copyleft (c) 2018 by
.An Vincenzo (KatolaZ) Nicosia <katolaz@freaknet.org>
.An Vincenzo (KatolaZ) Nicosia Aq Mt katolaz@freaknet.org
.Sh SECURITY CONSIDERATIONS
It is recommended to run
.Ic gosher
under chroot(8).
.Nm
under
.Xr chroot 8 .

Loading…
Cancel
Save