1
# Copyright (C) 1998,1999,2000,2001,2002 by the Free Software Foundation, Inc.
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.
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.
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.
17
"""Script which implements admin editing of the list's html templates."""
23
from Mailman import Utils
24
from Mailman import MailList
25
from Mailman.htmlformat import *
26
from Mailman.HTMLFormatter import HTMLFormatter
27
from Mailman import Errors
28
from Mailman.Cgi import Auth
29
from Mailman.Logging.Syslog import syslog
30
from Mailman import i18n
37
# Trick out pygettext since we want to mark template_data as translatable,
38
# but we don't want to actually translate it here.
43
('listinfo.html', _('General list information page')),
44
('subscribe.html', _('Subscribe results page')),
45
('options.html', _('User specific options page')),
51
# Set up the system default language
52
i18n.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
53
doc.set_language(mm_cfg.DEFAULT_SERVER_LANGUAGE)
55
parts = Utils.GetPathPieces()
57
doc.AddItem(Header(2, _("List name is required.")))
61
listname = parts[0].lower()
63
mlist = MailList.MailList(listname, lock=0)
64
except Errors.MMListError, e:
65
# Avoid cross-site scripting attacks
66
safelistname = Utils.websafe(listname)
67
doc.AddItem(Header(2, _('No such list <em>%(safelistname)s</em>')))
69
syslog('error', 'No such list "%s": %s', listname, e)
72
# Now that we have a valid list, set the language to its default
73
i18n.set_language(mlist.preferred_language)
74
doc.set_language(mlist.preferred_language)
76
# Must be authenticated to get any farther
77
cgidata = cgi.FieldStorage()
79
# Editing the html for a list is limited to the list admin and site admin.
80
if not mlist.WebAuthenticate((mm_cfg.AuthListAdmin,
81
mm_cfg.AuthSiteAdmin),
82
cgidata.getvalue('adminpw', '')):
83
if cgidata.has_key('admlogin'):
84
# This is a re-authorization attempt
85
msg = Bold(FontSize('+1', _('Authorization failed.'))).Format()
88
Auth.loginpage(mlist, 'admin', msg=msg)
91
realname = mlist.real_name
93
template_name = parts[1]
94
for (template, info) in template_data:
95
if template == template_name:
96
template_info = _(info)
98
'%(realname)s -- Edit html for %(template_info)s'))
101
# Avoid cross-site scripting attacks
102
safetemplatename = Utils.websafe(template_name)
103
doc.SetTitle(_('Edit HTML : Error'))
104
doc.AddItem(Header(2, _("%(safetemplatename)s: Invalid template")))
105
doc.AddItem(mlist.GetMailmanFooter())
109
doc.SetTitle(_('%(realname)s -- HTML Page Editing'))
110
doc.AddItem(Header(1, _('%(realname)s -- HTML Page Editing')))
111
doc.AddItem(Header(2, _('Select page to edit:')))
112
template_list = UnorderedList()
113
for (template, info) in template_data:
114
l = Link(mlist.GetScriptURL('edithtml') + '/' + template, _(info))
115
template_list.AddItem(l)
116
doc.AddItem(FontSize("+2", template_list))
117
doc.AddItem(mlist.GetMailmanFooter())
123
ChangeHTML(mlist, cgidata, template_name, doc)
124
FormatHTML(mlist, doc, template_name, template_info)
126
doc.AddItem(mlist.GetMailmanFooter())
131
def FormatHTML(mlist, doc, template_name, template_info):
132
doc.AddItem(Header(1,'%s:' % mlist.real_name))
133
doc.AddItem(Header(1, template_info))
136
link = Link(mlist.GetScriptURL('admin'),
137
_('View or edit the list configuration information.'))
139
doc.AddItem(FontSize("+1", link))
142
form = Form(mlist.GetScriptURL('edithtml') + '/' + template_name)
143
text = Utils.websafe(Utils.maketext(template_name, raw=1, mlist=mlist))
144
form.AddItem(TextArea('html_code', text, rows=40, cols=75))
145
form.AddItem('<p>' + _('When you are done making changes...'))
146
form.AddItem(SubmitButton('submit', _('Submit Changes')))
151
def ChangeHTML(mlist, cgi_info, template_name, doc):
152
if not cgi_info.has_key('html_code'):
153
doc.AddItem(Header(3,_("Can't have empty html page.")))
154
doc.AddItem(Header(3,_("HTML Unchanged.")))
157
code = cgi_info['html_code'].value
158
langdir = os.path.join(mlist.fullpath(), mlist.preferred_language)
159
# Make sure the directory exists
161
os.mkdir(langdir, 02775)
163
if e.errno <> errno.EEXIST: raise
164
fp = open(os.path.join(langdir, template_name), 'w')
169
doc.AddItem(Header(3, _('HTML successfully updated.')))