fix on nc invocation and several fixes on regexp

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

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

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

Loading…
Cancel
Save