1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
# Copyright (C) 1998,1999,2000,2001 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""Process input to user options form."""
import sys
import os
import cgi
import signal
from Mailman import mm_cfg
from Mailman import Utils
from Mailman import MailList
from Mailman import Errors
from Mailman.htmlformat import *
from Mailman.Logging.Syslog import syslog
from Mailman import i18n
# Set up i18n
_ = i18n._
i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
def PrintResults(mlist, operation, doc, results, user=None, lang=None):
if lang is None:
lang = mlist.preferred_language
if user:
url = '%s/%s' % (mlist.GetScriptURL('options'),
Utils.ObscureEmail(user))
results = results + _('<p>Continue to ') + \
Link(url, _('edit your personal options')).Format() + \
'.'
replacements = mlist.GetStandardReplacements(lang)
replacements['<mm-results>'] = results
replacements['<mm-operation>'] = operation
output = mlist.ParseTags('handle_opts.html', replacements, lang)
doc.AddItem(output)
print doc.Format(bgcolor="#ffffff")
# hrm...
sys.exit(0)
def main():
doc = Document()
doc.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
parts = Utils.GetPathPieces()
if not parts or len(parts) < 2:
doc.AddItem(Header(2, _("Error")))
doc.AddItem(Bold(_("Invalid options to CGI script.")))
print doc.Format(bgcolor="#ffffff")
return
listname = parts[0].lower()
user = parts[1]
try:
mlist = MailList.MailList(listname, lock=0)
except Errors.MMListError, e:
doc.AddItem(Header(2, _("Error")))
doc.AddItem(Bold(_('No such list <em>%(listname)s</em>')))
print doc.Format(bgcolor="#ffffff")
syslog('error', 'No such list "%s": %s\n' % (listname, e))
return
# Now that we have a valid list, set the language to its default
i18n.set_language(mlist.preferred_language)
doc.set_language(mlist.preferred_language)
# We need a signal handler to catch the SIGTERM that can come from Apache
# when the user hits the browser's STOP button. See the comment in
# admin.py for details.
#
# BAW: Strictly speaking, the list should not need to be locked just to
# read the request database. However the request database asserts that
# the list is locked in order to load it and it's not worth complicating
# that logic.
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)
mlist.Lock()
try:
# Install the emergency shutdown signal handler
signal.signal(signal.SIGTERM, sigterm_handler)
process_form(mlist, user, doc)
mlist.Save()
finally:
mlist.Unlock()
def process_form(mlist, user, doc):
form = cgi.FieldStorage()
error = 0
operation = ""
user = Utils.LCDomain(user)
# Set the user's preferred language
pluser = mlist.GetPreferredLanguage(user)
i18n.set_language(pluser)
doc.set_language(pluser)
if not Utils.FindMatchingAddresses(user, mlist.members,
mlist.digest_members):
PrintResults(mlist, operation, doc,
_("%(user)s not a member!<p>"),
pluser)
if form.has_key("unsub"):
operation = _("Unsubscribe")
if not form.has_key("upw"):
mlist.ConfirmUnsubscription(user, pluser)
PrintResults(mlist, operation, doc,
_('A removal confirmation will be emailed to you.'),
user, pluser)
else:
try:
pw = form["upw"].value
if mlist.ConfirmUserPassword(user, pw):
mlist.DeleteMember(user, "web cmd")
except Errors.MMListNotReadyError:
PrintResults(mlist, operation, doc,
_("List is not functional."),
user, pluser)
except Errors.MMNoSuchUserError:
PrintResults(mlist, operation, doc,
_("You seem to already be not a member.") + "<p>",
user, pluser)
except Errors.MMBadUserError:
PrintResults(mlist, operation, doc,
_("Your account has gone awry - "
"please contact the list administrator!") + "<p>",
user, pluser)
except Errors.MMBadPasswordError:
PrintResults(mlist, operation, doc,
_("That password was incorrect.") + "<p>")
PrintResults(mlist, operation, doc,
_("You have been unsubscribed.") + "<p>", None, pluser)
elif form.has_key("emailpw"):
try:
mlist.MailUserPassword(user)
PrintResults(mlist, operation, doc,
_("A reminder of your password "
"has been emailed to you.") + "<p>", user, pluser)
except Errors.MMBadUserError:
PrintResults(mlist, operation, doc,
_("The password entry for `%(user)s' has not "
'been found. The list administrator is being '
'notified.<p>'), user, pluser)
elif form.has_key("othersubs"):
if not form.has_key('othersubspw'):
PrintResults(mlist, operation, doc,
_("You must specify your password."), user, pluser)
else:
try:
mlist.ConfirmUserPassword(user, form['othersubspw'].value)
except Errors.MMListNotReadyError:
PrintResults(mlist, operation, doc,
_("The list is currently not functional."),
user, pluser)
except Errors.MMNotAMemberError:
PrintResults(mlist, operation, doc,
_("You seem to no longer be a list member."),
user, pluser)
except Errors.MMBadPasswordError:
PrintResults(mlist, operation, doc, _("Incorrect password."),
user, pluser)
except Errors.MMBadUserError:
PrintResults(
mlist, operation, doc,
_("You have no password. Contact the list administrator."),
user, pluser)
hostname = mlist.host_name
doc.AddItem(
Header(2,
_("List Subscriptions for %(user)s on %(hostname)s")
))
doc.AddItem(_("Click a link to visit your options page for"
" that mailing list:"))
def optionslinks(listname, user=user):
mlist = MailList.MailList(listname, lock=0)
addrs = Utils.FindMatchingAddresses(user, mlist.members,
mlist.digest_members)
if addrs:
addr = Utils.ObscureEmail(addrs[0])
if mlist.obscure_addresses:
addr = Utils.ObscureEmail(addr)
url = mlist.GetOptionsURL(addr)
link = Link(url, mlist.real_name)
return mlist.internal_name(), link
all_links = filter(None, map(optionslinks, Utils.list_names()))
all_links.sort()
items = OrderedList()
for name, link in all_links:
items.AddItem(link)
doc.AddItem(items)
print doc.Format(bgcolor="#ffffff")
elif form.has_key("changepw"):
if form.has_key('opw') and \
form.has_key('newpw') and \
form.has_key('confpw'):
# then
try:
mlist.ConfirmUserPassword(user, form['opw'].value)
mlist.ChangeUserPassword(user, form['newpw'].value,
form['confpw'].value)
except Errors.MMListNotReadyError:
PrintResults(mlist, operation, doc,
_("The list is currently not functional."),
user, pluser)
except Errors.MMNotAMemberError:
PrintResults(mlist, operation, doc,
_("You seem to no longer be a list member."),
user, pluser)
except Errors.MMBadPasswordError:
PrintResults(mlist, operation, doc,
_("The old password you supplied was incorrect."),
user, pluser)
except Errors.MMPasswordsMustMatch:
PrintResults(mlist, operation, doc, _("Passwords must match."),
user, pluser)
PrintResults(mlist, operation, doc,
_("Your password has been changed."),
user, pluser)
else:
PrintResults(mlist, operation, doc,
_("You must specify your old password,"
" and your new password twice."), user, pluser)
else:
# if key doesn't exist, or its value can't be int()'ified, return the
# current value (essentially a noop)
def getval(key, default, form=form):
if form.has_key(key):
try:
return int(form[key].value)
except ValueError:
return default
return default
useropt = mlist.GetUserOption
digest_value = getval('digest', useropt(user, mm_cfg.Digests))
mime = getval('mime', useropt(user, mm_cfg.DisableMime))
dont_receive = getval('dontreceive',
useropt(user, mm_cfg.DontReceiveOwnPosts))
ack_posts = getval('ackposts', useropt(user, mm_cfg.AcknowledgePosts))
disable_mail = getval('disablemail',
useropt(user, mm_cfg.DisableDelivery))
conceal = getval('conceal', useropt(user, mm_cfg.ConcealSubscription))
passwdremind = getval('passwdremind',
useropt(user, mm_cfg.SuppressPasswordReminder))
if not form.has_key("digpw"):
PrintResults(mlist, operation, doc,
_("You must supply a password to change options."),
user, pluser)
try:
mlist.ConfirmUserPassword(user, form['digpw'].value)
except Errors.MMAlreadyDigested:
pass
except Errors.MMAlreadyUndigested:
pass
except Errors.MMMustDigestError:
PrintResults(mlist, operation, doc,
_("List only accepts digest members."), user, pluser)
except Errors.MMCantDigestError:
PrintResults(mlist, operation, doc,
_("List doesn't accept digest members."),
user, pluser)
except Errors.MMNotAMemberError:
PrintResults(mlist, operation, doc,
_("%(user)s isn't subscribed to this list."),
user, pluser)
except Errors.MMListNotReadyError:
PrintResults(mlist, operation, doc, _("List is not functional."),
user, pluser)
except Errors.MMNoSuchUserError:
PrintResults(mlist, operation, doc,
_("%(user)s is not subscribed to this list."),
user, pluser)
except Errors.MMBadPasswordError:
PrintResults(mlist, operation, doc,
_("You gave the wrong password."), user, pluser)
# jcrey: read user's preferred language
try:
pluser = form['language'].value
except ValueError:
pluser = mlist.GetPreferredLanguage(user)
mlist.SetPreferredLanguage(user, pluser)
mlist.SetUserOption(user, mm_cfg.DisableDelivery, disable_mail)
mlist.SetUserOption(user, mm_cfg.DontReceiveOwnPosts, dont_receive)
mlist.SetUserOption(user, mm_cfg.AcknowledgePosts, ack_posts)
mlist.SetUserOption(user, mm_cfg.DisableMime, mime)
mlist.SetUserOption(user, mm_cfg.SuppressPasswordReminder,
passwdremind)
msg = _('You have successfully set your options.')
try:
mlist.SetUserDigest(user, digest_value)
# digest mode changed from on to off, so send the current digest
# to the user.
if digest_value == 0:
PrintResults(mlist, operation, doc,
_('You may get one last digest.'), user, pluser)
except (Errors.MMAlreadyDigested, Errors.MMAlreadyUndigested):
pass
except Errors.MMCantDigestError:
msg = _('''The list administrator has disabled digest delivery for
this list, so your delivery option has not been set. However your
other options have been set successfully.''')
except Errors.MMMustDigestError:
msg = _('''The list administrator has disabled non-digest delivery
for this list, so your delivery option has not been set. However
your other options have been set successfully.''')
mlist.SetUserOption(user, mm_cfg.ConcealSubscription, conceal)
PrintResults(mlist, operation, doc, msg, user, pluser)
|