X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=cgilite.sh;h=b90899344f849fb5e71f262a630ee1482e1aeadf;hp=cbfa72466e1b1217988493e02e12238245e4fa69;hb=3fdb8e7e2ed8fcf3129de33147d1dd3b4a204b21;hpb=280bf2c08da810bc4b31bff91ad77a366e749e2a diff --git a/cgilite.sh b/cgilite.sh index cbfa724..b908993 100755 --- a/cgilite.sh +++ b/cgilite.sh @@ -22,6 +22,32 @@ # set -o posix # ksh, not portable setopt -o OCTAL_ZEROES 2>&- +BR="$(printf '\n')" +CR="$(printf '\r')" + +if [ "$1" = '--inetd' -a -z "$REQUEST_METHOD" ]; then + REMOTE_ADDR="${TCPREMOTEIP:-$NCAT_REMOTE_ADDR}" + SERVER_NAME="${TCPLOCALIP:-$NCAT_LOCAL_ADDR}" + SERVER_PORT="${TCPLOCALPORT:-$NCAT_LOCAL_PORT}" + + read REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL + PATH_INFO="${REQUEST_URI%\?*}" + QUERY_STRING="${REQUEST_URI#*\?}" + cgilite_headers="$(sed -u '/^\r\?$/q')" + + HTTP_CONTENT_LENGTH="$(printf %s "$cgilite_headers" |grep -oiE '^Content-Length: [0-9]+')" + HTTP_CONTENT_LENGTH="${HTTP_CONTENT_LENGTH#*: }" + HTTP_COOKIE="$(printf %s "$cgilite_headers" |grep -oiE '^Cookie: [^\r]+')" + HTTP_COOKIE="${HTTP_COOKIE#*: }" + + export REMOTE_ADDR SERVER_NAME SERVER_PORT REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL \ + PATH_INFO QUERY_STRING HTTP_CONTENT_LENGTH HTTP_COOKIE + + . "$0" |sed '1{s;^Status: ;HTTP/1.0 ;; t; iHTTP/1.0 200 OK\r + }' + exit $? +fi + if [ "$REQUEST_METHOD" = POST -a "${HTTP_CONTENT_LENGTH:=${CONTENT_LENGTH:=0}}" -gt 0 ]; then cgilite_post="$(head -c "$HTTP_CONTENT_LENGTH")" fi @@ -64,6 +90,11 @@ POST_COUNT(){ cgilite_count POST $1; } REF(){ cgilite_value REF $@; } REF_COUNT(){ cgilite_count REF $1; } +HEADER(){ + printf %s "$cgilite_headers" \ + | sed -rn '/^'"${1}"': /{s;^[^:]+: ([^\r]+)\r?$;\1;p;q;}' +} + COOKIE(){ printf "$( printf %s " ${HTTP_COOKIE}" \ @@ -126,6 +157,7 @@ SET_COOKIE(){ } REDIRECT(){ - printf '%s 303 See Other\r\nLocation: %s\r\n\r\n' "$SERVER_PROTOCOL" "$*" + printf 'Status: 303 See Other\r\nLocation: %s\r\n\r\n' "$*" exit 0 } +