summaryrefslogtreecommitdiff
path: root/rc
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-03-14 01:02:43 +0100
committercinap_lenrek <cinap_lenrek@felloff.net>2015-03-14 01:02:43 +0100
commit8ef66ca21218af00181bf78f37a5ede0238a7fa1 (patch)
tree3f5dff0cd69f235340a6339fa86a7e9b54230835 /rc
parent060e69b15aae22ca9fcf9d9e7970bd2d611544f3 (diff)
downloadplan9front-8ef66ca21218af00181bf78f37a5ede0238a7fa1.tar.xz
rc-httpd: support for http basic authentication, fix cgi support to work with hgweb.cgi
Diffstat (limited to 'rc')
-rwxr-xr-xrc/bin/rc-httpd/handlers/authorize6
-rwxr-xr-xrc/bin/rc-httpd/handlers/cgi2
-rwxr-xr-xrc/bin/rc-httpd/handlers/error5
-rwxr-xr-xrc/bin/rc-httpd/rc-httpd4
4 files changed, 16 insertions, 1 deletions
diff --git a/rc/bin/rc-httpd/handlers/authorize b/rc/bin/rc-httpd/handlers/authorize
new file mode 100755
index 000000000..ea4db3ef7
--- /dev/null
+++ b/rc/bin/rc-httpd/handlers/authorize
@@ -0,0 +1,6 @@
+#!/bin/rc
+if(~ $REMOTE_USER ''){
+ extra_headers=($extra_headers 'WWW-Authenticate: Basic realm="'$"SERVER_NAME'"')
+ error 401
+ exit
+}
diff --git a/rc/bin/rc-httpd/handlers/cgi b/rc/bin/rc-httpd/handlers/cgi
index 96707630c..574cd13c3 100755
--- a/rc/bin/rc-httpd/handlers/cgi
+++ b/rc/bin/rc-httpd/handlers/cgi
@@ -4,7 +4,7 @@ fn filter_headers{
lines=''
done=false
while(~ $done false){
- line=`{read}
+ line=`{getline}
head=`{echo $line | awk '{print tolower($1)}'}
if(~ $head status:*){
tmp=`{echo $line | awk '{$1="" ; print}'}
diff --git a/rc/bin/rc-httpd/handlers/error b/rc/bin/rc-httpd/handlers/error
index e38d41f01..282d8706c 100755
--- a/rc/bin/rc-httpd/handlers/error
+++ b/rc/bin/rc-httpd/handlers/error
@@ -19,6 +19,11 @@ fn do_error{
'
}
+fn 401{
+ do_error '401 Unauthorized' \
+ 'The requested path '^$"location^' requires authorization.'
+}
+
fn 404{
do_error '404 Not Found' \
'The requested path '^$"location^' was not found on this server.'
diff --git a/rc/bin/rc-httpd/rc-httpd b/rc/bin/rc-httpd/rc-httpd
index e2a64948c..bb3fac94f 100755
--- a/rc/bin/rc-httpd/rc-httpd
+++ b/rc/bin/rc-httpd/rc-httpd
@@ -54,9 +54,13 @@ while(~ $"done false){
HTTP_USER_AGENT=`{echo $line | sed 's;[^:]+:[ ]+;;'}
case content-length:
CONTENT_LENGTH=$line(2)
+ case content-type:
+ CONTENT_TYPE=$line(2)
case cookie:
cookie=`{echo $line | sed 's;^[^:]+:[ ]*;;'}
HTTP_COOKIE=$"HTTP_COOKIE^$"cookie^'; '
+ case authorization:
+ REMOTE_USER=`{auth/httpauth $line(3)}
}
}
if(~ $REQUEST_URI http://*){