summaryrefslogtreecommitdiff
path: root/Mailman/Cgi
diff options
context:
space:
mode:
authorbwarsaw2006-10-15 22:04:16 +0000
committerbwarsaw2006-10-15 22:04:16 +0000
commite7fe84dca5681a6de55262a0eddd06758cbd1ce4 (patch)
treea4c5a0e2778269c2a77ee0fecae45ac3f8e64de0 /Mailman/Cgi
parentd75f597cb3ccfdd6de9c6bb3877e5452884002c9 (diff)
downloadmailman-e7fe84dca5681a6de55262a0eddd06758cbd1ce4.tar.gz
mailman-e7fe84dca5681a6de55262a0eddd06758cbd1ce4.tar.zst
mailman-e7fe84dca5681a6de55262a0eddd06758cbd1ce4.zip
More work on the WSGI support. So far, I've tested most of the admin.py links
and some of the admindb.py links. There may still be breakage in other parts of the interface and I haven't gone back to verify that traditional CGI still works. Changes: - Add wsgiref-0.1.2-py2.4.egg so that we can still do WSGI in Python 2.4, which doesn't come with wsgiref. Of course this means we /also/ have to add setuptools-0.5c3 because eggs require setuptools. - Style cleanups in HTTPRunner.py and wsgi_app.py. Also, use cStringIO instead of StringIO. - All internal links within the listinfo and admin pages are (or at least should be ;) relative now. This should make other things better, such as running Mailman over https or alternative ports. It does kind of mean that web_page_url is obsolete, but I haven't looked at whether we can completely eradicate it. - ValidateEmail(): Use ' ' in s instead of s.count(' ') > 0. - GetPathPieces(): When path is false, return the empty list instead of None, so we can still len() it. - ScriptURL(): Much simpler. To support relative urls as the default, we change the API so that it only takes a 'target' argument (i.e. the script we want to link to). It no longer takes 'absolute' or 'web_page_url', and it constructs its link from GetPathPieces(), the target, and the cgi extension. - GetRequestURI(): code style updates. - Mailman/bin/show_config.py: De-DOS-line-ending-ification. - export.py: A few modifications, although this is likely still not final (I'm still working on the import script). First, for <option> elements, don't put the value in an attribute, put it in the text body of the element. Second, put the list <option> tags in a <configuration> element. Third, put the preferred language on an <option> tag with a 'preferred_language' name attribute value. - SecurityManager: Make sure that MakeCookie() and ZapCookie() use the same 'path' cookie value by refactoring that into a separate method. That method now returns just the SCRIPT_NAME and the full listname. web_page_url doesn't enter into it. - loginit.py: Add a 'debug' logger since it's just too useful to have :) - admin.py: Remove the extra / right before the query string in ?VARHELP urls. That extra / turns out to be problematic with the relative url scheme we're using now. - Auth.py: whitespace normalization and copyright years update. Also, remove a couple of unnecessary imports. Also, make sure that the actionurl is relative. - create.py: Typo. - private.py: mm_cfg -> config object - In MailList.py: GetScriptURL() can be written in terms of Utils.ScriptURL() now.
Diffstat (limited to 'Mailman/Cgi')
-rw-r--r--Mailman/Cgi/Auth.py19
-rw-r--r--Mailman/Cgi/admin.py10
-rw-r--r--Mailman/Cgi/admindb.py2
-rw-r--r--Mailman/Cgi/create.py2
-rw-r--r--Mailman/Cgi/private.py19
-rw-r--r--Mailman/Cgi/wsgi_app.py60
6 files changed, 58 insertions, 54 deletions
diff --git a/Mailman/Cgi/Auth.py b/Mailman/Cgi/Auth.py
index 8c66c4d36..98e9fe49d 100644
--- a/Mailman/Cgi/Auth.py
+++ b/Mailman/Cgi/Auth.py
@@ -1,26 +1,25 @@
-# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc.
+# Copyright (C) 1998-2006 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
"""Common routines for logging in and logging out of the list administrator
and list moderator interface.
"""
-from Mailman import mm_cfg
from Mailman import Utils
-from Mailman import Errors
from Mailman.htmlformat import FontAttr
from Mailman.i18n import _
@@ -34,12 +33,14 @@ class NotLoggedInError(Exception):
-def loginpage(mlist, scriptname, msg='', frontpage=None):
+def loginpage(mlist, scriptname, msg='', frontpage=False):
url = mlist.GetScriptURL(scriptname)
if frontpage:
actionurl = url
else:
- actionurl = Utils.GetRequestURI(url)
+ request = Utils.GetRequestURI(url)
+ up = '../' * request.count('/')
+ actionurl = up + request
if msg:
msg = FontAttr(msg, color='#ff0000', size='+1').Format()
if scriptname == 'admindb':
diff --git a/Mailman/Cgi/admin.py b/Mailman/Cgi/admin.py
index 001004fa0..3fbbd4ca4 100644
--- a/Mailman/Cgi/admin.py
+++ b/Mailman/Cgi/admin.py
@@ -99,7 +99,7 @@ def main():
# Is this a log-out request?
if category == 'logout':
print mlist.ZapCookie(mm_cfg.AuthListAdmin)
- Auth.loginpage(mlist, 'admin', frontpage=1)
+ Auth.loginpage(mlist, 'admin', frontpage=True)
return
# Sanity check
@@ -795,9 +795,9 @@ def get_item_gui_description(mlist, category, subcat,
# the details page!
if detailsp:
if subcat:
- varhelp = '/?VARHELP=%s/%s/%s' % (category, subcat, varname)
+ varhelp = '?VARHELP=%s/%s/%s' % (category, subcat, varname)
else:
- varhelp = '/?VARHELP=%s/%s' % (category, varname)
+ varhelp = '?VARHELP=%s/%s' % (category, varname)
if descr == elaboration:
linktext = _('<br>(Edit <b>%(varname)s</b>)')
else:
@@ -817,7 +817,7 @@ def get_item_gui_description(mlist, category, subcat,
def membership_options(mlist, subcat, cgidata, doc, form):
# Show the main stuff
- adminurl = mlist.GetScriptURL('admin', absolute=1)
+ adminurl = mlist.GetScriptURL('admin')
container = Container()
header = Table(width="100%")
# If we're in the list subcategory, show the membership list
@@ -1200,7 +1200,7 @@ def mass_remove(mlist, container):
def password_inputs(mlist):
- adminurl = mlist.GetScriptURL('admin', absolute=1)
+ adminurl = mlist.GetScriptURL('admin')
table = Table(cellspacing=3, cellpadding=4)
table.AddRow([Center(Header(2, _('Change list ownership passwords')))])
table.AddCellInfo(table.GetCurrentRowIndex(), 0, colspan=2,
diff --git a/Mailman/Cgi/admindb.py b/Mailman/Cgi/admindb.py
index 188aabd1c..7d762a172 100644
--- a/Mailman/Cgi/admindb.py
+++ b/Mailman/Cgi/admindb.py
@@ -172,7 +172,7 @@ def main():
doc.AddItem(Header(2, title))
doc.AddItem(_('There are no pending requests.'))
doc.AddItem(' ')
- doc.AddItem(Link(mlist.GetScriptURL('admindb', absolute=1),
+ doc.AddItem(Link(mlist.GetScriptURL('admindb'),
_('Click here to reload this page.')))
doc.AddItem(mlist.GetMailmanFooter())
print doc.Format()
diff --git a/Mailman/Cgi/create.py b/Mailman/Cgi/create.py
index 9a5ab73d8..8db59fdc7 100644
--- a/Mailman/Cgi/create.py
+++ b/Mailman/Cgi/create.py
@@ -154,7 +154,7 @@ def process_request(doc, cgidata):
url_host = Utils.get_request_domain()
email_host = config.get_email_host(url_host)
if not email_host:
- safehostname = Utils.websafe(email_host)
+ safehostname = Utils.websafe(url_host)
request_creation(doc, cgidata,
_('Unknown virtual host: $safehostname'))
return
diff --git a/Mailman/Cgi/private.py b/Mailman/Cgi/private.py
index 97dc66690..c9e69944b 100644
--- a/Mailman/Cgi/private.py
+++ b/Mailman/Cgi/private.py
@@ -23,18 +23,17 @@ import cgi
import logging
import mimetypes
-from Mailman import mm_cfg
-from Mailman import Utils
-from Mailman import MailList
from Mailman import Errors
+from Mailman import MailList
+from Mailman import Utils
from Mailman import i18n
-from Mailman.htmlformat import *
from Mailman.configuration import config
+from Mailman.htmlformat import *
# Set up i18n. Until we know which list is being requested, we use the
# server's default.
_ = i18n._
-i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
+i18n.set_language(config.DEFAULT_SERVER_LANGUAGE)
SLASH = '/'
@@ -61,7 +60,7 @@ def guess_type(url, strict):
def main():
doc = Document()
- doc.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
+ doc.set_language(config.DEFAULT_SERVER_LANGUAGE)
parts = Utils.GetPathPieces()
if not parts:
@@ -127,10 +126,10 @@ def main():
realname = mlist.real_name
message = ''
- if not mlist.WebAuthenticate((mm_cfg.AuthUser,
- mm_cfg.AuthListModerator,
- mm_cfg.AuthListAdmin,
- mm_cfg.AuthSiteAdmin),
+ if not mlist.WebAuthenticate((config.AuthUser,
+ config.AuthListModerator,
+ config.AuthListAdmin,
+ config.AuthSiteAdmin),
password, username):
if cgidata.has_key('submit'):
# This is a re-authorization attempt
diff --git a/Mailman/Cgi/wsgi_app.py b/Mailman/Cgi/wsgi_app.py
index b7acd45fa..8e77352d6 100644
--- a/Mailman/Cgi/wsgi_app.py
+++ b/Mailman/Cgi/wsgi_app.py
@@ -1,5 +1,3 @@
-# -*- python -*-
-
# Copyright (C) 2006 by the Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
@@ -17,30 +15,36 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
+import os
import sys
+
+from cStringIO import StringIO
+from email import message_from_string
+
+from Mailman.configuration import config
+
+# XXX Should this be configurable in Defaults.py?
STEALTH_MODE = False
-# Shoul this be configurable in Defaults.py?
+
+
def websafe(s):
return s
-import os
-import StringIO
-from email import message_from_string
-from Mailman.configuration import config
SCRIPTS = ['admin', 'admindb', 'confirm', 'create',
'edithtml', 'listinfo', 'options', 'private',
'rmlist', 'roster', 'subscribe']
-SLASH = '/'
-NL2 = '\n\n'
-CRLF2 = '\r\n\r\n'
-# WSGI to CGI wrapper. Mostly copied from scripts/driver.
+SLASH = '/'
+NL2 = '\n\n'
+CRLF2 = '\r\n\r\n'
-def mailman_app(environ, start_response):
- """wrapper to *.py cgi commands"""
+
+# WSGI to CGI wrapper. Mostly copied from scripts/driver.
+def mailman_app(environ, start_response):
+ """Wrapper to *.py CGI commands"""
global STEALTH_MODE, websafe
try:
try:
@@ -65,7 +69,7 @@ def mailman_app(environ, start_response):
environ['PATH_INFO'] = SLASH + SLASH.join(paths[2:])
else:
environ['PATH_INFO'] = ''
- # reverse proxy environment.
+ # Reverse proxy environment.
if environ.has_key('HTTP_X_FORWARDED_HOST'):
environ['HTTP_HOST'] = environ['HTTP_X_FORWARDED_HOST']
if environ.has_key('HTTP_X_FORWARDED_FOR'):
@@ -75,14 +79,14 @@ def mailman_app(environ, start_response):
os.environ['HTTP_COOKIE'] = ''
for k, v in environ.items():
os.environ[k] = str(v)
- # Prepare for redirection.
+ # Prepare for redirection
save_stdin = sys.stdin
# CGI writes its output to sys.stdout, while wsgi app should
# return (list of) strings.
save_stdout = sys.stdout
save_stderr = sys.stderr
- tmpstdout = StringIO.StringIO()
- tmpstderr = StringIO.StringIO()
+ tmpstdout = StringIO()
+ tmpstderr = StringIO()
response = ''
try:
try:
@@ -117,7 +121,7 @@ def mailman_app(environ, start_response):
except:
start_response('200 OK', [('Content-Type', 'text/html')])
retstring = print_traceback(log)
- retstring +=print_environment(log)
+ retstring += print_environment(log)
return retstring
@@ -133,13 +137,13 @@ def print_traceback(log=None):
except ImportError:
traceback = None
try:
- from Mailman.mm_cfg import VERSION
+ from Mailman.Version import VERSION
except ImportError:
VERSION = '&lt;undetermined&gt;'
# Write to the log file first.
if log:
- outfp = StringIO.StringIO()
+ outfp = StringIO()
print >> outfp, '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'
print >> outfp, '[----- Mailman Version: %s -----]' % VERSION
@@ -155,7 +159,7 @@ def print_traceback(log=None):
log.error('%s', outfp.getvalue())
# return HTML sink.
- htfp = StringIO.StringIO()
+ htfp = StringIO()
print >> htfp, """\
<head><title>Bug in Mailman version %(VERSION)s</title></head>
<body bgcolor=#ffffff><h2>Bug in Mailman version %(VERSION)s</h2>
@@ -192,7 +196,7 @@ def print_environment(log=None):
os = None
if log:
- outfp = StringIO.StringIO()
+ outfp = StringIO()
# Write some information about our Python executable to the log file.
print >> outfp, '[----- Python Information -----]'
@@ -204,20 +208,20 @@ def print_environment(log=None):
print >> outfp, 'sys.platform =', sys.platform
# Write the same information to the HTML sink.
- htfp = StringIO.StringIO()
+ htfp = StringIO()
if not STEALTH_MODE:
- print >> htfp, '''\
+ print >> htfp, """\
<p><hr><h4>Python information:</h4>
<p><table>
<tr><th>Variable</th><th>Value</th></tr>
<tr><td><tt>sys.version</tt></td><td> %s </td></tr>
<tr><td><tt>sys.executable</tt></td><td> %s </td></tr>
-<tr><td><tt>sys.prefix</tt></td><td> %s </td></tr>'
+<tr><td><tt>sys.prefix</tt></td><td> %s </td></tr>
<tr><td><tt>sys.exec_prefix</tt></td><td> %s </td></tr>
<tr><td><tt>sys.path</tt></td><td> %s </td></tr>
<tr><td><tt>sys.platform</tt></td><td> %s </td></tr>
-</table>''' % (sys.version, sys.executable, sys.prefix,
+</table>""" % (sys.version, sys.executable, sys.prefix,
sys.exec_prefix, sys.path, sys.platform)
# Write environment variables to the log file.
@@ -231,12 +235,12 @@ def print_environment(log=None):
# Write environment variables to the HTML sink.
if not STEALTH_MODE:
- print >> htfp, '''\
+ print >> htfp, """\
<p><hr><h4>Environment variables:</h4>
<p><table>
<tr><th>Variable</th><th>Value</th></tr>
-'''
+"""
if os:
for k, v in os.environ.items():
print >> htfp, '<tr><td><tt>' + websafe(k) + \