summaryrefslogtreecommitdiff
path: root/bin/contrib/rc-httpd/handlers/cgi
diff options
context:
space:
mode:
authorglenda <glenda@9front.local>2020-11-15 15:13:27 +0000
committerglenda <glenda@9front.local>2020-11-15 15:13:27 +0000
commit39318169e0b50551db511851829f9337c5fa6313 (patch)
tree65a0ef5c1da9677532fa8105293d017919473057 /bin/contrib/rc-httpd/handlers/cgi
Import site to git
Diffstat (limited to 'bin/contrib/rc-httpd/handlers/cgi')
-rwxr-xr-xbin/contrib/rc-httpd/handlers/cgi46
1 files changed, 46 insertions, 0 deletions
diff --git a/bin/contrib/rc-httpd/handlers/cgi b/bin/contrib/rc-httpd/handlers/cgi
new file mode 100755
index 0000000..2c9a9b9
--- /dev/null
+++ b/bin/contrib/rc-httpd/handlers/cgi
@@ -0,0 +1,46 @@
+#!/bin/rc
+fn filter_headers{
+ response=(200 OK)
+ lines=''
+ done=false
+ while(~ $done false){
+ line=`{getline}
+ head=`{echo $line | awk '{print tolower($1)}'}
+ if(~ $head status:*)
+ response=`{echo $line | awk '{$1="" ; print}'}
+ if not if(~ $line '')
+ done=true
+ if not
+ lines=$"lines^$"line^$cr^'
+'
+ }
+ echo 'HTTP/1.1' $"response^$cr
+ echo -n $"lines
+ do_log $response(1)
+}
+
+fn run_cgi {
+ path=$cgi_path exec $"cgi_bin $params || echo 'Status: 500'
+}
+
+cgi_bin=$1
+cgi_dir=.
+if(! ~ $#* 1)
+ cgi_dir=$*($#*)
+if not if(~ $"cgi_bin /*){
+ cgi_dir=`{basename -d $"cgi_bin}
+ 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
+}
+
+run_cgi | {
+ filter_headers
+ emit_extra_headers
+ echo $cr
+ exec cat
+}