~futatuki/mailman/2.1-forbid-subscription

« back to all changes in this revision

Viewing changes to Mailman/Cgi/roster.py

  • Committer:
  • Date: 2003-01-02 05:25:50 UTC
  • Revision ID: vcs-imports@canonical.com-20030102052550-qqbl1i96tzg3bach
This commit was manufactured by cvs2svn to create branch
'Release_2_1-maint'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc.
 
2
#
 
3
# This program is free software; you can redistribute it and/or
 
4
# modify it under the terms of the GNU General Public License
 
5
# as published by the Free Software Foundation; either version 2
 
6
# of the License, or (at your option) any later version.
 
7
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software 
 
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
16
 
 
17
"""Produce subscriber roster, using listinfo form data, roster.html template.
 
18
 
 
19
Takes listname in PATH_INFO.
 
20
"""
 
21
 
 
22
 
 
23
# We don't need to lock in this script, because we're never going to change
 
24
# data. 
 
25
 
 
26
import sys
 
27
import os
 
28
import cgi
 
29
import urllib
 
30
 
 
31
from Mailman import mm_cfg
 
32
from Mailman import Utils
 
33
from Mailman import MailList
 
34
from Mailman import Errors
 
35
from Mailman import i18n
 
36
from Mailman.htmlformat import *
 
37
from Mailman.Logging.Syslog import syslog
 
38
 
 
39
# Set up i18n
 
40
_ = i18n._
 
41
i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
 
42
 
 
43
 
 
44
 
 
45
def main():
 
46
    parts = Utils.GetPathPieces()
 
47
    if not parts:
 
48
        error_page(_('Invalid options to CGI script'))
 
49
        return
 
50
 
 
51
    listname = parts[0].lower()
 
52
    try:
 
53
        mlist = MailList.MailList(listname, lock=0)
 
54
    except Errors.MMListError, e:
 
55
        # Avoid cross-site scripting attacks
 
56
        safelistname = Utils.websafe(listname)
 
57
        error_page(_('No such list <em>%(safelistname)s</em>'))
 
58
        syslog('error', 'roster: no such list "%s": %s', listname, e)
 
59
        return
 
60
 
 
61
    cgidata = cgi.FieldStorage()
 
62
 
 
63
    # messages in form should go in selected language (if any...)
 
64
    if cgidata.has_key('language'):
 
65
        lang = cgidata['language'].value
 
66
    else:
 
67
        lang = mlist.preferred_language
 
68
 
 
69
    i18n.set_language(lang)
 
70
 
 
71
    # Perform authentication for protected rosters.  If the roster isn't
 
72
    # protected, then anybody can see the pages.  If members-only or
 
73
    # "admin"-only, then we try to cookie authenticate the user, and failing
 
74
    # that, we check roster-email and roster-pw fields for a valid password.
 
75
    # (also allowed: the list moderator, the list admin, and the site admin).
 
76
    if mlist.private_roster == 0:
 
77
        # No privacy
 
78
        ok = 1
 
79
    elif mlist.private_roster == 1:
 
80
        # Members only
 
81
        addr = cgidata.getvalue('roster-email', '')
 
82
        password = cgidata.getvalue('roster-pw', '')
 
83
        ok = mlist.WebAuthenticate((mm_cfg.AuthUser,
 
84
                                    mm_cfg.AuthListModerator,
 
85
                                    mm_cfg.AuthListAdmin,
 
86
                                    mm_cfg.AuthSiteAdmin),
 
87
                                   password, addr)
 
88
    else:
 
89
        # Admin only, so we can ignore the address field
 
90
        password = cgidata.getvalue('roster-pw', '')
 
91
        ok = mlist.WebAuthenticate((mm_cfg.AuthListModerator,
 
92
                                    mm_cfg.AuthListAdmin,
 
93
                                    mm_cfg.AuthSiteAdmin),
 
94
                                   password)
 
95
    if not ok:
 
96
        realname = mlist.real_name
 
97
        doc = Document()
 
98
        doc.set_language(lang)
 
99
        error_page_doc(doc, _('%(realname)s roster authentication failed.'))
 
100
        doc.AddItem(mlist.GetMailmanFooter())
 
101
        print doc.Format()
 
102
        return
 
103
 
 
104
    # The document and its language
 
105
    doc = HeadlessDocument()
 
106
    doc.set_language(lang)
 
107
 
 
108
    replacements = mlist.GetAllReplacements(lang)
 
109
    replacements['<mm-displang-box>'] = mlist.FormatButton(
 
110
        'displang-button',
 
111
        text = _('View this page in'))
 
112
    replacements['<mm-lang-form-start>'] = mlist.FormatFormStart('roster')
 
113
    doc.AddItem(mlist.ParseTags('roster.html', replacements, lang))
 
114
    print doc.Format()
 
115
 
 
116
 
 
117
 
 
118
def error_page(errmsg):
 
119
    doc = Document()
 
120
    doc.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
 
121
    error_page_doc(doc, errmsg)
 
122
    print doc.Format()
 
123
 
 
124
 
 
125
def error_page_doc(doc, errmsg, *args):
 
126
    # Produce a simple error-message page on stdout and exit.
 
127
    doc.SetTitle(_("Error"))
 
128
    doc.AddItem(Header(2, _("Error")))
 
129
    doc.AddItem(Bold(errmsg % args))