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="UTF-8"');
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 changeTpl($tpl)
229 if (!empty($GLOBALS['IS_XNET_SITE'])) {
230 new_group_open_page($tpl);
233 $page->changeTpl($tpl);
237 function handler_members(&$page, $liste = null
)
239 if (is_null($liste)) {
243 $this->prepare_client($page);
245 $this->changeTpl('lists/members.tpl');
247 if (Get
::has('del')) {
248 $this->client
->unsubscribe($liste);
249 pl_redirect('lists/members/'.$liste);
252 if (Get
::has('add')) {
253 $this->client
->subscribe($liste);
254 pl_redirect('lists/members/'.$liste);
257 $members = $this->client
->get_members($liste);
259 $tri_promo = !Env
::b('alpha');
261 if (list($det,$mem,$own) = $members) {
262 $membres = list_sort_members($mem, $tri_promo);
263 $moderos = list_sort_owners($own, $tri_promo);
265 $page->assign_by_ref('details', $det);
266 $page->assign_by_ref('members', $membres);
267 $page->assign_by_ref('owners', $moderos);
268 $page->assign('nb_m', count($mem));
270 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
274 function _get_list($offset, $limit)
277 list($total, $members) = $this->client
->get_members_limit($platal->argv
[1], $offset, $limit);
280 foreach ($members as $member) {
281 list($m) = explode('@',$member[1]);
282 $res = XDB
::query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom,
283 promo, a.alias AS forlife
284 FROM auth_user_md5 AS u
285 INNER JOIN aliases AS a ON u.user_id = a.id
286 INNER JOIN photo AS p ON p.uid = u.user_id
287 WHERE a.alias = {?}", $m);
288 if ($tmp = $res->fetchOneAssoc()) {
289 $membres[$tmp['nom']] = $tmp;
294 uasort($membres, create_function('$a,$b', 'return $a["promo"] > $b["promo"] || '
295 . '($a["promo"] == $b["promo"] && (strcmp($a["nom"], $b["nom"]) > 0 || '
296 . '($a["nom"] == $b["nom"] && strcmp($a["prenom"], $b["prenom"]) > 0)));'));
297 return array($total, $membres);
300 function handler_trombi(&$page, $liste = null
)
302 if (is_null($liste)) {
306 $this->prepare_client($page);
308 $this->changeTpl('lists/trombi.tpl');
310 if (Get
::has('del')) {
311 $this->client
->unsubscribe($liste);
312 pl_redirect('lists/trombi/'.$liste);
314 if (Get
::has('add')) {
315 $this->client
->subscribe($liste);
316 pl_redirect('lists/trombi/'.$liste);
319 $owners = $this->client
->get_owners($liste);
321 if (is_array($owners)) {
322 $moderos = list_sort_owners($owners[1]);
324 $page->assign_by_ref('details', $owners[0]);
325 $page->assign_by_ref('owners', $moderos);
327 $trombi = new Trombi(array(&$this, '_get_list'));
328 $page->assign('trombi', $trombi);
330 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
334 function handler_archives(&$page, $liste = null
, $action = null
, $artid = null
)
338 if (is_null($liste)) {
342 $domain = $this->prepare_client($page);
344 $this->changeTpl('lists/archives.tpl');
346 if (list($det) = $this->client
->get_members($liste)) {
347 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
348 && !$det['own'] && ($det['sub'] < 2)) {
349 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
351 $get = Array('listname' => $liste, 'domain' => $domain);
352 if (Post
::has('updateall')) {
353 $get['updateall'] = Post
::v('updateall');
355 if (!is_null($action)) {
356 if ($action == 'new') {
357 $get['action'] = 'new';
358 } elseif (!is_null($artid)) {
359 $get['artid'] = $artid;
360 if ($action == 'reply') {
361 $get['action'] = 'new';
362 } elseif ($action == 'cancel') {
363 $get['action'] = $action;
364 } elseif ($action == 'from') {
365 $get['first'] = $artid;
366 unset($get['artid']);
367 } elseif ($action == 'read') {
368 $get['part'] = @$_GET['part'];
369 } elseif ($action == 'source') {
370 $get['part'] = 'source';
371 } elseif ($action == 'xface') {
372 $get['part'] = 'xface';
374 $get['part'] = str_replace('.', '/', $action);
376 if (Get
::v('action') == 'showext') {
377 $get['action'] = 'showext';
381 require_once('banana/ml.inc.php');
382 $banana = new MLBanana($get);
383 $page->assign('banana', $banana->run());
384 $page->addCssInline($banana->css());
385 $page->addCssLink('banana.css');
386 new PlBacktrace('MBox', $banana->backtrace(), 'response', 'time');
388 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
392 function moderate_mail($domain, $liste, $mid)
394 $mail = $this->client
->get_pending_mail($liste, $mid);
397 $prenom = S
::v('prenom');
400 if (Env
::has('mok')) {
401 $action = 1; /** 2 = ACCEPT **/
402 $subject = "Message accepté";
403 $append .= "a été accepté par $prenom $nom.\n";
404 } elseif (Env
::has('mno')) {
405 $action = 2; /** 2 = REJECT **/
406 $subject = "Message refusé";
407 $reason = Post
::v('reason');
408 $append = "a été refusé par $prenom $nom avec la raison :\n\n"
410 } elseif (Env
::has('mdel')) {
411 $action = 3; /** 3 = DISCARD **/
412 $subject = "Message supprimé";
413 $append = "a été supprimé par $prenom $nom.\n\n"
414 . "Rappel: il ne faut utiliser cette opération "
415 . "que dans le cas de spams ou de virus !\n";
418 if (isset($action) && $this->client
->handle_request($liste, $mid, $action, $reason)) {
419 $texte = "le message suivant :\n\n"
420 ." Auteur: {$mail['sender']}\n"
421 ." Sujet : « {$mail['subj']} »\n"
422 ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
424 $mailer = new PlMailer();
425 $mailer->addTo("$liste-owner@{$domain}");
426 $mailer->setFrom("$liste-bounces@{$domain}");
427 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
428 $mailer->setSubject($subject);
429 $mailer->setTxtBody(wordwrap($texte,72));
437 function handler_moderate(&$page, $liste = null
)
439 if (is_null($liste)) {
443 $domain = $this->prepare_client($page);
445 $this->changeTpl('lists/moderate.tpl');
447 $page->register_modifier('hdc', 'list_header_decode');
449 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
450 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
451 pl_redirect('lists/moderate/'.$liste);
453 if (Post
::has('sdel')) { /* 2 = REJECT */
454 $this->client
->handle_request($liste,Post
::v('sdel'),2,Post
::v('reason'));
457 if (Post
::has('moderate_mails') && Post
::has('select_mails')) {
458 $mails = array_keys(Post
::v('select_mails'));
459 foreach($mails as $mail) {
460 $this->moderate_mail($domain, $liste, $mail);
462 } elseif (Env
::has('mid')) {
463 if (Get
::has('mid') && !Env
::has('mok') && !Env
::has('mdel')) {
464 require_once('banana/moderate.inc.php');
465 $params = array('listname' => $liste, 'domain' => $domain,
466 'artid' => Get
::i('mid'), 'part' => Get
::v('part'), 'action' => Get
::v('action'));
467 $banana = new ModerationBanana($params, $this->client
);
468 $res = $banana->run();
469 $page->addCssInline($banana->css());
471 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
472 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
473 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
474 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
475 $msg = str_replace("%(listname)s", $liste, $msg);
476 $page->assign('msg', $msg);
478 $page->addCssLink('banana.css');
479 $this->changeTpl('lists/moderate_mail.tpl');
480 $page->assign_by_ref('mail', $res);
484 $mail = $this->moderate_mail($domain, $liste, Env
::i('mid'));
485 } elseif (Env
::has('sid')) {
486 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
487 foreach($subs as $user) {
488 if ($user['id'] == Env
::v('sid')) {
489 $this->changeTpl('lists/moderate_sub.tpl');
490 $page->assign('del_user', $user);
498 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
499 foreach ($mails as $key=>$mail) {
500 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
502 $page->assign_by_ref('subs', $subs);
503 $page->assign_by_ref('mails', $mails);
505 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
509 function handler_admin(&$page, $liste = null
)
513 if (is_null($liste)) {
517 $this->prepare_client($page);
519 $this->changeTpl('lists/admin.tpl');
521 if (Env
::has('add_member')) {
522 require_once('user.func.inc.php');
523 $members = get_users_forlife_list(Env
::v('add_member'));
524 $arr = $this->client
->mass_subscribe($liste, $members);
525 if (is_array($arr)) {
526 foreach($arr as $addr) {
527 $page->trig("{$addr[0]} inscrit.");
532 if (Env
::has('del_member')) {
533 if (strpos(Env
::v('del_member'), '@') === false
) {
534 $this->client
->mass_unsubscribe(
535 $liste, array(Env
::v('del_member').'@'.$globals->mail
->domain
));
537 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
539 pl_redirect('lists/admin/'.$liste);
542 if (Env
::has('add_owner')) {
543 require_once('user.func.inc.php');
544 $owners = get_users_forlife_list(Env
::v('add_owner'));
546 foreach ($owners as $login) {
547 if ($this->client
->add_owner($liste, $login)) {
548 $page->trig($alias." ajouté aux modérateurs.");
554 if (Env
::has('del_owner')) {
555 if (strpos(Env
::v('del_owner'), '@') === false
) {
556 $this->client
->del_owner($liste, Env
::v('del_owner').'@'.$globals->mail
->domain
);
558 $this->client
->del_owner($liste, Env
::v('del_owner'));
560 pl_redirect('lists/admin/'.$liste);
563 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
564 $membres = list_sort_members($mem, @$tri_promo);
565 $moderos = list_sort_owners($own, @$tri_promo);
567 $page->assign_by_ref('details', $det);
568 $page->assign_by_ref('members', $membres);
569 $page->assign_by_ref('owners', $moderos);
570 $page->assign('np_m', count($mem));
573 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
574 ." Si tu penses qu'il s'agit d'une erreur, "
575 ."<a href='mailto:support@polytechnique.org'>contact le support</a>");
579 function handler_options(&$page, $liste = null
)
581 if (is_null($liste)) {
585 $this->prepare_client($page);
587 $this->changeTpl('lists/options.tpl');
589 if (Post
::has('submit')) {
591 $values = array_map('utf8_decode', $values);
592 $this->client
->set_bogo_level($liste, intval($values['bogo_level']));
593 switch($values['moderate']) {
595 $values['generic_nonmember_action'] = 0;
596 $values['default_member_moderation'] = 0;
599 $values['generic_nonmember_action'] = 1;
600 $values['default_member_moderation'] = 0;
603 $values['generic_nonmember_action'] = 1;
604 $values['default_member_moderation'] = 1;
607 unset($values['submit'], $values['bogo_level'], $values['moderate']);
608 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
609 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
610 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
611 if (isset($values['subject_prefix'])) {
612 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
614 $this->client
->set_owner_options($liste, $values);
615 } elseif (isvalid_email(Post
::v('atn_add'))) {
616 $this->client
->add_to_wl($liste, Post
::v('atn_add'));
617 } elseif (Get
::has('atn_del')) {
618 $this->client
->del_from_wl($liste, Get
::v('atn_del'));
619 pl_redirect('lists/options/'.$liste);
622 if (list($details,$options) = $this->client
->get_owner_options($liste)) {
623 $page->assign_by_ref('details', $details);
624 $page->assign_by_ref('options', $options);
625 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
627 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
631 function handler_delete(&$page, $liste = null
)
634 if (is_null($liste)) {
638 $domain = $this->prepare_client($page);
639 if ($domain == $globals->mail
->domain ||
$domain == $globals->mail
->domain2
) {
644 $domain = '@' . $domain;
649 $this->changeTpl('lists/delete.tpl');
650 if (Post
::v('valid') == 'OUI') {
651 if ($this->client
->delete_list($liste, Post
::b('del_archive'))) {
652 foreach (array('', '-owner', '-admin', '-bounces') as $app) {
653 XDB
::execute("DELETE FROM $table
654 WHERE type={?} AND alias={?}",
655 $type, $liste.$app.$domain);
657 $page->assign('deleted', true
);
659 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
660 . 'Contact les administrateurs du site pour régler le problème : '
661 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>');
663 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
664 $page->assign_by_ref('details', $details);
665 $page->assign_by_ref('options', $options);
666 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
668 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
672 function handler_soptions(&$page, $liste = null
)
674 if (is_null($liste)) {
678 $this->prepare_client($page);
680 $this->changeTpl('lists/soptions.tpl');
682 if (Post
::has('submit')) {
684 $values = array_map('utf8_decode', $values);
685 unset($values['submit']);
686 $values['advertised'] = empty($values['advertised']) ? false
: true
;
687 $values['archive'] = empty($values['archive']) ? false
: true
;
688 $this->client
->set_admin_options($liste, $values);
691 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
692 $page->assign_by_ref('details', $details);
693 $page->assign_by_ref('options', $options);
695 $page->kill("La liste n'existe pas");
699 function handler_check(&$page, $liste = null
)
701 if (is_null($liste)) {
705 $this->prepare_client($page);
707 $this->changeTpl('lists/check.tpl');
709 if (Post
::has('correct')) {
710 $this->client
->check_options($liste, true
);
713 if (list($details,$options) = $this->client
->check_options($liste)) {
714 $page->assign_by_ref('details', $details);
715 $page->assign_by_ref('options', $options);
717 $page->kill("La liste n'existe pas");
721 function handler_admin_all(&$page) {
722 $this->changeTpl('lists/admin_all.tpl');
723 $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
725 $client = new MMList(S
::v('uid'), S
::v('password'));
726 $listes = $client->get_all_lists();
727 $page->assign_by_ref('listes', $listes);
731 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: