]> git.plutz.net Git - cgilite/commitdiff
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 f0f2fa90a02e0883e84b5b3c88b32b50eb6ced20..cac905ff6ace8ae929572c5ec8a9e69afbca54ad 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