summaryrefslogtreecommitdiff
path: root/rc/bin/rc-httpd/handlers/cgi
diff options
context:
space:
mode:
authorstanley lieber <stanley.lieber@gmail.com>2013-02-04 16:40:05 -0600
committerstanley lieber <stanley.lieber@gmail.com>2013-02-04 16:40:05 -0600
commitc877493fb00717de1a22860d88efb75ebf14ebec (patch)
treecb3cb0e47598e2880cdd20367925102856d41a5d /rc/bin/rc-httpd/handlers/cgi
parent0b212ed5054cd08bbc14a12936c07bc1ff5890a2 (diff)
downloadplan9front-c877493fb00717de1a22860d88efb75ebf14ebec.tar.xz
add rc-httpd
Diffstat (limited to 'rc/bin/rc-httpd/handlers/cgi')
-rwxr-xr-xrc/bin/rc-httpd/handlers/cgi54
1 files changed, 54 insertions, 0 deletions
diff --git a/rc/bin/rc-httpd/handlers/cgi b/rc/bin/rc-httpd/handlers/cgi
new file mode 100755
index 000000000..96707630c
--- /dev/null
+++ b/rc/bin/rc-httpd/handlers/cgi
@@ -0,0 +1,54 @@
+#!/bin/rc
+fn filter_headers{
+ response='HTTP/1.1 200 OK'^$cr
+ lines=''
+ done=false
+ while(~ $done false){
+ line=`{read}
+ head=`{echo $line | awk '{print tolower($1)}'}
+ if(~ $head status:*){
+ tmp=`{echo $line | awk '{$1="" ; print}'}
+ response='HTTP/1.1 '^$"tmp^$cr
+ }
+ if not if(~ $line '')
+ done=true
+ if not
+ lines=$"lines^$"line^$cr^'
+'
+ }
+ echo $response
+ echo -n $"lines
+}
+
+fn run_cgi {
+ path=$cgi_path exec $"cgi_bin $params
+}
+
+cgi_bin=$1
+if(! ~ $cgi_bin /*){
+ pwd=`{pwd}
+ cgi_bin=$"pwd ^ / ^ $cgi_bin
+}
+
+cgi_dir=$*($#*)
+if(! test -d $cgi_dir){
+ cgi_dir=`{basename -d $cgi_dir}
+ cgi_dir=$"cgi_dir
+}
+
+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 | {
+ filter_headers
+ emit_extra_headers
+ echo $cr
+ exec cat
+}