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
),
46 function prepare_client(&$page)
48 require_once 'lists.inc.php';
50 $this->client
=& lists_xmlrpc(S
::v('uid'), S
::v('password'));
53 function handler_lists(&$page)
55 $this->prepare_client($page);
57 $page->changeTpl('listes/index.tpl');
58 $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
61 if (Get
::has('del')) {
62 $this->client
->unsubscribe(Get
::v('del'));
65 if (Get
::has('add')) {
66 $this->client
->subscribe(Get
::v('add'));
69 if (Post
::has('promo_add')) {
70 $promo = Post
::i('promo_add');
71 if ($promo >= 1900 and $promo < 2100) {
72 $this->client
->subscribe("promo$promo");
74 $page->trig("promo incorrecte, il faut une promo sur 4 chiffres.");
77 $listes = $this->client
->get_lists();
78 $page->assign_by_ref('listes', $listes);
81 function handler_create(&$page)
83 $page->changeTpl('listes/create.tpl');
85 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
86 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
88 // click on validate button 'add_owner_sub' or type <enter>
89 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
90 require_once('user.func.inc.php');
91 // if we want to add an owner and then type <enter>, then both
92 // add_owner_sub and add_owner are filled.
93 if (Post
::v('add_owner') != "") {
94 if (($forlife = get_user_forlife(Post
::v('add_owner'))) !== false
) {
95 $owners [] = $forlife;
97 // if we want to add a member and then type <enter>, then
98 // add_owner_sub is filled, whereas add_owner is empty.
99 } else if (Post
::has('add_member')) {
100 if (($forlife = get_user_forlife(Post
::v('add_member'))) !== false
) {
101 $members[] = $forlife;
106 // click on validate button 'add_member_sub'
107 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
108 require_once('user.func.inc.php');
109 if (($forlife = get_user_forlife(Post
::v('add_member'))) !== false
) {
110 $members[] = $forlife;
114 ksort($owners); array_unique($owners);
115 ksort($members); array_unique($members);
117 $page->assign('owners', join(' ', $owners));
118 $page->assign('members', join(' ', $members));
120 if (!Post
::has('submit')) {
124 $liste = Post
::v('liste');
127 $page->trig('champs «addresse souhaitée» vide');
129 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
130 $page->trig('le nom de la liste ne doit contenir que des lettres, chiffres et tirets');
133 $res = XDB
::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
134 $n = $res->fetchOneCell();
137 $page->trig('cet alias est déjà pris');
140 if (!Post
::v(desc
)) {
141 $page->trig('le sujet est vide');
144 if (!count($owners)) {
145 $page->trig('pas de gestionnaire');
148 if (count($members)<4) {
149 $page->trig('pas assez de membres');
152 if (!$page->nb_errs()) {
153 $page->assign('created', true
);
154 require_once 'validations.inc.php';
155 $req = new ListeReq(S
::v('uid'), $liste,
156 Post
::v('desc'), Post
::i('advertise'),
157 Post
::i('modlevel'), Post
::i('inslevel'),
163 function handler_members(&$page, $liste = null
)
165 if (is_null($liste)) {
169 $this->prepare_client($page);
171 $page->changeTpl('listes/members.tpl');
173 if (Get
::has('del')) {
174 $this->client
->unsubscribe($liste);
175 pl_redirect('lists/members/'.$liste);
178 if (Get
::has('add')) {
179 $this->client
->subscribe($liste);
180 pl_redirect('lists/members/'.$liste);
183 $members = $this->client
->get_members($liste);
185 $tri_promo = !Env
::b('alpha');
187 if (list($det,$mem,$own) = $members) {
188 $membres = list_sort_members($mem, $tri_promo);
189 $moderos = list_sort_owners($own, $tri_promo);
191 $page->assign_by_ref('details', $det);
192 $page->assign_by_ref('members', $membres);
193 $page->assign_by_ref('owners', $moderos);
194 $page->assign('nb_m', count($mem));
196 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
200 function _get_list($offset, $limit)
203 list($total, $members) = $this->client
->get_members_limit($platal->argv
[1], $offset, $limit);
206 foreach ($members as $member) {
207 list($m) = explode('@',$member[1]);
208 $res = XDB
::query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom,
209 promo, a.alias AS forlife
210 FROM auth_user_md5 AS u
211 INNER JOIN aliases AS a ON u.user_id = a.id
212 WHERE a.alias = {?}", $m);
213 if ($tmp = $res->fetchOneAssoc()) {
214 $membres[$tmp['nom']] = $tmp;
216 $membres[$member[0]] = array('addr' => $member[0]);
219 return array($total, $membres);
222 function handler_trombi(&$page, $liste = null
)
224 if (is_null($liste)) {
228 $this->prepare_client($page);
230 $page->changeTpl('listes/trombi.tpl');
232 if (Get
::has('del')) {
233 $this->client
->unsubscribe($liste);
234 pl_redirect('lists/tromi/'.$liste);
236 if (Get
::has('add')) {
237 $this->client
->subscribe($liste);
238 pl_redirect('lists/tromi/'.$liste);
241 $owners = $this->client
->get_owners($liste);
243 if (is_array($owners)) {
244 require_once 'trombi.inc.php';
245 $moderos = list_sort_owners($owners[1]);
247 $page->assign_by_ref('details', $owners[0]);
248 $page->assign_by_ref('owners', $moderos);
250 $trombi = new Trombi(array(&$this, '_get_list'));
251 $page->assign('trombi', $trombi);
253 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
257 function handler_archives(&$page, $liste = null
)
261 if (is_null($liste)) {
265 $this->prepare_client($page);
267 $page->changeTpl('listes/archives.tpl');
269 $page->addCssLink('css/lists.archives.css');
270 if (list($det) = $this->client
->get_members($liste)) {
271 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
272 && !$det['own'] && ($det['sub'] < 2))
274 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
275 } elseif (Get
::has('file')) {
276 $file = Get
::v('file');
277 $rep = Get
::v('rep');
278 if (strstr('/', $file)!==false ||
!preg_match(',^\d+/\d+$,', $rep)) {
279 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
281 $page->assign('archives', $globals->lists
->spool
282 ."/{$domain}{$globals->lists->vhost_sep}$liste/$rep/$file");
286 foreach (glob($globals->lists
->spool
287 ."/{$domain}{$globals->lists->vhost_sep}$liste/*/*") as $rep)
289 if (preg_match(",/(\d*)/(\d*)$,", $rep, $matches)) {
290 $archs[intval($matches[1])][intval($matches[2])] = true
;
293 $page->assign('archs', $archs);
294 $page->assign('range', range(1,12));
297 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
301 function handler_moderate(&$page, $liste = null
)
303 if (is_null($liste)) {
307 $this->prepare_client($page);
309 $page->changeTpl('listes/moderate.tpl');
311 $page->register_modifier('qpd', 'quoted_printable_decode');
313 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
314 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
315 pl_redirect('lists/moderate/'.$liste);
318 if (Post
::has('sdel')) { /* 2 = REJECT */
319 $this->client
->handle_request($liste,Post
::v('sdel'),2,Post
::v('reason'));
322 if (Env
::has('mid')) {
323 $mid = Env
::v('mid');
324 $mail = $this->client
->get_pending_mail($liste, $mid);
327 $prenom = S
::v('prenom');
330 if (Env
::has('mok')) {
331 $action = 1; /** 2 = ACCEPT **/
332 $subject = "Message accepté";
333 $append .= "a été accepté par $prenom $nom.\n";
334 } elseif (Env
::has('mno')) {
335 $action = 2; /** 2 = REJECT **/
336 $subject = "Message refusé";
337 $reason = Post
::v('reason');
338 $append = "a été refusé par $prenom $nom avec la raison :\n\n"
340 } elseif (Env
::has('mdel')) {
341 $action = 3; /** 3 = DISCARD **/
342 $subject = "Message supprimé";
343 $append = "a été supprimé par $prenom $nom.\n\n"
344 . "Rappel: il ne faut utiliser cette opération "
345 . "que dans le cas de spams ou de virus !\n";
348 if (isset($action) && $this->client
->handle_request($liste, $mid, $action, $reason)) {
349 $texte = "le message suivant :\n\n"
350 ." Auteur: {$mail['sender']}\n"
351 ." Sujet : « {$mail['subj']} »\n"
352 ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
354 require_once 'diogenes/diogenes.hermes.inc.php';
355 $mailer = new HermesMailer();
356 $mailer->addTo("$liste-owner@{$domain}");
357 $mailer->setFrom("$liste-bounces@{$domain}");
358 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
359 $mailer->setSubject($subject);
360 $mailer->setTxtBody(wordwrap($texte,72));
365 if (Get
::has('mid') && is_array($mail)) {
366 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
367 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
368 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
369 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
370 $msg = str_replace("%(listname)s", $liste, $msg);
371 $page->assign('msg', $msg);
373 $page->changeTpl('listes/moderate_mail.tpl');
374 $page->assign_by_ref('mail', $mail);
378 } elseif (Env
::has('sid')) {
380 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
381 foreach($subs as $user) {
382 if ($user['id'] == Env
::v('sid')) {
383 $page->changeTpl('listes/moderate_sub.tpl');
384 $page->assign('del_user', $user);
392 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
393 $page->assign_by_ref('subs', $subs);
394 $page->assign_by_ref('mails', $mails);
396 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
400 function handler_admin(&$page, $liste = null
)
404 if (is_null($liste)) {
408 $this->prepare_client($page);
410 $page->changeTpl('listes/admin.tpl');
412 if (Env
::has('add_member')) {
414 require_once('user.func.inc.php');
415 $members = explode(' ', Env
::v('add_member'));
416 if ($members) foreach ($members as $i => $alias) {
417 if (($login = get_user_forlife($alias)) !== false
) {;
418 $members[$i] = $login;
422 $arr = $this->client
->mass_subscribe($liste, $members);
423 if (is_array($arr)) {
424 foreach($arr as $addr) {
425 $page->trig("{$addr[0]} inscrit.");
430 if (Env
::has('del_member')) {
431 if (strpos(Env
::v('del_member'), '@') === false
) {
432 $this->client
->mass_unsubscribe(
433 $liste, array(Env
::v('del_member').'@'.$globals->mail
->domain
));
435 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
437 pl_redirect('lists/admin/'.$liste);
440 if (Env
::has('add_owner')) {
441 require_once('user.func.inc.php');
443 $owners = explode(' ', Env
::v('add_owner'));
445 if ($owners) foreach ($owners as $alias) {
446 if (($login = get_user_forlife($alias)) === false
) {;
450 if ($this->client
->add_owner($liste, $login)) {
451 $page->trig($alias." ajouté aux modérateurs.");
456 if (Env
::has('del_owner')) {
457 if (strpos(Env
::v('del_owner'), '@') === false
) {
458 $this->client
->del_owner($liste, Env
::v('del_owner').'@'.$globals->mail
->domain
);
460 $this->client
->del_owner($liste, Env
::v('del_owner'));
462 pl_redirect('lists/admin/'.$liste);
465 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
467 $membres = list_sort_members($mem, $tri_promo);
468 $moderos = list_sort_owners($own, $tri_promo);
470 $page->assign_by_ref('details', $det);
471 $page->assign_by_ref('members', $membres);
472 $page->assign_by_ref('owners', $moderos);
473 $page->assign('np_m', count($mem));
476 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
480 function handler_options(&$page, $liste = null
)
482 if (is_null($liste)) {
486 $this->prepare_client($page);
488 $page->changeTpl('listes/options.tpl');
490 if (Post
::has('submit')) {
492 $this->client
->set_bogo_level($liste, intval($values['bogo_level']));
493 switch($values['moderate']) {
495 $values['generic_nonmember_action'] = 0;
496 $values['default_member_moderation'] = 0;
499 $values['generic_nonmember_action'] = 1;
500 $values['default_member_moderation'] = 0;
503 $values['generic_nonmember_action'] = 1;
504 $values['default_member_moderation'] = 1;
507 unset($values['submit'], $values['bogo_level'], $values['moderate']);
508 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
509 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
510 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
511 if (isset($values['subject_prefix'])) {
512 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
514 $this->client
->set_owner_options($liste, $values);
515 } elseif (isvalid_email(Post
::v('atn_add'))) {
516 $this->client
->add_to_wl($liste, Post
::v('atn_add'));
517 } elseif (Get
::has('atn_del')) {
518 $this->client
->del_from_wl($liste, Get
::v('atn_del'));
519 pl_redirect('lists/options/'.$liste);
522 if (list($details,$options) = $this->client
->get_owner_options($liste)) {
523 $page->assign_by_ref('details', $details);
524 $page->assign_by_ref('options', $options);
525 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
527 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
531 function handler_delete(&$page, $liste = null
)
533 if (is_null($liste)) {
537 $this->prepare_client($page);
539 $page->changeTpl('listes/delete.tpl');
541 if (Post
::v('valid') == 'OUI'
542 && $this->client
->delete_list($liste, Post
::b('del_archive')))
544 foreach (array('', '-owner', '-admin', '-bounces') as $app) {
545 XDB
::execute("DELETE FROM aliases
546 WHERE type='liste' AND alias='{?}'",
549 $page->assign('deleted', true
);
550 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
551 $page->assign_by_ref('details', $details);
552 $page->assign_by_ref('options', $options);
553 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
555 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
559 function handler_soptions(&$page, $liste = null
)
561 if (is_null($liste)) {
565 $this->prepare_client($page);
567 $page->changeTpl('listes/soptions.tpl');
569 if (Post
::has('submit')) {
571 unset($values['submit']);
572 $values['advertised'] = empty($values['advertised']) ? false
: true
;
573 $values['archive'] = empty($values['archive']) ? false
: true
;
574 $this->client
->set_admin_options($liste, $values);
577 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
578 $page->assign_by_ref('details', $details);
579 $page->assign_by_ref('options', $options);
581 $page->kill("La liste n'existe pas");
585 function handler_check(&$page, $liste = null
)
587 if (is_null($liste)) {
591 $this->prepare_client($page);
593 $page->changeTpl('listes/check.tpl');
595 if (Post
::has('correct')) {
596 $this->client
->check_options($liste, true
);
599 if (list($details,$options) = $this->client
->check_options($liste)) {
600 $page->assign_by_ref('details', $details);
601 $page->assign_by_ref('options', $options);
603 $page->kill("La liste n'existe pas");