Skip to content

Commit 5a44da9

Browse files
committed
update cgi
1 parent 4ef8e46 commit 5a44da9

5 files changed

Lines changed: 60 additions & 173 deletions

File tree

Mailman/Cgi/admin.py

Lines changed: 21 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,23 @@ def show_results(mlist, doc, category, subcat, cgidata):
533533
'realname': mlist.real_name,
534534
'label': label
535535
})
536-
doc.AddItem(Center(Header(2, _(
537-
'%(realname)s mailing list administration<br>%(label)s Section') % {
538-
'realname': mlist.real_name,
539-
'label': label
540-
})))
541-
doc.AddItem('<hr>')
542-
# Now we need to craft the form that will be submitted, which will contain
543-
# all the variable settings, etc. This is a bit of a kludge because we
544-
# know that the autoreply and members categories supports file uploads.
536+
537+
# Use ParseTags for the main content
538+
replacements = {
539+
'realname': mlist.real_name,
540+
'label': label,
541+
'adminurl': adminurl,
542+
'admindburl': mlist.GetScriptURL('admindb'),
543+
'listinfourl': mlist.GetScriptURL('listinfo'),
544+
'edithtmlurl': mlist.GetScriptURL('edithtml'),
545+
'archiveurl': mlist.GetBaseArchiveURL(),
546+
'rmlisturl': mlist.GetScriptURL('rmlist') if mm_cfg.OWNERS_CAN_DELETE_THEIR_OWN_LISTS and mlist.internal_name() != mm_cfg.MAILMAN_SITE_LIST else None
547+
}
548+
549+
output = mlist.ParseTags('admin_results.html', replacements, mlist.preferred_language)
550+
doc.AddItem(output)
551+
552+
# Now we need to craft the form that will be submitted
545553
encoding = None
546554
if category in ('autoreply', 'members'):
547555
encoding = 'multipart/form-data'
@@ -556,127 +564,19 @@ def show_results(mlist, doc, category, subcat, cgidata):
556564
'adminurl': adminurl,
557565
'category': category
558566
}, encoding=encoding, mlist=mlist, contexts=AUTH_CONTEXTS)
559-
# This holds the two columns of links
560-
linktable = Table(valign='top', width='100%')
561-
linktable.AddRow([Center(Bold(_("Configuration Categories"))),
562-
Center(Bold(_("Other Administrative Activities")))])
563-
# The `other links' are stuff in the right column.
564-
otherlinks = UnorderedList()
565-
otherlinks.AddItem(Link(mlist.GetScriptURL('admindb'),
566-
_('Tend to pending moderator requests')))
567-
otherlinks.AddItem(Link(mlist.GetScriptURL('listinfo'),
568-
_('Go to the general list information page')))
569-
otherlinks.AddItem(Link(mlist.GetScriptURL('edithtml'),
570-
_('Edit the public HTML pages and text files')))
571-
otherlinks.AddItem(Link(mlist.GetBaseArchiveURL(),
572-
_('Go to list archives')).Format() +
573-
'<br>&nbsp;<br>')
574-
# We do not allow through-the-web deletion of the site list!
575-
if mm_cfg.OWNERS_CAN_DELETE_THEIR_OWN_LISTS and \
576-
mlist.internal_name() != mm_cfg.MAILMAN_SITE_LIST:
577-
otherlinks.AddItem(Link(mlist.GetScriptURL('rmlist'),
578-
_('Delete this mailing list')).Format() +
579-
_(' (requires confirmation)<br>&nbsp;<br>'))
580-
otherlinks.AddItem(Link('%s/logout' % adminurl,
581-
# BAW: What I really want is a blank line, but
582-
# adding an &nbsp; won't do it because of the
583-
# bullet added to the list item.
584-
'<FONT SIZE="+2"><b>%s</b></FONT>' %
585-
_('Logout')))
586-
# These are links to other categories and live in the left column
587-
categorylinks_1 = categorylinks = UnorderedList()
588-
categorylinks_2 = ''
589-
categorykeys = list(categories.keys())
590-
half = len(categorykeys) / 2
591-
counter = 0
592-
subcat = None
593-
for k in categorykeys:
594-
label = _(categories[k][0])
595-
url = '%s/%s' % (adminurl, k)
596-
if k == category:
597-
# Handle subcategories
598-
subcats = mlist.GetConfigSubCategories(k)
599-
if subcats:
600-
subcat = Utils.GetPathPieces()[-1]
601-
for k, v in subcats:
602-
if k == subcat:
603-
break
604-
else:
605-
# The first subcategory in the list is the default
606-
subcat = subcats[0][0]
607-
subcat_items = []
608-
for sub, text in subcats:
609-
if sub == subcat:
610-
text = Bold('[%s]' % text).Format()
611-
subcat_items.append(Link(url + '/' + sub, text))
612-
categorylinks.AddItem(
613-
Bold(label).Format() +
614-
UnorderedList(*subcat_items).Format())
615-
else:
616-
formatted_label = '[%s]' % label
617-
categorylinks.AddItem(Link(url, Bold(formatted_label)))
618-
else:
619-
categorylinks.AddItem(Link(url, label))
620-
counter += 1
621-
if counter >= half:
622-
categorylinks_2 = categorylinks = UnorderedList()
623-
counter = -len(categorykeys)
624-
# Make the emergency stop switch a rude solo light
625-
etable = Table()
626-
# Add all the links to the links table...
627-
etable.AddRow([categorylinks_1, categorylinks_2])
628-
etable.AddRowInfo(etable.GetCurrentRowIndex(), valign='top')
629-
if mlist.emergency:
630-
label = _('Emergency moderation of all list traffic is enabled')
631-
etable.AddRow([Center(
632-
Link('?VARHELP=general/emergency', Bold(label)))])
633-
color = mm_cfg.WEB_ERROR_COLOR
634-
etable.AddCellInfo(etable.GetCurrentRowIndex(), 0,
635-
colspan=2, bgcolor=color)
636-
linktable.AddRow([etable, otherlinks])
637-
# ...and add the links table to the document.
638-
form.AddItem(linktable)
639-
form.AddItem('<hr>')
640-
form.AddItem(
641-
_(f'''Make your changes in the following section, then submit them
642-
using the <em>Submit Your Changes</em> button below.''')
643-
+ '<p>')
644-
645-
# The members and passwords categories are special in that they aren't
646-
# defined in terms of gui elements. Create those pages here.
567+
568+
# Add the form content based on category
647569
if category == 'members':
648-
# Figure out which subcategory we should display
649-
subcat = Utils.GetPathPieces()[-1]
650-
if subcat not in ('list', 'add', 'remove', 'change', 'sync'):
651-
subcat = 'list'
652-
# Add member category specific tables
653570
form.AddItem(membership_options(mlist, subcat, cgidata, doc, form))
654571
form.AddItem(Center(submit_button('setmemberopts_btn')))
655-
# In "list" subcategory, we can also search for members
656-
if subcat == 'list':
657-
form.AddItem('<hr>\n')
658-
table = Table(width='100%')
659-
table.AddRow([Center(Header(2, _('Additional Member Tasks')))])
660-
table.AddCellInfo(table.GetCurrentRowIndex(), 0, colspan=2,
661-
bgcolor=mm_cfg.WEB_HEADER_COLOR)
662-
# Add a blank separator row
663-
table.AddRow(['&nbsp;', '&nbsp;'])
664-
# Add a section to set the moderation bit for all members
665-
table.AddRow([_(f"""<li>Set everyone's moderation bit, including
666-
those members not currently visible""")])
667-
table.AddCellInfo(table.GetCurrentRowIndex(), 0, colspan=2)
668-
table.AddRow([RadioButtonArray('allmodbit_val',
669-
(_('Off'), _('On')),
670-
mlist.default_member_moderation),
671-
SubmitButton('allmodbit_btn', _('Set'))])
672-
form.AddItem(table)
673572
elif category == 'passwords':
674573
form.AddItem(Center(password_inputs(mlist)))
675574
form.AddItem(Center(submit_button()))
676575
else:
677576
form.AddItem(show_variables(mlist, category, subcat, cgidata, doc))
678577
form.AddItem(Center(submit_button()))
679-
# And add the form
578+
579+
# Add the form to the document
680580
doc.AddItem(form)
681581
doc.AddItem(mlist.GetMailmanFooter())
682582

