Skip to content

Commit 4d86ca6

Browse files
committed
admin cgi fix
1 parent 90014ba commit 4d86ca6

1 file changed

Lines changed: 76 additions & 17 deletions

File tree

Mailman/Cgi/admin.py

Lines changed: 76 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -187,28 +187,87 @@ def main():
187187
else:
188188
category = parts[1]
189189
subcat = parts[2]
190+
191+
# Sanity check - validate category against available categories
192+
if category not in list(mlist.GetConfigCategories().keys()):
193+
category = 'general'
194+
195+
# Is the request for variable details?
196+
varhelp = None
197+
qsenviron = os.environ.get('QUERY_STRING')
198+
parsedqs = None
199+
if qsenviron:
200+
parsedqs = urllib.parse.parse_qs(qsenviron)
201+
if 'VARHELP' in cgidata:
202+
varhelp = cgidata['VARHELP'][0]
203+
elif parsedqs:
204+
# POST methods, even if their actions have a query string, don't get
205+
# put into FieldStorage's keys :-(
206+
qs = parsedqs.get('VARHELP')
207+
if qs and type(qs) is list:
208+
varhelp = qs[0]
209+
if varhelp:
210+
option_help(mlist, varhelp)
211+
return
212+
190213
doc = Document()
191214
doc.set_language(mlist.preferred_language)
192215
form = Form(mlist=mlist, contexts=AUTH_CONTEXTS)
193216
mailman_log('debug', 'category=%s, subcat=%s', category, subcat)
194-
# Now dispatch to the appropriate handler
195-
if category == 'general':
217+
218+
# From this point on, the MailList object must be locked
219+
mlist.Lock()
220+
try:
221+
# Install the emergency shutdown signal handler
222+
def sigterm_handler(signum, frame, mlist=mlist):
223+
# Make sure the list gets unlocked...
224+
mlist.Unlock()
225+
# ...and ensure we exit
226+
sys.exit(0)
227+
signal.signal(signal.SIGTERM, sigterm_handler)
228+
229+
if cgidata:
230+
if csrf_checked:
231+
# There are options to change
232+
change_options(mlist, category, subcat, cgidata, doc)
233+
else:
234+
doc.addError(
235+
_('The form lifetime has expired. (request forgery check)'))
236+
# Let the list sanity check the changed values
237+
mlist.CheckValues()
238+
239+
# Additional sanity checks
240+
if not mlist.digestable and not mlist.nondigestable:
241+
doc.addError(
242+
_(f'''You have turned off delivery of both digest and
243+
non-digest messages. This is an incompatible state of
244+
affairs. You must turn on either digest delivery or
245+
non-digest delivery or your mailing list will basically be
246+
unusable.'''), tag=_('Warning: '))
247+
248+
dm = mlist.getDigestMemberKeys()
249+
if not mlist.digestable and dm:
250+
doc.addError(
251+
_(f'''You have digest members, but digests are turned
252+
off. Those people will not receive mail.
253+
Affected member(s) %(dm)r.'''),
254+
tag=_('Warning: '))
255+
rm = mlist.getRegularMemberKeys()
256+
if not mlist.nondigestable and rm:
257+
doc.addError(
258+
_(f'''You have regular list members but non-digestified mail is
259+
turned off. They will receive non-digestified mail until you
260+
fix this problem. Affected member(s) %(rm)r.'''),
261+
tag=_('Warning: '))
262+
263+
# Show the results page
196264
show_results(mlist, doc, category, subcat, cgidata)
197-
elif category == 'members':
198-
membership_options(mlist, subcat, cgidata, doc, form)
199-
elif category == 'passwords':
200-
password_inputs(mlist)
201-
elif category == 'options':
202-
change_options(mlist, category, subcat, cgidata, doc)
203-
elif category == 'help':
204-
option_help(mlist, cgidata.get('VARHELP', [''])[0])
205-
else:
206-
doc.AddItem(Header(2, _('Error')))
207-
doc.AddItem(Bold(_('No such category: %(category)s') % {
208-
'category': category
209-
}))
210-
mailman_log('debug', 'About to print doc.Format()')
211-
print(doc.Format())
265+
mailman_log('debug', 'About to print doc.Format()')
266+
print(doc.Format())
267+
mlist.Save()
268+
finally:
269+
# Now be sure to unlock the list
270+
mlist.Unlock()
212271
except Exception as e:
213272
doc = Document()
214273
doc.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)

0 commit comments

Comments
 (0)