#! /usr/bin/python import cgitb; cgitb.enable() import cgi import os import sys import glob import re import smtplib f = cgi.FieldStorage() l = f.getfirst('l') if not l: l = os.environ.get('PATH_INFO', '/')[1:] desc_re = re.compile(r'List-Id: "?([^<]*)"? <') def getdesc(d): fn = '%s/control/customheaders' % d try: hdrs = file(fn).read() except IOError: return '(none)' ret = desc_re.search(hdrs) if ret: return cgi.escape(ret.group(1)).replace('#', '') else: return '(none)' listdir = '/var/spool/mlmmj/%s' % l if l and os.path.isdir(os.path.join(listdir, 'control')): title = '%s membership' % l a = f.getfirst('a') addr = f.getfirst('addr') if ((a == 'subscribe') or (a == 'unsubscribe')) and addr: server = smtplib.SMTP('localhost') faddr = addr taddr = '%s-%s@woozle.org' % (l, a) try: server.sendmail(faddr, [taddr], 'From: %s\nTo: %s\n\n' % (faddr, taddr)) content = '

I have sent a confirmation message to %s. ' % addr content += 'It should be in your mailbox shortly.

' except Exception, err: content = "

Uh oh. That didn't work.

" content += "
%s
" % cgi.escape(str(err)) else: content = '

%s@woozle.org' % l content += ": %s" % getdesc(listdir) content += '

' content += '

To subscribe to or unsubscribe from the %s list,' % l content += ' just enter your email address in this handy dandy form!

' content += '
' content += ' ' % l content += ' Email address: ' content += ' ' content += ' ' content += '
' if os.path.exists(os.path.join(listdir, 'control', 'archive')): content += "

Message archive

" % l else: title = 'Email lists' content = '

Public email lists on this host

' content += '' content += ' ' content += ' ' content += ' ' content += ' ' content += ' ' content += ' ' content += ' ' content += ' ' for d in sorted(glob.glob('/var/spool/mlmmj/*')): if os.path.islink(d): continue if os.path.exists('%s/control/private' % d): continue l = os.path.basename(d) content += '' % (l, l) content += '' % getdesc(d) content += '\n' content += ' ' content += '
listdescriptionactions
%s%s
' content += ' ' content += '
' % l content += ' ' content += ' ' content += '
' if os.path.exists('%s/control/archive' % d): content += 'view archive' % l content += '
' print 'Content-type: text/html' print sys.stdout.flush() p = os.popen('m4 -DTITLE="%s" template.html.m4 -' % title, 'w') p.write(content) p.close()