From 3bbf868d4f5ab576397ed554d839f31f190e4abe Mon Sep 17 00:00:00 2001 From: hmeland Date: Tue, 2 Mar 1999 12:40:56 +0000 Subject: Utils.GetRequestURI(): New function, returns the full virtual path the calling CGI script was invoked with. Uses (non-standard, but convenient) environment variable REQUEST_URI when available, otherwise SCRIPT_NAME and PATH_INFO (which are part of the CGI/1.1 spec) if available, or simply returns optional argument `fallback' (which defaults to None). Cgi/admin.py, Cgi/admindb.py: Use it when generating admin authentication page. --- Mailman/Cgi/admin.py | 4 ++-- Mailman/Cgi/admindb.py | 2 +- Mailman/Utils.py | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Mailman/Cgi/admin.py b/Mailman/Cgi/admin.py index 07589d2ab..371e1421e 100644 --- a/Mailman/Cgi/admin.py +++ b/Mailman/Cgi/admin.py @@ -119,12 +119,12 @@ def main(): is_auth = isAuthenticated(lst) message = "" if not is_auth: - defaulturi = 'mailman/admin%s/%s' % (mm_cfg.CGIEXT, list_name) + defaulturi = '/mailman/admin%s/%s' % (mm_cfg.CGIEXT, list_name) print "Content-type: text/html\n\n" text = Utils.maketext( 'admlogin.txt', {"listname": list_name, - "path" : os.environ.get("REQUEST_URI", defaulturi), + "path" : Utils.GetRequestURI(defaulturi), "message" : message, }) print text diff --git a/Mailman/Cgi/admindb.py b/Mailman/Cgi/admindb.py index c38a1155d..7dfa00b58 100644 --- a/Mailman/Cgi/admindb.py +++ b/Mailman/Cgi/admindb.py @@ -113,7 +113,7 @@ def main(): text = Utils.maketext( 'admlogin.txt', {'listname': list_name, - 'path' : os.environ.get('REQUEST_URI', defaulturi), + 'path' : Utils.GetRequestURI(defaulturi), 'message' : message, }) print text diff --git a/Mailman/Utils.py b/Mailman/Utils.py index b9dc4a44b..d79d3543a 100644 --- a/Mailman/Utils.py +++ b/Mailman/Utils.py @@ -664,3 +664,22 @@ def open_ex(filename, mode='r', bufsize=-1, perms=0664): reraise(IOError, e) finally: os.umask(ou) + +def GetRequestURI(fallback=None): + """Return the full virtual path this CGI script was invoked with. + + Newer web servers seems to supply this info in the REQUEST_URI + environment variable -- which isn't part of the CGI/1.1 spec. + Thus, if REQUEST_URI isn't available, we concatenate SCRIPT_NAME + and PATH_INFO, both of which are part of CGI/1.1. + + Optional argument `fallback' (default `None') is returned if both of + the above methods fail. + + """ + if os.environ.has_key('REQUEST_URI'): + return os.environ['REQUEST_URI'] + elif os.environ.has_key('SCRIPT_NAME') and os.environ.has_key('PATH_INFO'): + return os.environ['SCRIPT_NAME'] + os.environ['PATH_INFO'] + else: + return fallback -- cgit v1.3.1