From 1e32c8cd3db78d2494dc30b08ac2fe23a2247f6c Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 4 Nov 2018 11:33:55 +0000 Subject: Support changing realm --- cgi-bin/auth.cgi | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cgi-bin/auth.cgi b/cgi-bin/auth.cgi index 83210d8..7f7aa71 100755 --- a/cgi-bin/auth.cgi +++ b/cgi-bin/auth.cgi @@ -4,23 +4,23 @@ import cgi import cgitb cgitb.enable() -print('WWW-Authenticate: Basic realm="NetSurf Authentication test"') -print('Content-Type: text/plain') -print('') - import os from base64 import b64decode auth = os.getenv("HTTP_AUTHORIZATION") -query = os.getenv("QUERY_STRING") or "user=foo&pass=bar" +query = os.getenv("QUERY_STRING") or "user=foo&pass=bar&realm=NetSurf+Authentication+Test" query = cgi.parse_qs(query) username = query.get("user", ["foo"])[0] password = query.get("pass", query.get("password", ["bar"]))[0] +realm = query.get("realm", ["NetSurf Authentication Test"]) gotuser = None gotpass = None def badauth(reason="NOAUTH"): + print('WWW-Authenticate: Basic realm="{}"'.format(realm)) + print('Content-Type: text/plain') + print('') print('result=BAD, username={}/{}, password={}/{}, reason={}'.format(gotuser, username, gotpass, password, reason)) raise SystemExit @@ -42,4 +42,6 @@ else: badauth("BADPASS") +print('Content-Type: text/plain') +print('') print("result=GOOD, username={}, password={}".format(username, password)) -- cgit v1.2.3