summaryrefslogtreecommitdiff
path: root/sys
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 /sys
parent0b212ed5054cd08bbc14a12936c07bc1ff5890a2 (diff)
add rc-httpd
Diffstat (limited to 'sys')
-rwxr-xr-xsys/lib/dist/rc/bin/rc-httpd/select-handler71
-rw-r--r--sys/man/8/rc-httpd177
2 files changed, 248 insertions, 0 deletions
diff --git a/sys/lib/dist/rc/bin/rc-httpd/select-handler b/sys/lib/dist/rc/bin/rc-httpd/select-handler
new file mode 100755
index 000000000..a5c6efa3c
--- /dev/null
+++ b/sys/lib/dist/rc/bin/rc-httpd/select-handler
@@ -0,0 +1,71 @@
+#!/bin/rc
+
+PATH_INFO=$location
+FS_ROOT=/sys/doc
+exec static-or-index
+
+## EXAMPLES
+#
+#SERVER_NAME=`{echo $SERVER_NAME | sed 's/^www\.//g'}
+#
+#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>
+# '
+#}
+#
+## surprise!
+#if(~ $HTTP_REFERER *hiphopstan.com/forum* *slax.*/forum*){
+# 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 '27b/6'
+# exit
+#}
+#
+## sites
+#if(~ $SERVER_NAME 1oct1993.com 9front.org *.9front.org emma.stanleylieber.com flamesgif.com gl.* iawtp.com inri.net massivefictions.com mold.dk osx.* other.* pop.* qualitycountrylyrics.com sp.* stanleylieber.com tcasey.* textadventure.* volksutils.com){
+# PATH_INFO=$location
+# FS_ROOT=/usr/sl/www/werc/sites/$SERVER_NAME
+# exec static-or-index
+#}
+#if not if(~ $SERVER_NAME 9front.bell-labs.co bell-labs.co cs.bell-labs.co plan9.bell-labs.co sources.cs.bell-labs.co){
+# PATH_INFO=$location
+# FS_ROOT=/usr/sl/www/werc/sites/bell-labs.co
+# 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/sitesvr.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 applied.bell-labs.co *cat-v.org flesh.* img.* linux.* notreally.info okturing.com openbsd.* *osuny.co.uk plan9.* read.* scandisk.bell-labs.co * url.*){
+# PATH_INFO=$location
+# FS_ROOT=/usr/sl/www/werc/sites/$SERVER_NAME
+# exec static-or-cgi /usr/sl/www/werc/bin/werc.rc
+#}
+#if not
+# error 503
diff --git a/sys/man/8/rc-httpd b/sys/man/8/rc-httpd
new file mode 100644
index 000000000..887a90c8c
--- /dev/null
+++ b/sys/man/8/rc-httpd
@@ -0,0 +1,177 @@
+.TH RC-HTTPD 8
+.SH NAME
+rc-httpd \- HTTP server
+.SH SYNOPSIS
+.B rc-httpd/rc-httpd
+.SH DESCRIPTION
+.I Rc-httpd
+serves the requested file or an index of files found under
+a website's root directory, or, in the case of CGI, executes
+a specified CGI program.
+.SH CONFIGURATION
+.PP
+As all pieces of
+.B rc-httpd
+are shell scripts, configuration is achieved by setting variables
+and adding, removing or modifying commands in various files.
+.PP
+.B rc-httpd
+.PP
+.I rc_httpd_dir
+must be set to the root of the rc-httpd installation,
+the directory containing the rc-httpd script.
+.PP
+.I path
+must include
+.I rc_httpd_dir/handlers
+ahead of the base system's path elements.
+.PP
+.I cgi_path
+is substituted for
+.I path
+when cgi scripts are run. (Be sure
+to set
+.I path
+back in rc-based cgi scripts.)
+.PP
+.I extra_headers
+is an optional list of strings to emit when sending http headers.
+.PP
+.I SERVER_PORT
+is the port HTTP is to be served on.
+.PP
+.B select-handler
+.PP
+.I PATH_INFO
+is the location relative to the website's root directory of the file
+to be displayed.
+Typically, the
+.I location
+from the incoming request is honored.
+.PP
+.I FS_ROOT
+sets the root directory of the website.
+.PP
+.I NOINDEXFILE
+instructs the
+.B dir-index
+module not to
+look for
+.B index.html
+files, otherwise if an
+.B index.html
+file is found
+.B dir-index
+will exec
+.B serve-static
+to serve the file. At present there
+is no module to serve an index file but not a directory.
+.PP
+If you do not want directory indexing at all, replace
+.B static-or-index
+with
+.B serve-static,
+which will report 503 forbidden for directories.
+.PP
+Multiple virtual hosts may be configured by creating conditional
+statements that act upon the
+.I SERVER_NAME
+variable. Fine-grained control of specific request strings may
+be configured via a similar method acting upon the
+.I location
+and/or other variables.
+.SH EXAMPLES
+The following examples demonstrate possible ways to configure
+.BR select-handler.
+.PP
+Serve static files:
+.RS
+.EX
+if(~ $SERVER_NAME 9front.org){
+ PATH_INFO=$location
+ FS_ROOT=/usr/sl/www/$SERVER_NAME
+ exec static-or-index
+}
+.EE
+.RE
+.PP
+CGI:
+.RS
+.EX
+if(~ $SERVER_NAME *cat-v.org){
+ PATH_INFO=$location
+ FS_ROOT=/usr/sl/www/werc/sites/$SERVER_NAME
+ exec static-or-cgi /usr/sl/www/werc/bin/werc.rc
+}
+.EE
+.RE
+.PP
+Custom error message for a denied URL:
+.RS
+.EX
+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>
+ '
+}
+if(~ $location /v8.tar.bz2){
+ do_error '27b/6'
+ exit
+}
+.EE
+.RE
+.SH STARTUP
+.I Rc-httpd
+is run from a file in the directory scanned by
+.IR listen (8),
+or called as an argument to
+.IR listen1 (8).
+The program's standard error may be captured to a log file:
+.RS
+.EX
+exec /rc/bin/rc-httpd/rc-httpd >>[2]/sys/log/www
+.EE
+.RE
+.SH FILES
+.TF /sys/lib/httpd.rewrite
+.TP
+.B /rc/bin/rc-httpd/rc-httpd
+.TP
+.B /rc/bin/rc-httpd/select-handlers
+.TP
+.B /rc/bin/rc-httpd/handlers/cgi
+.TP
+.B /rc/bin/rc-httpd/handlers/dir-index
+.TP
+.B /rc/bin/rc-httpd/handlers/error
+.TP
+.B /rc/bin/rc-httpd/handlers/redirect
+.TP
+.B /rc/bin/rc-httpd/handlers/serve-static
+.TP
+.B /rc/bin/rc-httpd/handlers/static-or-cgi
+.TP
+.B /rc/bin/rc-httpd/handlers/static-or-index
+.TP
+.B /rc/bin/service/tcp80
+.TP
+.B /sys/log/www
+.SH SOURCE
+.B /rc/bin/rc-httpd
+.SH "SEE ALSO"
+.IR rc (1),
+.IR listen (8)