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)
57 require_once dirname(__FILE__
).'/lists/lists.inc.php';
59 $this->client
= new MMList(S
::v('uid'), S
::v('password'));
60 return $globals->mail
->domain
;
63 function clean_html($res)
65 $res = html_entity_decode($res);
66 $res = preg_replace('@<a[^>]*href=["\']([^ >]+)["\'][^>]*>([^<]*)</a>@ie',
67 "'\\2 [' . htmlentities('\\1') . ']'", $res);
68 $res = preg_replace("@<(/br|p|/div)[^>]*>(\\s*\n)?@i", "\n", $res);
69 $res = trim(strip_tags($res));
70 $res = preg_replace("/\n(\\s*\n)+/", "\n\n", $res);
74 function handler_lists(&$page)
76 $this->prepare_client($page);
78 $page->changeTpl('listes/index.tpl');
79 $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
82 if (Get
::has('del')) {
83 $this->client
->unsubscribe(Get
::v('del'));
86 if (Get
::has('add')) {
87 $this->client
->subscribe(Get
::v('add'));
90 if (Post
::has('promo_add')) {
91 $promo = Post
::i('promo_add');
92 if ($promo >= 1900 and $promo < 2100) {
93 $this->client
->subscribe("promo$promo");
95 $page->trig("promo incorrecte, il faut une promo sur 4 chiffres.");
98 $listes = $this->client
->get_lists();
99 $page->assign_by_ref('listes', $listes);
102 function handler_create(&$page)
104 $page->changeTpl('listes/create.tpl');
106 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
107 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
109 // click on validate button 'add_owner_sub' or type <enter>
110 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
111 require_once('user.func.inc.php');
112 // if we want to add an owner and then type <enter>, then both
113 // add_owner_sub and add_owner are filled.
114 $oforlifes = get_users_forlife_list(Post
::v('add_owner'), true
);
115 $mforlifes = get_users_forlife_list(Post
::v('add_member'), true
);
116 if (!is_null($oforlifes)) {
117 $owners = array_merge($owners, $oforlifes);
119 // if we want to add a member and then type <enter>, then
120 // add_owner_sub is filled, whereas add_owner is empty.
121 if (!is_null($mforlifes)) {
122 $members = array_merge($members, $mforlifes);
126 // click on validate button 'add_member_sub'
127 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
128 require_once('user.func.inc.php');
129 $forlifes = get_users_forlife_list(Post
::v('add_member'), true
);
130 if (!is_null($forlifes)) {
131 $members = array_merge($members, $forlifes);
136 $owners = array_unique($owners);
138 $members = array_unique($members);
140 $page->assign('owners', join(' ', $owners));
141 $page->assign('members', join(' ', $members));
143 if (!Post
::has('submit')) {
147 $liste = Post
::v('liste');
150 $page->trig('champs «addresse souhaitée» vide');
152 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
153 $page->trig('le nom de la liste ne doit contenir que des lettres, chiffres et tirets');
156 $res = XDB
::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
157 $n = $res->fetchOneCell();
160 $page->trig('cet alias est déjà pris');
163 if (!Post
::v(desc
)) {
164 $page->trig('le sujet est vide');
167 if (!count($owners)) {
168 $page->trig('pas de gestionnaire');
171 if (count($members)<4) {
172 $page->trig('pas assez de membres');
175 if (!$page->nb_errs()) {
176 $page->assign('created', true
);
177 require_once 'validations.inc.php';
178 $req = new ListeReq(S
::v('uid'), $liste,
179 Post
::v('desc'), Post
::i('advertise'),
180 Post
::i('modlevel'), Post
::i('inslevel'),
186 function handler_members(&$page, $liste = null
)
188 if (is_null($liste)) {
192 $this->prepare_client($page);
194 $page->changeTpl('listes/members.tpl');
196 if (Get
::has('del')) {
197 $this->client
->unsubscribe($liste);
198 pl_redirect('lists/members/'.$liste);
201 if (Get
::has('add')) {
202 $this->client
->subscribe($liste);
203 pl_redirect('lists/members/'.$liste);
206 $members = $this->client
->get_members($liste);
208 $tri_promo = !Env
::b('alpha');
210 if (list($det,$mem,$own) = $members) {
211 $membres = list_sort_members($mem, $tri_promo);
212 $moderos = list_sort_owners($own, $tri_promo);
214 $page->assign_by_ref('details', $det);
215 $page->assign_by_ref('members', $membres);
216 $page->assign_by_ref('owners', $moderos);
217 $page->assign('nb_m', count($mem));
219 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
223 function _get_list($offset, $limit)
226 list($total, $members) = $this->client
->get_members_limit($platal->argv
[1], $offset, $limit);
229 foreach ($members as $member) {
230 list($m) = explode('@',$member[1]);
231 $res = XDB
::query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom,
232 promo, a.alias AS forlife
233 FROM auth_user_md5 AS u
234 INNER JOIN aliases AS a ON u.user_id = a.id
235 WHERE a.alias = {?}", $m);
236 if ($tmp = $res->fetchOneAssoc()) {
237 $membres[$tmp['nom']] = $tmp;
239 $membres[$member[0]] = array('addr' => $member[0]);
242 return array($total, $membres);
245 function handler_trombi(&$page, $liste = null
)
247 if (is_null($liste)) {
251 $this->prepare_client($page);
253 $page->changeTpl('listes/trombi.tpl');
255 if (Get
::has('del')) {
256 $this->client
->unsubscribe($liste);
257 pl_redirect('lists/tromi/'.$liste);
259 if (Get
::has('add')) {
260 $this->client
->subscribe($liste);
261 pl_redirect('lists/tromi/'.$liste);
264 $owners = $this->client
->get_owners($liste);
266 if (is_array($owners)) {
267 $moderos = list_sort_owners($owners[1]);
269 $page->assign_by_ref('details', $owners[0]);
270 $page->assign_by_ref('owners', $moderos);
272 $trombi = new Trombi(array(&$this, '_get_list'));
273 $page->assign('trombi', $trombi);
275 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
279 function handler_archives(&$page, $liste = null
)
283 if (is_null($liste)) {
287 $domain = $this->prepare_client($page);
289 $page->changeTpl('listes/archives.tpl');
291 $page->addCssLink('lists.archives.css');
292 if (list($det) = $this->client
->get_members($liste)) {
293 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
294 && !$det['own'] && ($det['sub'] < 2))
296 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
297 } elseif (Get
::has('file')) {
298 $file = Get
::v('file');
299 $rep = Get
::v('rep');
300 if (strstr('/', $file)!==false ||
!preg_match(',^\d+/\d+$,', $rep)) {
301 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
303 $page->assign('archives', $globals->lists
->spool
304 ."/{$domain}{$globals->lists->vhost_sep}$liste/$rep/$file");
308 foreach (glob($globals->lists
->spool
309 ."/{$domain}{$globals->lists->vhost_sep}$liste/*/*") as $rep)
311 if (preg_match(",/(\d*)/(\d*)$,", $rep, $matches)) {
312 $archs[intval($matches[1])][intval($matches[2])] = true
;
315 $page->assign('archs', $archs);
316 $page->assign('range', range(1,12));
319 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
323 function handler_moderate(&$page, $liste = null
)
325 if (is_null($liste)) {
329 $domain = $this->prepare_client($page);
331 $page->changeTpl('listes/moderate.tpl');
333 $page->register_modifier('qpd', 'quoted_printable_decode');
334 $page->register_modifier('hdc', 'list_header_decode');
335 $page->register_modifier('clean_html', array($this, 'clean_html'));
337 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
338 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
339 pl_redirect('lists/moderate/'.$liste);
342 if (Post
::has('sdel')) { /* 2 = REJECT */
343 $this->client
->handle_request($liste,Post
::v('sdel'),2,Post
::v('reason'));
346 if (Env
::has('mid')) {
347 $mid = Env
::v('mid');
348 $mail = $this->client
->get_pending_mail($liste, $mid);
351 $prenom = S
::v('prenom');
354 if (Env
::has('mok')) {
355 $action = 1; /** 2 = ACCEPT **/
356 $subject = "Message accepté";
357 $append .= "a été accepté par $prenom $nom.\n";
358 } elseif (Env
::has('mno')) {
359 $action = 2; /** 2 = REJECT **/
360 $subject = "Message refusé";
361 $reason = Post
::v('reason');
362 $append = "a été refusé par $prenom $nom avec la raison :\n\n"
364 } elseif (Env
::has('mdel')) {
365 $action = 3; /** 3 = DISCARD **/
366 $subject = "Message supprimé";
367 $append = "a été supprimé par $prenom $nom.\n\n"
368 . "Rappel: il ne faut utiliser cette opération "
369 . "que dans le cas de spams ou de virus !\n";
372 if (isset($action) && $this->client
->handle_request($liste, $mid, $action, $reason)) {
373 $texte = "le message suivant :\n\n"
374 ." Auteur: {$mail['sender']}\n"
375 ." Sujet : « {$mail['subj']} »\n"
376 ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
378 require_once 'diogenes/diogenes.hermes.inc.php';
379 $mailer = new HermesMailer();
380 $mailer->addTo("$liste-owner@{$domain}");
381 $mailer->setFrom("$liste-bounces@{$domain}");
382 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
383 $mailer->setSubject($subject);
384 $mailer->setTxtBody(wordwrap($texte,72));
389 if (Get
::has('mid') && is_array($mail)) {
390 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
391 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
392 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
393 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
394 $msg = str_replace("%(listname)s", $liste, $msg);
395 $page->assign('msg', $msg);
397 $page->changeTpl('listes/moderate_mail.tpl');
398 $page->assign_by_ref('mail', $mail);
402 } elseif (Env
::has('sid')) {
404 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
405 foreach($subs as $user) {
406 if ($user['id'] == Env
::v('sid')) {
407 $page->changeTpl('listes/moderate_sub.tpl');
408 $page->assign('del_user', $user);
416 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
417 $page->assign_by_ref('subs', $subs);
418 $page->assign_by_ref('mails', $mails);
420 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
424 function handler_admin(&$page, $liste = null
)
428 if (is_null($liste)) {
432 $this->prepare_client($page);
434 $page->changeTpl('listes/admin.tpl');
436 if (Env
::has('add_member')) {
437 require_once('user.func.inc.php');
438 $members = get_users_forlife_list(Env
::v('add_member'));
439 $arr = $this->client
->mass_subscribe($liste, $members);
440 if (is_array($arr)) {
441 foreach($arr as $addr) {
442 $page->trig("{$addr[0]} inscrit.");
447 if (Env
::has('del_member')) {
448 if (strpos(Env
::v('del_member'), '@') === false
) {
449 $this->client
->mass_unsubscribe(
450 $liste, array(Env
::v('del_member').'@'.$globals->mail
->domain
));
452 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
454 pl_redirect('lists/admin/'.$liste);
457 if (Env
::has('add_owner')) {
458 require_once('user.func.inc.php');
459 $owners = get_users_forlife_list(Env
::v('add_owner'));
461 foreach ($owners as $login) {
462 if ($this->client
->add_owner($liste, $login)) {
463 $page->trig($alias." ajouté aux modérateurs.");
469 if (Env
::has('del_owner')) {
470 if (strpos(Env
::v('del_owner'), '@') === false
) {
471 $this->client
->del_owner($liste, Env
::v('del_owner').'@'.$globals->mail
->domain
);
473 $this->client
->del_owner($liste, Env
::v('del_owner'));
475 pl_redirect('lists/admin/'.$liste);
478 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
479 $membres = list_sort_members($mem, $tri_promo);
480 $moderos = list_sort_owners($own, $tri_promo);
482 $page->assign_by_ref('details', $det);
483 $page->assign_by_ref('members', $membres);
484 $page->assign_by_ref('owners', $moderos);
485 $page->assign('np_m', count($mem));
488 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
492 function handler_options(&$page, $liste = null
)
494 if (is_null($liste)) {
498 $this->prepare_client($page);
500 $page->changeTpl('listes/options.tpl');
502 if (Post
::has('submit')) {
504 $this->client
->set_bogo_level($liste, intval($values['bogo_level']));
505 switch($values['moderate']) {
507 $values['generic_nonmember_action'] = 0;
508 $values['default_member_moderation'] = 0;
511 $values['generic_nonmember_action'] = 1;
512 $values['default_member_moderation'] = 0;
515 $values['generic_nonmember_action'] = 1;
516 $values['default_member_moderation'] = 1;
519 unset($values['submit'], $values['bogo_level'], $values['moderate']);
520 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
521 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
522 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
523 if (isset($values['subject_prefix'])) {
524 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
526 $this->client
->set_owner_options($liste, $values);
527 } elseif (isvalid_email(Post
::v('atn_add'))) {
528 $this->client
->add_to_wl($liste, Post
::v('atn_add'));
529 } elseif (Get
::has('atn_del')) {
530 $this->client
->del_from_wl($liste, Get
::v('atn_del'));
531 pl_redirect('lists/options/'.$liste);
534 if (list($details,$options) = $this->client
->get_owner_options($liste)) {
535 $page->assign_by_ref('details', $details);
536 $page->assign_by_ref('options', $options);
537 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
539 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
543 function handler_delete(&$page, $liste = null
)
545 if (is_null($liste)) {
549 $this->prepare_client($page);
551 $page->changeTpl('listes/delete.tpl');
553 if (Post
::v('valid') == 'OUI'
554 && $this->client
->delete_list($liste, Post
::b('del_archive')))
556 foreach (array('', '-owner', '-admin', '-bounces') as $app) {
557 XDB
::execute("DELETE FROM aliases
558 WHERE type='liste' AND alias='{?}'",
561 $page->assign('deleted', true
);
562 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
563 $page->assign_by_ref('details', $details);
564 $page->assign_by_ref('options', $options);
565 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
567 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
571 function handler_soptions(&$page, $liste = null
)
573 if (is_null($liste)) {
577 $this->prepare_client($page);
579 $page->changeTpl('listes/soptions.tpl');
581 if (Post
::has('submit')) {
583 unset($values['submit']);
584 $values['advertised'] = empty($values['advertised']) ? false
: true
;
585 $values['archive'] = empty($values['archive']) ? false
: true
;
586 $this->client
->set_admin_options($liste, $values);
589 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
590 $page->assign_by_ref('details', $details);
591 $page->assign_by_ref('options', $options);
593 $page->kill("La liste n'existe pas");
597 function handler_check(&$page, $liste = null
)
599 if (is_null($liste)) {
603 $this->prepare_client($page);
605 $page->changeTpl('listes/check.tpl');
607 if (Post
::has('correct')) {
608 $this->client
->check_options($liste, true
);
611 if (list($details,$options) = $this->client
->check_options($liste)) {
612 $page->assign_by_ref('details', $details);
613 $page->assign_by_ref('options', $options);
615 $page->kill("La liste n'existe pas");
619 function handler_admin_all(&$page) {
620 $page->changeTpl('listes/admin_all.tpl');
621 $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
623 $client = new MMList(S
::v('uid'), S
::v('password'));
624 $listes = $client->get_all_lists();
625 $page->assign_by_ref('listes', $listes);