# Copyright (C) 1998-2018 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. """Produce and handle the member options.""" import re import sys import os import cgi import signal import urllib from types import ListType from Mailman import mm_cfg from Mailman import Utils from Mailman import MailList from Mailman import Errors from Mailman import MemberAdaptor from Mailman import i18n from Mailman.htmlformat import * from Mailman.Logging.Syslog import syslog from Mailman.CSRFcheck import csrf_check OR = '|' SLASH = '/' SETLANGUAGE = -1 DIGRE = re.compile( '.*', re.DOTALL) # Set up i18n _ = i18n._ i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE) def D_(s): return s try: True, False except NameError: True = 1 False = 0 AUTH_CONTEXTS = (mm_cfg.AuthListAdmin, mm_cfg.AuthSiteAdmin, mm_cfg.AuthListModerator, mm_cfg.AuthUser) def main(): global _ doc = Document() doc.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE) method = Utils.GetRequestMethod() if method.lower() not in ('get', 'post'): title = _('CGI script error') doc.SetTitle(title) doc.AddItem(Header(2, title)) doc.addError(_('Invalid request method: %(method)s')) doc.AddItem('
Important: From this point on, you must have
cookies enabled in your browser, otherwise none of your changes will take
effect.
""")])
# Password and login button
ptable = Table(width='50%', border=0, cellspacing=4, cellpadding=5)
if user is None:
ptable.AddRow([Label(_('Email address:')),
TextBox('email', size=20)])
else:
ptable.AddRow([Hidden('email', user)])
ptable.AddRow([Label(_('Password:')),
PasswordBox('password', size=20)])
ptable.AddRow([Center(SubmitButton('login', _('Log in')))])
ptable.AddCellInfo(ptable.GetCurrentRowIndex(), 0, colspan=2)
table.AddRow([Center(ptable)])
# Unsubscribe section
table.AddRow([Center(Header(2, _('Unsubscribe')))])
table.AddCellInfo(table.GetCurrentRowIndex(), 0,
bgcolor=mm_cfg.WEB_HEADER_COLOR)
table.AddRow([_("""By clicking on the Unsubscribe button, a
confirmation message will be emailed to you. This message will have a
link that you should click on to complete the removal process (you can
also confirm by email; see the instructions in the confirmation
message).""")])
table.AddRow([Center(SubmitButton('login-unsub', _('Unsubscribe')))])
# Password reminder section
table.AddRow([Center(Header(2, _('Password reminder')))])
table.AddCellInfo(table.GetCurrentRowIndex(), 0,
bgcolor=mm_cfg.WEB_HEADER_COLOR)
table.AddRow([_("""By clicking on the Remind button, your
password will be emailed to you.""")])
table.AddRow([Center(SubmitButton('login-remind', _('Remind')))])
# Finish up glomming together the login page
form.AddItem(table)
doc.AddItem(form)
doc.AddItem(mlist.GetMailmanFooter())
def lists_of_member(mlist, user):
hostname = mlist.host_name
onlists = []
for listname in Utils.list_names():
# The current list will always handle things in the mainline
if listname == mlist.internal_name():
continue
glist = MailList.MailList(listname, lock=0)
if glist.host_name <> hostname:
continue
if not glist.isMember(user):
continue
onlists.append(glist)
return onlists
def change_password(mlist, user, newpw, confirmpw):
# This operation requires the list lock, so let's set up the signal
# handling so the list lock will get released when the user hits the
# browser stop button.
def sigterm_handler(signum, frame, mlist=mlist):
# Make sure the list gets unlocked...
mlist.Unlock()
# ...and ensure we exit, otherwise race conditions could cause us to
# enter MailList.Save() while we're in the unlocked state, and that
# could be bad!
sys.exit(0)
# Must own the list lock!
mlist.Lock()
try:
# Install the emergency shutdown signal handler
signal.signal(signal.SIGTERM, sigterm_handler)
# change the user's password. The password must already have been
# compared to the confirmpw and otherwise been vetted for
# acceptability.
mlist.setMemberPassword(user, newpw)
mlist.Save()
finally:
mlist.Unlock()
def global_options(mlist, user, globalopts):
# Is there anything to do?
for attr in dir(globalopts):
if attr.startswith('_'):
continue
if getattr(globalopts, attr) is not None:
break
else:
return
def sigterm_handler(signum, frame, mlist=mlist):
# Make sure the list gets unlocked...
mlist.Unlock()
# ...and ensure we exit, otherwise race conditions could cause us to
# enter MailList.Save() while we're in the unlocked state, and that
# could be bad!
sys.exit(0)
# Must own the list lock!
mlist.Lock()
try:
# Install the emergency shutdown signal handler
signal.signal(signal.SIGTERM, sigterm_handler)
if globalopts.enable is not None:
mlist.setDeliveryStatus(user, globalopts.enable)
if globalopts.remind is not None:
mlist.setMemberOption(user, mm_cfg.SuppressPasswordReminder,
globalopts.remind)
if globalopts.nodupes is not None:
mlist.setMemberOption(user, mm_cfg.DontReceiveDuplicates,
globalopts.nodupes)
if globalopts.mime is not None:
mlist.setMemberOption(user, mm_cfg.DisableMime, globalopts.mime)
mlist.Save()
finally:
mlist.Unlock()
def topic_details(mlist, doc, user, cpuser, userlang, varhelp):
# Find out which topic the user wants to get details of
reflist = varhelp.split('/')
name = None
topicname = _('' + Utils.websafe(OR.join(pattern.splitlines()))
+ '
'])
table.AddRow([Bold(Label(_('Description:'))),
Utils.websafe(description)])
# Make colors look nice
for row in range(1, 4):
table.AddCellInfo(row, 0, bgcolor=mm_cfg.WEB_ADMINITEM_COLOR)
options_page(mlist, doc, user, cpuser, userlang, table.Format())
print doc.Format()