From: paul Date: Sat, 26 May 2018 15:23:34 +0000 (+0000) Subject: basic inetd support X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=32cacdeb99a6b9c864be839fcd4963d8ec502e29;p=cgilite basic inetd support svn path=/trunk/; revision=67 --- diff --git a/cgilite.sh b/cgilite.sh index e009a2f..b6ccd7f 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" + SERVER_NAME="$TCPLOCALIP" + SERVER_PORT="$TCPLOCALPORT" + + read REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL + PATH_INFO="${REQUEST_URI%\?*}" + QUERY_STRING="${REQUEST_URI#*\?}" + HTTP_HEADERS="$(sed -u '/^\r\?$/q')" + + HTTP_CONTENT_LENGTH="$(printf %s "$HTTP_HEADERS" |grep -oiE '^Content-Length: [0-9]+')" + HTTP_CONTENT_LENGTH="${HTTP_CONTENT_LENGTH%%: *}" + HTTP_COOKIE="$(printf %s "$HTTP_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 @@ -129,3 +155,4 @@ REDIRECT(){ printf 'Status: 303 See Other\r\nLocation: %s\r\n\r\n' "$*" exit 0 } +