[Mailman-Developers] Possible bug in 1.0b8
Harald Meland
Harald.Meland@usit.uio.no
24 Feb 1999 21:30:45 +0100
[Harald Meland]
> Please bear in mind that this is the first time I'm trying to do any
> CGI-related programming at all, but I still _think_ this patch is good
> (from reading the CGI/1.1 spec, and testing quickly that it doesn't
> break my web interface).
I was slightly wrong about the patch being perfectly good -- the
Utils.CGIpath() function would, if both of the "proper" methods for
getting at the path failed, fall back to ("/mailman/admin/" +
list_name), regardless of which CGI script called it. This would,
obviously, be wrong if called from e.g. "admindb".
It could also be argued that referencing the (hopefully defined)
global variable list_name from CGIpath() is unnecessarily risky.
Below is a patch (against current CVS) which fixes these problems by
operating in a manner very similar to os.environ.get(), i.e. letting
the caller supply the complete fallback value.
[ I'm not really sure that putting a pretty special-purpose function
like CGIpath() into the generic Utils module is the Right Thing --
but I couldn't see anywhere else where it would fit better. ]
Index: Mailman/Utils.py
===================================================================
RCS file: /projects/cvsroot/mailman/Mailman/Utils.py,v
retrieving revision 1.62
diff -u -r1.62 Utils.py
--- Utils.py 1999/01/14 04:07:28 1.62
+++ Utils.py 1999/02/24 20:26:00
@@ -664,3 +664,22 @@
reraise(IOError, e)
finally:
os.umask(ou)
+
+def CGIpath(env, 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 second argument `fallback' (default `None') is returned if
+ both of the above methods fail.
+
+ """
+ if env.has_key("REQUEST_URI"):
+ return env["REQUEST_URI"]
+ elif env.has_key("SCRIPT_NAME") and env.has_key("PATH_INFO"):
+ return (env["SCRIPT_NAME"] + env["PATH_INFO"])
+ else:
+ return fallback
Index: Mailman/Cgi/admin.py
===================================================================
RCS file: /projects/cvsroot/mailman/Mailman/Cgi/admin.py,v
retrieving revision 1.31
diff -u -r1.31 admin.py
--- admin.py 1999/01/09 05:57:17 1.31
+++ admin.py 1999/02/24 20:26:01
@@ -123,8 +123,8 @@
text = Utils.maketext(
'admlogin.txt',
{"listname": list_name,
- "path" : os.environ.get("REQUEST_URI",
- '/mailman/admin/' + list_name),
+ "path" : Utils.CGIpath(os.environ,
+ '/mailman/admin/' + list_name),
"message" : message,
})
print text
Index: Mailman/Cgi/admindb.py
===================================================================
RCS file: /projects/cvsroot/mailman/Mailman/Cgi/admindb.py,v
retrieving revision 1.9
diff -u -r1.9 admindb.py
--- admindb.py 1999/01/09 06:22:44 1.9
+++ admindb.py 1999/02/24 20:26:01
@@ -112,8 +112,8 @@
text = Utils.maketext(
'admlogin.txt',
{'listname': list_name,
- 'path' : os.environ.get('REQUEST_URI',
- '/mailman/admindb/' + list_name),
+ 'path' : Utils.CGIpath(os.environ,
+ '/mailman/admindb/' + list_name),
'message' : message,
})
print text
--
Harald