2 #***************************************************************************
3 #* Copyright (C) 2003-2010 Polytechnique.org *
4 #* http://opensource.polytechnique.org/ *
6 #* This program is free software; you can redistribute it and/or modify *
7 #* it under the terms of the GNU General Public License as published by *
8 #* the Free Software Foundation; either version 2 of the License, or *
9 #* (at your option) any later version. *
11 #* This program is distributed in the hope that it will be useful, *
12 #* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 #* GNU General Public License for more details. *
16 #* You should have received a copy of the GNU General Public License *
17 #* along with this program; if not, write to the Free Software *
18 #* Foundation, Inc., *
19 #* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 #***************************************************************************
22 import base64
, MySQLdb
, os
, getopt
, sys
, sha
, signal
, re
, shutil
, ConfigParser
23 import MySQLdb
.converters
26 sys
.path
.append('/usr/lib/mailman/bin')
28 from pwd
import getpwnam
29 from grp
import getgrnam
31 from SimpleXMLRPCServer
import SimpleXMLRPCServer
32 from SimpleXMLRPCServer
import SimpleXMLRPCRequestHandler
35 from Mailman
import MailList
36 from Mailman
import Utils
37 from Mailman
import Message
38 from Mailman
import Errors
39 from Mailman
import mm_cfg
40 from Mailman
import i18n
41 from Mailman
.UserDesc
import UserDesc
42 from Mailman
.ListAdmin
import readMessage
43 from email
.Iterators
import typed_subpart_iterator
44 from threading
import Lock
46 class AuthFailed(Exception): pass
48 ################################################################################
52 #------------------------------------------------
54 config
= ConfigParser
.ConfigParser()
55 config
.read(os
.path
.dirname(__file__
)+'/../configs/platal.ini')
56 config
.read(os
.path
.dirname(__file__
)+'/../configs/platal.conf')
58 def get_config(sec
, val
, default
=None):
60 return config
.get(sec
, val
)[1:-1]
61 except ConfigParser
.NoOptionError
, e
:
63 sys
.stderr
.write('%s\n' % str
(e
))
68 MYSQL_USER
= get_config('Core', 'dbuser')
69 MYSQL_PASS
= get_config('Core', 'dbpwd')
70 MYSQL_DB
= get_config('Core', 'dbdb')
72 PLATAL_DOMAIN
= get_config('Mail', 'domain')
73 PLATAL_DOMAIN2
= get_config('Mail', 'domain2', '')
74 sys
.stderr
.write('PLATAL_DOMAIN = %s\n' % PLATAL_DOMAIN
)
75 sys
.stderr
.write("MYSQL_DB = %s\n" % MYSQL_DB
)
77 VHOST_SEP
= get_config('Lists', 'vhost_sep', '_')
78 ON_CREATE_CMD
= get_config('Lists', 'on_create', '')
80 SRV_HOST
= get_config('Lists', 'rpchost', 'localhost')
81 SRV_PORT
= int(get_config('Lists', 'rpcport', '4949'))
83 ################################################################################
87 #------------------------------------------------
88 # Manage Basic authentication
91 class BasicAuthXMLRPCRequestHandler(SimpleXMLRPCRequestHandler
):
93 """XMLRPC Request Handler
94 This request handler is used to provide BASIC HTTP user authentication.
95 It first overloads the do_POST() function, authenticates the user, then
96 calls the super.do_POST().
98 Moreover, we override _dispatch, so that we call functions with as first
99 argument a UserDesc taken from the database, containing name, email and perms
102 def _get_function(self
, method
):
104 # check to see if a matching function has been registered
105 return self
.server
.funcs
[method
]
107 raise Exception('method "%s" is not supported' % method
)
109 def is_rpc_path_valid(self
):
112 def _dispatch(self
, method
, params
):
113 return list_call_dispatcher(self
._get_function(method
), self
.data
[0], self
.data
[1], self
.data
[2], *params
)
117 _
, auth
= self
.headers
["authorization"].split()
118 uid
, md5
= base64
.decodestring(auth
).strip().split(':')
119 vhost
= self
.path
.split('/')[1].lower()
120 self
.data
= self
.getUser(uid
, md5
, vhost
)
121 if self
.data
is None:
123 # Call super.do_POST() to do the actual work
124 SimpleXMLRPCRequestHandler
.do_POST(self
)
126 self
.send_response(401)
129 def getUser(self
, uid
, md5
, vhost
):
130 res
= mysql_fetchone ("""SELECT a.full_name, IF(aa.alias IS NULL, a.email, CONCAT(aa.alias, '@%s')),
131 IF (a.is_admin, 'admin',
132 IF(FIND_IN_SET('lists', at.perms) OR FIND_IN_SET('lists', a.user_perms), 'lists', NULL))
134 INNER JOIN account_types AS at ON (at.type = a.type)
135 LEFT JOIN aliases AS aa ON (a.uid = aa.uid AND aa.type = 'a_vie')
136 WHERE a.uid = '%s' AND a.password = '%s' AND a.state = 'active'
138 %
(PLATAL_DOMAIN
, uid
, md5
))
140 name
, forlife
, perms
= res
141 if vhost
!= PLATAL_DOMAIN
and perms
!= 'admin':
142 res
= mysql_fetchone ("""SELECT m.uid, IF(m.perms = 'admin', 'admin', 'lists')
143 FROM group_members AS m
144 INNER JOIN groups AS g ON (m.asso_id = g.id)
145 WHERE uid = '%s' AND mail_domain = '%s'""" \
149 userdesc
= UserDesc(forlife
, name
, None, 0)
150 return (userdesc
, perms
, vhost
)
152 print >> sys
.stderr
, "no user found for uid: %s, passwd: %s" %
(uid
, md5
)
155 ################################################################################
159 #-------------------------------------------------------------------------------
164 db
= MySQLdb
.connect(
168 unix_socket
='/var/run/mysqld/mysqld.sock')
172 def mysql_fetchone(query
):
177 if int(mysql
.rowcount
) > 0:
178 ret
= mysql
.fetchone()
183 def is_admin_on(userdesc
, perms
, mlist
):
184 return ( perms
== 'admin' ) or ( userdesc
.address
in mlist
.owner
)
187 def quote(s
, is_header
=False):
189 h
= Utils
.oneline(s
, 'iso-8859-1')
192 h
= str('').join(re
.split('[\x00-\x08\x0B-\x1f]+', h
))
193 return Utils
.uquote(h
.replace('&', '&').replace('>', '>').replace('<', '<'))
195 def to_forlife(email
):
197 mbox
, fqdn
= email
.split('@')
201 if ( fqdn
== PLATAL_DOMAIN
) or ( fqdn
== PLATAL_DOMAIN2
):
202 res
= mysql_fetchone("""SELECT CONCAT(f.alias, '@%s'), a.full_name
204 INNER JOIN aliases AS f ON (f.uid = a.uid AND f.type = 'a_vie')
205 INNER JOIN aliases AS aa ON (aa.uid = a.uid AND aa.alias = '%s'
206 AND a.type != 'homonyme')
207 WHERE a.state = 'active'
209 %
(PLATAL_DOMAIN
, mbox
))
214 return (email
.lower(), mbox
)
217 # see /usr/lib/mailman/bin/rmlist
219 def remove_it(listname
, filename
):
220 if os
.path
.islink(filename
) or os
.path
.isfile(filename
):
222 elif os
.path
.isdir(filename
):
223 shutil
.rmtree(filename
)
229 def has_annotation(method
, name
):
230 """ Check if the method contains the given annoation.
232 return method
.__doc__
and method
.__doc__
.find("@%s" % name
) > -1
234 def list_call_dispatcher(method
, userdesc
, perms
, vhost
, *arg
):
235 """Dispatch the call to the right handler.
236 This function checks the options of the called method the set the environment of the call.
237 The dispatcher uses method annotation (special tokens in the documentation of the method) to
238 guess the requested environment:
239 @mlist: the handler requires a mlist object instead of the vhost/listname couple
240 @lock: the handler requires the mlist to be locked (@mlist MUST be specified)
241 @edit: the handler edit the mlist (@mlist MUST be specified)
242 @admin: the handler requires admin rights on the list (@mlist MUST be specified)
243 @root: the handler requires site admin rights
246 print >> sys
.stderr
, "calling method: %s" % method
247 if has_annotation(method
, "root") and perms
!= "admin":
249 if has_annotation(method
, "mlist"):
250 listname
= str(arg
[0])
252 mlist
= MailList
.MailList(vhost
+ VHOST_SEP
+ listname
.lower(), lock
=0)
253 if has_annotation(method
, "admin") and not is_admin_on(userdesc
, perms
, mlist
):
255 if has_annotation(method
, "edit") or has_annotation(method
, "lock"):
256 return list_call_locked(method
, userdesc
, perms
, mlist
, has_annotation(method
, "edit"), *arg
)
258 return method(userdesc
, perms
, mlist
, *arg
)
260 return method(userdesc
, perms
, vhost
, *arg
)
262 sys
.stderr
.write('Exception in dispatcher %s\n' % str
(e
))
266 def list_call_locked(method
, userdesc
, perms
, mlist
, edit
, *arg
):
267 """Call the given method after locking the mlist.
271 ret
= method(userdesc
, perms
, mlist
, *arg
)
277 sys
.stderr
.write('Exception in locked call %s: %s\n' %
(method
.__name__
, str(e
)))
280 # TODO: use finally when switching to python 2.5
282 #-------------------------------------------------------------------------------
286 def is_subscription_pending(userdesc
, perms
, mlist
):
287 for id in mlist
.GetSubscriptionIds():
288 if userdesc
.address
== mlist
.GetRecord(id)[1]:
292 def get_list_info(userdesc
, perms
, mlist
, front_page
=0):
293 members
= mlist
.getRegularMemberKeys()
294 is_member
= userdesc
.address
in members
295 is_owner
= userdesc
.address
in mlist
.owner
296 if (mlist
.advertised
and perms
in ('lists', 'admin')) or is_member
or is_owner
or (not front_page
and perms
== 'admin'):
298 if not is_member
and (mlist
.subscribe_policy
> 1):
299 is_pending
= list_call_locked(is_subscription_pending
, userdesc
, perms
, mlist
, False)
303 host
= mlist
.internal_name().split(VHOST_SEP
)[0].lower()
305 'list' : mlist
.real_name
,
306 'addr' : mlist
.real_name
.lower() + '@' + host
,
308 'desc' : quote(mlist
.description
),
309 'info' : quote(mlist
.info
),
310 'diff' : (mlist
.default_member_moderation
>0) + (mlist
.generic_nonmember_action
>0),
311 'ins' : mlist
.subscribe_policy
> 1,
312 'priv' : 1-mlist
.advertised
,
313 'sub' : 2*is_member
+ is_pending
,
315 'nbsub': len(members
)
317 return (details
, members
)
320 def get_options(userdesc
, perms
, mlist
, opts
):
321 """ Get the options of a list.
326 for (k
, v
) in mlist
.__dict__
.iteritems():
329 options
[k
] = quote(v
)
331 details
= get_list_info(userdesc
, perms
, mlist
)[0]
332 return (details
, options
)
334 def set_options(userdesc
, perms
, mlist
, opts
, vals
):
335 for (k
, v
) in vals
.iteritems():
338 if k
== 'default_member_moderation':
339 for member
in mlist
.getMembers():
340 mlist
.setMemberOption(member
, mm_cfg
.Moderate
, int(v
))
341 t
= type(mlist
.__dict__
[k
])
342 if t
is bool: mlist
.__dict__
[k
] = bool(v
)
343 elif t
is int: mlist
.__dict__
[k
] = int(v
)
344 elif t
is str: mlist
.__dict__
[k
] = Utils
.uncanonstr(v
, 'fr')
345 else: mlist
.__dict__
[k
] = v
348 #-------------------------------------------------------------------------------
349 # users procedures for [ index.php ]
352 def get_lists(userdesc
, perms
, vhost
, email
=None):
353 """ List available lists for the given vhost
358 udesc
= UserDesc(email
.lower(), email
.lower(), None, 0)
359 prefix
= vhost
.lower()+VHOST_SEP
360 names
= Utils
.list_names()
364 if not name
.startswith(prefix
):
367 mlist
= MailList
.MailList(name
, lock
=0)
371 details
= get_list_info(udesc
, perms
, mlist
, (email
is None and vhost
== PLATAL_DOMAIN
))
372 if details
is not None:
373 result
.append(details
[0])
375 sys
.stderr
.write('Can\'t get list %s: %s\n' %
(name
, str(e
)))
379 def subscribe(userdesc
, perms
, mlist
):
380 """ Subscribe to a list.
384 if ( mlist
.subscribe_policy
in (0, 1) ) or userdesc
.address
in mlist
.owner
:
385 mlist
.ApprovedAddMember(userdesc
)
390 mlist
.AddMember(userdesc
)
391 except Errors
.MMNeedApproval
:
395 def unsubscribe(userdesc
, perms
, mlist
):
396 """ Unsubscribe from a list
400 mlist
.ApprovedDeleteMember(userdesc
.address
)
403 #-------------------------------------------------------------------------------
404 # users procedures for [ index.php ]
407 def get_name(member
):
409 return quote(mlist
.getMemberName(member
))
413 def get_members(userdesc
, perms
, mlist
):
414 """ List the members of a list.
417 infos
= get_list_info(userdesc
, perms
, mlist
)
419 # Do not return None, this is not serializable
421 details
, members
= infos
423 members
= map(lambda member
: (get_name(member
), member
), members
)
424 return (details
, members
, mlist
.owner
)
427 #-------------------------------------------------------------------------------
428 # users procedures for [ trombi.php ]
431 def get_members_limit(userdesc
, perms
, mlist
, page
, nb_per_page
):
432 """ Get a range of members of the list.
435 members
= get_members(userdesc
, perms
, mlist
)[1]
436 i
= int(page
) * int(nb_per_page
)
437 return (len(members
), members
[i
:i
+int(nb_per_page
)])
439 def get_owners(userdesc
, perms
, mlist
):
440 """ Get the owners of the list.
443 details
, members
, owners
= get_members(userdesc
, perms
, mlist
)
444 return (details
, owners
)
447 #-------------------------------------------------------------------------------
448 # owners procedures [ admin.php ]
451 def replace_email(userdesc
, perms
, mlist
, from_email
, to_email
):
452 """ Replace the address of a member by another one.
457 mlist
.ApprovedChangeMemberAddress(from_email
.lower(), to_email
.lower(), 0)
460 def mass_subscribe(userdesc
, perms
, mlist
, users
):
461 """ Add a list of users to the list.
466 members
= mlist
.getRegularMemberKeys()
469 email
, name
= to_forlife(user
)
470 if ( email
is None ) or ( email
in members
):
472 userd
= UserDesc(email
, name
, None, 0)
473 mlist
.ApprovedAddMember(userd
)
474 added
.append( (quote(userd
.fullname
), userd
.address
) )
477 def mass_unsubscribe(userdesc
, perms
, mlist
, users
):
478 """ Remove a list of users from the list.
483 map(lambda user
: mlist
.ApprovedDeleteMember(user
), users
)
486 def add_owner(userdesc
, perms
, mlist
, user
):
487 """ Add a owner to the list.
492 email
= to_forlife(user
)[0]
495 if email
not in mlist
.owner
:
496 mlist
.owner
.append(email
)
499 def del_owner(userdesc
, perms
, mlist
, user
):
500 """ Remove a owner of the list.
505 if len(mlist
.owner
) < 2:
507 mlist
.owner
.remove(user
)
510 #-------------------------------------------------------------------------------
511 # owners procedures [ admin.php ]
514 def get_pending_ops(userdesc
, perms
, mlist
):
515 """ Get the list of operation waiting for an action from the owners.
523 for id in mlist
.GetSubscriptionIds():
524 time
, addr
, fullname
, passwd
, digest
, lang
= mlist
.GetRecord(id)
526 mlist
.HandleRequest(id, mm_cfg
.DISCARD
)
531 login
= re
.match("^[^.]*\.[^.]*\.\d\d\d\d$", addr
.split('@')[0]).group()
532 subs
.append({'id': id, 'name': quote(fullname
), 'addr': addr
, 'login': login
})
534 subs
.append({'id': id, 'name': quote(fullname
), 'addr': addr
})
537 for id in mlist
.GetHeldMessageIds():
538 ptime
, sender
, subject
, reason
, filename
, msgdata
= mlist
.GetRecord(id)
539 fpath
= os
.path
.join(mm_cfg
.DATA_DIR
, filename
)
541 size
= os
.path
.getsize(fpath
)
543 if e
.errno
<> errno
.ENOENT
: raise
546 msg
= readMessage(fpath
)
547 fromX
= msg
.has_key("X-Org-Mail")
552 'sender': quote(sender
, True),
554 'subj' : quote(subject
, True),
562 def handle_request(userdesc
, perms
, mlist
, id, value
, comment
):
563 """ Handle a moderation request.
568 mlist
.HandleRequest(int(id), int(value
), comment
)
571 def get_pending_sub(userdesc
, perms
, mlist
, id):
572 """ Get informations about a given subscription moderation.
579 if id in mlist
.GetSubscriptionIds():
580 time
, addr
, fullname
, passwd
, digest
, lang
= mlist
.GetRecord(id)
582 login
= re
.match("^[^.]*\.[^.]*\.\d\d\d\d$", addr
.split('@')[0]).group()
583 sub
= {'id': id, 'name': quote(fullname
), 'addr': addr
, 'login': login
}
585 sub
= {'id': id, 'name': quote(fullname
), 'addr': addr
}
588 def get_pending_mail(userdesc
, perms
, mlist
, id, raw
=0):
589 """ Get informations about a given mail moderation.
594 ptime
, sender
, subject
, reason
, filename
, msgdata
= mlist
.GetRecord(int(id))
595 fpath
= os
.path
.join(mm_cfg
.DATA_DIR
, filename
)
596 size
= os
.path
.getsize(fpath
)
597 msg
= readMessage(fpath
)
600 return quote(str(msg
))
603 for part
in typed_subpart_iterator(msg
, 'text', 'plain'):
604 c
= part
.get_payload()
605 if c
is not None: results_plain
.append (c
)
606 results_plain
= map(lambda x
: quote(x
), results_plain
)
607 for part
in typed_subpart_iterator(msg
, 'text', 'html'):
608 c
= part
.get_payload()
609 if c
is not None: results_html
.append (c
)
610 results_html
= map(lambda x
: quote(x
), results_html
)
612 'sender': quote(sender
, True),
614 'subj' : quote(subject
, True),
616 'parts_plain' : results_plain
,
617 'parts_html': results_html
}
619 #-------------------------------------------------------------------------------
620 # owner options [ options.php ]
623 owner_opts
= ['accept_these_nonmembers', 'admin_notify_mchanges', 'description', \
624 'default_member_moderation', 'generic_nonmember_action', 'info', \
625 'subject_prefix', 'goodbye_msg', 'send_goodbye_msg', 'subscribe_policy', \
628 def get_owner_options(userdesc
, perms
, mlist
):
629 """ Get the owner options of a list.
633 return get_options(userdesc
, perms
, mlist
, owner_opts
)
635 def set_owner_options(userdesc
, perms
, mlist
, values
):
636 """ Set the owner options of a list.
641 return set_options(userdesc
, perms
, mlist
, owner_opts
, values
)
643 def add_to_wl(userdesc
, perms
, mlist
, addr
):
644 """ Add addr to the whitelist
649 mlist
.accept_these_nonmembers
.append(addr
)
652 def del_from_wl(userdesc
, perms
, mlist
, addr
):
653 """ Remove an address from the whitelist
658 mlist
.accept_these_nonmembers
.remove(addr
)
661 def get_bogo_level(userdesc
, perms
, mlist
):
662 """ Compute bogo level from the filtering rules set up on the list.
666 if len(mlist
.header_filter_rules
) == 0:
673 # The first rule filters Unsure mails
674 if mlist
.header_filter_rules
[0][0] == 'X-Spam-Flag: Unsure, tests=bogofilter':
678 # Check the other rules:
679 # - we have 2 rules: this is level 2 (drop > 0.999999, moderate Yes)
680 # - we have only one rule with HOLD directive : this is level 1 (moderate spams)
681 # - we have only one rule with DISCARD directive : this is level 3 (drop spams)
683 action
= mlist
.header_filter_rules
[filterbase
+ 1][1]
686 action
= mlist
.header_filter_rules
[filterbase
][1]
687 if action
== mm_cfg
.HOLD
:
689 elif action
== mm_cfg
.DISCARD
:
691 return (filterlevel
<< 1) + unsurelevel
693 def set_bogo_level(userdesc
, perms
, mlist
, level
):
694 """ Set filter to the specified level.
701 # The level is a combination of a spam filtering level and unsure filtering level
702 # - the unsure filtering level is only 1 bit (1 = HOLD unsures, 0 = Accept unsures)
703 # - the spam filtering level is a number growing with filtering strength
704 # (0 = no filtering, 1 = moderate spam, 2 = drop 0.999999 and moderate others, 3 = drop spams)
705 bogolevel
= int(level
)
706 filterlevel
= bogolevel
>> 1
707 unsurelevel
= bogolevel
& 1
709 # Set up unusre filtering
711 hfr
.append(('X-Spam-Flag: Unsure, tests=bogofilter', mm_cfg
.HOLD
, False))
713 # Set up spam filtering
715 hfr
.append(('X-Spam-Flag: Yes, tests=bogofilter', mm_cfg
.HOLD
, False))
716 elif filterlevel
is 2:
717 hfr
.append(('X-Spam-Flag: Yes, tests=bogofilter, spamicity=(0\.999999|1\.000000)', mm_cfg
.DISCARD
, False))
718 hfr
.append(('X-Spam-Flag: Yes, tests=bogofilter', mm_cfg
.HOLD
, False))
719 elif filterlevel
is 3:
720 hfr
.append(('X-Spam-Flag: Yes, tests=bogofilter', mm_cfg
.DISCARD
, False))
723 if mlist
.header_filter_rules
!= hfr
:
724 mlist
.header_filter_rules
= hfr
727 #-------------------------------------------------------------------------------
728 # admin procedures [ soptions.php ]
731 admin_opts
= [ 'advertised', 'archive', \
732 'max_message_size', 'msg_footer', 'msg_header']
734 def get_admin_options(userdesc
, perms
, mlist
):
735 """ Get administrator options.
739 return get_options(userdesc
, perms
, mlist
, admin_opts
)
741 def set_admin_options(userdesc
, perms
, mlist
, values
):
742 """ Set administrator options.
747 return set_options(userdesc
, perms
, mlist
, admin_opts
, values
)
749 #-------------------------------------------------------------------------------
750 # admin procedures [ check.php ]
754 'acceptable_aliases' : '',
755 'admin_immed_notify' : True,
756 'administrivia' : True,
757 'anonymous_list' : False,
758 'autorespond_admin' : False,
759 'autorespond_postings' : False,
760 'autorespond_requests' : False,
761 'available_languages' : ['fr'],
763 'bounce_matching_headers' : '',
764 'bounce_processing' : False,
765 'convert_html_to_plaintext' : False,
766 'digestable' : False,
767 'digest_is_default' : False,
768 'discard_these_nonmembers' : [],
770 'encode_ascii_prefixes' : 2,
771 'filter_content' : False,
772 'first_strip_reply_to' : False,
773 'forward_auto_discards' : True,
774 'hold_these_nonmembers' : [],
775 'host_name' : 'listes.polytechnique.org',
776 'include_list_post_header' : False,
777 'include_rfc2369_headers' : False,
778 'max_num_recipients' : 0,
779 'new_member_options' : 256,
780 'nondigestable' : True,
781 'obscure_addresses' : True,
782 'preferred_language' : 'fr',
783 'reject_these_nonmembers' : [],
784 'reply_goes_to_list' : 0,
785 'reply_to_address' : '',
786 'require_explicit_destination' : False,
787 'send_reminders' : 0,
788 'send_welcome_msg' : True,
789 'topics_enabled' : False,
790 'umbrella_list' : False,
791 'unsubscribe_policy' : 0,
794 def check_options_runner(userdesc
, perms
, mlist
, listname
, correct
):
796 for (k
, v
) in check_opts
.iteritems():
797 if mlist
.__dict__
[k
] != v
:
798 options
[k
] = v
, mlist
.__dict__
[k
]
799 if correct
: mlist
.__dict__
[k
] = v
800 if mlist
.real_name
.lower() != listname
:
801 options
['real_name'] = listname
, mlist
.real_name
802 if correct
: mlist
.real_name
= listname
806 def check_options(userdesc
, perms
, vhost
, listname
, correct
=False):
810 listname
= listname
.lower()
811 mlist
= MailList
.MailList(vhost
+ VHOST_SEP
+ listname
, lock
=0)
813 return list_call_locked(check_options_runner
, userdesc
, perms
, mlist
, True, listname
, True)
815 return check_options_runner(userdesc
, perms
, mlist
, listname
, False)
817 #-------------------------------------------------------------------------------
818 # super-admin procedures
821 def get_all_lists(userdesc
, perms
, vhost
):
822 """ Get all the list for the given vhost
825 prefix
= vhost
.lower()+VHOST_SEP
826 names
= Utils
.list_names()
830 if not name
.startswith(prefix
):
832 result
.append(name
.replace(prefix
, ''))
835 def get_all_user_lists(userdesc
, perms
, vhost
, email
):
836 """ Get all the lists for the given user
839 names
= Utils
.list_names()
844 mlist
= MailList
.MailList(name
, lock
=0)
845 ismember
= email
in mlist
.getRegularMemberKeys()
846 isowner
= email
in mlist
.owner
847 if not ismember
and not isowner
:
849 host
= mlist
.internal_name().split(VHOST_SEP
)[0].lower()
850 result
.append({ 'list': mlist
.real_name
,
851 'addr': mlist
.real_name
.lower() + '@' + host
,
860 def change_user_email(userdesc
, perms
, vhost
, from_email
, to_email
):
861 """ Change the email of a user
864 from_email
= from_email
.lower()
865 to_email
= to_email
.lower()
866 for list in Utils
.list_names():
868 mlist
= MailList
.MailList(list, lock
=0)
873 mlist
.ApprovedChangeMemberAddress(from_email
, to_email
, 0)
881 def create_list(userdesc
, perms
, vhost
, listname
, desc
, advertise
, modlevel
, inslevel
, owners
, members
):
882 """ Create a new list.
885 name
= vhost
.lower() + VHOST_SEP
+ listname
.lower();
886 if Utils
.list_exists(name
):
891 email
= to_forlife(o
)[0]
892 if email
is not None:
897 mlist
= MailList
.MailList()
899 oldmask
= os
.umask(002)
900 pw
= sha
.new('foobar').hexdigest()
903 mlist
.Create(name
, owner
[0], pw
)
907 mlist
.real_name
= listname
908 mlist
.host_name
= 'listes.polytechnique.org'
909 mlist
.description
= desc
911 mlist
.advertised
= int(advertise
) is 0
912 mlist
.default_member_moderation
= int(modlevel
) is 2
913 mlist
.generic_nonmember_action
= int(modlevel
) > 0
914 mlist
.subscribe_policy
= 2 * (int(inslevel
) is 1)
915 mlist
.admin_notify_mchanges
= (mlist
.subscribe_policy
or mlist
.generic_nonmember_action
or mlist
.default_member_moderation
or not mlist
.advertised
)
919 mlist
.subject_prefix
= '['+listname
+'] '
920 mlist
.max_message_size
= 0
922 inverted_listname
= listname
.lower() + '_' + vhost
.lower()
923 mlist
.msg_footer
= "_______________________________________________\n" \
924 + "Liste de diffusion %(real_name)s\n" \
925 + "http://listes.polytechnique.org/members/" + inverted_listname
927 mlist
.header_filter_rules
= []
928 mlist
.header_filter_rules
.append(('X-Spam-Flag: Unsure, tests=bogofilter', mm_cfg
.HOLD
, False))
929 mlist
.header_filter_rules
.append(('X-Spam-Flag: Yes, tests=bogofilter', mm_cfg
.HOLD
, False))
931 if ON_CREATE_CMD
!= '':
932 try: os
.system(ON_CREATE_CMD
+ ' ' + name
)
935 check_options_runner(userdesc
, perms
, mlist
, listname
.lower(), True)
936 mass_subscribe(userdesc
, perms
, mlist
, members
)
941 # avoid the "-1 mail to moderate" bug
942 mlist
= MailList
.MailList(name
)
944 mlist
._UpdateRecords()
950 def delete_list(userdesc
, perms
, mlist
, del_archives
=0):
955 lname
= mlist
.internal_name()
957 REMOVABLES
= [ os
.path
.join('lists', lname
), ]
958 # remove stalled locks
959 for filename
in os
.listdir(mm_cfg
.LOCK_DIR
):
960 fn_lname
= filename
.split('.')[0]
961 if fn_lname
== lname
:
962 REMOVABLES
.append(os
.path
.join(mm_cfg
.LOCK_DIR
, filename
))
966 os
.path
.join('archives', 'private', lname
),
967 os
.path
.join('archives', 'private', lname
+'.mbox'),
968 os
.path
.join('archives', 'public', lname
),
969 os
.path
.join('archives', 'public', lname
+'.mbox')
971 map(lambda dir: remove_it(lname
, os
.path
.join(mm_cfg
.VAR_PREFIX
, dir)), REMOVABLES
)
974 def kill(userdesc
, perms
, vhost
, alias
, del_from_promo
):
975 """ Remove a user from all the lists.
978 if not del_from_promo
:
979 exclude
.append(PLATAL_DOMAIN
+ VHOST_SEP
+ 'promo' + alias
[-4:])
980 for list in Utils
.list_names():
984 mlist
= MailList
.MailList(list, lock
=0)
989 mlist
.ApprovedDeleteMember(alias
+'@'+PLATAL_DOMAIN
, None, 0, 0)
997 #-------------------------------------------------------------------------------
1000 class FastXMLRPCServer(SocketServer
.ThreadingMixIn
, SimpleXMLRPCServer
):
1001 allow_reuse_address
= True
1003 ################################################################################
1007 #-------------------------------------------------------------------------------
1008 # use Mailman user and group (not root)
1009 # fork in background if asked to
1012 uid
= getpwnam(mm_cfg
.MAILMAN_USER
)[2]
1013 gid
= getgrnam(mm_cfg
.MAILMAN_GROUP
)[2]
1016 os
.setregid(gid
, gid
)
1017 os
.setreuid(uid
, uid
)
1019 signal
.signal(signal
.SIGHUP
, signal
.SIG_IGN
)
1021 if ( os
.getuid() is not uid
) or ( os
.getgid() is not gid
):
1024 opts
, args
= getopt
.getopt(sys
.argv
[1:], 'f')
1026 if o
== '-f' and os
.fork():
1029 i18n
.set_language('fr')
1033 #-------------------------------------------------------------------------------
1036 server
= FastXMLRPCServer((SRV_HOST
, SRV_PORT
), BasicAuthXMLRPCRequestHandler
)
1039 server
.register_function(get_lists
)
1040 server
.register_function(subscribe
)
1041 server
.register_function(unsubscribe
)
1043 server
.register_function(get_members
)
1045 server
.register_function(get_members_limit
)
1046 server
.register_function(get_owners
)
1048 server
.register_function(replace_email
)
1049 server
.register_function(mass_subscribe
)
1050 server
.register_function(mass_unsubscribe
)
1051 server
.register_function(add_owner
)
1052 server
.register_function(del_owner
)
1054 server
.register_function(get_pending_ops
)
1055 server
.register_function(handle_request
)
1056 server
.register_function(get_pending_sub
)
1057 server
.register_function(get_pending_mail
)
1059 server
.register_function(get_owner_options
)
1060 server
.register_function(set_owner_options
)
1061 server
.register_function(add_to_wl
)
1062 server
.register_function(del_from_wl
)
1063 server
.register_function(get_bogo_level
)
1064 server
.register_function(set_bogo_level
)
1066 server
.register_function(get_admin_options
)
1067 server
.register_function(set_admin_options
)
1069 server
.register_function(check_options
)
1071 server
.register_function(get_all_lists
)
1072 server
.register_function(get_all_user_lists
)
1073 server
.register_function(change_user_email
)
1074 server
.register_function(create_list
)
1075 server
.register_function(delete_list
)
1077 server
.register_function(kill
)
1079 server
.serve_forever()
1081 # vim:set et sw=4 sts=4 sws=4: