summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgosher74
1 files changed, 36 insertions, 38 deletions
diff --git a/gosher b/gosher
index fa2eeb8..60c2eae 100755
--- a/gosher
+++ b/gosher
@@ -98,20 +98,22 @@ if [ -z "${MYNAME#gosher}" ]; then
[ "$STYLE" = "pipe" ] && {
mkfifo -m 600 "$INF"
# shellcheck disable=SC2050
- while [ 1 -eq 1 ]; do
+ while :; do
# shellcheck disable=SC2094
${GOSHER_SERVE} "${GOPHERDIR}" \
"${HOSTNAME}" "${PORT}" <"$INF" |\
${NETCAT} -vvvvv -l "${HOSTNAME}" "${PORT}" >"$INF"
+ sleep 1
done
rm -f $INF
exit 0
}
[ "$STYLE" = 'fork' ] && {
# shellcheck disable=SC2050
- while [ 1 -eq 1 ]; do
+ while :; do
${NETCAT} -vv -l -p "$PORT" -c \
"${GOSHER_SERVE} ${GOPHERDIR} ${HOSTNAME} ${PORT}"
+ sleep 1
done
exit 0
}
@@ -153,28 +155,26 @@ serve_selector(){
exit 0
}
-
### transform a .gph file into a gophermap
## function
serve_index(){
- IDX=$1
- IFS='
-'
+ IDX=$1
echo "[$(date +%Y-%m-%d\ %H:%M:%S)|GPH|${IDX}|\"\"]" >&2
- while read -r line; do
- rline=$(echo "$line" | tr -d '\r')
- case "$rline" in
- '['*)
- echo "$rline" | sed -r -e 's/\[//g;s/\]//g;s/\|/ /g;s/ //;s/$/\r/g'
- ;;
- t*)
- echo "$rline" | cut -c 2-
- ;;
- *)
- echo "$line"
- esac
- done < "$IDX"
+ while read -r line; do
+ rline=$(echo "$line" | tr -d '\r')
+ case "$rline" in
+ '['*)
+ line=$(echo "$rline" | sed -r -e 's/\[//g;s/\]//g;s/\|/ /g;s/ / /;')
+ ;;
+ t*)
+ line=$(echo "$rline" | cut -b 2-)
+ ;;
+ *)
+ ;;
+ esac
+ printf '%s\r\n' "$line"
+ done < "$IDX"
# shellcheck disable=SC1117
printf ".\r\n"
exec 1>&-
@@ -210,19 +210,19 @@ serve_cgi(){
script_name=$( echo "$1" | sed -r 's:^/+::')
query_string="$2"
echo "[$(date +%Y-%m-%d\ %H:%M:%S)|CGI|${script_name}|\"${query_string}\"]" >&2
- GATEWAY_INTERFACE="CGI/1.1"
- PATH_INFO="${script_name}"
- PATH_TRANSLATED="${script_name}"
+ GATEWAY_INTERFACE="CGI/1.1"
+ PATH_INFO="${script_name}"
+ PATH_TRANSLATED="${script_name}"
[ -n "${QUERY_STRING}" ] && QUERY_STRING="${query_string}"
- REMOTE_ADDR=
- REMOTE_HOST=
- REQUEST_METHOD="GET"
- SCRIPT_NAME="${script_name}"
- SERVER_NAME="${HOSTNAME}"
- SERVER_PORT="${PORT}"
- SERVER_PROTOCOL="gopher/1.0"
- SERVER_SOFTWARE="gosher"
- ####X_GOPHER_SEARCH= search (See above.)
+ REMOTE_ADDR=
+ REMOTE_HOST=
+ REQUEST_METHOD="GET"
+ SCRIPT_NAME="${script_name}"
+ SERVER_NAME="${HOSTNAME}"
+ SERVER_PORT="${PORT}"
+ SERVER_PROTOCOL="gopher/1.0"
+ SERVER_SOFTWARE="gosher"
+ ####X_GOPHER_SEARCH= search (See above.)
export GATEWAY_INTERFACE PATH_INFO PATH_TRANSLATED QUERY_STRING
export REMOTE_ADDR REMOTE_HOST REQUEST_METHOD SCRIPT_NAME
export SERVER_NAME SERVER_PORT SERVER_PROTOCOL SERVER_SOFTWARE
@@ -238,7 +238,6 @@ HOSTNAME=${2:-"localhost"}
PORT=${3:-"70"}
read -r selector
-
selector=$(echo "$selector" | tr -d '\r' )
[ -n "$DEBUG" ] && {
@@ -249,19 +248,19 @@ selector=$(echo "$selector" | tr -d '\r' )
case "$selector" in
URL:*)
## it's a special URL selector
- url=$(echo "$selector" | cut -d ":" -f 2- | sed 's:^//::g')
+ url=$(echo "$selector" | cut -d ":" -f 2-)
serve_redirect "$url"
- ;;
+ ;;
/?*.cgi*)
## it's a CGI
script_name=$(echo "$selector" | cut -d "?" -f 1)
query_string=$(echo "$selector" | cut -d "?" -f 2)
[ "${script_name}" = "${query_string}" ] && query_string=""
- RP1=$(readlink -f "${GOPHERDIR}""${script_name}" || "")
+ RP1=$(readlink -f "${GOPHERDIR}""${script_name}")
# shellcheck disable=SC2181
[ $? -eq 0 ] || invalid_selector "${selector}"
RP2=$(readlink -f "${GOPHERDIR}")"${script_name}"
- RP2=$(echo "${RP2}" | sed -r 's/\/+/\//g')
+ RP2=$(echo "${RP2}" | sed -r 's:/+:/:g')
# shellcheck disable=SC2181
[ $? -eq 0 ] || invalid_selector "${selector}"
[ -n "$DEBUG" ] && {
@@ -278,7 +277,7 @@ case "$selector" in
;;
/?*|"")
## it's a regular selector
- RP1=$(readlink -f "${GOPHERDIR}"/"${selector}" || "")
+ RP1=$(readlink -f "${GOPHERDIR}"/"${selector}")
# shellcheck disable=SC2181
[ $? -eq 0 ] || invalid_selector "$selector"
RP2=$(readlink -f "${GOPHERDIR}")"${selector}"
@@ -312,4 +311,3 @@ case "$selector" in
invalid_selector "/"
;;
esac
-