Created
April 21, 2011 15:42
-
-
Save eatnumber1/934798 to your computer and use it in GitHub Desktop.
Drink Sunday -> HTTP Proxy
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/zsh | |
emulate -L zsh | |
typeset -r PROGRAM="$0" | |
function parent() { | |
typeset -r HOST="${${PROGRAM##*/}%\.cgi}.csh.rit.edu" | |
echo "Content-Type: text/plain" | |
echo | |
CHILD=1 exec /usr/bin/socat OPENSSL:"$HOST":4243,cafile=/etc/ssl/certs/csh-ca.pem EXEC:"$PROGRAM",fdin=3,fdout=4,sighup,sigint,sigquit | |
} | |
function child() { | |
local cmd line | |
while read -ru 3 line; do | |
print -r "$line" | |
if [[ $line =~ (OK|ERR).* ]]; then | |
read -r cmd || exit 0 | |
print -ru 4 "$cmd" | |
fi | |
done | |
} | |
if (( ${+CHILD} )); then | |
exec child | |
else | |
exec parent | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment