Created
March 2, 2012 15:59
-
-
Save robspassky/1959319 to your computer and use it in GitHub Desktop.
bash shell script to serve an http request via inetd
This file contains hidden or 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/bash | |
# | |
# Shell script usable as web "server" | |
# Code mostly copied from web, my contribution was to add the sanitation. | |
# | |
### | |
### PARSE THE REQUEST | |
### | |
# first line is request | |
read request | |
# ignore the header | |
while /bin/true; do | |
read header | |
[ "$header" == $'\r' ] && break | |
done | |
# extract url, path, and query from request | |
url="${request#GET }" | |
url="${url% HTTP/*}" | |
path="${url%%\?*}" | |
query="${url#*\?}" | |
# make p_variables out of parameter string | |
for i in $(echo $query | sed 's/\&/\n/g') ; do | |
key=${i%%=*} | |
key=$(echo $key | sed 's/[^a-z_]//g') # sanitize, accept lowercase only + underscore | |
value=${i#*=} | |
value=$(echo $value | tr -d ';''\001'-'\011''\013''\014''\016'-'\037''\200'-'\377') # sanitize, remove non-printing chars and semicolon | |
eval "p_$key=$value" | |
done | |
### | |
### DO THE WORK | |
### | |
# | |
# there are plenty of extant examples for serving a file here | |
# google for "bash web server", etc. | |
# | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@thanks,
this is nice, but dont use it in services on the internet. Use it only on a protected network!