X-Git-Url: http://git.plutz.net/?p=cgilite;a=blobdiff_plain;f=cgilite.sh;h=b90899344f849fb5e71f262a630ee1482e1aeadf;hp=e009a2fed49748e4a9fd9905861643818f766c0c;hb=3fdb8e7e2ed8fcf3129de33147d1dd3b4a204b21;hpb=cb80645196ee9d9a757434e33d2a2a1c48b0a2a3 diff --git a/cgilite.sh b/cgilite.sh index e009a2f..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}" \ @@ -129,3 +160,4 @@ REDIRECT(){ printf 'Status: 303 See Other\r\nLocation: %s\r\n\r\n' "$*" exit 0 } +