X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Flists.php;h=d00bae975f5fb5559f8ce83b62f6f2ddeabf478d;hb=1dc71da137a384e771723b8a893539a7f5cc9fab;hp=c7aed33994dd14e43f5cfff2bfc88531d2758e02;hpb=1610f13adfdd3cadd5fba359973b8e04afc1e527;p=platal.git diff --git a/modules/lists.php b/modules/lists.php index c7aed33..d00bae9 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -1,6 +1,6 @@ $this->make_hook('lists', AUTH_MDP), - 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP, 'user', NO_AUTH), + 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP, 'user', NO_AUTH), 'lists/create' => $this->make_hook('create', AUTH_MDP), 'lists/members' => $this->make_hook('members', AUTH_COOKIE), + 'lists/csv' => $this->make_hook('csv', AUTH_COOKIE), 'lists/annu' => $this->make_hook('annu', AUTH_COOKIE), 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE), 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS), @@ -42,21 +43,15 @@ class ListsModule extends PLModule 'lists/soptions' => $this->make_hook('soptions', AUTH_MDP), 'lists/check' => $this->make_hook('check', AUTH_MDP), - 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP, 'admin'), + 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP, 'admin'), ); } - function on_subscribe($forlife, $uid, $promo, $password) - { - $this->prepare_client(null); - $this->client->subscribe("promo$promo"); - } - function prepare_client(&$page) { global $globals; - require_once dirname(__FILE__).'/lists/lists.inc.php'; + $this->load('lists.inc.php'); $this->client = new MMList(S::v('uid'), S::v('password')); return $globals->mail->domain; @@ -94,18 +89,22 @@ class ListsModule extends PLModule $page->changeTpl('lists/index.tpl'); $page->addJsLink('ajax.js'); - $page->setTitle('Polytechnique.org - Listes de diffusion'); + $page->setTitle('Listes de diffusion'); if (Get::has('del')) { + S::assert_xsrf_token(); $this->client->unsubscribe(Get::v('del')); pl_redirect('lists'); } if (Get::has('add')) { + S::assert_xsrf_token(); $this->client->subscribe(Get::v('add')); pl_redirect('lists'); } if (Post::has('promo_add')) { + S::assert_xsrf_token(); + $promo = Post::i('promo_add'); if ($promo >= 1900 and $promo < 2100) { $this->client->subscribe("promo$promo"); @@ -113,6 +112,7 @@ class ListsModule extends PLModule $page->trigSuccess("promo incorrecte, il faut une promo sur 4 chiffres."); } } + $listes = $this->client->get_lists(); $owner = array_filter($listes, 'filter_owner'); $listes = array_diff_key($listes, $owner); @@ -134,6 +134,8 @@ class ListsModule extends PLModule header('Content-Type: text/html; charset="UTF-8"'); $domain = $this->prepare_client($page); $page->changeTpl('lists/liste.inc.tpl', NO_SKIN); + S::assert_xsrf_token(); + if (Get::has('unsubscribe')) { $this->client->unsubscribe($list); } @@ -163,16 +165,28 @@ class ListsModule extends PLModule $page->changeTpl('lists/create.tpl'); + $user_promo = S::i('promo'); + $year = date('Y'); + $month = date('m'); + $young_promo = $very_young_promo = 0; + if ((($year > $user_promo) && ($month > 3)) && ($year < $user_promo + 5)) { + $young_promo = 1; + } + if ((($year > $user_promo) && ($month > 7)) && (($year < $user_promo + 1) && ($month < 8))) { + $very_young_promo = 1; + } + $page->assign('young_promo', $young_promo); + $page->assign('very_young_promo', $very_young_promo); + $owners = preg_split("/[\s]+/", Post::v('owners'), -1, PREG_SPLIT_NO_EMPTY); $members = preg_split("/[\s]+/", Post::v('members'), -1, PREG_SPLIT_NO_EMPTY); // click on validate button 'add_owner_sub' or type if (Post::has('add_owner_sub') && Post::has('add_owner')) { - require_once('user.func.inc.php'); // if we want to add an owner and then type , then both // add_owner_sub and add_owner are filled. - $oforlifes = get_users_forlife_list(Post::v('add_owner'), true); - $mforlifes = get_users_forlife_list(Post::v('add_member'), true); + $oforlifes = User::getBulkForlifeEmails(Post::v('add_owner'), true); + $mforlifes = User::getBulkForlifeEmails(Post::v('add_member'), true); if (!is_null($oforlifes)) { $owners = array_merge($owners, $oforlifes); } @@ -184,19 +198,18 @@ class ListsModule extends PLModule } // click on validate button 'add_member_sub' - require_once('user.func.inc.php'); if (Post::has('add_member_sub') && Post::has('add_member')) { - $forlifes = get_users_forlife_list(Post::v('add_member'), true); + $forlifes = User::getBulkForlifeEmails(Post::v('add_member'), true); if (!is_null($forlifes)) { $members = array_merge($members, $forlifes); } } if (Post::has('add_member_sub') && isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) { - $upload =& PlUpload::get($_FILES['add_member_file'], S::v('forlife'), 'list.addmember', true); + $upload =& PlUpload::get($_FILES['add_member_file'], S::user()->login(), 'list.addmember', true); if (!$upload) { $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier'); } else { - $forlifes = get_users_forlife_list($upload->getContents(), true); + $forlifes = User::getBulkForlifeEmails($upload->getContents(), true); if (!is_null($forlifes)) { $members = array_merge($members, $forlifes); } @@ -213,13 +226,15 @@ class ListsModule extends PLModule if (!Post::has('submit')) { return; + } else { + S::assert_xsrf_token(); } $asso = Post::v('asso'); $liste = Post::v('liste'); if (empty($liste)) { - $page->trigError('Le champ «adresse souhaitée» est vide.'); + $page->trigError('Le champ « adresse souhaitée Â» est vide.'); } if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) { $page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.'); @@ -230,7 +245,7 @@ class ListsModule extends PLModule $domain = $promo . '.' . $globals->mail->domain; if (($promo < 1921) || ($promo > date('Y'))) { - $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.'); + $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.'); } $new = $liste . '@' . $domain; @@ -258,7 +273,7 @@ class ListsModule extends PLModule $n = $res->fetchOneCell(); if ($n) { - $page->trigError('L\'«adresse souhaitée» est déjà prise.'); + $page->trigError("L'« adresse souhaitée Â» est déjà prise."); } if (!Post::v('desc')) { @@ -276,7 +291,7 @@ class ListsModule extends PLModule if (!$page->nb_errs()) { $page->assign('created', true); require_once 'validations.inc.php'; - $req = new ListeReq(S::v('uid'), $asso, $liste, $domain, + $req = new ListeReq(S::user(), $asso, $liste, $domain, Post::v('desc'), Post::i('advertise'), Post::i('modlevel'), Post::i('inslevel'), $owners, $members); @@ -295,11 +310,13 @@ class ListsModule extends PLModule $page->changeTpl('lists/members.tpl'); if (Get::has('del')) { + S::assert_xsrf_token(); $this->client->unsubscribe($liste); pl_redirect('lists/members/'.$liste); } if (Get::has('add')) { + S::assert_xsrf_token(); $this->client->subscribe($liste); pl_redirect('lists/members/'.$liste); } @@ -317,8 +334,27 @@ class ListsModule extends PLModule $page->assign_by_ref('owners', $moderos); $page->assign('nb_m', count($mem)); } else { - $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails"); + $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails."); + } + } + + function handler_csv(PlPage &$page, $liste = null) + { + if (is_null($liste)) { + return PL_NOT_FOUND; + } + $this->prepare_client($page); + $members = $this->client->get_members($liste); + $list = list_fetch_names(list_extract_members($members[1])); + header('Content-Type: text/x-csv; charset=utf-8;'); + header('Pragma: '); + header('Cache-Control: '); + + echo "email,nom,prenom,promo\n"; + foreach ($list as $member) { + echo @$member['email'] . ',' . @$member['nom'] . ',' . @$member['prenom'] . ',' . @$member['promo'] . "\n"; } + exit; } function handler_annu(&$page, $liste = null, $action = null, $subaction = null) @@ -330,17 +366,19 @@ class ListsModule extends PLModule $this->prepare_client($page); if (Get::has('del')) { + S::assert_xsrf_token(); $this->client->unsubscribe($liste); pl_redirect('lists/annu/'.$liste); } if (Get::has('add')) { + S::assert_xsrf_token(); $this->client->subscribe($liste); pl_redirect('lists/annu/'.$liste); } $owners = $this->client->get_owners($liste); if (!is_array($owners)) { - $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails"); + $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails."); } global $platal; @@ -353,7 +391,7 @@ class ListsModule extends PLModule $view = new ArraySet($users); $view->addMod('trombi', 'Trombinoscope', true, array('with_promo' => true)); if (empty($GLOBALS['IS_XNET_SITE'])) { - $view->addMod('minifiche', 'Minifiches', false); + $view->addMod('minifiche', 'Mini-fiches', false); } $view->addMod('geoloc', 'Planisphère'); $view->apply("lists/annu/$liste", $page, $action, $subaction); @@ -418,7 +456,7 @@ class ListsModule extends PLModule exit; } require_once('banana/ml.inc.php'); - $banana = new MLBanana(S::v('forlife'), Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2')); + $banana = new MLBanana(S::user(), Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2')); $banana->run(); } exit; @@ -454,6 +492,8 @@ class ListsModule extends PLModule $page->register_modifier('hdc', 'list_header_decode'); if (Env::has('sadd') || Env::has('sdel')) { + S::assert_xsrf_token(); + if (Env::has('sadd')) { /* 4 = SUBSCRIBE */ $sub = $this->client->get_pending_sub($liste, Env::v('sadd')); $this->client->handle_request($liste,Env::v('sadd'),4,''); @@ -484,6 +524,8 @@ class ListsModule extends PLModule } if (Post::has('moderate_mails') && Post::has('select_mails')) { + S::assert_xsrf_token(); + $mails = array_keys(Post::v('select_mails')); foreach($mails as $mail) { $this->moderate_mail($domain, $liste, $mail); @@ -504,6 +546,21 @@ class ListsModule extends PLModule $msg = str_replace("%(listname)s", $liste, $msg); $page->assign('msg', $msg); return; + } elseif (Get::has('mid') && Env::has('mok')) { + $page->changeTpl('lists/moderate_mail.tpl'); + require_once('banana/moderate.inc.php'); + $params = array('listname' => $liste, 'domain' => $domain, + 'artid' => Get::i('mid'), 'part' => Get::v('part'), 'action' => Get::v('action')); + $params['client'] = $this->client; + run_banana($page, 'ModerationBanana', $params); + + $msg = file_get_contents('/etc/mailman/fr/accept.txt'); + $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg); + $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg); + $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg); + $msg = str_replace("%(listname)s", $liste, $msg); + $page->assign('msg', $msg); + return; } $mail = $this->moderate_mail($domain, $liste, Env::i('mid')); @@ -532,7 +589,7 @@ class ListsModule extends PLModule $page->assign_by_ref('subs', $subs); $page->assign_by_ref('mails', $mails); } else { - $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer"); + $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer."); } } @@ -550,7 +607,7 @@ class ListsModule extends PLModule } else { list($name, $dom) = @explode('@', $login); if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) { - _default_user_callback($login); + User::_default_user_callback($login); } } } @@ -568,6 +625,8 @@ class ListsModule extends PLModule $page->changeTpl('lists/admin.tpl'); if (Env::has('send_mark')) { + S::assert_xsrf_token(); + $actions = Env::v('mk_action'); $uids = Env::v('mk_uid'); $mails = Env::v('mk_email'); @@ -598,10 +657,11 @@ class ListsModule extends PLModule } if (Env::has('add_member')) { - require_once('user.func.inc.php'); - $members = get_users_forlife_list(Env::v('add_member'), - false, - array('ListsModule', 'no_login_callback')); + S::assert_xsrf_token(); + + $members = User::getBulkForlifeEmails(Env::v('add_member'), + false, + array('ListsModule', 'no_login_callback')); $arr = $this->client->mass_subscribe($liste, $members); if (is_array($arr)) { foreach($arr as $addr) { @@ -611,13 +671,15 @@ class ListsModule extends PLModule } if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) { - $upload =& PlUpload::get($_FILES['add_member_file'], S::v('forlife'), 'list.addmember', true); + S::assert_xsrf_token(); + + $upload =& PlUpload::get($_FILES['add_member_file'], S::user()->login(), 'list.addmember', true); if (!$upload) { $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier'); } else { - $members = get_users_forlife_list($upload->getContents(), - false, - array('ListsModule', 'no_login_callback')); + $members = User::getBulkForlifeEmails($upload->getContents(), + false, + array('ListsModule', 'no_login_callback')); $arr = $this->client->mass_subscribe($liste, $members); if (is_array($arr)) { foreach($arr as $addr) { @@ -628,6 +690,8 @@ class ListsModule extends PLModule } if (Env::has('del_member')) { + S::assert_xsrf_token(); + if (strpos(Env::v('del_member'), '@') === false) { $this->client->mass_unsubscribe( $liste, array(Env::v('del_member').'@'.$globals->mail->domain)); @@ -638,18 +702,21 @@ class ListsModule extends PLModule } if (Env::has('add_owner')) { - require_once('user.func.inc.php'); - $owners = get_users_forlife_list(Env::v('add_owner'), false, array('ListsModule', 'no_login_callback')); + S::assert_xsrf_token(); + + $owners = User::getBulkForlifeEmails(Env::v('add_owner'), false, array('ListsModule', 'no_login_callback')); if ($owners) { foreach ($owners as $login) { if ($this->client->add_owner($liste, $login)) { - $page->trigSuccess($alias." ajouté aux modérateurs."); + $page->trigSuccess($login ." ajouté aux modérateurs."); } } } } if (Env::has('del_owner')) { + S::assert_xsrf_token(); + if (strpos(Env::v('del_owner'), '@') === false) { $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain); } else { @@ -673,8 +740,8 @@ class ListsModule extends PLModule } else { $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.
" - ." Si tu penses qu'il s'agit d'une erreur, " - ."contact le support"); + . " Si tu penses qu'il s'agit d'une erreur, " + . "contact le support."); } } @@ -689,6 +756,8 @@ class ListsModule extends PLModule $page->changeTpl('lists/options.tpl'); if (Post::has('submit')) { + S::assert_xsrf_token(); + $values = $_POST; $values = array_map('utf8_decode', $values); $spamlevel = intval($values['bogo_level']); @@ -724,8 +793,10 @@ class ListsModule extends PLModule } $this->client->set_owner_options($liste, $values); } elseif (isvalid_email(Post::v('atn_add'))) { + S::assert_xsrf_token(); $this->client->add_to_wl($liste, Post::v('atn_add')); } elseif (Get::has('atn_del')) { + S::assert_xsrf_token(); $this->client->del_from_wl($liste, Get::v('atn_del')); pl_redirect('lists/options/'.$liste); } @@ -761,6 +832,8 @@ class ListsModule extends PLModule $page->changeTpl('lists/delete.tpl'); if (Post::v('valid') == 'OUI') { + S::assert_xsrf_token(); + if ($this->client->delete_list($liste, Post::b('del_archive'))) { foreach (array('', '-owner', '-admin', '-bounces', '-unsubscribe') as $app) { XDB::execute("DELETE FROM $table @@ -768,17 +841,21 @@ class ListsModule extends PLModule $type, $liste.$app.$domain); } $page->assign('deleted', true); + $page->trigSuccess('La liste a été détruite !'); } else { $page->kill('Une erreur est survenue lors de la suppression de la liste.
' . 'Contact les administrateurs du site pour régler le problème : ' - . 'support@polytechnique.org'); + . 'support@polytechnique.org.'); } } elseif (list($details,$options) = $this->client->get_owner_options($liste)) { + if (!$details['own']) { + $page->trigWarning('Tu n\'es pas administrateur de la liste, mais du site.'); + } $page->assign_by_ref('details', $details); $page->assign_by_ref('options', $options); $page->assign('bogo_level', $this->client->get_bogo_level($liste)); } else { - $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer"); + $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer."); } } @@ -793,6 +870,8 @@ class ListsModule extends PLModule $page->changeTpl('lists/soptions.tpl'); if (Post::has('submit')) { + S::assert_xsrf_token(); + $values = $_POST; $values = array_map('utf8_decode', $values); unset($values['submit']); @@ -805,7 +884,7 @@ class ListsModule extends PLModule $page->assign_by_ref('details', $details); $page->assign_by_ref('options', $options); } else { - $page->kill("La liste n'existe pas"); + $page->kill("La liste n'existe pas."); } } @@ -820,6 +899,7 @@ class ListsModule extends PLModule $page->changeTpl('lists/check.tpl'); if (Post::has('correct')) { + S::assert_xsrf_token(); $this->client->check_options($liste, true); } @@ -827,13 +907,13 @@ class ListsModule extends PLModule $page->assign_by_ref('details', $details); $page->assign_by_ref('options', $options); } else { - $page->kill("La liste n'existe pas"); + $page->kill("La liste n'existe pas."); } } function handler_admin_all(&$page) { $page->changeTpl('lists/admin_all.tpl'); - $page->setTitle('Polytechnique.org - Administration - Mailing lists'); + $page->setTitle('Administration - Mailing lists'); $client = new MMList(S::v('uid'), S::v('password')); $listes = $client->get_all_lists();