Mailman/Cgi/admindb.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -873,16 +873,12 @@ def safe_get(key, default=''):
873873
# Check if there are any pending requests
874874
admindburl = mlist.GetScriptURL('admindb', absolute=1)
875875
if not mlist.NumRequestsPending():
876-
doc.AddItem(_('There are no pending requests.'))
877-
doc.AddItem(' ')
878-
doc.AddItem(Link(admindburl, _('Click here to reload this page.')))
879-
# Put 'Logout' link before the footer
880-
doc.AddItem('\n<div align="right"><font size="+2">')
881-
doc.AddItem(Link('%s/logout' % admindburl,
882-
'<b>%s</b>' % _('Logout')))
883-
doc.AddItem('</font></div>\n')
884-
# Add the footer
885-
doc.AddItem(mlist.GetMailmanFooter())
876+
replacements = {
877+
'admindburl': admindburl,
878+
'logout_url': '%s/logout' % admindburl
879+
}
880+
output = mlist.ParseTags('admindb_empty.html', replacements, mlist.preferred_language)
881+
doc.AddItem(output)
886882
return
887883

888884
# Create a form for the overview with proper encoding
@@ -909,21 +905,19 @@ def safe_get(key, default=''):
909905
# Process the form data
910906
process_submissions(mlist, cgidata)
911907
# Show success message
912-
doc.AddItem(_('Your changes have been made.'))
913-
doc.AddItem(' ')
914-
admindburl = mlist.GetScriptURL('admindb', absolute=1)
915-
doc.AddItem(Link(admindburl, _('Click here to return to the pending requests page.')))
916-
# Add the footer
917-
doc.AddItem(mlist.GetMailmanFooter())
908+
replacements = {
909+
'admindburl': admindburl
910+
}
911+
output = mlist.ParseTags('admindb_success.html', replacements, mlist.preferred_language)
912+
doc.AddItem(output)
918913
return
919914

