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 'lists.inc.php';
59 $this->client
=& lists_xmlrpc(S
::v('uid'), S
::v('password'));
60 return $globals->mail
->domain
;
63 function handler_lists(&$page)
65 $this->prepare_client($page);
67 $page->changeTpl('listes/index.tpl');
68 $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
71 if (Get
::has('del')) {
72 $this->client
->unsubscribe(Get
::v('del'));
75 if (Get
::has('add')) {
76 $this->client
->subscribe(Get
::v('add'));
79 if (Post
::has('promo_add')) {
80 $promo = Post
::i('promo_add');
81 if ($promo >= 1900 and $promo < 2100) {
82 $this->client
->subscribe("promo$promo");
84 $page->trig("promo incorrecte, il faut une promo sur 4 chiffres.");
87 $listes = $this->client
->get_lists();
88 $page->assign_by_ref('listes', $listes);
91 function handler_create(&$page)
93 $page->changeTpl('listes/create.tpl');
95 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
96 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
98 // click on validate button 'add_owner_sub' or type <enter>
99 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
100 require_once('user.func.inc.php');
101 // if we want to add an owner and then type <enter>, then both
102 // add_owner_sub and add_owner are filled.
103 if (Post
::v('add_owner') != "") {
104 if (($forlife = get_user_forlife(Post
::v('add_owner'))) !== false
) {
105 $owners [] = $forlife;
107 // if we want to add a member and then type <enter>, then
108 // add_owner_sub is filled, whereas add_owner is empty.
109 } else if (Post
::has('add_member')) {
110 if (($forlife = get_user_forlife(Post
::v('add_member'))) !== false
) {
111 $members[] = $forlife;
116 // click on validate button 'add_member_sub'
117 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
118 require_once('user.func.inc.php');
119 if (($forlife = get_user_forlife(Post
::v('add_member'))) !== false
) {
120 $members[] = $forlife;
124 ksort($owners); array_unique($owners);
125 ksort($members); array_unique($members);
127 $page->assign('owners', join(' ', $owners));
128 $page->assign('members', join(' ', $members));
130 if (!Post
::has('submit')) {
134 $liste = Post
::v('liste');
137 $page->trig('champs «addresse souhaitée» vide');
139 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
140 $page->trig('le nom de la liste ne doit contenir que des lettres, chiffres et tirets');
143 $res = XDB
::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
144 $n = $res->fetchOneCell();
147 $page->trig('cet alias est déjà pris');
150 if (!Post
::v(desc
)) {
151 $page->trig('le sujet est vide');
154 if (!count($owners)) {
155 $page->trig('pas de gestionnaire');
158 if (count($members)<4) {
159 $page->trig('pas assez de membres');
162 if (!$page->nb_errs()) {
163 $page->assign('created', true
);
164 require_once 'validations.inc.php';
165 $req = new ListeReq(S
::v('uid'), $liste,
166 Post
::v('desc'), Post
::i('advertise'),
167 Post
::i('modlevel'), Post
::i('inslevel'),
173 function handler_members(&$page, $liste = null
)
175 if (is_null($liste)) {
179 $this->prepare_client($page);
181 $page->changeTpl('listes/members.tpl');
183 if (Get
::has('del')) {
184 $this->client
->unsubscribe($liste);
185 pl_redirect('lists/members/'.$liste);
188 if (Get
::has('add')) {
189 $this->client
->subscribe($liste);
190 pl_redirect('lists/members/'.$liste);
193 $members = $this->client
->get_members($liste);
195 $tri_promo = !Env
::b('alpha');
197 if (list($det,$mem,$own) = $members) {
198 $membres = list_sort_members($mem, $tri_promo);
199 $moderos = list_sort_owners($own, $tri_promo);
201 $page->assign_by_ref('details', $det);
202 $page->assign_by_ref('members', $membres);
203 $page->assign_by_ref('owners', $moderos);
204 $page->assign('nb_m', count($mem));
206 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
210 function _get_list($offset, $limit)
213 list($total, $members) = $this->client
->get_members_limit($platal->argv
[1], $offset, $limit);
216 foreach ($members as $member) {
217 list($m) = explode('@',$member[1]);
218 $res = XDB
::query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom,
219 promo, a.alias AS forlife
220 FROM auth_user_md5 AS u
221 INNER JOIN aliases AS a ON u.user_id = a.id
222 WHERE a.alias = {?}", $m);
223 if ($tmp = $res->fetchOneAssoc()) {
224 $membres[$tmp['nom']] = $tmp;
226 $membres[$member[0]] = array('addr' => $member[0]);
229 return array($total, $membres);
232 function handler_trombi(&$page, $liste = null
)
234 if (is_null($liste)) {
238 $this->prepare_client($page);
240 $page->changeTpl('listes/trombi.tpl');
242 if (Get
::has('del')) {
243 $this->client
->unsubscribe($liste);
244 pl_redirect('lists/tromi/'.$liste);
246 if (Get
::has('add')) {
247 $this->client
->subscribe($liste);
248 pl_redirect('lists/tromi/'.$liste);
251 $owners = $this->client
->get_owners($liste);
253 if (is_array($owners)) {
254 require_once 'trombi.inc.php';
255 $moderos = list_sort_owners($owners[1]);
257 $page->assign_by_ref('details', $owners[0]);
258 $page->assign_by_ref('owners', $moderos);
260 $trombi = new Trombi(array(&$this, '_get_list'));
261 $page->assign('trombi', $trombi);
263 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
267 function handler_archives(&$page, $liste = null
)
271 if (is_null($liste)) {
275 $domain = $this->prepare_client($page);
277 $page->changeTpl('listes/archives.tpl');
279 $page->addCssLink('lists.archives.css');
280 if (list($det) = $this->client
->get_members($liste)) {
281 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
282 && !$det['own'] && ($det['sub'] < 2))
284 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
285 } elseif (Get
::has('file')) {
286 $file = Get
::v('file');
287 $rep = Get
::v('rep');
288 if (strstr('/', $file)!==false ||
!preg_match(',^\d+/\d+$,', $rep)) {
289 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
291 $page->assign('archives', $globals->lists
->spool
292 ."/{$domain}{$globals->lists->vhost_sep}$liste/$rep/$file");
296 foreach (glob($globals->lists
->spool
297 ."/{$domain}{$globals->lists->vhost_sep}$liste/*/*") as $rep)
299 if (preg_match(",/(\d*)/(\d*)$,", $rep, $matches)) {
300 $archs[intval($matches[1])][intval($matches[2])] = true
;
303 $page->assign('archs', $archs);
304 $page->assign('range', range(1,12));
307 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
311 function handler_moderate(&$page, $liste = null
)
313 if (is_null($liste)) {
317 $domain = $this->prepare_client($page);
319 $page->changeTpl('listes/moderate.tpl');
321 $page->register_modifier('qpd', 'quoted_printable_decode');
322 $page->register_modifier('hdc', 'list_header_decode');
324 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
325 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
326 pl_redirect('lists/moderate/'.$liste);
329 if (Post
::has('sdel')) { /* 2 = REJECT */
330 $this->client
->handle_request($liste,Post
::v('sdel'),2,Post
::v('reason'));
333 if (Env
::has('mid')) {
334 $mid = Env
::v('mid');
335 $mail = $this->client
->get_pending_mail($liste, $mid);
338 $prenom = S
::v('prenom');
341 if (Env
::has('mok')) {
342 $action = 1; /** 2 = ACCEPT **/
343 $subject = "Message accepté";
344 $append .= "a été accepté par $prenom $nom.\n";
345 } elseif (Env
::has('mno')) {
346 $action = 2; /** 2 = REJECT **/
347 $subject = "Message refusé";
348 $reason = Post
::v('reason');
349 $append = "a été refusé par $prenom $nom avec la raison :\n\n"
351 } elseif (Env
::has('mdel')) {
352 $action = 3; /** 3 = DISCARD **/
353 $subject = "Message supprimé";
354 $append = "a été supprimé par $prenom $nom.\n\n"
355 . "Rappel: il ne faut utiliser cette opération "
356 . "que dans le cas de spams ou de virus !\n";
359 if (isset($action) && $this->client
->handle_request($liste, $mid, $action, $reason)) {
360 $texte = "le message suivant :\n\n"
361 ." Auteur: {$mail['sender']}\n"
362 ." Sujet : « {$mail['subj']} »\n"
363 ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
365 require_once 'diogenes/diogenes.hermes.inc.php';
366 $mailer = new HermesMailer();
367 $mailer->addTo("$liste-owner@{$domain}");
368 $mailer->setFrom("$liste-bounces@{$domain}");
369 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
370 $mailer->setSubject($subject);
371 $mailer->setTxtBody(wordwrap($texte,72));
376 if (Get
::has('mid') && is_array($mail)) {
377 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
378 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
379 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
380 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
381 $msg = str_replace("%(listname)s", $liste, $msg);
382 $page->assign('msg', $msg);
384 $page->changeTpl('listes/moderate_mail.tpl');
385 $page->assign_by_ref('mail', $mail);
389 } elseif (Env
::has('sid')) {
391 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
392 foreach($subs as $user) {
393 if ($user['id'] == Env
::v('sid')) {
394 $page->changeTpl('listes/moderate_sub.tpl');
395 $page->assign('del_user', $user);
403 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
404 $page->assign_by_ref('subs', $subs);
405 $page->assign_by_ref('mails', $mails);
407 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
411 function handler_admin(&$page, $liste = null
)
415 if (is_null($liste)) {
419 $this->prepare_client($page);
421 $page->changeTpl('listes/admin.tpl');
423 if (Env
::has('add_member')) {
425 require_once('user.func.inc.php');
426 $members = explode(' ', Env
::v('add_member'));
427 if ($members) foreach ($members as $i => $alias) {
428 if (($login = get_user_forlife($alias)) !== false
) {;
429 $members[$i] = $login;
433 $arr = $this->client
->mass_subscribe($liste, $members);
434 if (is_array($arr)) {
435 foreach($arr as $addr) {
436 $page->trig("{$addr[0]} inscrit.");
441 if (Env
::has('del_member')) {
442 if (strpos(Env
::v('del_member'), '@') === false
) {
443 $this->client
->mass_unsubscribe(
444 $liste, array(Env
::v('del_member').'@'.$globals->mail
->domain
));
446 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
448 pl_redirect('lists/admin/'.$liste);
451 if (Env
::has('add_owner')) {
452 require_once('user.func.inc.php');
454 $owners = explode(' ', Env
::v('add_owner'));
456 if ($owners) foreach ($owners as $alias) {
457 if (($login = get_user_forlife($alias)) === false
) {;
461 if ($this->client
->add_owner($liste, $login)) {
462 $page->trig($alias." ajouté aux modérateurs.");
467 if (Env
::has('del_owner')) {
468 if (strpos(Env
::v('del_owner'), '@') === false
) {
469 $this->client
->del_owner($liste, Env
::v('del_owner').'@'.$globals->mail
->domain
);
471 $this->client
->del_owner($liste, Env
::v('del_owner'));
473 pl_redirect('lists/admin/'.$liste);
476 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');
621 require_once 'lists.inc.php';
623 $client =& lists_xmlrpc(S
::v('uid'), S
::v('password'));
624 $listes = $client->get_all_lists();
625 $page->assign_by_ref('listes',$listes);