Skip to content

Instantly share code, notes, and snippets.

@bourgeois
Created October 29, 2015 18:13
Show Gist options
  • Save bourgeois/2073b73a19f65720521b to your computer and use it in GitHub Desktop.
Save bourgeois/2073b73a19f65720521b to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
while true; do
netcat -lp 1234 -e '
read request_line
resource=$(echo $request_line | cut -f2 -d" " | cut -c 2-)
[ -n "$resource" ] || resource=.
say "Received request: $resource" 2> /dev/null
if [ -e "$resource" ]; then
echo "HTTP/1.0 200 OK"
if [ -d "$resource" ]; then
echo "Content-Type: text/html"
echo
ls "$resource" | while read file; do
if [ -d "$resource/$file" ]; then
echo "<a href=\"$resource/$file/\">$file/</a><br />"
else
echo "<a href=\"$resource/$file\">$file</a><br />"
fi
done
elif [[ "$resource" == *".php" ]]; then
echo
php -q "$resource"
else
echo
cat "$resource"
fi
else
echo "HTTP/1.0 404 Not Found"
echo "Content-Type: text/plain"
echo
echo "Resource \"$resource\" not found."
fi'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment