Skip to content

Instantly share code, notes, and snippets.

@noktoborus
Created June 20, 2016 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noktoborus/26263b735039603d85953a26514d8a3b to your computer and use it in GitHub Desktop.
Save noktoborus/26263b735039603d85953a26514d8a3b to your computer and use it in GitHub Desktop.
#!/bin/sh
# vim: ft=sh ff=unix fenc=utf-8
# file: /httpsh.sh
if [ x"$X_BEGIN" != x"yes" ];
then
export X_BEGIN=yes
timeout 5 $0 $@
exit $?
fi
while read line;
do
echo "$line" | logger -t httpsh
echo "$line" | grep "^\(.\)\?$" >/dev/null && break
_FILE=$(echo "$line" | sed -e 's/^\(GET \(.*\) HTTP\/.*\|.*\)\(\r\|$\)/\2/')
_HOST=$(echo "$line" | sed -e 's/^\(Host: \(.*\)\|.*\)\(\r\|$\)/\2/')
_AENC=$(echo "$line" | sed -e 's/^\(Accept-Encoding: \(.*\)\|.*\)\(\r\|$\)/\2/')
_ALANG=$(echo "$line" | sed -e 's/^\(Accept-Language: \(.*\)\|.*\)\(\r\|\n\)/\2/')
_COOKIE=$(echo "$line" | sed -e 's/^\(Cookie: \(.*\)\|.*\)\(\r\|$\)/\2/')
[ -z "$FILE" -a ! -z "$_FILE" ] && FILE=$_FILE
[ -z "$HOST" -a ! -z "$_HOST" ] && HOST=$_HOST
[ -z "$AENC" -a ! -z "$_AENC" ] && AENC=$_AENC
[ -z "$ALANG" -a ! -z "$_ALANG" ] && ALANG=$_ALANG
[ -z "$COOKIE" -a ! -z "$_COOKIE" ] && COOKIE=$_COOKIE
done
enc_gzip=$(echo "$AENC" | grep '\([^a-z]\|^\)gzip\([^a-z]\|$\)')
_lang=$(echo "$ALANG" | sed -e 's/\([a-zA-Z\-]*\).*\|.*/\1/' -e 's/-/_/')
_locale=$(locale -a | grep -im1 "^${_lang}.*\.\(utf8\|UTF-8\|UTF_8\)$")
if [ ! -z "$_locale" ];
then
export LC_ALL=$_locale
export LANG=$_locale
fi
printf "HTTP/1.0 200 OK\r\n"
printf "Content-Type: text/plain; charset=utf8\r\n"
[ ! -z "$enc_gzip" ] && printf "Content-Encoding: gzip\r\n"
printf "\r\n"
print_mongosel() {
}
case "$FILE" in
/cal)
cal -y
;;
/)
;;
*)
echo "go to http://$HOST/cal for cal for this year"
;;
esac | ([ ! -z "$enc_gzip" ] && gzip -9 || cat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment