2013-02-04 22:40:05 +00:00
|
|
|
#!/bin/rc
|
|
|
|
fn filter_headers{
|
2015-06-02 14:56:19 +00:00
|
|
|
response=(200 OK)
|
2013-02-04 22:40:05 +00:00
|
|
|
lines=''
|
|
|
|
done=false
|
|
|
|
while(~ $done false){
|
2015-03-14 00:02:43 +00:00
|
|
|
line=`{getline}
|
2013-02-04 22:40:05 +00:00
|
|
|
head=`{echo $line | awk '{print tolower($1)}'}
|
2015-06-02 14:56:19 +00:00
|
|
|
if(~ $head status:*)
|
|
|
|
response=`{echo $line | awk '{$1="" ; print}'}
|
2013-02-04 22:40:05 +00:00
|
|
|
if not if(~ $line '')
|
|
|
|
done=true
|
|
|
|
if not
|
|
|
|
lines=$"lines^$"line^$cr^'
|
|
|
|
'
|
|
|
|
}
|
2015-06-02 14:56:19 +00:00
|
|
|
echo 'HTTP/1.1' $"response^$cr
|
2013-02-04 22:40:05 +00:00
|
|
|
echo -n $"lines
|
2015-06-02 14:56:19 +00:00
|
|
|
do_log $response(1)
|
2013-02-04 22:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn run_cgi {
|
2015-06-02 14:56:19 +00:00
|
|
|
path=$cgi_path exec $"cgi_bin $params || echo 'Status: 500'
|
2013-02-04 22:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cgi_bin=$1
|
2015-06-02 14:56:19 +00:00
|
|
|
cgi_dir=.
|
|
|
|
if(! ~ $#* 1)
|
|
|
|
cgi_dir=$*($#*)
|
|
|
|
if not if(~ $"cgi_bin /*){
|
|
|
|
cgi_dir=`{basename -d $"cgi_bin}
|
2013-02-04 22:40:05 +00:00
|
|
|
cgi_dir=$"cgi_dir
|
|
|
|
}
|
2015-06-02 14:56:19 +00:00
|
|
|
if(! ~ $"cgi_bin */*)
|
|
|
|
cgi_bin=./$"cgi_bin
|
|
|
|
if(! builtin cd $"cgi_dir >[2]/dev/null || ! test -x $"cgi_bin){
|
2013-02-04 22:40:05 +00:00
|
|
|
error 500
|
|
|
|
exit
|
|
|
|
}
|
2015-06-02 14:56:19 +00:00
|
|
|
|
2013-02-04 22:40:05 +00:00
|
|
|
run_cgi | {
|
|
|
|
filter_headers
|
|
|
|
emit_extra_headers
|
|
|
|
echo $cr
|
|
|
|
exec cat
|
|
|
|
}
|