ref: 1ba3bb1c65e076b508c5e615582e777ef39240dd
parent: 9681c09647c3d4ef8bd5ab25df88cf7176c55707
author: sl <[email protected]>
date: Thu Feb 4 16:47:22 EST 2016
bin/contrib/rc-httpd/: fix default paths and environment variables; create a generic default select-handler; add tcp80, used for launching rc-httpd from listen(8)
--- a/bin/contrib/rc-httpd/rc-httpd
+++ b/bin/contrib/rc-httpd/rc-httpd
@@ -1,7 +1,7 @@
#!/bin/rc
-rc_httpd_dir=/rc/bin/rc-httpd
-path=(/bin $rc_httpd_dir/handlers)
-cgi_path=/bin
+rc_httpd_dir=/home/sl/www/werc/bin/contrib/rc-httpd
+path=($PLAN9/bin $rc_httpd_dir/handlers)
+cgi_path=$PLAN9/bin
SERVER_PORT=80 # default for CGI scripts, may be overridden by the Host header
extra_headers='Server: rc-httpd'
cr=
--- a/bin/contrib/rc-httpd/select-handler
+++ b/bin/contrib/rc-httpd/select-handler
@@ -1,177 +1,12 @@
#!/bin/rc
-# 2016-02-01T19:31:03-0500
rfork n
-fn do_error{
- do_log $1
- echo 'HTTP/1.1 '^$1^$cr
- emit_extra_headers
- echo 'Content-type: text/html'^$cr
- echo $cr
- echo '<html>
-<head>
-<title>'^$1^'</title>
-</head>
-<body>
-<h1>'^$1^'</h1>'
- echo $2
- echo '<p><i>rc-httpd at' $SERVER_NAME '</i>'
- echo '
- </body>
- </html>
- '
-}
-fn http_redirect {
- if(~ $1 http://* https://*)
- t=$1
- if not if(~ $1 /*)
- t=$"base_url^$1
- if not
- t=$"base_url^$"req_path^$1
- exec /bin/echo 'Status: '^$2^'
-Location: '^$t^'
-
-'
- exit
-}
-
-fn okstatic{
- full_path=`{echo $"FS_ROOT^$"PATH_INFO | urlencode -d}
- full_path=$"full_path
- if(~ $full_path */)
- error 503
- if(test -d $full_path){
- redirect perm $"location^'/' \
- 'URL not quite right, and browser did not accept redirect.'
- exit
- }
- if(! test -e $full_path){
- error 404
- exit
- }
- if(! test -r $full_path){
- error 503
- exit
- }
- do_log 200
- type='text/plain'
- max_age=3600 # 1 hour
- echo 'HTTP/1.1 200 OK'^$cr
- emit_extra_headers
- echo 'Content-type: '^$type^'; charset=utf-8'^$cr
- echo 'Content-length: '^`{ls -l $full_path | awk '{print $6}'}
- echo 'Cache-control: max-age='^$max_age^$cr
- echo $cr
- exec cat $full_path
-}
-
-# surprise!
-if(~ $HTTP_REFERER *hiphopstan.com/forum* *slax.*/forum*){
+# Route requests to werc.
+# Change the werc path to match your system.
+if(~ $SERVER_NAME *){
PATH_INFO=$location
- FS_ROOT=/usr/sl/www/werc/sites/hotlink
- exec static-or-index
-}
-if(~ $HTTP_REFERER 'http://okturing.com/index.rc?start=100' || {~ $SERVER_NAME okturing.com && ~ $location /index.rc} || ~ $location /qemu/plan9.flp.gz){
- do_error '402 PAYMENT REQUIRED'
- exit
-}
-if(~ $location /*/wp-admin* /wiki/index.php* /wp/wp-admin* /wp-config* /wp-content/* wp-login.php* /admin.php* /index.php/admin* /phpinfo.php* /phpMyAdmin/* /phpMyAdmin-2/* /*xmlrpc.php){
- do_error '402 PAYMENT REQUIRED'
- exit
-}
-
-# build environment and namespace
-SERVER_NAME=`{echo $SERVER_NAME | sed 's/^www\.//g'}
-
-if(~ $location *~nis*)
- location=`{echo $location | sed 's/\/\~nis/\/_nis/g'}
-
-if(~ $SERVER_NAME 9front.org){
- bind /usr/sl/plan9front /usr/sl/www/werc/sites/9front.org/9front
- bind /usr/sl/www/werc/sites/9front.org/_werc/pub/style.css /usr/sl/www/werc/pub/style/style.css
- bind /usr/sl/www/werc/sites/plan9.stanleylieber.com/src /usr/sl/www/werc/sites/9front.org/extra
- aux/stub -d /usr/sl/www/werc/sites/9front.org/extra/rc
- bind /usr/sl/www/werc/sites/plan9.stanleylieber.com/rc /usr/sl/www/werc/sites/9front.org/extra/rc
- bind /usr/sl/www/werc/sites/bell-labs.co/9front/iso /usr/sl/www/werc/sites/9front.org/iso
- bind /usr/sl/www/werc/sites/plan9.stanleylieber.com/pkg /usr/sl/www/werc/sites/9front.org/pkg
- if(~ $location /who/*){
- for(i in Aram aiju alvaro cinap_lenrek eekee erik joy kenji lf94 martian67 mveety rminnich sl)
- bind /usr/sl/www/werc/sites/9front.org/$i /usr/sl/www/werc/sites/9front.org/who/$i/index.txt
- }
- aux/stub /usr/sl/www/werc/sites/9front.org/9front.torrent
- bind /usr/sl/www/werc/sites/bell-labs.co/9front/iso/9front-5048.e16a172bcae6.iso.bz2.torrent /usr/sl/www/werc/sites/9front.org/9front.torrent
- if(~ $location /list.html)
- location=/lists.html
-}
-if(~ $SERVER_NAME bugs.9front.org){
- bind /usr/sl/www/werc/sites/bugs.9front.org/_werc/pub/style.css /usr/sl/www/werc/pub/style/style.css
- bind -a /usr/bugs /usr/sl/www/werc/sites/bugs.9front.org
- if(~ $location /closed/[a-z0-9]* /open/[a-z0-9]*){
- d=`{basename -d $location}
- aux/stub /usr/sl/www/werc/sites/bugs.9front.org^$d^/index.md
- bind /usr/bugs^$d^/readme /usr/sl/www/werc/sites/bugs.9front.org^$d^/index.md
- }
-}
-if(~ $SERVER_NAME fqa.9front.org){
- #location=`{echo $"location | sed 's/^(fqa|appendix).*\.html$//g'}
-}
-if(~ $SERVER_NAME lists.9front.org){
- for(i in 9atom 9changes 9fans 9front 9front-bugs 9front-commits 9front-sysinfo 9nag acme-sac cat-v cypherpunks dlr harvey harvey-commits harvey-issues inferno nix plan9port-dev sam-fans sierra31 skunk-works tscm-l tuhs werc www-html www-talk www-vrml)
- bind /mail/box/$i/mbox /usr/sl/www/werc/sites/lists.9front.org/$i
-}
-if(~ $SERVER_NAME wiki.9front.org)
- bind /usr/sl/www/werc/sites/wiki.9front.org/_werc/pub/style.css /usr/sl/www/werc/pub/style/style.css
-if(~ $SERVER_NAME golang.cat-v.org)
- bind /usr/sl/www/werc/sites/go-lang.cat-v.org /usr/sl/www/werc/sites/golang.cat-v.org
-if(~ $SERVER_NAME plan9.stanleylieber.com){
- bind /usr/sl/www/werc/sites/plan9.stanleylieber.com/_werc/pub/style.css /usr/sl/www/werc/pub/style/style.css
- bind /mail/lib /usr/sl/www/werc/sites/plan9.stanleylieber.com/mail/lib
- bind /sys/lib/dist/mail/lib/names.local /usr/sl/www/werc/sites/plan9.stanleylieber.com/mail/lib/names.local
- bind /rc/bin/service.crazy/tcp587 /usr/sl/www/werc/sites/plan9.stanleylieber.com/mail/service/tcp587
- bind /rc/bin/service.crazy/tcp993 /usr/sl/www/werc/sites/plan9.stanleylieber.com/mail/service/tcp993
- bind /rc/bin/rc-httpd/select-handler /usr/sl/www/werc/sites/plan9.stanleylieber.com/rc-httpd/select-handler
- bind /rc/bin/service.crazy/tcp80 /usr/sl/www/werc/sites/plan9.stanleylieber.com/rc-httpd/tcp80
- bind /rc/bin/service.crazy/tcp443 /usr/sl/www/werc/sites/plan9.stanleylieber.com/rc-httpd/tcp443
-}
-
-# route requests
-if(~ $SERVER_NAME okturing.com && ~ $location /src/*/body){
- PATH_INFO=$location
- FS_ROOT=/usr/sl/www/werc/sites/okturing.com
- okstatic
-}
-if not if(~ $SERVER_NAME emma.stanleylieber.com fqa.* gl.* iawtp.com ln.* lists.* mold.dk nm.* nsacom.net osuny.co.uk osx.* ph.* pop.* pp.* qualitycountrylyrics.com ragnarok.* tcasey.* tip.9front.org tn.* ur.* volksutils.com weekly.9front.org zeroxpark.com || ~ $location /cbz/* /favicon.ico /img/* /pdf/* /src/* /txt/*){
- PATH_INFO=$location
- FS_ROOT=/usr/sl/www/werc/sites/$SERVER_NAME
- exec static-or-index
-}
-if not if(~ $SERVER_NAME *bell-labs.co){
- bind -a /usr/sl/www/werc/sites/9front.org/who /usr/sl/www/werc/sites/bell-labs.co/who
- PATH_INFO=$location
- FS_ROOT=/usr/sl/www/werc/sites/bell-labs.co
- exec static-or-index
-}
-if not if(~ $SERVER_NAME ttr.inri.net){
- PATH_INFO=$location
- FS_ROOT=/usr/sl/t
- exec static-or-index
-}
-if not if(~ $SERVER_NAME vr.stanleylieber.com){
- if(~ $location / /bin/* /etc/* /*htaccess /*htpasswd /index.rc* /lib/* /stats/*){
- PATH_INFO=$location
- FS_ROOT=/usr/sl/www/werc/sites/vr.stanleylieber.com
- exec cgi /usr/sl/www/werc/sites/vr.stanleylieber.com/index.rc $*
- }
- if not{
- PATH_INFO=$location
- FS_ROOT=/usr/sl/www/werc/sites/vr.stanleylieber.com
- exec static-or-index
- }
-}
-if not if(~ $SERVER_NAME *){
- PATH_INFO=$location
- FS_ROOT=/usr/sl/www/werc/sites/$SERVER_NAME
- exec static-or-cgi /usr/sl/www/werc/bin/werc.rc
+ FS_ROOT=/home/sl/www/werc/sites/$SERVER_NAME
+ exec static-or-cgi /home/sl/www/werc/bin/werc.rc
}
if not
error 503
--- /dev/null
+++ b/bin/contrib/tcp80
@@ -1,0 +1,5 @@
+#!/bin/rc
+# For use with listen(8).
+# Change rc-httpd path to match your system.
+# Change /dev/null to location of logfile.
+exec /home/sl/www/werc/bin/contrib/rc-httpd/rc-httpd >>[2]/dev/null