From 22a4400664be8c36123a9046b5d2caa7e74637e6 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 28 Sep 2011 22:24:19 +0200 Subject: added list create logic create list via shell execution send mail to admins to notify creation add listadmin to admin mailinglist --- index.py | 14 ++++++++++++-- util.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/index.py b/index.py index b8d1167..bdb569d 100755 --- a/index.py +++ b/index.py @@ -89,8 +89,18 @@ class new: if not form.validates(): return render.new(form, user) else: - # create list - return "Done." + listname = form.d.name.lower() + listadmin = form.d.email + + (success, progress) = util.create_list(listname, listadmin) + + util.notify_admins(listname, listadmin, success, progress) + + if config.listadmins_list: + (is_member, message) = util.add_to_list(config.listadmins_list, listadmin) + progress += '\n' + message + + return render.progress(listname, not success, progress) if __name__ == "__main__": diff --git a/util.py b/util.py index e375aa1..d3b7ee2 100644 --- a/util.py +++ b/util.py @@ -4,6 +4,7 @@ import config import web from random import Random +from Mailman import MailList, Errors, UserDesc rng = Random() @@ -32,3 +33,62 @@ def validate_listname(name): return True +def create_list(listname, listadmin, passwd=None): + if passwd == None: + passwd = generate_password() + + try: + # create list + p = subprocess.Popen(['sudo', '-n', os.path.join(config.mailman_path, 'bin', 'neueliste.bash'), + listname, listadmin, passwd], + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + (progress, junk) = p.communicate() + return (p.returncode == 0, progress) + except Exception as e: + progress = e + + return (False, progress) + + +def notify_admins(listname, listadmin, success, progress): + # send mail to admins + web.sendmail('mailman@list.spline.inf.fu-berlin.de', + config.admin_emails, + u'Mailingliste "%s" für %s %serzeugt' % (listname, listadmin, 'NICHT ' if not success else ''), + u'''Die Mailingliste "%s" wurde am %s für %s von %s aus %serzeugt. + + Log: + %s''' % (listname, time.strftime('%Y-%m-%d um %H:%M:%S', time.gmtime()), + listadmin, ctx.ip, 'NICHT ' if not success else '', progress) + ) + + +def add_to_list(listname, listadmin): + try: + mlist = MailList.MailList(listname) + except Errors.MMUnknownListError: + return 'Could not add %s to %s: List not found.' % (listadmin, listname) + + userdesc = UserDesc(address = listadmin, + fullname = '', + digest = 0) + + try: + mlist.ApprovedAddMember(userdesc, 0, 0) + success = True + progress = 'Successfully added %s to %s list.' + + except Errors.MMAlreadyAMember: + success = True + progress = '%s was already member of %s list.' + except Errors.MembershipIsBanned: + success = False + progress = 'Could not add %s to %s: Address ist banned.' + except Errors.MMBadEmailError: + success = False + progress = 'Could not add %s to %s: Bad email address.' + except Errors.MMHostileAddress: + success = False + progress = 'Could not add %s to %s: Illegal characters in email address.' + + return (success, progress % (listadmin, listname)) -- cgit v1.2.3-1-g7c22