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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
#!/usr/local/bin/python
"""Produce the list-administration web page on stdout.
We need the environment var PATH_INFO to name the list."""
import sys, os, cgi, string, crypt, types
f = open('/tmp/quick', 'a+')
#sys.stderr = sys.stdout
sys.stderr = f
sys.path.append('/home/mailman/mailman/modules')
import mm_utils, maillist, mm_cfg, htmlformat
def InitDocument():
return htmlformat.Document()
doc = InitDocument()
path = os.environ['PATH_INFO']
list_info = mm_utils.GetPathPieces(path)
if len(list_info) < 1:
doc.AddItem(htmlformat.Header(2, "Invalid options to CGI script."))
print doc.Format()
sys.exit(0)
list_name = list_info[0]
try:
list = maillist.MailList(list_name)
except:
doc.AddItem(htmlformat.Header(2, "%s : No such list" % list_name))
print doc.Format()
sys.exit(0)
if not list._ready:
doc.AddItem(htmlformat.Header(2, "%s : No such list" % list_name))
print doc.Format()
sys.exit(0)
def GetGuiItem(table_entry):
varname, type, params, dependancies, descr = table_entry
if type == mm_cfg.Radio or type == mm_cfg.Toggle:
gui_part = htmlformat.RadioButtonArray(varname, params,
getattr(list, varname))
elif (type == mm_cfg.String or type == mm_cfg.Email or type == mm_cfg.Host
or type == mm_cfg.Number):
gui_part = htmlformat.TextBox(varname, getattr(list, varname), params)
elif type == mm_cfg.Text:
if params:
r, c = params
else:
r, c = None, None
val = getattr(list, varname)
if not val:
val = ''
gui_part = htmlformat.TextArea(varname, val, r, c)
elif type == mm_cfg.EmailList:
if params:
r, c = params
else:
r, c = None, None
res = string.join(getattr(list, varname), '\n')
gui_part = htmlformat.TextArea(varname, res, r, c, wrap='off')
return gui_part
def FormatConfiguration(doc):
doc.SetTitle('%s Administration' % list.real_name)
doc.AddItem(htmlformat.Header(2, 'Configuration for %s' % list.real_name))
doc.AddItem('<hr>')
link = htmlformat.Link(list.GetScriptURL('admindb'),
'View or edit the administrative requests database.')
doc.AddItem(htmlformat.FontSize("+1", link))
doc.AddItem('<p>')
link = htmlformat.Link(list.GetScriptURL('listinfo'),
'Go to the general list information page.')
doc.AddItem(htmlformat.FontSize("+1", link))
doc.AddItem('<p>')
link = htmlformat.Link(list.GetScriptURL('edithtml'),
'Edit the HTML for the public list pages.')
doc.AddItem(htmlformat.FontSize("+1", link))
doc.AddItem('<p>')
doc.AddItem('<hr>')
form = htmlformat.Form(list.GetScriptURL('admin'))
doc.AddItem(form)
password_table = htmlformat.Table()
password_table.AddRow(['Enter the admin password to change options:',
htmlformat.PasswordBox('adminpw')])
password_table.AddRow(['When you are done...',
htmlformat.SubmitButton('submit', 'Submit Changes')])
form.AddItem(password_table)
big_table = htmlformat.Table(border=2)
big_table.AddRow([htmlformat.Center(htmlformat.Header(2, 'General Options'))])
big_table.AddCellInfo(0,0,colspan=2)
big_table.AddRow([htmlformat.Bold('Option'), htmlformat.Bold('Value')])
for item in general:
gui_item = GetGuiItem(item)
big_table.AddRow([item[4], gui_item])
# This wasn't handled too well.
if item[1] == mm_cfg.Toggle:
big_table.AddRow([htmlformat.Header(2, "If so:")])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
big_table.AddRow(['<br>'])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
big_table.AddRow([htmlformat.Center(htmlformat.Header(2, 'Digest Options'))])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
big_table.AddRow([htmlformat.Bold('Option'), htmlformat.Bold('Value')])
for item in digest:
gui_item = GetGuiItem(item)
big_table.AddRow([item[4], gui_item])
# Yuck.
if item[1] == mm_cfg.Toggle:
big_table.AddRow([htmlformat.Header(2, "If so:")])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
big_table.AddRow(['<br>'])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
big_table.AddRow([htmlformat.Center(htmlformat.Header(2,
'Non-Digested Options'))])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
big_table.AddRow([htmlformat.Bold('Option'), htmlformat.Bold('Value')])
for item in nodigest:
gui_item = GetGuiItem(item)
big_table.AddRow([item[4], gui_item])
# *sigh*
if item[1] == mm_cfg.Toggle:
big_table.AddRow([htmlformat.Header(2, "If so:")])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
big_table.AddRow(['<br>'])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
big_table.AddRow([htmlformat.Center(htmlformat.Header(2, 'Bounce Administration Options'))])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
for item in bounce:
gui_item = GetGuiItem(item)
big_table.AddRow([item[4], gui_item])
# This code sux...
if item[1] == mm_cfg.Toggle:
big_table.AddRow([htmlformat.Header(2, "If so:")])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
big_table.AddRow(['<br>'])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
big_table.AddRow([htmlformat.Center(htmlformat.Header(2, 'Archival Options'))])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
big_table.AddRow([htmlformat.Bold('Option'), htmlformat.Bold('Value')])
for item in archives:
gui_item = GetGuiItem(item)
big_table.AddRow([item[4], gui_item])
# This code sux...
if item[1] == mm_cfg.Toggle:
big_table.AddRow([htmlformat.Header(2, "If so:")])
big_table.AddCellInfo(big_table.GetCurrentRowIndex(), 0, colspan=2)
form.AddItem(big_table)
form.AddItem('<p>')
change_pw_table = htmlformat.Table(border=2)
change_pw_table.AddRow([htmlformat.Header(2,
htmlformat.Center(
'Change Your Password:'))])
change_pw_table.AddCellInfo(change_pw_table.GetCurrentRowIndex(), 0,
colspan=2)
change_pw_table.AddRow(['Enter your new password:',
htmlformat.PasswordBox('newpw')])
change_pw_table.AddRow(['And also confirm it:',
htmlformat.PasswordBox('confirmpw')])
form.AddItem(htmlformat.Center(change_pw_table))
# Improve the html here...
form.AddItem('<hr>')
form.AddItem('<h3>Mass Subscribe People</h3>')
form.AddItem('<h4>enter one email address per line</h4>')
form.AddItem(htmlformat.TextArea(name='subscribees',rows=20,cols=60,wrap=None))
form.AddItem(list.GetMailmanFooter())
turn_on_moderation = 0
def GetValidValue(list, prop, my_type, val, dependant):
if my_type == mm_cfg.Radio or my_type == mm_cfg.Toggle:
if type(val) <> types.IntType:
try:
val = eval(val)
except:
pass
# Don't know what to do here...
return val
elif my_type == mm_cfg.String or my_type == mm_cfg.Text:
return val
elif my_type == mm_cfg.Email:
try:
valid = mm_utils.ValidEmail(val)
if valid:
return val
except:
pass
# Revert to the old value.
return getattr(list, prop)
elif my_type == mm_cfg.EmailList:
def SafeValidAddr(addr):
import mm_utils
try:
valid = mm_utils.ValidEmail(addr)
if valid:
return 1
else:
return 0
except:
return 0
val = filter(SafeValidAddr, map(string.strip, string.split(val, '\n')))
if dependant and len(val):
# Wait till we've set everything to turn it on,
# as we don't want to clobber our special case.
turn_on_moderation = 1
return val
elif my_type == mm_cfg.Host:
return val
##
## This code is sendmail dependant, so we'll just live w/o the error
## Checking for now.
##
## # Shouldn't have to read in the whole file.
## file = open('/etc/sendmail.cf', 'r')
## lines = string.split(file.read(), '\n')
## file.close()
## def ConfirmCWEntry(item):
## return item[0:2] == 'Cw'
## lines = filter(ConfirmCWEntry, lines)
## if not len(lines):
## # Revert to the old value.
## return getattr(list, prop)
## for line in lines:
## if string.lower(string.strip(line[2:])) == string.lower(val):
## return val
## return getattr(list, prop)
elif my_type == mm_cfg.Number:
try:
num = eval(val)
if num < 0:
return getattr(list, prop)
return num
except:
return getattr(list, prop)
else:
# Should never get here...
return val
def ChangeOptions(list, opt_list, cgi_info, document):
for item in opt_list:
property, type, args, dependancies, desc = item
if not cgi_info.has_key(property):
if (type <> mm_cfg.Text and
type <> mm_cfg.String and
type <> mm_cfg.EmailList):
continue
else:
val = ''
else:
val = cgi_info[property].value
value = GetValidValue(list, property, type, val, dependancies)
setattr(list, property, value)
if cgi_info.has_key('subscribees'):
name_text = cgi_info['subscribees'].value
names = string.split(name_text, '\r\n')
for new_name in names:
try:
#FIXME: The admin needs to be able to specify the options to subscribe w/
list.AddMember(new_name, mm_utils.GetRandomSeed())
#FIXME: Give some sort of an indication of which names didn't work, and why
# they didn't work...
except:
pass
if cgi_info.has_key('newpw'):
if cgi_info.has_key('confirmpw'):
new = cgi_info['newpw'].value
confirm = cgi_info['confirmpw'].value
if new == confirm:
list.password = crypt.crypt(new, mm_utils.GetRandomSeed())
else:
document.AddItem(htmlformat.Header(3, htmlformat.Italic(
'Error: Passwords did not match.')))
else:
document.AddItem(htmlformat.Header(3, htmlformat.Italic(
'Error: You must type in your new password twice.')))
list.Save()
try:
info = list.GetConfigInfo()
general = info['general']
nodigest = info['nondigest']
digest = info['digest']
archives = info['archive']
if len(list._internal_name) < 3 or list._internal_name[-3:] <> '.jp':
bounce = info['bounce']
else:
bounce = []
cgi_data = cgi.FieldStorage()
if len(cgi_data.keys()):
if not cgi_data.has_key('adminpw'):
doc.AddItem('<hr>')
doc.AddItem(
htmlformat.Header(3, htmlformat.Italic('Error: '
'You must supply the admin password to change options.')))
else:
try:
list.ConfirmAdminPassword(cgi_data['adminpw'].value)
ChangeOptions(list, general + nodigest + digest + archives + bounce,
cgi_data, doc)
# Yuck. This shouldn't need to be here.
if not list.digestable and not list.nondigestable:
list.nondigestable = 1
except:
doc.AddItem('<hr>')
doc.AddItem(
htmlformat.Header(3, htmlformat.Italic(
'Error: Incorrect admin password.')))
if not list.digestable and len(list.digest_members):
doc.AddItem('<hr>')
doc.AddItem(htmlformat.Header(3, 'Warning: you have digest members, '
'but digests are turned off. Those people will not receive mail.'))
if not list.nondigestable and len(list.members):
doc.AddItem('<hr>')
doc.AddItem(htmlformat.Header(3, 'Warning: you have list members, but '
'non-digestified mail is turned off. They will receive mail until '
'you fix this problem.'))
FormatConfiguration(doc)
finally:
try:
print doc.Format()
except:
pass
list.Unlock()
|