2 /***************************************************************************
3 * Copyright (C) 2003-2007 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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class ListsModule
extends PLModule
29 'lists' => $this->make_hook('lists', AUTH_MDP
),
30 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP
, '', NO_AUTH
),
31 'lists/create' => $this->make_hook('create', AUTH_MDP
),
33 'lists/members' => $this->make_hook('members', AUTH_COOKIE
),
34 'lists/trombi' => $this->make_hook('trombi', AUTH_COOKIE
),
35 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE
),
37 'lists/moderate' => $this->make_hook('moderate', AUTH_MDP
),
38 'lists/admin' => $this->make_hook('admin', AUTH_MDP
),
39 'lists/options' => $this->make_hook('options', AUTH_MDP
),
40 'lists/delete' => $this->make_hook('delete', AUTH_MDP
),
42 'lists/soptions' => $this->make_hook('soptions', AUTH_MDP
),
43 'lists/check' => $this->make_hook('check', AUTH_MDP
),
44 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP
, 'admin'),
48 function on_subscribe($forlife, $uid, $promo, $password)
50 $this->prepare_client(null
);
51 $this->client
->subscribe("promo$promo");
54 function prepare_client(&$page)
58 require_once dirname(__FILE__
).'/lists/lists.inc.php';
60 $this->client
= new MMList(S
::v('uid'), S
::v('password'));
61 return $globals->mail
->domain
;
64 function handler_lists(&$page)
66 function filter_owner($list)
71 function filter_member($list)
76 $this->prepare_client($page);
78 $page->changeTpl('lists/index.tpl');
79 $page->addJsLink('ajax.js');
80 $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
83 if (Get
::has('del')) {
84 $this->client
->unsubscribe(Get
::v('del'));
87 if (Get
::has('add')) {
88 $this->client
->subscribe(Get
::v('add'));
91 if (Post
::has('promo_add')) {
92 $promo = Post
::i('promo_add');
93 if ($promo >= 1900 and $promo < 2100) {
94 $this->client
->subscribe("promo$promo");
96 $page->trig("promo incorrecte, il faut une promo sur 4 chiffres.");
99 $listes = $this->client
->get_lists();
100 $owner = array_filter($listes, 'filter_owner');
101 $listes = array_diff_key($listes, $owner);
102 $member = array_filter($listes, 'filter_member');
103 $listes = array_diff_key($listes, $member);
104 foreach ($owner as $key=>$liste) {
105 list($subs,$mails) = $this->client
->get_pending_ops($liste['list']);
106 $owner[$key]['subscriptions'] = $subs;
107 $owner[$key]['mails'] = $mails;
109 $page->register_modifier('hdc', 'list_header_decode');
110 $page->assign_by_ref('owner', $owner);
111 $page->assign_by_ref('member', $member);
112 $page->assign_by_ref('public', $listes);
115 function handler_ajax(&$page, $list = null
)
117 header('Content-Type: text/html; charset="iso-8859-15"');
118 $domain = $this->prepare_client($page);
119 $page->changeTpl('lists/liste.inc.tpl', NO_SKIN
);
120 if (Get
::has('unsubscribe')) {
121 $this->client
->unsubscribe($list);
123 if (Get
::has('subscribe')) {
124 $this->client
->subscribe($list);
126 if (Get
::has('sadd')) { /* 4 = SUBSCRIBE */
127 $this->client
->handle_request($list, Get
::v('sadd'), 4, '');
129 if (Get
::has('mid')) {
130 $this->moderate_mail($domain, $list, Get
::i('mid'));
133 list($liste, $members, $owners) = $this->client
->get_members($list);
135 list($subs,$mails) = $this->client
->get_pending_ops($list);
136 $liste['subscriptions'] = $subs;
137 $liste['mails'] = $mails;
139 $page->register_modifier('hdc', 'list_header_decode');
140 $page->assign_by_ref('liste', $liste);
143 function handler_create(&$page)
145 $page->changeTpl('lists/create.tpl');
147 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
148 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
150 // click on validate button 'add_owner_sub' or type <enter>
151 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
152 require_once('user.func.inc.php');
153 // if we want to add an owner and then type <enter>, then both
154 // add_owner_sub and add_owner are filled.
155 $oforlifes = get_users_forlife_list(Post
::v('add_owner'), true
);
156 $mforlifes = get_users_forlife_list(Post
::v('add_member'), true
);
157 if (!is_null($oforlifes)) {
158 $owners = array_merge($owners, $oforlifes);
160 // if we want to add a member and then type <enter>, then
161 // add_owner_sub is filled, whereas add_owner is empty.
162 if (!is_null($mforlifes)) {
163 $members = array_merge($members, $mforlifes);
167 // click on validate button 'add_member_sub'
168 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
169 require_once('user.func.inc.php');
170 $forlifes = get_users_forlife_list(Post
::v('add_member'), true
);
171 if (!is_null($forlifes)) {
172 $members = array_merge($members, $forlifes);
177 $owners = array_unique($owners);
179 $members = array_unique($members);
181 $page->assign('owners', join(' ', $owners));
182 $page->assign('members', join(' ', $members));
184 if (!Post
::has('submit')) {
188 $liste = Post
::v('liste');
191 $page->trig('champs «addresse souhaitée» vide');
193 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
194 $page->trig('le nom de la liste ne doit contenir que des lettres, chiffres et tirets');
197 $res = XDB
::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
198 $n = $res->fetchOneCell();
201 $page->trig('cet alias est déjà pris');
204 if (!Post
::v(desc
)) {
205 $page->trig('le sujet est vide');
208 if (!count($owners)) {
209 $page->trig('pas de gestionnaire');
212 if (count($members)<4) {
213 $page->trig('pas assez de membres');
216 if (!$page->nb_errs()) {
217 $page->assign('created', true
);
218 require_once 'validations.inc.php';
219 $req = new ListeReq(S
::v('uid'), $liste,
220 Post
::v('desc'), Post
::i('advertise'),
221 Post
::i('modlevel'), Post
::i('inslevel'),
227 function handler_members(&$page, $liste = null
)
229 if (is_null($liste)) {
233 $this->prepare_client($page);
235 $page->changeTpl('lists/members.tpl');
237 if (Get
::has('del')) {
238 $this->client
->unsubscribe($liste);
239 pl_redirect('lists/members/'.$liste);
242 if (Get
::has('add')) {
243 $this->client
->subscribe($liste);
244 pl_redirect('lists/members/'.$liste);
247 $members = $this->client
->get_members($liste);
249 $tri_promo = !Env
::b('alpha');
251 if (list($det,$mem,$own) = $members) {
252 $membres = list_sort_members($mem, $tri_promo);
253 $moderos = list_sort_owners($own, $tri_promo);
255 $page->assign_by_ref('details', $det);
256 $page->assign_by_ref('members', $membres);
257 $page->assign_by_ref('owners', $moderos);
258 $page->assign('nb_m', count($mem));
260 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
264 function _get_list($offset, $limit)
267 list($total, $members) = $this->client
->get_members_limit($platal->argv
[1], $offset, $limit);
270 foreach ($members as $member) {
271 list($m) = explode('@',$member[1]);
272 $res = XDB
::query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom,
273 promo, a.alias AS forlife
274 FROM auth_user_md5 AS u
275 INNER JOIN aliases AS a ON u.user_id = a.id
276 WHERE a.alias = {?}", $m);
277 if ($tmp = $res->fetchOneAssoc()) {
278 $membres[$tmp['nom']] = $tmp;
280 $membres[$member[0]] = array('addr' => $member[0]);
283 return array($total, $membres);
286 function handler_trombi(&$page, $liste = null
)
288 if (is_null($liste)) {
292 $this->prepare_client($page);
294 $page->changeTpl('lists/trombi.tpl');
296 if (Get
::has('del')) {
297 $this->client
->unsubscribe($liste);
298 pl_redirect('lists/tromi/'.$liste);
300 if (Get
::has('add')) {
301 $this->client
->subscribe($liste);
302 pl_redirect('lists/tromi/'.$liste);
305 $owners = $this->client
->get_owners($liste);
307 if (is_array($owners)) {
308 $moderos = list_sort_owners($owners[1]);
310 $page->assign_by_ref('details', $owners[0]);
311 $page->assign_by_ref('owners', $moderos);
313 $trombi = new Trombi(array(&$this, '_get_list'));
314 $page->assign('trombi', $trombi);
316 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
320 function handler_archives(&$page, $liste = null
, $action = null
, $artid = null
)
324 if (is_null($liste)) {
328 $domain = $this->prepare_client($page);
330 $page->changeTpl('lists/archives.tpl');
332 if (list($det) = $this->client
->get_members($liste)) {
333 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
334 && !$det['own'] && ($det['sub'] < 2)) {
335 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
337 $get = Array('listname' => $liste, 'domain' => $domain);
338 if (Post
::has('updateall')) {
339 $get['updateall'] = Post
::v('updateall');
341 if (!is_null($action)) {
342 if ($action == 'new') {
343 $get['action'] = 'new';
344 } elseif (!is_null($artid)) {
345 $get['artid'] = $artid;
346 if ($action == 'reply') {
347 $get['action'] = 'new';
348 } elseif ($action == 'cancel') {
349 $get['action'] = $action;
350 } elseif ($action == 'from') {
351 $get['first'] = $artid;
352 } elseif ($action == 'read') {
353 $get['part'] = @$_GET['part'];
354 } elseif ($action == 'source') {
355 $get['part'] = 'source';
356 } elseif ($action == 'xface') {
357 $get['part'] = 'xface';
361 require_once('banana/ml.inc.php');
362 $banana = new MLBanana($get);
363 $page->assign('banana', $banana->run());
364 $page->addCssInline($banana->css());
365 $page->addCssLink('banana.css');
367 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
371 function moderate_mail($domain, $liste, $mid)
373 $mail = $this->client
->get_pending_mail($liste, $mid);
376 $prenom = S
::v('prenom');
379 if (Env
::has('mok')) {
380 $action = 1; /** 2 = ACCEPT **/
381 $subject = "Message accepté";
382 $append .= "a été accepté par $prenom $nom.\n";
383 } elseif (Env
::has('mno')) {
384 $action = 2; /** 2 = REJECT **/
385 $subject = "Message refusé";
386 $reason = Post
::v('reason');
387 $append = "a été refusé par $prenom $nom avec la raison :\n\n"
389 } elseif (Env
::has('mdel')) {
390 $action = 3; /** 3 = DISCARD **/
391 $subject = "Message supprimé";
392 $append = "a été supprimé par $prenom $nom.\n\n"
393 . "Rappel: il ne faut utiliser cette opération "
394 . "que dans le cas de spams ou de virus !\n";
397 if (isset($action) && $this->client
->handle_request($liste, $mid, $action, $reason)) {
398 $texte = "le message suivant :\n\n"
399 ." Auteur: {$mail['sender']}\n"
400 ." Sujet : « {$mail['subj']} »\n"
401 ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
403 $mailer = new PlMailer();
404 $mailer->addTo("$liste-owner@{$domain}");
405 $mailer->setFrom("$liste-bounces@{$domain}");
406 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
407 $mailer->setSubject($subject);
408 $mailer->setTxtBody(wordwrap($texte,72));
416 function handler_moderate(&$page, $liste = null
)
418 if (is_null($liste)) {
422 $domain = $this->prepare_client($page);
424 $page->changeTpl('lists/moderate.tpl');
426 $page->register_modifier('hdc', 'list_header_decode');
428 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
429 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
430 pl_redirect('lists/moderate/'.$liste);
432 if (Post
::has('sdel')) { /* 2 = REJECT */
433 $this->client
->handle_request($liste,Post
::v('sdel'),2,Post
::v('reason'));
436 if (Post
::has('moderate_mails') && Post
::has('select_mails')) {
437 $mails = array_keys(Post
::v('select_mails'));
438 foreach($mails as $mail) {
439 $this->moderate_mail($domain, $liste, $mail);
441 } elseif (Env
::has('mid')) {
442 if (Get
::has('mid')) {
443 require_once('banana/moderate.inc.php');
444 $params = array('listname' => $liste, 'domain' => $domain, 'artid' => Get
::i('mid'), 'part' => Get
::v('part'));
445 $banana = new ModerationBanana($params, $this->client
);
446 $res = $banana->run();
447 $page->addCssInline($banana->css());
449 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
450 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
451 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
452 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
453 $msg = str_replace("%(listname)s", $liste, $msg);
454 $page->assign('msg', $msg);
456 $page->addCssLink('banana.css');
457 $page->changeTpl('lists/moderate_mail.tpl');
458 $page->assign_by_ref('mail', $res);
462 $mail = $this->moderate_mail($domain, $liste, Env
::i('mid'));
463 } elseif (Env
::has('sid')) {
464 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
465 foreach($subs as $user) {
466 if ($user['id'] == Env
::v('sid')) {
467 $page->changeTpl('lists/moderate_sub.tpl');
468 $page->assign('del_user', $user);
476 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
477 foreach ($mails as $key=>$mail) {
478 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
480 $page->assign_by_ref('subs', $subs);
481 $page->assign_by_ref('mails', $mails);
483 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
487 function handler_admin(&$page, $liste = null
)
491 if (is_null($liste)) {
495 $this->prepare_client($page);
497 $page->changeTpl('lists/admin.tpl');
499 if (Env
::has('add_member')) {
500 require_once('user.func.inc.php');
501 $members = get_users_forlife_list(Env
::v('add_member'));
502 $arr = $this->client
->mass_subscribe($liste, $members);
503 if (is_array($arr)) {
504 foreach($arr as $addr) {
505 $page->trig("{$addr[0]} inscrit.");
510 if (Env
::has('del_member')) {
511 if (strpos(Env
::v('del_member'), '@') === false
) {
512 $this->client
->mass_unsubscribe(
513 $liste, array(Env
::v('del_member').'@'.$globals->mail
->domain
));
515 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
517 pl_redirect('lists/admin/'.$liste);
520 if (Env
::has('add_owner')) {
521 require_once('user.func.inc.php');
522 $owners = get_users_forlife_list(Env
::v('add_owner'));
524 foreach ($owners as $login) {
525 if ($this->client
->add_owner($liste, $login)) {
526 $page->trig($alias." ajouté aux modérateurs.");
532 if (Env
::has('del_owner')) {
533 if (strpos(Env
::v('del_owner'), '@') === false
) {
534 $this->client
->del_owner($liste, Env
::v('del_owner').'@'.$globals->mail
->domain
);
536 $this->client
->del_owner($liste, Env
::v('del_owner'));
538 pl_redirect('lists/admin/'.$liste);
541 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
542 $membres = list_sort_members($mem, @$tri_promo);
543 $moderos = list_sort_owners($own, @$tri_promo);
545 $page->assign_by_ref('details', $det);
546 $page->assign_by_ref('members', $membres);
547 $page->assign_by_ref('owners', $moderos);
548 $page->assign('np_m', count($mem));
551 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
552 ." Si tu penses qu'il s'agit d'une erreur, "
553 ."<a href='mailto:support@polytechnique.org'>contact le support</a>");
557 function handler_options(&$page, $liste = null
)
559 if (is_null($liste)) {
563 $this->prepare_client($page);
565 $page->changeTpl('lists/options.tpl');
567 if (Post
::has('submit')) {
569 $this->client
->set_bogo_level($liste, intval($values['bogo_level']));
570 switch($values['moderate']) {
572 $values['generic_nonmember_action'] = 0;
573 $values['default_member_moderation'] = 0;
576 $values['generic_nonmember_action'] = 1;
577 $values['default_member_moderation'] = 0;
580 $values['generic_nonmember_action'] = 1;
581 $values['default_member_moderation'] = 1;
584 unset($values['submit'], $values['bogo_level'], $values['moderate']);
585 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
586 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
587 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
588 if (isset($values['subject_prefix'])) {
589 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
591 $this->client
->set_owner_options($liste, $values);
592 } elseif (isvalid_email(Post
::v('atn_add'))) {
593 $this->client
->add_to_wl($liste, Post
::v('atn_add'));
594 } elseif (Get
::has('atn_del')) {
595 $this->client
->del_from_wl($liste, Get
::v('atn_del'));
596 pl_redirect('lists/options/'.$liste);
599 if (list($details,$options) = $this->client
->get_owner_options($liste)) {
600 $page->assign_by_ref('details', $details);
601 $page->assign_by_ref('options', $options);
602 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
604 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
608 function handler_delete(&$page, $liste = null
)
611 if (is_null($liste)) {
615 $domain = $this->prepare_client($page);
616 if ($domain == $globals->mail
->domain ||
$domain == $globals->mail
->domain2
) {
621 $domain = '@' . $domain;
626 $page->changeTpl('lists/delete.tpl');
627 if (Post
::v('valid') == 'OUI') {
628 if ($this->client
->delete_list($liste, Post
::b('del_archive'))) {
629 foreach (array('', '-owner', '-admin', '-bounces') as $app) {
630 XDB
::execute("DELETE FROM $table
631 WHERE type={?} AND alias={?}",
632 $type, $liste.$app.$domain);
634 $page->assign('deleted', true
);
636 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
637 . 'Contact les administrateurs du site pour régler le problème : '
638 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>');
640 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
641 $page->assign_by_ref('details', $details);
642 $page->assign_by_ref('options', $options);
643 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
645 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
649 function handler_soptions(&$page, $liste = null
)
651 if (is_null($liste)) {
655 $this->prepare_client($page);
657 $page->changeTpl('lists/soptions.tpl');
659 if (Post
::has('submit')) {
661 unset($values['submit']);
662 $values['advertised'] = empty($values['advertised']) ? false
: true
;
663 $values['archive'] = empty($values['archive']) ? false
: true
;
664 $this->client
->set_admin_options($liste, $values);
667 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
668 $page->assign_by_ref('details', $details);
669 $page->assign_by_ref('options', $options);
671 $page->kill("La liste n'existe pas");
675 function handler_check(&$page, $liste = null
)
677 if (is_null($liste)) {
681 $this->prepare_client($page);
683 $page->changeTpl('lists/check.tpl');
685 if (Post
::has('correct')) {
686 $this->client
->check_options($liste, true
);
689 if (list($details,$options) = $this->client
->check_options($liste)) {
690 $page->assign_by_ref('details', $details);
691 $page->assign_by_ref('options', $options);
693 $page->kill("La liste n'existe pas");
697 function handler_admin_all(&$page) {
698 $page->changeTpl('lists/admin_all.tpl');
699 $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
701 $client = new MMList(S
::v('uid'), S
::v('password'));
702 $listes = $client->get_all_lists();
703 $page->assign_by_ref('listes', $listes);