920915
# If we get here, something went wrong
921-
doc.AddItem(_('Invalid action specified.'))
922-
doc.AddItem(' ')
923-
admindburl = mlist.GetScriptURL('admindb', absolute=1)
924-
doc.AddItem(Link(admindburl, _('Click here to return to the pending requests page.')))
925-
# Add the footer
926-
doc.AddItem(mlist.GetMailmanFooter())
916+
replacements = {
917+
'admindburl': admindburl
918+
}
919+
output = mlist.ParseTags('admindb_error.html', replacements, mlist.preferred_language)
920+
doc.AddItem(output)
927921

928922
except Exception as e:
929923
mailman_log('error', 'admindb: Error in process_form: %s\n%s',

Mailman/Cgi/edithtml.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,13 @@ def _(s):
173173
print(doc.Format())
174174
return
175175
else:
176-
doc.SetTitle(_('{realname} -- HTML Page Editing'))
177-
doc.AddItem(Header(1, _('{realname} -- HTML Page Editing')))
178-
doc.AddItem(Header(2, _('Select page to edit:')))
179-
template_list = UnorderedList()
180-
for (template, info) in template_data:
181-
l = Link(mlist.GetScriptURL('edithtml') + '/' + template, _(info))
182-
template_list.AddItem(l)
183-
doc.AddItem(FontSize("+2", template_list))
184-
doc.AddItem(mlist.GetMailmanFooter())
176+
# Use ParseTags for the template selection page
177+
replacements = {
178+
'realname': realname,
179+
'templates': template_data
180+
}
181+
output = mlist.ParseTags('edithtml_select.html', replacements, language)
182+
doc.AddItem(output)
185183
print(doc.Format())
186184
return
187185

@@ -192,7 +190,10 @@ def _(s):
192190
else:
193191
doc.addError(
194192
_('The form lifetime has expired. (request forgery check)'))
195-
FormatHTML(mlist, doc, template_name, template_info, lang=language)
193+
# Use ParseTags for proper template processing
194+
replacements = mlist.GetStandardReplacements(language)
195+
output = mlist.ParseTags(template_name, replacements, language)
196+
doc.AddItem(output)
196197
finally:
197198
doc.AddItem(mlist.GetMailmanFooter())
198199
print(doc.Format())

Mailman/Cgi/listinfo.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,19 +326,9 @@ def list_listinfo(mlist, language):
326326

327327
# Process the template with replacements
328328
try:
329-
# Ensure template content is unicode
330-
if isinstance(template_content, bytes):
331-
template_content = template_content.decode('utf-8', 'replace')
332-
333-
# Process replacements
334-
for key, value in replacements.items():
335-
if isinstance(value, bytes):
336-
value = value.decode('utf-8', 'replace')
337-
template_content = template_content.replace(key, str(value))
338-
339-
# Add the processed content to the document
340-
doc.AddItem(template_content)
341-
329+
# Use ParseTags for proper template processing
330+
output = mlist.ParseTags('listinfo.html', replacements, language)
331+
doc.AddItem(output)
342332
except Exception as e:
343333
mailman_log('error', 'Error processing template: %s', str(e))
344334
return

Mailman/Cgi/private.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def main():
111111
doc.AddItem(Header(3, error_msg))
112112
print('Status: 400 Bad Request')
113113
print(doc.Format())
114+
syslog('mischief', 'Private archive invalid path: %s', parts[0])
114115
return
115116

116117
# Validate and sanitize the full path
@@ -233,13 +234,14 @@ def main():
233234
# page don't work.
234235
if true_filename.endswith('/index.html') and parts[-1] != 'index.html':
235236
action += SLASH
236-
# Escape web input parameter to avoid cross-site scripting.
237-
print(Utils.maketext(
238-
'private.html',
239-
{'action' : Utils.websafe(action),
240-
'realname': mlist.real_name,
241-
'message' : message,
242-
}, mlist=mlist))
237+
# Use ParseTags for proper template processing
238+
replacements = {
239+
'action': Utils.websafe(action),
240+
'realname': mlist.real_name,
241+
'message': message
242+
}
243+
output = mlist.ParseTags('private.html', replacements, lang)
244+
print(output)
243245
return
244246

245247
lang = mlist.getMemberLanguage(username)

0 commit comments

Comments
 (0)