2 #HTTPd.bash (Harvie 2oo9)
3 #WebServer+Small-INSECURE+Emergency+Filelisting+Mime+Unicode-BASH
4 #TODO: Security, Dynamic pages in BASH/PHP, Speed
5 #dependencies: GNU NetCat, Links, sed
8 web_root
='/home/harvie';
9 nc
='nc'; links
='links'; #binaries
11 if [ "$1" == '--serve' ]; then
12 urldecode
() { echo -e $
( echo "$@" |
sed -e 's/+/ /g;s/%/\\x/g' ); }
14 get
="$( head -n 1 | cut -d ' ' -f 2 )";
15 get
="$web_root$(urldecode $get)";
17 if [ -d "$get" ]; then content_type
='text/html;charset=utf-8';
18 else content_type
=$
(file -i "$get" | cut
-d ' ' -f 2-); fi;
23 Content-Type: '"$content_type"'
24 Connection: close\n\n';
26 if [ -d "$get" ]; then "$links" -source "$get"; else cat "$get"; fi;
30 listen
() { "$nc" -l -p "$listen_port" -e "kill -s USR1 '$$' & '$0' --serve"; }
32 trap 'listen &' SIGUSR1
;
33 trap "echo -e '\nHTTPd.bash stoped'; exit" SIGINT
;
35 echo -e "HTTPd.bash started\nHarvie 2oo9\nport: $listen_port\nroot: $web_root"
36 while true
; do sleep 0.1; done;
This page took 0.33777 seconds and 4 git commands to generate.