diff options
Diffstat (limited to 'gosher')
-rwxr-xr-x | gosher | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -134,9 +134,9 @@ fi ## function invalid_selector(){ sel="$1" - echo "3Error: Invalid selector: \"$sel\"" + echo "[$(date +%Y-%m-%d\ %H:%M:%S)|ERROR|${sel}|\"\"]" >&2 + printf "3Error: Invalid selector\tErr\t\t\r\n.\r\n" # shellcheck disable=SC1117 - printf ".\r\n" exec 1>&- exec 2>&- exit 1 @@ -147,7 +147,7 @@ serve_selector(){ sel="$1" cat "${sel}" - echo "$0: selector $sel served -- exiting " >&2 + echo "[$(date +%Y-%m-%d\ %H:%M:%S)|SELECTOR|${sel}|\"\"]" >&2 exec 1>&- exec 2>&- exit 0 @@ -160,6 +160,8 @@ serve_index(){ IDX=$1 IFS=' ' + + 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') case "$rline" in @@ -184,6 +186,8 @@ serve_index(){ ## function serve_redirect(){ url=$1 + + echo "[$(date +%Y-%m-%d\ %H:%M:%S)|REDIRECT|${url}|\"\"]" >&2 cat<< EOF <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> @@ -205,7 +209,7 @@ EOF serve_cgi(){ script_name=$( echo "$1" | sed -r 's:^/+::') query_string="$2" - echo "serving script_name: ${script_name} with query_string: ${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}" @@ -223,6 +227,8 @@ serve_cgi(){ export REMOTE_ADDR REMOTE_HOST REQUEST_METHOD SCRIPT_NAME export SERVER_NAME SERVER_PORT SERVER_PROTOCOL SERVER_SOFTWARE ${GOPHERDIR}${script_name} "" "${query_string}" "${HOSTNAME}" "${PORT}" 2>&1 + exec 1>&- + exec 2>&- exit $? } @@ -243,7 +249,7 @@ selector=$(echo "$selector" | sed -r 's:\$.*::g;s:\r::g' ) case $selector in URL:*) ## it's a special URL selector - url=$(echo "$selector" | cut -d ":" -f 2-) + url=$(echo "$selector" | cut -d ":" -f 2- | sed 's:^//::g') serve_redirect "$url" ;; /?*.cgi*) |