Last active
December 24, 2015 17:38
-
-
Save strake/6836680 to your computer and use it in GitHub Desktop.
HyperText GateKeeper: All requests go to given CGI script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/rc | |
fn hdrs { | |
ifs=' | |
' while ( x=`{ read | sed 's/:[ ]*/:/' } && ! ~ $#x 0) { | |
v=`{ echo $x | sed 's/:.*//' | tr - _ } | |
x=`{ echo $x | sed 's/^[^:]*:[ ]*//' } | |
HTTP_$v=$x | |
} | |
} | |
SERVER_SOFTWARE=htgs | |
SERVER_NAME=`{ cat /proc/sys/kernel/hostname } | |
GATEWAY_INTERFACE=1.1 | |
$//' } read | sed 's/ | |
~ $#req 3 || { | |
' echo 'HTTP/1.1 400 Bad Request | |
exit 1 | |
} | |
REQUEST_METHOD=$req(1) | |
REQUEST_URI=$req(2) | |
SERVER_PROTOCOL=$req(3) | |
hdrs | |
~ $#HTTP_Host 0 || SERVER_NAME=`{ echo $HTTP_Host | sed 's/:[^:]*$//' | tr -d '\x0A' } | |
statfile=`{ mktemp } | |
$* | { | |
{ | |
for (x in `{ printenv | grep '^HTTP_' | sed 's/=.*$//' }) $x=() | |
hdrs | |
~ $#HTTP_Status 0 && HTTP_Status=(200 Schön) | |
echo HTTP/1.1 $HTTP_Status | |
echo $HTTP_Status(1) >$statfile | |
printenv | grep '^HTTP_' | grep -v '^HTTP_Status=' | sed 's/^HTTP_//; s/=/: /; y/_/-/' | tr '\x01' ' ' | |
echo | |
/' } | sed 's/$/ | |
cat | |
} | |
if (~ $#HTGK_FETCH_LOG_FILE 0) HTGK_FETCH_LOG_FILE=/dev/null | |
awk 'BEGIN { system ("date -n | tr ''\n'' '' ''"); req=ENVIRON["req"]; gsub ("\x01", " ", req); getline stat <ENVIRON["statfile"]; printf "%s\t%s\t%s\n", ENVIRON["REMOTE_ADDR"], ENVIRON["SERVER_NAME"], req, stat; }' >>$HTGK_FETCH_LOG_FILE </dev/null | |
rm -f $statfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment