rc-httpd: cleanup cgi handler
- avoid silly stats and checks for $cgi_dir, just use status from builtin cd. - log proper http status code from the cgi script
This commit is contained in:
parent
8caf4d3bcb
commit
1a1863e5dc
1 changed files with 17 additions and 25 deletions
|
@ -1,51 +1,43 @@
|
||||||
#!/bin/rc
|
#!/bin/rc
|
||||||
fn filter_headers{
|
fn filter_headers{
|
||||||
response='HTTP/1.1 200 OK'^$cr
|
response=(200 OK)
|
||||||
lines=''
|
lines=''
|
||||||
done=false
|
done=false
|
||||||
while(~ $done false){
|
while(~ $done false){
|
||||||
line=`{getline}
|
line=`{getline}
|
||||||
head=`{echo $line | awk '{print tolower($1)}'}
|
head=`{echo $line | awk '{print tolower($1)}'}
|
||||||
if(~ $head status:*){
|
if(~ $head status:*)
|
||||||
tmp=`{echo $line | awk '{$1="" ; print}'}
|
response=`{echo $line | awk '{$1="" ; print}'}
|
||||||
response='HTTP/1.1 '^$"tmp^$cr
|
|
||||||
}
|
|
||||||
if not if(~ $line '')
|
if not if(~ $line '')
|
||||||
done=true
|
done=true
|
||||||
if not
|
if not
|
||||||
lines=$"lines^$"line^$cr^'
|
lines=$"lines^$"line^$cr^'
|
||||||
'
|
'
|
||||||
}
|
}
|
||||||
echo $response
|
echo 'HTTP/1.1' $"response^$cr
|
||||||
echo -n $"lines
|
echo -n $"lines
|
||||||
|
do_log $response(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_cgi {
|
fn run_cgi {
|
||||||
path=$cgi_path exec $"cgi_bin $params
|
path=$cgi_path exec $"cgi_bin $params || echo 'Status: 500'
|
||||||
}
|
}
|
||||||
|
|
||||||
cgi_bin=$1
|
cgi_bin=$1
|
||||||
if(! ~ $cgi_bin /*){
|
cgi_dir=.
|
||||||
pwd=`{pwd}
|
if(! ~ $#* 1)
|
||||||
cgi_bin=$"pwd ^ / ^ $cgi_bin
|
cgi_dir=$*($#*)
|
||||||
}
|
if not if(~ $"cgi_bin /*){
|
||||||
|
cgi_dir=`{basename -d $"cgi_bin}
|
||||||
cgi_dir=$*($#*)
|
|
||||||
if(! test -d $cgi_dir){
|
|
||||||
cgi_dir=`{basename -d $cgi_dir}
|
|
||||||
cgi_dir=$"cgi_dir
|
cgi_dir=$"cgi_dir
|
||||||
}
|
}
|
||||||
|
if(! ~ $"cgi_bin */*)
|
||||||
|
cgi_bin=./$"cgi_bin
|
||||||
|
if(! builtin cd $"cgi_dir >[2]/dev/null || ! test -x $"cgi_bin){
|
||||||
|
error 500
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
if(! test -d $"cgi_dir){
|
|
||||||
error 500
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
if(! test -f $cgi_bin -x $cgi_bin){
|
|
||||||
error 500
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
do_log 200
|
|
||||||
builtin cd $"cgi_dir
|
|
||||||
run_cgi | {
|
run_cgi | {
|
||||||
filter_headers
|
filter_headers
|
||||||
emit_extra_headers
|
emit_extra_headers
|
||||||
|
|
Loading…
Reference in a new issue