6435b4d44e5ca6acd6a6bd4b03ced727fdc8739c
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(Session
::getInt('uid'), Session
::get('password'));
53 function handler_lists(&$page)
57 $this->prepare_client($page);
59 $page->changeTpl('listes/index.tpl');
60 $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
63 if (Get
::has('del')) {
64 $this->client
->unsubscribe(Get
::get('del'));
67 if (Get
::has('add')) {
68 $this->client
->subscribe(Get
::get('add'));
71 if (Post
::has('promo_add')) {
72 $promo = Post
::getInt('promo_add');
73 if ($promo >= 1900 and $promo < 2100) {
74 $this->client
->subscribe("promo$promo");
76 $page->trig("promo incorrecte, il faut une promo sur 4 chiffres.");
79 $listes = $this->client
->get_lists();
80 $page->assign_by_ref('listes', $listes);
83 function handler_create(&$page)
86 $page->changeTpl('listes/create.tpl');
88 $owners = preg_split("/[\s]+/", Post
::get('owners'), -1, PREG_SPLIT_NO_EMPTY
);
89 $members = preg_split("/[\s]+/", Post
::get('members'), -1, PREG_SPLIT_NO_EMPTY
);
91 // click on validate button 'add_owner_sub' or type <enter>
92 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
93 require_once('user.func.inc.php');
94 // if we want to add an owner and then type <enter>, then both
95 // add_owner_sub and add_owner are filled.
96 if (Post
::get('add_owner') != "") {
97 if (($forlife = get_user_forlife(Post
::get('add_owner'))) !== false
) {
98 $owners [] = $forlife;
100 // if we want to add a member and then type <enter>, then
101 // add_owner_sub is filled, whereas add_owner is empty.
102 } else if (Post
::has('add_member')) {
103 if (($forlife = get_user_forlife(Post
::get('add_member'))) !== false
) {
104 $members[] = $forlife;
109 // click on validate button 'add_member_sub'
110 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
111 require_once('user.func.inc.php');
112 if (($forlife = get_user_forlife(Post
::get('add_member'))) !== false
) {
113 $members[] = $forlife;
117 ksort($owners); array_unique($owners);
118 ksort($members); array_unique($members);
120 $page->assign('owners', join(' ', $owners));
121 $page->assign('members', join(' ', $members));
123 if (!Post
::has('submit')) {
127 $liste = Post
::get('liste');
130 $page->trig('champs «addresse souhaitée» vide');
132 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
133 $page->trig('le nom de la liste ne doit contenir que des lettres, chiffres et tirets');
136 $res = $globals->xdb
->query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
137 $n = $res->fetchOneCell();
140 $page->trig('cet alias est déjà pris');
143 if (!Post
::get(desc
)) {
144 $page->trig('le sujet est vide');
147 if (!count($owners)) {
148 $page->trig('pas de gestionnaire');
151 if (count($members)<4) {
152 $page->trig('pas assez de membres');
155 if (!$page->nb_errs()) {
156 $page->assign('created', true
);
157 require_once 'validations.inc.php';
158 $req = new ListeReq(Session
::getInt('uid'), $liste,
159 Post
::get('desc'), Post
::getInt('advertise'),
160 Post
::getInt('modlevel'), Post
::getInt('inslevel'),
166 function handler_members(&$page, $liste = null
)
170 if (is_null($liste)) {
174 $this->prepare_client($page);
176 $page->changeTpl('listes/members.tpl');
178 if (Get
::has('del')) {
179 $this->client
->unsubscribe($liste);
183 if (Get
::has('add')) {
184 $this->client
->subscribe($liste);
188 $members = $this->client
->get_members($liste);
190 $tri_promo = !Env
::getBool('alpha');
192 if (list($det,$mem,$own) = $members) {
193 $membres = list_sort_members($mem, $tri_promo);
194 $moderos = list_sort_owners($own, $tri_promo);
196 $page->assign_by_ref('details', $det);
197 $page->assign_by_ref('members', $membres);
198 $page->assign_by_ref('owners', $moderos);
199 $page->assign('nb_m', count($mem));
201 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
205 function _get_list($offset, $limit)
207 global $globals, $platal;
208 list($total, $members) = $this->client
->get_members_limit($platal->argv
[1], $offset, $limit);
211 foreach ($members as $member) {
212 list($m) = explode('@',$member[1]);
213 $res = $globals->xdb
->query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom,
214 promo, a.alias AS forlife
215 FROM auth_user_md5 AS u
216 INNER JOIN aliases AS a ON u.user_id = a.id
217 WHERE a.alias = {?}", $m);
218 if ($tmp = $res->fetchOneAssoc()) {
219 $membres[$tmp['nom']] = $tmp;
221 $membres[$member[0]] = array('addr' => $member[0]);
224 return array($total, $membres);
227 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);
243 if (Get
::has('add')) {
244 $this->client
->subscribe($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
::get('file');
284 $rep = Get
::get('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
)
312 if (is_null($liste)) {
316 $this->prepare_client($page);
318 $page->changeTpl('listes/moderate.tpl');
320 $page->register_modifier('qpd', 'quoted_printable_decode');
322 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
323 $this->client
->handle_request($liste,Env
::get('sadd'),4,'');
327 if (Post
::has('sdel')) { /* 2 = REJECT */
328 $this->client
->handle_request($liste,Post
::get('sdel'),2,Post
::get('reason'));
331 if (Env
::has('mid')) {
332 $mid = Env
::get('mid');
333 $mail = $this->client
->get_pending_mail($liste, $mid);
336 $prenom = Session
::get('prenom');
337 $nom = Session
::get('nom');
339 if (Env
::has('mok')) {
340 $action = 1; /** 2 = ACCEPT **/
341 $subject = "Message accepté";
342 $append .= "a été accepté par $prenom $nom.\n";
343 } elseif (Env
::has('mno')) {
344 $action = 2; /** 2 = REJECT **/
345 $subject = "Message refusé";
346 $reason = Post
::get('reason');
347 $append = "a été refusé par $prenom $nom avec la raison :\n\n"
349 } elseif (Env
::has('mdel')) {
350 $action = 3; /** 3 = DISCARD **/
351 $subject = "Message supprimé";
352 $append = "a été supprimé par $prenom $nom.\n\n"
353 . "Rappel: il ne faut utiliser cette opération "
354 . "que dans le cas de spams ou de virus !\n";
357 if (isset($action) && $this->client
->handle_request($liste, $mid, $action, $reason)) {
358 $texte = "le message suivant :\n\n"
359 ." Auteur: {$mail['sender']}\n"
360 ." Sujet : « {$mail['subj']} »\n"
361 ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
363 require_once 'diogenes/diogenes.hermes.inc.php';
364 $mailer = new HermesMailer();
365 $mailer->addTo("$liste-owner@{$domain}");
366 $mailer->setFrom("$liste-bounces@{$domain}");
367 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
368 $mailer->setSubject($subject);
369 $mailer->setTxtBody(wordwrap($texte,72));
374 if (Get
::has('mid') && is_array($mail)) {
375 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
376 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
377 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
378 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
379 $msg = str_replace("%(listname)s", $liste, $msg);
380 $page->assign('msg', $msg);
382 $page->changeTpl('listes/moderate_mail.tpl');
383 $page->assign_by_ref('mail', $mail);
387 } elseif (Env
::has('sid')) {
389 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
390 foreach($subs as $user) {
391 if ($user['id'] == Env
::get('sid')) {
392 $page->changeTpl('listes/moderate_sub.tpl');
393 $page->assign('del_user',$user);
401 if (list($subs,$mails) = $this->client
->get_pending_ops($liste)) {
402 $page->assign_by_ref('subs', $subs);
403 $page->assign_by_ref('mails', $mails);
405 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
409 function handler_admin(&$page, $liste = null
)
413 if (is_null($liste)) {
417 $this->prepare_client($page);
419 $page->changeTpl('listes/admin.tpl');
421 if (Env
::has('add_member')) {
423 require_once('user.func.inc.php');
424 $members = explode(' ', Env
::get('add_member'));
425 if ($members) foreach ($members as $i => $alias) {
426 if (($login = get_user_forlife($alias)) !== false
) {;
427 $members[$i] = $login;
431 $arr = $this->client
->mass_subscribe($liste, $members);
432 if (is_array($arr)) {
433 foreach($arr as $addr) {
434 $page->trig("{$addr[0]} inscrit.");
439 if (Env
::has('del_member')) {
440 if (strpos(Env
::get('del_member'), '@') === false
) {
441 $this->client
->mass_unsubscribe(
442 $liste, array(Env
::get('del_member').'@'.$globals->mail
->domain
));
444 $this->client
->mass_unsubscribe($liste, array(Env
::get('del_member')));
449 if (Env
::has('add_owner')) {
450 require_once('user.func.inc.php');
452 $owners = explode(' ', Env
::get('add_owner'));
454 if ($owners) foreach ($owners as $alias) {
455 if (($login = get_user_forlife($alias)) === false
) {;
459 if ($this->client
->add_owner($liste, $login)) {
460 $page->trig($alias." ajouté aux modérateurs.");
465 if (Env
::has('del_owner')) {
466 if (strpos(Env
::get('del_owner'), '@') === false
) {
467 $this->client
->del_owner($liste, Env
::get('del_owner').'@'.$globals->mail
->domain
);
469 $this->client
->del_owner($liste, Env
::get('del_owner'));
474 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
476 $membres = list_sort_members($mem, $tri_promo);
477 $moderos = list_sort_owners($own, $tri_promo);
479 $page->assign_by_ref('details', $det);
480 $page->assign_by_ref('members', $membres);
481 $page->assign_by_ref('owners', $moderos);
482 $page->assign('np_m', count($mem));
485 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
489 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
::get('atn_add'))) {
527 $this->client
->add_to_wl($liste, Post
::get('atn_add'));
528 } elseif (Get
::has('atn_del')) {
529 $this->client
->del_from_wl($liste, Get
::get('atn_del'));
530 redirect("{$_SERVER['PHP_SELF']}?liste=$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
)
546 if (is_null($liste)) {
550 $this->prepare_client($page);
552 $page->changeTpl('listes/delete.tpl');
554 if (Post
::get('valid') == 'OUI'
555 && $this->client
->delete_list($liste, Post
::getBool('del_archive')))
557 foreach (array('', '-owner', '-admin', '-bounces') as $app) {
558 $globals->xdb
->execute("DELETE FROM aliases
559 WHERE type='liste' AND alias='{?}'",
562 $page->assign('deleted', true
);
563 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
564 $page->assign_by_ref('details', $details);
565 $page->assign_by_ref('options', $options);
566 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
568 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
572 function handler_soptions(&$page, $liste = null
)
576 if (is_null($liste)) {
580 $this->prepare_client($page);
582 $page->changeTpl('listes/soptions.tpl');
584 if (Post
::has('submit')) {
586 unset($values['submit']);
587 $values['advertised'] = empty($values['advertised']) ? false
: true
;
588 $values['archive'] = empty($values['archive']) ? false
: true
;
589 $this->client
->set_admin_options($liste, $values);
592 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
593 $page->assign_by_ref('details', $details);
594 $page->assign_by_ref('options', $options);
596 $page->kill("La liste n'existe pas");
600 function handler_check(&$page, $liste = null
)
604 if (is_null($liste)) {
608 $this->prepare_client($page);
610 $page->changeTpl('listes/check.tpl');
612 if (Post
::has('correct')) {
613 $this->client
->check_options($liste, true
);
616 if (list($details,$options) = $this->client
->check_options($liste)) {
617 $page->assign_by_ref('details', $details);
618 $page->assign_by_ref('options', $options);
620 $page->kill("La liste n'existe pas");