2 /***************************************************************************
3 * Copyright (C) 2003-2006 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/create' => $this->make_hook('create', AUTH_MDP
),
32 'lists/members' => $this->make_hook('members', AUTH_COOKIE
),
33 'lists/trombi' => $this->make_hook('trombi', AUTH_COOKIE
),
34 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE
),
36 'lists/moderate' => $this->make_hook('moderate', AUTH_MDP
),
37 'lists/admin' => $this->make_hook('admin', AUTH_MDP
),
38 'lists/options' => $this->make_hook('options', AUTH_MDP
),
39 'lists/delete' => $this->make_hook('delete', AUTH_MDP
),
41 'lists/soptions' => $this->make_hook('soptions', AUTH_MDP
),
42 'lists/check' => $this->make_hook('check', AUTH_MDP
),
43 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP
, 'admin'),
47 function on_subscribe($forlife, $uid, $promo, $password)
49 $this->prepare_client(null
);
50 $this->client
->subscribe("promo$promo");
53 function prepare_client(&$page)
55 require_once 'lists.inc.php';
57 $this->client
=& lists_xmlrpc(S
::v('uid'), S
::v('password'));
60 function handler_lists(&$page)
62 $this->prepare_client($page);
64 $page->changeTpl('listes/index.tpl');
65 $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
68 if (Get
::has('del')) {
69 $this->client
->unsubscribe(Get
::v('del'));
72 if (Get
::has('add')) {
73 $this->client
->subscribe(Get
::v('add'));
76 if (Post
::has('promo_add')) {
77 $promo = Post
::i('promo_add');
78 if ($promo >= 1900 and $promo < 2100) {
79 $this->client
->subscribe("promo$promo");
81 $page->trig("promo incorrecte, il faut une promo sur 4 chiffres.");
84 $listes = $this->client
->get_lists();
85 $page->assign_by_ref('listes', $listes);
88 function handler_create(&$page)
90 $page->changeTpl('listes/create.tpl');
92 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
93 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
95 // click on validate button 'add_owner_sub' or type <enter>
96 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
97 require_once('user.func.inc.php');
98 // if we want to add an owner and then type <enter>, then both
99 // add_owner_sub and add_owner are filled.
100 if (Post
::v('add_owner') != "") {
101 if (($forlife = get_user_forlife(Post
::v('add_owner'))) !== false
) {
102 $owners [] = $forlife;
104 // if we want to add a member and then type <enter>, then
105 // add_owner_sub is filled, whereas add_owner is empty.
106 } else if (Post
::has('add_member')) {
107 if (($forlife = get_user_forlife(Post
::v('add_member'))) !== false
) {
108 $members[] = $forlife;
113 // click on validate button 'add_member_sub'
114 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
115 require_once('user.func.inc.php');
116 if (($forlife = get_user_forlife(Post
::v('add_member'))) !== false
) {
117 $members[] = $forlife;
121 ksort($owners); array_unique($owners);
122 ksort($members); array_unique($members);
124 $page->assign('owners', join(' ', $owners));
125 $page->assign('members', join(' ', $members));
127 if (!Post
::has('submit')) {
131 $liste = Post
::v('liste');
134 $page->trig('champs «addresse souhaitée» vide');
136 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
137 $page->trig('le nom de la liste ne doit contenir que des lettres, chiffres et tirets');
140 $res = XDB
::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
141 $n = $res->fetchOneCell();
144 $page->trig('cet alias est déjà pris');
147 if (!Post
::v(desc
)) {
148 $page->trig('le sujet est vide');
151 if (!count($owners)) {
152 $page->trig('pas de gestionnaire');
155 if (count($members)<4) {
156 $page->trig('pas assez de membres');
159 if (!$page->nb_errs()) {
160 $page->assign('created', true
);
161 require_once 'validations.inc.php';
162 $req = new ListeReq(S
::v('uid'), $liste,
163 Post
::v('desc'), Post
::i('advertise'),
164 Post
::i('modlevel'), Post
::i('inslevel'),
170 function handler_members(&$page, $liste = null
)
172 if (is_null($liste)) {
176 $this->prepare_client($page);
178 $page->changeTpl('listes/members.tpl');
180 if (Get
::has('del')) {
181 $this->client
->unsubscribe($liste);
182 pl_redirect('lists/members/'.$liste);
185 if (Get
::has('add')) {
186 $this->client
->subscribe($liste);
187 pl_redirect('lists/members/'.$liste);
190 $members = $this->client
->get_members($liste);
192 $tri_promo = !Env
::b('alpha');
194 if (list($det,$mem,$own) = $members) {
195 $membres = list_sort_members($mem, $tri_promo);
196 $moderos = list_sort_owners($own, $tri_promo);
198 $page->assign_by_ref('details', $det);
199 $page->assign_by_ref('members', $membres);
200 $page->assign_by_ref('owners', $moderos);
201 $page->assign('nb_m', count($mem));
203 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
207 function _get_list($offset, $limit)
210 list($total, $members) = $this->client
->get_members_limit($platal->argv
[1], $offset, $limit);
213 foreach ($members as $member) {
214 list($m) = explode('@',$member[1]);
215 $res = XDB
::query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom,
216 promo, a.alias AS forlife
217 FROM auth_user_md5 AS u
218 INNER JOIN aliases AS a ON u.user_id = a.id
219 WHERE a.alias = {?}", $m);
220 if ($tmp = $res->fetchOneAssoc()) {
221 $membres[$tmp['nom']] = $tmp;
223 $membres[$member[0]] = array('addr' => $member[0]);
226 return array($total, $membres);
229 function handler_trombi(&$page, $liste = null
)
231 if (is_null($liste)) {
235 $this->prepare_client($page);
237 $page->changeTpl('listes/trombi.tpl');
239 if (Get
::has('del')) {
240 $this->client
->unsubscribe($liste);
241 pl_redirect('lists/tromi/'.$liste);
243 if (Get
::has('add')) {
244 $this->client
->subscribe($liste);
245 pl_redirect('lists/tromi/'.$liste);
248 $owners = $this->client
->get_owners($liste);
250 if (is_array($owners)) {
251 require_once 'trombi.inc.php';
252 $moderos = list_sort_owners($owners[1]);
254 $page->assign_by_ref('details', $owners[0]);
255 $page->assign_by_ref('owners', $moderos);
257 $trombi = new Trombi(array(&$this, '_get_list'));
258 $page->assign('trombi', $trombi);
260 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
264 function handler_archives(&$page, $liste = null
)
268 if (is_null($liste)) {
272 $this->prepare_client($page);
274 $page->changeTpl('listes/archives.tpl');
276 $page->addCssLink('css/lists.archives.css');
277 if (list($det) = $this->client
->get_members($liste)) {
278 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
279 && !$det['own'] && ($det['sub'] < 2))
281 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
282 } elseif (Get
::has('file')) {
283 $file = Get
::v('file');
284 $rep = Get
::v('rep');
285 if (strstr('/', $file)!==false ||
!preg_match(',^\d+/\d+$,', $rep)) {
286 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
288 $page->assign('archives', $globals->lists
->spool
289 ."/{$domain}{$globals->lists->vhost_sep}$liste/$rep/$file");
293 foreach (glob($globals->lists
->spool
294 ."/{$domain}{$globals->lists->vhost_sep}$liste/*/*") as $rep)
296 if (preg_match(",/(\d*)/(\d*)$,", $rep, $matches)) {
297 $archs[intval($matches[1])][intval($matches[2])] = true
;
300 $page->assign('archs', $archs);
301 $page->assign('range', range(1,12));
304 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
308 function handler_moderate(&$page, $liste = null
)
310 if (is_null($liste)) {
314 $this->prepare_client($page);
316 $page->changeTpl('listes/moderate.tpl');
318 $page->register_modifier('qpd', 'quoted_printable_decode');
319 $page->register_modifier('hdc', 'list_header_decode');
321 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
322 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
323 pl_redirect('lists/moderate/'.$liste);
326 if (Post
::has('sdel')) { /* 2 = REJECT */
327 $this->client
->handle_request($liste,Post
::v('sdel'),2,Post
::v('reason'));
330 if (Env
::has('mid')) {
331 $mid = Env
::v('mid');
332 $mail = $this->client
->get_pending_mail($liste, $mid);
335 $prenom = S
::v('prenom');
338 if (Env
::has('mok')) {
339 $action = 1; /** 2 = ACCEPT **/
340 $subject = "Message accepté";
341 $append .= "a été accepté par $prenom $nom.\n";
342 } elseif (Env
::has('mno')) {
343 $action = 2; /** 2 = REJECT **/
344 $subject = "Message refusé";
345 $reason = Post
::v('reason');
346 $append = "a été refusé par $prenom $nom avec la raison :\n\n"
348 } elseif (Env
::has('mdel')) {
349 $action = 3; /** 3 = DISCARD **/
350 $subject = "Message supprimé";
351 $append = "a été supprimé par $prenom $nom.\n\n"
352 . "Rappel: il ne faut utiliser cette opération "
353 . "que dans le cas de spams ou de virus !\n";
356 if (isset($action) && $this->client
->handle_request($liste, $mid, $action, $reason)) {
357 $texte = "le message suivant :\n\n"
358 ." Auteur: {$mail['sender']}\n"
359 ." Sujet : « {$mail['subj']} »\n"
360 ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
362 require_once 'diogenes/diogenes.hermes.inc.php';
363 $mailer = new HermesMailer();
364 $mailer->addTo("$liste-owner@{$domain}");
365 $mailer->setFrom("$liste-bounces@{$domain}");
366 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
367 $mailer->setSubject($subject);
368 $mailer->setTxtBody(wordwrap($texte,72));
373 if (Get
::has('mid') && is_array($mail)) {
374 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
375 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
376 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
377 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
378 $msg = str_replace("%(listname)s", $liste, $msg);
379 $page->assign('msg', $msg);
381 $page->changeTpl('listes/moderate_mail.tpl');
382 $page->assign_by_ref('mail', $mail);
386 } elseif (Env
::has('sid')) {
388 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
389 foreach($subs as $user) {
390 if ($user['id'] == Env
::v('sid')) {
391 $page->changeTpl('listes/moderate_sub.tpl');
392 $page->assign('del_user', $user);
400 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
401 $page->assign_by_ref('subs', $subs);
402 $page->assign_by_ref('mails', $mails);
404 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
408 function handler_admin(&$page, $liste = null
)
412 if (is_null($liste)) {
416 $this->prepare_client($page);
418 $page->changeTpl('listes/admin.tpl');
420 if (Env
::has('add_member')) {
422 require_once('user.func.inc.php');
423 $members = explode(' ', Env
::v('add_member'));
424 if ($members) foreach ($members as $i => $alias) {
425 if (($login = get_user_forlife($alias)) !== false
) {;
426 $members[$i] = $login;
430 $arr = $this->client
->mass_subscribe($liste, $members);
431 if (is_array($arr)) {
432 foreach($arr as $addr) {
433 $page->trig("{$addr[0]} inscrit.");
438 if (Env
::has('del_member')) {
439 if (strpos(Env
::v('del_member'), '@') === false
) {
440 $this->client
->mass_unsubscribe(
441 $liste, array(Env
::v('del_member').'@'.$globals->mail
->domain
));
443 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
445 pl_redirect('lists/admin/'.$liste);
448 if (Env
::has('add_owner')) {
449 require_once('user.func.inc.php');
451 $owners = explode(' ', Env
::v('add_owner'));
453 if ($owners) foreach ($owners as $alias) {
454 if (($login = get_user_forlife($alias)) === false
) {;
458 if ($this->client
->add_owner($liste, $login)) {
459 $page->trig($alias." ajouté aux modérateurs.");
464 if (Env
::has('del_owner')) {
465 if (strpos(Env
::v('del_owner'), '@') === false
) {
466 $this->client
->del_owner($liste, Env
::v('del_owner').'@'.$globals->mail
->domain
);
468 $this->client
->del_owner($liste, Env
::v('del_owner'));
470 pl_redirect('lists/admin/'.$liste);
473 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
475 $membres = list_sort_members($mem, $tri_promo);
476 $moderos = list_sort_owners($own, $tri_promo);
478 $page->assign_by_ref('details', $det);
479 $page->assign_by_ref('members', $membres);
480 $page->assign_by_ref('owners', $moderos);
481 $page->assign('np_m', count($mem));
484 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
488 function handler_options(&$page, $liste = null
)
490 if (is_null($liste)) {
494 $this->prepare_client($page);
496 $page->changeTpl('listes/options.tpl');
498 if (Post
::has('submit')) {
500 $this->client
->set_bogo_level($liste, intval($values['bogo_level']));
501 switch($values['moderate']) {
503 $values['generic_nonmember_action'] = 0;
504 $values['default_member_moderation'] = 0;
507 $values['generic_nonmember_action'] = 1;
508 $values['default_member_moderation'] = 0;
511 $values['generic_nonmember_action'] = 1;
512 $values['default_member_moderation'] = 1;
515 unset($values['submit'], $values['bogo_level'], $values['moderate']);
516 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
517 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
518 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
519 if (isset($values['subject_prefix'])) {
520 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
522 $this->client
->set_owner_options($liste, $values);
523 } elseif (isvalid_email(Post
::v('atn_add'))) {
524 $this->client
->add_to_wl($liste, Post
::v('atn_add'));
525 } elseif (Get
::has('atn_del')) {
526 $this->client
->del_from_wl($liste, Get
::v('atn_del'));
527 pl_redirect('lists/options/'.$liste);
530 if (list($details,$options) = $this->client
->get_owner_options($liste)) {
531 $page->assign_by_ref('details', $details);
532 $page->assign_by_ref('options', $options);
533 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
535 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
539 function handler_delete(&$page, $liste = null
)
541 if (is_null($liste)) {
545 $this->prepare_client($page);
547 $page->changeTpl('listes/delete.tpl');
549 if (Post
::v('valid') == 'OUI'
550 && $this->client
->delete_list($liste, Post
::b('del_archive')))
552 foreach (array('', '-owner', '-admin', '-bounces') as $app) {
553 XDB
::execute("DELETE FROM aliases
554 WHERE type='liste' AND alias='{?}'",
557 $page->assign('deleted', true
);
558 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
559 $page->assign_by_ref('details', $details);
560 $page->assign_by_ref('options', $options);
561 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
563 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
567 function handler_soptions(&$page, $liste = null
)
569 if (is_null($liste)) {
573 $this->prepare_client($page);
575 $page->changeTpl('listes/soptions.tpl');
577 if (Post
::has('submit')) {
579 unset($values['submit']);
580 $values['advertised'] = empty($values['advertised']) ? false
: true
;
581 $values['archive'] = empty($values['archive']) ? false
: true
;
582 $this->client
->set_admin_options($liste, $values);
585 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
586 $page->assign_by_ref('details', $details);
587 $page->assign_by_ref('options', $options);
589 $page->kill("La liste n'existe pas");
593 function handler_check(&$page, $liste = null
)
595 if (is_null($liste)) {
599 $this->prepare_client($page);
601 $page->changeTpl('listes/check.tpl');
603 if (Post
::has('correct')) {
604 $this->client
->check_options($liste, true
);
607 if (list($details,$options) = $this->client
->check_options($liste)) {
608 $page->assign_by_ref('details', $details);
609 $page->assign_by_ref('options', $options);
611 $page->kill("La liste n'existe pas");
615 function handler_admin_all(&$page) {
616 $page->changeTpl('listes/admin_all.tpl');
617 $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
618 require_once 'lists.inc.php';
620 $client =& lists_xmlrpc(S
::v('uid'), S
::v('password'));
621 $listes = $client->get_all_lists();
622 $page->assign_by_ref('listes',$listes);