From: Paul Hänsch Date: Mon, 2 Jul 2018 11:37:46 +0000 (+0200) Subject: auto recognize inetd mode, enabling use with busybox nc -ll X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=83858b60dffca6249f763e89a3a49c323dd76331;hp=3a5f8da6c094474cb5de33d40fc94e4497450a25;p=clickslide auto recognize inetd mode, enabling use with busybox nc -ll --- diff --git a/cgilite.sh b/cgilite.sh index f0f2fa9..cac905f 100755 --- a/cgilite.sh +++ b/cgilite.sh @@ -49,7 +49,9 @@ HEX_DECODE(){ ')" } -if [ "$1" = '--inetd' -a -z "$REQUEST_METHOD" ]; then +if [ -z "$REQUEST_METHOD" -a -z "$SERVER_PROTOCOL" ]; then + # no webserver variables means we are running via inetd / ncat + # so use builtin web server REMOTE_ADDR="${TCPREMOTEIP:-$NCAT_REMOTE_ADDR}" SERVER_NAME="${TCPLOCALIP:-$NCAT_LOCAL_ADDR}" SERVER_PORT="${TCPLOCALPORT:-$NCAT_LOCAL_PORT}" @@ -60,13 +62,11 @@ if [ "$1" = '--inetd' -a -z "$REQUEST_METHOD" ]; then cgilite_headers="$(sed -u '/^\r\?$/q')" HTTP_CONTENT_LENGTH="$(HEADER Content-Length |grep -xE '[0-9]+')" - HTTP_COOKIE="$(HEADER Cookie)" export REMOTE_ADDR SERVER_NAME SERVER_PORT REQUEST_METHOD REQUEST_URI SERVER_PROTOCOL \ - PATH_INFO QUERY_STRING HTTP_CONTENT_LENGTH HTTP_COOKIE + PATH_INFO QUERY_STRING HTTP_CONTENT_LENGTH - . "$0" |sed '1{s;^Status: ;HTTP/1.0 ;; t; iHTTP/1.0 200 OK\r - }' + . "$0" |sed '1{s;^Status: ;HTTP/1.0 ;; t; s;^;HTTP/1.0 200 OK\r\n;;}' exit $? fi