werc-1.5.0-tweaks

Tweaks for the werc website builder created by the mad architect Uriel
Log | Files | Refs | README

cgi (796B)


      1 #!/bin/rc
      2 fn filter_headers{
      3 	response=(200 OK)
      4 	lines=''
      5 	done=false
      6 	while(~ $done false){
      7 		line=`{getline}
      8 		head=`{echo $line | awk '{print tolower($1)}'}
      9 		if(~ $head status:*)
     10 			response=`{echo $line | awk '{$1="" ; print}'}
     11 		if not if(~ $line '')
     12 			done=true
     13 		if not
     14 			lines=$"lines^$"line^$cr^'
     15 '
     16 	}
     17 	echo 'HTTP/1.1' $"response^$cr
     18 	echo -n $"lines
     19 	do_log $response(1)
     20 }
     21 
     22 fn run_cgi {
     23 	path=$cgi_path exec $"cgi_bin $params || echo 'Status: 500'
     24 }
     25 
     26 cgi_bin=$1
     27 cgi_dir=.
     28 if(! ~ $#* 1)
     29 	cgi_dir=$*($#*)
     30 if not if(~ $"cgi_bin /*){
     31 	cgi_dir=`{basename -d $"cgi_bin}
     32 	cgi_dir=$"cgi_dir
     33 }
     34 if(! ~ $"cgi_bin */*)
     35 	cgi_bin=./$"cgi_bin
     36 if(! builtin cd $"cgi_dir >[2]/dev/null || ! test -x $"cgi_bin){
     37 	error 500
     38 	exit
     39 }
     40 
     41 run_cgi | {
     42 	filter_headers
     43 	emit_extra_headers
     44 	echo $cr
     45 	exec cat
     46 }