summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2011-09-28 22:24:19 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2011-09-28 22:29:25 +0200
commit22a4400664be8c36123a9046b5d2caa7e74637e6 (patch)
tree1b640149c70ceb35ca7a6132558ecbe6ce96a666
parenta537ee33121b7f43966661c37e13682524820983 (diff)
downloadsites-22a4400664be8c36123a9046b5d2caa7e74637e6.tar.gz
sites-22a4400664be8c36123a9046b5d2caa7e74637e6.tar.bz2
sites-22a4400664be8c36123a9046b5d2caa7e74637e6.zip
added list create logic
create list via shell execution send mail to admins to notify creation add listadmin to admin mailinglist
-rwxr-xr-xindex.py14
-rw-r--r--util.py60
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))