changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > werc / changeset: 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)

changeset 658: b501d0f9afa4
parent 657: fb460a671d19
child 659: e46fbed848f2
author: sl
date: Thu, 04 Feb 2016 21:47:22 -0500
files: bin/contrib/rc-httpd/rc-httpd bin/contrib/rc-httpd/select-handler bin/contrib/tcp80
description: 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)
     1.1--- a/bin/contrib/rc-httpd/rc-httpd	Thu Feb 04 15:05:05 2016 -0500
     1.2+++ b/bin/contrib/rc-httpd/rc-httpd	Thu Feb 04 21:47:22 2016 -0500
     1.3@@ -1,7 +1,7 @@
     1.4 #!/bin/rc
     1.5-rc_httpd_dir=/rc/bin/rc-httpd
     1.6-path=(/bin $rc_httpd_dir/handlers)
     1.7-cgi_path=/bin
     1.8+rc_httpd_dir=/home/sl/www/werc/bin/contrib/rc-httpd
     1.9+path=($PLAN9/bin $rc_httpd_dir/handlers)
    1.10+cgi_path=$PLAN9/bin
    1.11 SERVER_PORT=80 # default for CGI scripts, may be overridden by the Host header
    1.12 extra_headers='Server: rc-httpd'
    1.13 cr=
     2.1--- a/bin/contrib/rc-httpd/select-handler	Thu Feb 04 15:05:05 2016 -0500
     2.2+++ b/bin/contrib/rc-httpd/select-handler	Thu Feb 04 21:47:22 2016 -0500
     2.3@@ -1,177 +1,12 @@
     2.4 #!/bin/rc
     2.5-# 2016-02-01T19:31:03-0500
     2.6 rfork n
     2.7-fn do_error{
     2.8-	do_log $1
     2.9-	echo 'HTTP/1.1 '^$1^$cr
    2.10-	emit_extra_headers
    2.11-	echo 'Content-type: text/html'^$cr
    2.12-	echo $cr
    2.13-	echo '<html>
    2.14-<head>
    2.15-<title>'^$1^'</title>
    2.16-</head>
    2.17-<body>
    2.18-<h1>'^$1^'</h1>'
    2.19-	echo $2
    2.20-	echo '<p><i>rc-httpd at' $SERVER_NAME '</i>'
    2.21-	echo '
    2.22-	</body>
    2.23-	</html>
    2.24-	'
    2.25-}
    2.26-
    2.27-fn http_redirect {
    2.28-    if(~ $1 http://* https://*)
    2.29-        t=$1
    2.30-    if not if(~ $1 /*)
    2.31-        t=$"base_url^$1
    2.32-    if not
    2.33-        t=$"base_url^$"req_path^$1
    2.34-    exec /bin/echo 'Status: '^$2^'
    2.35-Location: '^$t^'
    2.36-
    2.37-'
    2.38-    exit
    2.39-}
    2.40-
    2.41-fn okstatic{
    2.42-	full_path=`{echo $"FS_ROOT^$"PATH_INFO | urlencode -d}
    2.43-	full_path=$"full_path
    2.44-	if(~ $full_path */)
    2.45-		error 503
    2.46-	if(test -d $full_path){
    2.47-		redirect perm $"location^'/' \
    2.48-			'URL not quite right, and browser did not accept redirect.'
    2.49-		exit
    2.50-	}
    2.51-	if(! test -e $full_path){
    2.52-		error 404
    2.53-		exit
    2.54-	}
    2.55-	if(! test -r $full_path){
    2.56-		error 503
    2.57-		exit
    2.58-	}
    2.59-	do_log 200
    2.60-	type='text/plain'
    2.61-	max_age=3600	# 1 hour
    2.62-	echo 'HTTP/1.1 200 OK'^$cr
    2.63-	emit_extra_headers
    2.64-	echo 'Content-type: '^$type^'; charset=utf-8'^$cr
    2.65-	echo 'Content-length: '^`{ls -l $full_path | awk '{print $6}'}
    2.66-	echo 'Cache-control: max-age='^$max_age^$cr
    2.67-	echo $cr
    2.68-	exec cat $full_path
    2.69-}
    2.70-
    2.71-# surprise!
    2.72-if(~ $HTTP_REFERER *hiphopstan.com/forum* *slax.*/forum*){
    2.73-	PATH_INFO=$location
    2.74-	FS_ROOT=/usr/sl/www/werc/sites/hotlink
    2.75-	exec static-or-index
    2.76-}
    2.77-if(~ $HTTP_REFERER 'http://okturing.com/index.rc?start=100' || {~ $SERVER_NAME okturing.com && ~ $location /index.rc} || ~ $location /qemu/plan9.flp.gz){
    2.78-	do_error '402 PAYMENT REQUIRED'
    2.79-	exit
    2.80-}
    2.81-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){
    2.82-	do_error '402 PAYMENT REQUIRED'
    2.83-	exit
    2.84-}
    2.85-
    2.86-# build environment and namespace
    2.87-SERVER_NAME=`{echo $SERVER_NAME | sed 's/^www\.//g'}
    2.88 
    2.89-if(~ $location *~nis*)
    2.90-	location=`{echo $location | sed 's/\/\~nis/\/_nis/g'}
    2.91-
    2.92-if(~ $SERVER_NAME 9front.org){
    2.93-	bind /usr/sl/plan9front /usr/sl/www/werc/sites/9front.org/9front
    2.94-	bind /usr/sl/www/werc/sites/9front.org/_werc/pub/style.css /usr/sl/www/werc/pub/style/style.css
    2.95-	bind /usr/sl/www/werc/sites/plan9.stanleylieber.com/src /usr/sl/www/werc/sites/9front.org/extra
    2.96-	aux/stub -d /usr/sl/www/werc/sites/9front.org/extra/rc
    2.97-	bind /usr/sl/www/werc/sites/plan9.stanleylieber.com/rc /usr/sl/www/werc/sites/9front.org/extra/rc
    2.98-	bind /usr/sl/www/werc/sites/bell-labs.co/9front/iso /usr/sl/www/werc/sites/9front.org/iso
    2.99-	bind /usr/sl/www/werc/sites/plan9.stanleylieber.com/pkg /usr/sl/www/werc/sites/9front.org/pkg
   2.100-	if(~ $location /who/*){
   2.101-		for(i in Aram aiju alvaro cinap_lenrek eekee erik joy kenji lf94 martian67 mveety rminnich sl)
   2.102-		bind /usr/sl/www/werc/sites/9front.org/$i /usr/sl/www/werc/sites/9front.org/who/$i/index.txt
   2.103-	}
   2.104-	aux/stub /usr/sl/www/werc/sites/9front.org/9front.torrent
   2.105-	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
   2.106-	if(~ $location /list.html)
   2.107-		location=/lists.html
   2.108-}
   2.109-if(~ $SERVER_NAME bugs.9front.org){
   2.110-	bind /usr/sl/www/werc/sites/bugs.9front.org/_werc/pub/style.css /usr/sl/www/werc/pub/style/style.css
   2.111-	bind -a /usr/bugs /usr/sl/www/werc/sites/bugs.9front.org
   2.112-	if(~ $location /closed/[a-z0-9]* /open/[a-z0-9]*){
   2.113-		d=`{basename -d $location}
   2.114-		aux/stub /usr/sl/www/werc/sites/bugs.9front.org^$d^/index.md
   2.115-		bind /usr/bugs^$d^/readme /usr/sl/www/werc/sites/bugs.9front.org^$d^/index.md
   2.116-	}
   2.117-}
   2.118-if(~ $SERVER_NAME fqa.9front.org){
   2.119-	#location=`{echo $"location | sed 's/^(fqa|appendix).*\.html$//g'}
   2.120-}
   2.121-if(~ $SERVER_NAME lists.9front.org){
   2.122-	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)
   2.123-		bind /mail/box/$i/mbox /usr/sl/www/werc/sites/lists.9front.org/$i
   2.124-}
   2.125-if(~ $SERVER_NAME wiki.9front.org)
   2.126-	bind /usr/sl/www/werc/sites/wiki.9front.org/_werc/pub/style.css /usr/sl/www/werc/pub/style/style.css
   2.127-if(~ $SERVER_NAME golang.cat-v.org)
   2.128-	bind /usr/sl/www/werc/sites/go-lang.cat-v.org /usr/sl/www/werc/sites/golang.cat-v.org
   2.129-if(~ $SERVER_NAME plan9.stanleylieber.com){
   2.130-	bind /usr/sl/www/werc/sites/plan9.stanleylieber.com/_werc/pub/style.css /usr/sl/www/werc/pub/style/style.css
   2.131-	bind /mail/lib /usr/sl/www/werc/sites/plan9.stanleylieber.com/mail/lib
   2.132-	bind /sys/lib/dist/mail/lib/names.local /usr/sl/www/werc/sites/plan9.stanleylieber.com/mail/lib/names.local
   2.133-	bind /rc/bin/service.crazy/tcp587 /usr/sl/www/werc/sites/plan9.stanleylieber.com/mail/service/tcp587
   2.134-	bind /rc/bin/service.crazy/tcp993 /usr/sl/www/werc/sites/plan9.stanleylieber.com/mail/service/tcp993
   2.135-	bind /rc/bin/rc-httpd/select-handler /usr/sl/www/werc/sites/plan9.stanleylieber.com/rc-httpd/select-handler
   2.136-	bind /rc/bin/service.crazy/tcp80 /usr/sl/www/werc/sites/plan9.stanleylieber.com/rc-httpd/tcp80
   2.137-	bind /rc/bin/service.crazy/tcp443 /usr/sl/www/werc/sites/plan9.stanleylieber.com/rc-httpd/tcp443
   2.138-}
   2.139-
   2.140-# route requests
   2.141-if(~ $SERVER_NAME okturing.com && ~ $location /src/*/body){
   2.142+# Route requests to werc.
   2.143+# Change the werc path to match your system.
   2.144+if(~ $SERVER_NAME *){
   2.145 	PATH_INFO=$location
   2.146-	FS_ROOT=/usr/sl/www/werc/sites/okturing.com
   2.147-	okstatic
   2.148-}
   2.149-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/*){
   2.150-	PATH_INFO=$location
   2.151-	FS_ROOT=/usr/sl/www/werc/sites/$SERVER_NAME
   2.152-	exec static-or-index
   2.153-}
   2.154-if not if(~ $SERVER_NAME *bell-labs.co){
   2.155-	bind -a /usr/sl/www/werc/sites/9front.org/who /usr/sl/www/werc/sites/bell-labs.co/who
   2.156-	PATH_INFO=$location
   2.157-	FS_ROOT=/usr/sl/www/werc/sites/bell-labs.co
   2.158-	exec static-or-index
   2.159-}
   2.160-if not if(~ $SERVER_NAME ttr.inri.net){
   2.161-	PATH_INFO=$location
   2.162-	FS_ROOT=/usr/sl/t
   2.163-	exec static-or-index
   2.164-}
   2.165-if not if(~ $SERVER_NAME vr.stanleylieber.com){
   2.166-	if(~ $location / /bin/* /etc/* /*htaccess /*htpasswd /index.rc* /lib/* /stats/*){
   2.167-		PATH_INFO=$location
   2.168-		FS_ROOT=/usr/sl/www/werc/sites/vr.stanleylieber.com
   2.169-		exec cgi /usr/sl/www/werc/sites/vr.stanleylieber.com/index.rc $*
   2.170-	}
   2.171-	if not{
   2.172-		PATH_INFO=$location
   2.173-		FS_ROOT=/usr/sl/www/werc/sites/vr.stanleylieber.com
   2.174-		exec static-or-index
   2.175-	}
   2.176-}
   2.177-if not if(~ $SERVER_NAME *){
   2.178-	PATH_INFO=$location
   2.179-	FS_ROOT=/usr/sl/www/werc/sites/$SERVER_NAME
   2.180-	exec static-or-cgi /usr/sl/www/werc/bin/werc.rc
   2.181+	FS_ROOT=/home/sl/www/werc/sites/$SERVER_NAME
   2.182+	exec static-or-cgi /home/sl/www/werc/bin/werc.rc
   2.183 }
   2.184 if not
   2.185 	error 503
     3.1--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2+++ b/bin/contrib/tcp80	Thu Feb 04 21:47:22 2016 -0500
     3.3@@ -0,0 +1,5 @@
     3.4+#!/bin/rc
     3.5+# For use with listen(8).
     3.6+# Change rc-httpd path to match your system.
     3.7+# Change /dev/null to location of logfile.
     3.8+exec /home/sl/www/werc/bin/contrib/rc-httpd/rc-httpd >>[2]/dev/null