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>@i', "\\2 [\\1]", $res);
67 $res = preg_replace("@<(/br|p|/div)[^>]*>(\\s*\n)?@i", "\n", $res);
68 $res = trim(strip_tags($res));
69 $res = preg_replace("/\n(\\s*\n)+/", "\n\n", $res);
70 return htmlentities($res);
73 function handler_lists(&$page)
75 $this->prepare_client($page);
77 $page->changeTpl('listes/index.tpl');
78 $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
81 if (Get
::has('del')) {
82 $this->client
->unsubscribe(Get
::v('del'));
85 if (Get
::has('add')) {
86 $this->client
->subscribe(Get
::v('add'));
89 if (Post
::has('promo_add')) {
90 $promo = Post
::i('promo_add');
91 if ($promo >= 1900 and $promo < 2100) {
92 $this->client
->subscribe("promo$promo");
94 $page->trig("promo incorrecte, il faut une promo sur 4 chiffres.");
97 $listes = $this->client
->get_lists();
98 $page->assign_by_ref('listes', $listes);
101 function handler_create(&$page)
103 $page->changeTpl('listes/create.tpl');
105 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
106 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
108 // click on validate button 'add_owner_sub' or type <enter>
109 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
110 require_once('user.func.inc.php');
111 // if we want to add an owner and then type <enter>, then both
112 // add_owner_sub and add_owner are filled.
113 $oforlifes = get_users_forlife_list(Post
::v('add_owner'), true
);
114 $mforlifes = get_users_forlife_list(Post
::v('add_member'), true
);
115 if (!is_null($oforlifes)) {
116 $owners = array_merge($owners, $oforlifes);
118 // if we want to add a member and then type <enter>, then
119 // add_owner_sub is filled, whereas add_owner is empty.
120 if (!is_null($mforlifes)) {
121 $members = array_merge($members, $mforlifes);
125 // click on validate button 'add_member_sub'
126 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
127 require_once('user.func.inc.php');
128 $forlifes = get_users_forlife_list(Post
::v('add_member'), true
);
129 if (!is_null($forlifes)) {
130 $members = array_merge($members, $forlifes);
135 $owners = array_unique($owners);
137 $members = array_unique($members);
139 $page->assign('owners', join(' ', $owners));
140 $page->assign('members', join(' ', $members));
142 if (!Post
::has('submit')) {
146 $liste = Post
::v('liste');
149 $page->trig('champs «addresse souhaitée» vide');
151 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
152 $page->trig('le nom de la liste ne doit contenir que des lettres, chiffres et tirets');
155 $res = XDB
::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
156 $n = $res->fetchOneCell();
159 $page->trig('cet alias est déjà pris');
162 if (!Post
::v(desc
)) {
163 $page->trig('le sujet est vide');
166 if (!count($owners)) {
167 $page->trig('pas de gestionnaire');
170 if (count($members)<4) {
171 $page->trig('pas assez de membres');
174 if (!$page->nb_errs()) {
175 $page->assign('created', true
);
176 require_once 'validations.inc.php';
177 $req = new ListeReq(S
::v('uid'), $liste,
178 Post
::v('desc'), Post
::i('advertise'),
179 Post
::i('modlevel'), Post
::i('inslevel'),
185 function handler_members(&$page, $liste = null
)
187 if (is_null($liste)) {
191 $this->prepare_client($page);
193 $page->changeTpl('listes/members.tpl');
195 if (Get
::has('del')) {
196 $this->client
->unsubscribe($liste);
197 pl_redirect('lists/members/'.$liste);
200 if (Get
::has('add')) {
201 $this->client
->subscribe($liste);
202 pl_redirect('lists/members/'.$liste);
205 $members = $this->client
->get_members($liste);
207 $tri_promo = !Env
::b('alpha');
209 if (list($det,$mem,$own) = $members) {
210 $membres = list_sort_members($mem, $tri_promo);
211 $moderos = list_sort_owners($own, $tri_promo);
213 $page->assign_by_ref('details', $det);
214 $page->assign_by_ref('members', $membres);
215 $page->assign_by_ref('owners', $moderos);
216 $page->assign('nb_m', count($mem));
218 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
222 function _get_list($offset, $limit)
225 list($total, $members) = $this->client
->get_members_limit($platal->argv
[1], $offset, $limit);
228 foreach ($members as $member) {
229 list($m) = explode('@',$member[1]);
230 $res = XDB
::query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom,
231 promo, a.alias AS forlife
232 FROM auth_user_md5 AS u
233 INNER JOIN aliases AS a ON u.user_id = a.id
234 WHERE a.alias = {?}", $m);
235 if ($tmp = $res->fetchOneAssoc()) {
236 $membres[$tmp['nom']] = $tmp;
238 $membres[$member[0]] = array('addr' => $member[0]);
241 return array($total, $membres);
244 function handler_trombi(&$page, $liste = null
)
246 if (is_null($liste)) {
250 $this->prepare_client($page);
252 $page->changeTpl('listes/trombi.tpl');
254 if (Get
::has('del')) {
255 $this->client
->unsubscribe($liste);
256 pl_redirect('lists/tromi/'.$liste);
258 if (Get
::has('add')) {
259 $this->client
->subscribe($liste);
260 pl_redirect('lists/tromi/'.$liste);
263 $owners = $this->client
->get_owners($liste);
265 if (is_array($owners)) {
266 $moderos = list_sort_owners($owners[1]);
268 $page->assign_by_ref('details', $owners[0]);
269 $page->assign_by_ref('owners', $moderos);
271 $trombi = new Trombi(array(&$this, '_get_list'));
272 $page->assign('trombi', $trombi);
274 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
278 function handler_archives(&$page, $liste = null
)
282 if (is_null($liste)) {
286 $domain = $this->prepare_client($page);
288 $page->changeTpl('listes/archives.tpl');
290 $page->addCssLink('lists.archives.css');
291 if (list($det) = $this->client
->get_members($liste)) {
292 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
293 && !$det['own'] && ($det['sub'] < 2))
295 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
296 } elseif (Get
::has('file')) {
297 $file = Get
::v('file');
298 $rep = Get
::v('rep');
299 if (strstr('/', $file)!==false ||
!preg_match(',^\d+/\d+$,', $rep)) {
300 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
302 $page->assign('archives', $globals->lists
->spool
303 ."/{$domain}{$globals->lists->vhost_sep}$liste/$rep/$file");
307 foreach (glob($globals->lists
->spool
308 ."/{$domain}{$globals->lists->vhost_sep}$liste/*/*") as $rep)
310 if (preg_match(",/(\d*)/(\d*)$,", $rep, $matches)) {
311 $archs[intval($matches[1])][intval($matches[2])] = true
;
314 $page->assign('archs', $archs);
315 $page->assign('range', range(1,12));
318 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
322 function handler_moderate(&$page, $liste = null
)
324 if (is_null($liste)) {
328 $domain = $this->prepare_client($page);
330 $page->changeTpl('listes/moderate.tpl');
332 $page->register_modifier('qpd', 'quoted_printable_decode');
333 $page->register_modifier('hdc', 'list_header_decode');
334 $page->register_modifier('clean_html', array($this, 'clean_html'));
336 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
337 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
338 pl_redirect('lists/moderate/'.$liste);
341 if (Post
::has('sdel')) { /* 2 = REJECT */
342 $this->client
->handle_request($liste,Post
::v('sdel'),2,Post
::v('reason'));
345 if (Env
::has('mid')) {
346 $mid = Env
::v('mid');
347 $mail = $this->client
->get_pending_mail($liste, $mid);
350 $prenom = S
::v('prenom');
353 if (Env
::has('mok')) {
354 $action = 1; /** 2 = ACCEPT **/
355 $subject = "Message accepté";
356 $append .= "a été accepté par $prenom $nom.\n";
357 } elseif (Env
::has('mno')) {
358 $action = 2; /** 2 = REJECT **/
359 $subject = "Message refusé";
360 $reason = Post
::v('reason');
361 $append = "a été refusé par $prenom $nom avec la raison :\n\n"
363 } elseif (Env
::has('mdel')) {
364 $action = 3; /** 3 = DISCARD **/
365 $subject = "Message supprimé";
366 $append = "a été supprimé par $prenom $nom.\n\n"
367 . "Rappel: il ne faut utiliser cette opération "
368 . "que dans le cas de spams ou de virus !\n";
371 if (isset($action) && $this->client
->handle_request($liste, $mid, $action, $reason)) {
372 $texte = "le message suivant :\n\n"
373 ." Auteur: {$mail['sender']}\n"
374 ." Sujet : « {$mail['subj']} »\n"
375 ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
377 require_once 'diogenes/diogenes.hermes.inc.php';
378 $mailer = new HermesMailer();
379 $mailer->addTo("$liste-owner@{$domain}");
380 $mailer->setFrom("$liste-bounces@{$domain}");
381 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
382 $mailer->setSubject($subject);
383 $mailer->setTxtBody(wordwrap($texte,72));
388 if (Get
::has('mid') && is_array($mail)) {
389 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
390 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
391 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
392 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
393 $msg = str_replace("%(listname)s", $liste, $msg);
394 $page->assign('msg', $msg);
396 $page->changeTpl('listes/moderate_mail.tpl');
397 $page->assign_by_ref('mail', $mail);
401 } elseif (Env
::has('sid')) {
403 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
404 foreach($subs as $user) {
405 if ($user['id'] == Env
::v('sid')) {
406 $page->changeTpl('listes/moderate_sub.tpl');
407 $page->assign('del_user', $user);
415 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
416 $page->assign_by_ref('subs', $subs);
417 $page->assign_by_ref('mails', $mails);
419 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
423 function handler_admin(&$page, $liste = null
)
427 if (is_null($liste)) {
431 $this->prepare_client($page);
433 $page->changeTpl('listes/admin.tpl');
435 if (Env
::has('add_member')) {
436 require_once('user.func.inc.php');
437 $members = get_users_forlife_list(Env
::v('add_member'));
438 $arr = $this->client
->mass_subscribe($liste, $members);
439 if (is_array($arr)) {
440 foreach($arr as $addr) {
441 $page->trig("{$addr[0]} inscrit.");
446 if (Env
::has('del_member')) {
447 if (strpos(Env
::v('del_member'), '@') === false
) {
448 $this->client
->mass_unsubscribe(
449 $liste, array(Env
::v('del_member').'@'.$globals->mail
->domain
));
451 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
453 pl_redirect('lists/admin/'.$liste);
456 if (Env
::has('add_owner')) {
457 require_once('user.func.inc.php');
458 $owners = get_users_forlife_list(Env
::v('add_owner'));
460 foreach ($owners as $login) {
461 if ($this->client
->add_owner($liste, $login)) {
462 $page->trig($alias." ajouté aux modérateurs.");
468 if (Env
::has('del_owner')) {
469 if (strpos(Env
::v('del_owner'), '@') === false
) {
470 $this->client
->del_owner($liste, Env
::v('del_owner').'@'.$globals->mail
->domain
);
472 $this->client
->del_owner($liste, Env
::v('del_owner'));
474 pl_redirect('lists/admin/'.$liste);
477 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
478 $membres = list_sort_members($mem, $tri_promo);
479 $moderos = list_sort_owners($own, $tri_promo);
481 $page->assign_by_ref('details', $det);
482 $page->assign_by_ref('members', $membres);
483 $page->assign_by_ref('owners', $moderos);
484 $page->assign('np_m', count($mem));
487 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
491 function handler_options(&$page, $liste = null
)
493 if (is_null($liste)) {
497 $this->prepare_client($page);
499 $page->changeTpl('listes/options.tpl');
501 if (Post
::has('submit')) {
503 $this->client
->set_bogo_level($liste, intval($values['bogo_level']));
504 switch($values['moderate']) {
506 $values['generic_nonmember_action'] = 0;
507 $values['default_member_moderation'] = 0;
510 $values['generic_nonmember_action'] = 1;
511 $values['default_member_moderation'] = 0;
514 $values['generic_nonmember_action'] = 1;
515 $values['default_member_moderation'] = 1;
518 unset($values['submit'], $values['bogo_level'], $values['moderate']);
519 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
520 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
521 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
522 if (isset($values['subject_prefix'])) {
523 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
525 $this->client
->set_owner_options($liste, $values);
526 } elseif (isvalid_email(Post
::v('atn_add'))) {
527 $this->client
->add_to_wl($liste, Post
::v('atn_add'));
528 } elseif (Get
::has('atn_del')) {
529 $this->client
->del_from_wl($liste, Get
::v('atn_del'));
530 pl_redirect('lists/options/'.$liste);
533 if (list($details,$options) = $this->client
->get_owner_options($liste)) {
534 $page->assign_by_ref('details', $details);
535 $page->assign_by_ref('options', $options);
536 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
538 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
542 function handler_delete(&$page, $liste = null
)
544 if (is_null($liste)) {
548 $this->prepare_client($page);
550 $page->changeTpl('listes/delete.tpl');
552 if (Post
::v('valid') == 'OUI'
553 && $this->client
->delete_list($liste, Post
::b('del_archive')))
555 foreach (array('', '-owner', '-admin', '-bounces') as $app) {
556 XDB
::execute("DELETE FROM aliases
557 WHERE type='liste' AND alias='{?}'",
560 $page->assign('deleted', true
);
561 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
562 $page->assign_by_ref('details', $details);
563 $page->assign_by_ref('options', $options);
564 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
566 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
570 function handler_soptions(&$page, $liste = null
)
572 if (is_null($liste)) {
576 $this->prepare_client($page);
578 $page->changeTpl('listes/soptions.tpl');
580 if (Post
::has('submit')) {
582 unset($values['submit']);
583 $values['advertised'] = empty($values['advertised']) ? false
: true
;
584 $values['archive'] = empty($values['archive']) ? false
: true
;
585 $this->client
->set_admin_options($liste, $values);
588 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
589 $page->assign_by_ref('details', $details);
590 $page->assign_by_ref('options', $options);
592 $page->kill("La liste n'existe pas");
596 function handler_check(&$page, $liste = null
)
598 if (is_null($liste)) {
602 $this->prepare_client($page);
604 $page->changeTpl('listes/check.tpl');
606 if (Post
::has('correct')) {
607 $this->client
->check_options($liste, true
);
610 if (list($details,$options) = $this->client
->check_options($liste)) {
611 $page->assign_by_ref('details', $details);
612 $page->assign_by_ref('options', $options);
614 $page->kill("La liste n'existe pas");
618 function handler_admin_all(&$page) {
619 $page->changeTpl('listes/admin_all.tpl');
620 $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
622 $client = new MMList(S
::v('uid'), S
::v('password'));
623 $listes = $client->get_all_lists();
624 $page->assign_by_ref('listes', $listes);