auto recognize inetd mode, enabling use with busybox nc -ll
authorPaul Hänsch <paul@plutz.net>
Mon, 2 Jul 2018 11:37:46 +0000 (13:37 +0200)
committerPaul Hänsch <paul@plutz.net>
Mon, 2 Jul 2018 11:37:46 +0000 (13:37 +0200)
cgilite.sh

index f0f2fa9..cac905f 100755 (executable)
@@ -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