changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: rc-httpd: support for http basic authentication, fix cgi support to work with hgweb.cgi

changeset 4342: 74455da2d86a
parent 4341: fb57cf510d2b
child 4343: 6d999c39a9f0
author: cinap_lenrek@felloff.net
date: Sat, 14 Mar 2015 01:02:43 +0100
files: rc/bin/rc-httpd/handlers/authorize rc/bin/rc-httpd/handlers/cgi rc/bin/rc-httpd/handlers/error rc/bin/rc-httpd/rc-httpd
description: rc-httpd: support for http basic authentication, fix cgi support to work with hgweb.cgi
     1.1new file mode 100755
     1.2--- /dev/null
     1.3+++ b/rc/bin/rc-httpd/handlers/authorize
     1.4@@ -0,0 +1,6 @@
     1.5+#!/bin/rc
     1.6+if(~ $REMOTE_USER ''){
     1.7+	extra_headers=($extra_headers 'WWW-Authenticate: Basic realm="'$"SERVER_NAME'"')
     1.8+	error 401
     1.9+	exit
    1.10+}
     2.1--- a/rc/bin/rc-httpd/handlers/cgi
     2.2+++ b/rc/bin/rc-httpd/handlers/cgi
     2.3@@ -4,7 +4,7 @@ fn filter_headers{
     2.4 	lines=''
     2.5 	done=false
     2.6 	while(~ $done false){
     2.7-		line=`{read}
     2.8+		line=`{getline}
     2.9 		head=`{echo $line | awk '{print tolower($1)}'}
    2.10 		if(~ $head status:*){
    2.11 			tmp=`{echo $line | awk '{$1="" ; print}'}
     3.1--- a/rc/bin/rc-httpd/handlers/error
     3.2+++ b/rc/bin/rc-httpd/handlers/error
     3.3@@ -19,6 +19,11 @@ fn do_error{
     3.4 	'
     3.5 }
     3.6 
     3.7+fn 401{
     3.8+	do_error '401 Unauthorized' \
     3.9+	'The requested path '^$"location^' requires authorization.'
    3.10+}
    3.11+
    3.12 fn 404{
    3.13 	do_error '404 Not Found' \
    3.14 	'The requested path '^$"location^' was not found on this server.'
     4.1--- a/rc/bin/rc-httpd/rc-httpd
     4.2+++ b/rc/bin/rc-httpd/rc-httpd
     4.3@@ -54,9 +54,13 @@ while(~ $"done false){
     4.4 		HTTP_USER_AGENT=`{echo $line | sed 's;[^:]+:[ 	]+;;'}
     4.5 	case content-length:
     4.6 		CONTENT_LENGTH=$line(2)
     4.7+	case content-type:
     4.8+		CONTENT_TYPE=$line(2)
     4.9 	case cookie:
    4.10 		cookie=`{echo $line | sed 's;^[^:]+:[ 	]*;;'}
    4.11 		HTTP_COOKIE=$"HTTP_COOKIE^$"cookie^'; '
    4.12+	case authorization:
    4.13+		REMOTE_USER=`{auth/httpauth $line(3)}
    4.14 	}
    4.15 }
    4.16 if(~ $REQUEST_URI http://*){