X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=bin%2Flists.rpc.py;h=9ed42d81df165ea6368ee10ca40c4fe13ff31475;hb=aab2ffddfc8597dfce114b18c737b791e949b6ea;hp=694cee9b93f864832e81bcea52fad2d61041862d;hpb=af744c2d5f4ddf83b738b9cb390926eaca4cf7c3;p=platal.git diff --git a/bin/lists.rpc.py b/bin/lists.rpc.py index 694cee9..9ed42d8 100755 --- a/bin/lists.rpc.py +++ b/bin/lists.rpc.py @@ -1,6 +1,6 @@ #!/usr/bin/env python #*************************************************************************** -#* Copyright (C) 2004-2009 polytechnique.org * +#* Copyright (C) 2003-2010 Polytechnique.org * #* http://opensource.polytechnique.org/ * #* * #* This program is free software; you can redistribute it and/or modify * @@ -67,6 +67,7 @@ def get_config(sec, val, default=None): MYSQL_USER = get_config('Core', 'dbuser') MYSQL_PASS = get_config('Core', 'dbpwd') +MYSQL_DB = get_config('Core', 'dbdb') PLATAL_DOMAIN = get_config('Mail', 'domain') PLATAL_DOMAIN2 = get_config('Mail', 'domain2', '') @@ -104,9 +105,10 @@ class BasicAuthXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): except: raise Exception('method "%s" is not supported' % method) + def is_rpc_path_valid(self): + return True def _dispatch(self, method, params): - new_params = list(params) return list_call_dispatcher(self._get_function(method), self.data[0], self.data[1], self.data[2], *params) def do_POST(self): @@ -124,19 +126,22 @@ class BasicAuthXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): self.end_headers() def getUser(self, uid, md5, vhost): - res = mysql_fetchone ("""SELECT CONCAT(u.prenom, ' ', u.nom), a.alias, u.perms - FROM auth_user_md5 AS u - INNER JOIN aliases AS a ON ( a.id=u.user_id AND a.type='a_vie' ) - WHERE u.user_id = '%s' AND u.password = '%s' AND u.perms IN ('admin', 'user') - LIMIT 1""" %( uid, md5 ) ) + res = mysql_fetchone ("""SELECT a.full_name, aa.alias, IF (a.is_admin, 'admin', NULL) + FROM accounts AS a + INNER JOIN aliases AS aa ON (a.uid = aa.uid AND aa.type = 'a_vie') + WHERE a.uid = '%s' AND a.password = '%s' AND a.state = 'active' + LIMIT 1""" \ + % (uid, md5)) if res: name, forlife, perms = res if vhost != PLATAL_DOMAIN: - res = mysql_fetchone ("""SELECT uid - FROM groupex.membres AS m - INNER JOIN groupex.asso AS a ON (m.asso_id = a.id) - WHERE perms='admin' AND uid='%s' AND mail_domain='%s'""" %( uid , vhost ) ) - if res: perms= 'admin' + res = mysql_fetchone ("""SELECT m.uid + FROM group_members AS m + INNER JOIN groups AS g ON (m.asso_id = g.id) + WHERE perms = 'admin' AND uid = '%s' AND mail_domain = '%s'""" \ + % (uid, vhost)) + if res: + perms= 'admin' userdesc = UserDesc(forlife+'@'+PLATAL_DOMAIN, name, None, 0) return (userdesc, perms, vhost) else: @@ -152,7 +157,7 @@ class BasicAuthXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): def connectDB(): db = MySQLdb.connect( - db='x4dat', + db=MYSQL_DB, user=MYSQL_USER, passwd=MYSQL_PASS, unix_socket='/var/run/mysqld/mysqld.sock') @@ -189,12 +194,14 @@ def to_forlife(email): mbox = email fqdn = PLATAL_DOMAIN if ( fqdn == PLATAL_DOMAIN ) or ( fqdn == PLATAL_DOMAIN2 ): - res = mysql_fetchone("""SELECT CONCAT(f.alias, '@%s'), CONCAT(u.prenom, ' ', u.nom) - FROM auth_user_md5 AS u - INNER JOIN aliases AS f ON (f.id=u.user_id AND f.type='a_vie') - INNER JOIN aliases AS a ON (a.id=u.user_id AND a.alias='%s' AND a.type!='homonyme') - WHERE u.perms IN ('admin', 'user') - LIMIT 1""" %( PLATAL_DOMAIN, mbox ) ) + res = mysql_fetchone("""SELECT CONCAT(f.alias, '@%s'), a.full_name + FROM accounts AS a + INNER JOIN aliases AS f ON (f.uid = a.uid AND f.type = 'a_vie') + INNER JOIN aliases AS aa ON (aa.uid = a.uid AND aa.alias = '%s' + AND a.type != 'homonyme') + WHERE a.state = 'active' + LIMIT 1""" \ + % (PLATAL_DOMAIN, mbox)) if res: return res else: @@ -875,8 +882,11 @@ def create_list(userdesc, perms, vhost, listname, desc, advertise, modlevel, ins # avoid the "-1 mail to moderate" bug mlist = MailList.MailList(name) - mlist._UpdateRecords() - mlist.Save() + try: + mlist._UpdateRecords() + mlist.Save() + finally: + mlist.Unlock() return 1 def delete_list(userdesc, perms, mlist, del_archives=0):