Commit | Line | Data |
---|---|---|
81b5b746 | 1 | <?php |
2 | /*************************************************************************** | |
5ddeb07c | 3 | * Copyright (C) 2003-2007 Polytechnique.org * |
81b5b746 | 4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
22 | class EmailModule extends PLModule | |
23 | { | |
81b5b746 | 24 | function handlers() |
25 | { | |
26 | return array( | |
27 | 'emails' => $this->make_hook('emails', AUTH_COOKIE), | |
28 | 'emails/alias' => $this->make_hook('alias', AUTH_MDP), | |
29 | 'emails/antispam' => $this->make_hook('antispam', AUTH_MDP), | |
30 | 'emails/broken' => $this->make_hook('broken', AUTH_COOKIE), | |
31 | 'emails/redirect' => $this->make_hook('redirect', AUTH_MDP), | |
32 | 'emails/send' => $this->make_hook('send', AUTH_MDP), | |
62ce6356 | 33 | 'emails/antispam/submit' => $this->make_hook('submit', AUTH_COOKIE), |
5ff3f06b | 34 | 'emails/test' => $this->make_hook('test', AUTH_PUBLIC), |
9e570fe0 | 35 | |
7727ffc7 | 36 | 'admin/emails/duplicated' => $this->make_hook('duplicated', AUTH_MDP, 'admin'), |
f141945d | 37 | 'admin/emails/watch' => $this->make_hook('duplicated', AUTH_MDP, 'admin'), |
5ff3f06b | 38 | 'admin/emails/lost' => $this->make_hook('lost', AUTH_MDP, 'admin'), |
81b5b746 | 39 | ); |
40 | } | |
41 | ||
b7582015 | 42 | function handler_emails(&$page, $action = null, $email = null) |
81b5b746 | 43 | { |
44 | global $globals; | |
45 | ||
46 | $page->changeTpl('emails/index.tpl'); | |
47 | $page->assign('xorg_title','Polytechnique.org - Mes emails'); | |
48 | ||
cab08090 | 49 | $uid = S::v('uid'); |
81b5b746 | 50 | |
b7582015 | 51 | if ($action == 'best' && $email) { |
81b5b746 | 52 | // bestalias is the first bit : 1 |
53 | // there will be maximum 8 bits in flags : 255 | |
08cce2ff | 54 | XDB::execute("UPDATE aliases SET flags=flags & (255 - 1) WHERE id={?}", $uid); |
55 | XDB::execute("UPDATE aliases SET flags=flags | 1 WHERE id={?} AND alias={?}", | |
b7582015 | 56 | $uid, $email); |
81b5b746 | 57 | } |
58 | ||
a7de4ef7 | 59 | // on regarde si on a affaire à un homonyme |
81b5b746 | 60 | $sql = "SELECT alias, (type='a_vie') AS a_vie, |
61 | (alias REGEXP '\\\\.[0-9]{2}$') AS cent_ans, | |
62 | FIND_IN_SET('bestalias',flags) AS best, expire | |
63 | FROM aliases | |
64 | WHERE id = {?} AND type!='homonyme' | |
65 | ORDER BY LENGTH(alias)"; | |
08cce2ff | 66 | $page->assign('aliases', XDB::iterator($sql, $uid)); |
81b5b746 | 67 | |
31170a38 | 68 | $homonyme = XDB::query("SELECT alias FROM aliases INNER JOIN homonymes ON (id = homonyme_id) WHERE user_id = {?} AND type = 'homonyme'", $uid); |
69 | $page->assign('homonyme', $homonyme->fetchOneCell()); | |
70 | ||
81b5b746 | 71 | $sql = "SELECT email |
72 | FROM emails | |
73 | WHERE uid = {?} AND FIND_IN_SET('active', flags)"; | |
08cce2ff | 74 | $page->assign('mails', XDB::iterator($sql, $uid)); |
81b5b746 | 75 | |
76 | ||
77 | // on regarde si l'utilisateur a un alias et si oui on l'affiche ! | |
cab08090 | 78 | $forlife = S::v('forlife'); |
08cce2ff | 79 | $res = XDB::query( |
81b5b746 | 80 | "SELECT alias |
81 | FROM virtual AS v | |
82 | INNER JOIN virtual_redirect AS vr USING(vid) | |
eaf30d86 | 83 | WHERE (redirect={?} OR redirect={?}) |
81b5b746 | 84 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
85 | $forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2); | |
86 | $page->assign('melix', $res->fetchOneCell()); | |
81b5b746 | 87 | } |
88 | ||
89 | function handler_alias(&$page, $action = null, $value = null) | |
90 | { | |
91 | require_once 'validations.inc.php'; | |
92 | ||
93 | global $globals; | |
94 | ||
95 | $page->changeTpl('emails/alias.tpl'); | |
96 | $page->assign('xorg_title','Polytechnique.org - Alias melix.net'); | |
97 | ||
cab08090 | 98 | $uid = S::v('uid'); |
99 | $forlife = S::v('forlife'); | |
81b5b746 | 100 | |
101 | $page->assign('demande', AliasReq::get_request($uid)); | |
102 | ||
a5361008 | 103 | if ($action == 'delete' && $value) { |
81b5b746 | 104 | //Suppression d'un alias |
08cce2ff | 105 | XDB::execute( |
81b5b746 | 106 | 'DELETE virtual, virtual_redirect |
107 | FROM virtual | |
108 | INNER JOIN virtual_redirect USING (vid) | |
109 | WHERE alias = {?} AND (redirect = {?} OR redirect = {?})', $value, | |
110 | $forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2); | |
111 | } | |
112 | ||
a7de4ef7 | 113 | //Récupération des alias éventuellement existants |
08cce2ff | 114 | $res = XDB::query( |
81b5b746 | 115 | "SELECT alias, emails_alias_pub |
116 | FROM auth_user_quick, virtual | |
117 | INNER JOIN virtual_redirect USING(vid) | |
118 | WHERE ( redirect={?} OR redirect= {?} ) | |
eaf30d86 | 119 | AND alias LIKE '%@{$globals->mail->alias_dom}' AND user_id = {?}", |
81b5b746 | 120 | $forlife.'@'.$globals->mail->domain, |
cab08090 | 121 | $forlife.'@'.$globals->mail->domain2, S::v('uid')); |
81b5b746 | 122 | list($alias, $visibility) = $res->fetchOneRow(); |
123 | $page->assign('actuel', $alias); | |
124 | ||
125 | if ($action == 'ask' && Env::has('alias') and Env::has('raison')) { | |
126 | //Si l'utilisateur vient de faire une damande | |
127 | ||
5e2307dc | 128 | $alias = Env::v('alias'); |
129 | $raison = Env::v('raison'); | |
130 | $public = (Env::v('public', 'off') == 'on')?"public":"private"; | |
81b5b746 | 131 | |
132 | $page->assign('r_alias', $alias); | |
133 | $page->assign('r_raison', $raison); | |
134 | if ($public == 'public') { | |
135 | $page->assign('r_public', true); | |
136 | } | |
137 | ||
a7de4ef7 | 138 | //Quelques vérifications sur l'alias (caractères spéciaux) |
81b5b746 | 139 | if (!preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $alias)) { |
a7de4ef7 | 140 | $page->trig("L'adresse demandée n'est pas valide. |
141 | Vérifie qu'elle comporte entre 3 et 20 caractères | |
142 | et qu'elle ne contient que des lettres non accentuées, | |
143 | des chiffres ou les caractères - et ."); | |
fd8f77de | 144 | return; |
81b5b746 | 145 | } else { |
a7de4ef7 | 146 | //vérifier que l'alias n'est pas déja pris |
08cce2ff | 147 | $res = XDB::query('SELECT COUNT(*) FROM virtual WHERE alias={?}', |
81b5b746 | 148 | $alias.'@'.$globals->mail->alias_dom); |
149 | if ($res->fetchOneCell() > 0) { | |
a7de4ef7 | 150 | $page->trig("L'alias $alias@{$globals->mail->alias_dom} a déja été attribué. |
81b5b746 | 151 | Tu ne peux donc pas l'obtenir."); |
fd8f77de | 152 | return; |
81b5b746 | 153 | } |
154 | ||
a7de4ef7 | 155 | //vérifier que l'alias n'est pas déja en demande |
81b5b746 | 156 | $it = new ValidateIterator (); |
157 | while($req = $it->next()) { | |
1f07f6c2 | 158 | if ($req->type == "alias" and $req->alias == $alias . '@' . $globals->mail->alias_dom) { |
a7de4ef7 | 159 | $page->trig("L'alias $alias@{$globals->mail->alias_dom} a déja été demandé. |
81b5b746 | 160 | Tu ne peux donc pas l'obtenir pour l'instant."); |
fd8f77de | 161 | return ; |
81b5b746 | 162 | } |
163 | } | |
164 | ||
a7de4ef7 | 165 | //Insertion de la demande dans la base, écrase les requêtes précédente |
81b5b746 | 166 | $myalias = new AliasReq($uid, $alias, $raison, $public); |
167 | $myalias->submit(); | |
168 | $page->assign('success',$alias); | |
fd8f77de | 169 | return; |
81b5b746 | 170 | } |
171 | } | |
172 | elseif ($action == 'set' | |
173 | && ($value == 'public' || $value == 'private')) | |
174 | { | |
175 | if ($value == 'public') { | |
08cce2ff | 176 | XDB::execute("UPDATE auth_user_quick SET emails_alias_pub = 'public' |
cab08090 | 177 | WHERE user_id = {?}", S::v('uid')); |
81b5b746 | 178 | } else { |
08cce2ff | 179 | XDB::execute("UPDATE auth_user_quick SET emails_alias_pub = 'private' |
cab08090 | 180 | WHERE user_id = {?}", S::v('uid')); |
81b5b746 | 181 | } |
182 | ||
183 | $visibility = $value; | |
184 | } | |
185 | ||
186 | $page->assign('mail_public', ($visibility == 'public')); | |
81b5b746 | 187 | } |
188 | ||
189 | function handler_redirect(&$page, $action = null, $email = null) | |
190 | { | |
191 | global $globals; | |
192 | ||
193 | require_once 'emails.inc.php'; | |
194 | ||
195 | $page->changeTpl('emails/redirect.tpl'); | |
196 | ||
cab08090 | 197 | $uid = S::v('uid'); |
198 | $forlife = S::v('forlife'); | |
81b5b746 | 199 | |
3b83212e | 200 | $page->assign('eleve', S::i('promo') >= date("Y") - 5); |
201 | ||
cab08090 | 202 | $redirect = new Redirect(S::v('uid')); |
81b5b746 | 203 | |
6d6b65bf | 204 | // FS#703 : $_GET is urldecoded twice, hence |
205 | // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding) | |
206 | // Since there can be no spaces in emails, we can fix this with : | |
207 | $email = str_replace(' ', '+', $email); | |
208 | ||
81b5b746 | 209 | if ($action == 'remove' && $email) { |
b7582015 | 210 | $retour = $redirect->delete_email($email); |
211 | $page->assign('retour', $retour); | |
81b5b746 | 212 | } |
b7582015 | 213 | |
214 | if ($action == 'active' && $email) { | |
215 | $redirect->modify_one_email($email, true); | |
216 | } | |
217 | ||
218 | if ($action == 'inactive' && $email) { | |
219 | $redirect->modify_one_email($email, false); | |
220 | } | |
221 | ||
222 | if ($action == 'rewrite' && $email) { | |
223 | $rewrite = @func_get_arg(3); | |
224 | $redirect->modify_one_email_redirect($email, $rewrite); | |
225 | } | |
226 | ||
81b5b746 | 227 | if (Env::has('emailop')) { |
5e2307dc | 228 | $actifs = Env::v('emails_actifs', Array()); |
b7582015 | 229 | print_r(Env::v('emails_rewrite')); |
5e2307dc | 230 | if (Env::v('emailop') == "ajouter" && Env::has('email')) { |
231 | $page->assign('retour', $redirect->add_email(Env::v('email'))); | |
81b5b746 | 232 | } elseif (empty($actifs)) { |
233 | $page->assign('retour', ERROR_INACTIVE_REDIRECTION); | |
234 | } elseif (is_array($actifs)) { | |
235 | $page->assign('retour', $redirect->modify_email($actifs, | |
5e2307dc | 236 | Env::v('emails_rewrite',Array()))); |
81b5b746 | 237 | } |
238 | } | |
239 | ||
08cce2ff | 240 | $res = XDB::query( |
81b5b746 | 241 | "SELECT alias |
242 | FROM virtual | |
243 | INNER JOIN virtual_redirect USING(vid) | |
244 | WHERE (redirect={?} OR redirect={?}) | |
eaf30d86 | 245 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
81b5b746 | 246 | $forlife.'@'.$globals->mail->domain, $forlife.'@'.$globals->mail->domain2); |
247 | $melix = $res->fetchOneCell(); | |
248 | if ($melix) { | |
249 | list($melix) = explode('@', $melix); | |
250 | $page->assign('melix',$melix); | |
251 | } | |
252 | ||
08cce2ff | 253 | $res = XDB::query( |
81b5b746 | 254 | "SELECT alias,expire |
255 | FROM aliases | |
256 | WHERE id={?} AND (type='a_vie' OR type='alias') | |
257 | ORDER BY !FIND_IN_SET('usage',flags), LENGTH(alias)", $uid); | |
258 | $page->assign('alias', $res->fetchAllAssoc()); | |
259 | $page->assign('emails',$redirect->emails); | |
81b5b746 | 260 | } |
261 | ||
b7582015 | 262 | function handler_antispam(&$page, $statut_filtre = null) |
81b5b746 | 263 | { |
264 | require_once 'emails.inc.php'; | |
841cfb97 | 265 | require_once('wiki.inc.php'); |
266 | wiki_require_page('Xorg.Antispam'); | |
81b5b746 | 267 | |
268 | $page->changeTpl('emails/antispam.tpl'); | |
269 | ||
cab08090 | 270 | $bogo = new Bogo(S::v('uid')); |
b7582015 | 271 | if (isset($statut_filtre)) { |
272 | $bogo->change(S::v('uid'), $statut_filtre + 0); | |
81b5b746 | 273 | } |
274 | $page->assign('filtre',$bogo->level()); | |
81b5b746 | 275 | } |
276 | ||
62ce6356 | 277 | function handler_submit(&$page) |
278 | { | |
4b9ba601 | 279 | require_once('wiki.inc.php'); |
280 | wiki_require_page('Xorg.Mails'); | |
62ce6356 | 281 | $page->changeTpl('emails/submit_spam.tpl'); |
282 | ||
283 | if (Post::has('send_email')) { | |
15603084 | 284 | $upload = PlUpload::get($_FILES['mail'], S::v('forlife'), 'spam.submit', true); |
285 | if (!$upload) { | |
a7de4ef7 | 286 | $page->trig('Une erreur a été rencontrée lors du transfert du fichier'); |
62ce6356 | 287 | return; |
288 | } | |
15603084 | 289 | $mime = $upload->contentType(); |
62ce6356 | 290 | if ($mime != 'text/x-mail' && $mime != 'message/rfc822') { |
15603084 | 291 | $upload->clear(); |
62ce6356 | 292 | $page->trig('Le fichier ne contient pas un mail complet'); |
293 | return; | |
294 | } | |
295 | global $globals; | |
296 | $box = Post::v('type') . '@' . $globals->mail->domain; | |
297 | $mailer = new PlMailer(); | |
298 | $mailer->addTo($box); | |
299 | $mailer->setFrom('"' . S::v('prenom') . ' ' . S::v('nom') . '" <web@' . $globals->mail->domain . '>'); | |
300 | $mailer->setTxtBody(Post::v('type') . ' soumis par ' . S::v('forlife') . ' via le web'); | |
15603084 | 301 | $mailer->addUploadAttachment($upload, Post::v('type') . '.mail'); |
62ce6356 | 302 | $mailer->send(); |
a7de4ef7 | 303 | $page->trig('Le message a été transmis à ' . $box); |
15603084 | 304 | $upload->clear(); |
62ce6356 | 305 | } |
306 | } | |
307 | ||
81b5b746 | 308 | function handler_send(&$page) |
309 | { | |
310 | global $globals; | |
81b5b746 | 311 | $page->changeTpl('emails/send.tpl'); |
da419622 | 312 | $page->addJsLink('ajax.js'); |
81b5b746 | 313 | |
314 | $page->assign('xorg_title','Polytechnique.org - Envoyer un email'); | |
315 | ||
316 | // action si on recoit un formulaire | |
3360c04f FB |
317 | if (Post::has('save')) { |
318 | unset($_POST['save']); | |
319 | if (trim(preg_replace('/-- .*/', '', Post::v('contenu'))) != "") { | |
320 | $_POST['to_contacts'] = explode(';', @$_POST['to_contacts']); | |
321 | $_POST['cc_contacts'] = explode(';', @$_POST['cc_contacts']); | |
322 | $data = serialize($_POST); | |
323 | XDB::execute("REPLACE INTO email_send_save | |
324 | VALUES ({?}, {?})", S::i('uid'), $data); | |
325 | } | |
326 | exit; | |
327 | } else if (Env::v('submit') == 'Envoyer') { | |
91a14f73 | 328 | function getEmails($aliases) |
329 | { | |
330 | if (!is_array($aliases)) { | |
331 | return null; | |
332 | } | |
333 | $rel = Env::v('contacts'); | |
334 | $ret = array(); | |
335 | foreach ($aliases as $alias) { | |
336 | $ret[$alias] = $rel[$alias]; | |
337 | } | |
338 | return join(', ', $ret); | |
339 | } | |
340 | ||
da419622 | 341 | foreach ($_FILES as &$file) { |
f3fb8eda | 342 | if ($file['name'] && !PlUpload::get($file, S::v('forlife'), 'emails.send', false)) { |
da419622 | 343 | $page->trig("Impossible de télécharger '" . pl_entities($file['name']) . "'"); |
344 | } | |
345 | } | |
346 | ||
3360c04f FB |
347 | XDB::execute("DELETE FROM email_send_save |
348 | WHERE uid = {?}", S::i('uid')); | |
349 | ||
91a14f73 | 350 | $to2 = getEmails(Env::v('to_contacts')); |
351 | $cc2 = getEmails(Env::v('cc_contacts')); | |
5e2307dc | 352 | $txt = str_replace('^M', '', Env::v('contenu')); |
353 | $to = Env::v('to'); | |
354 | $subj = Env::v('sujet'); | |
355 | $from = Env::v('from'); | |
13627bef | 356 | $cc = trim(Env::v('cc')); |
357 | $bcc = trim(Env::v('bcc')); | |
81b5b746 | 358 | |
f3fb8eda | 359 | if (empty($to) && empty($cc) && empty($to2) && empty($bcc) && empty($cc2)) { |
81b5b746 | 360 | $page->trig("Indique au moins un destinataire."); |
da419622 | 361 | $page->assign('uploaded_f', PlUpload::listFilenames(S::v('forlife'), 'emails.send')); |
81b5b746 | 362 | } else { |
1e33266a | 363 | $mymail = new PlMailer(); |
81b5b746 | 364 | $mymail->setFrom($from); |
365 | $mymail->setSubject($subj); | |
366 | if (!empty($to)) { $mymail->addTo($to); } | |
367 | if (!empty($cc)) { $mymail->addCc($cc); } | |
368 | if (!empty($bcc)) { $mymail->addBcc($bcc); } | |
369 | if (!empty($to2)) { $mymail->addTo($to2); } | |
91a14f73 | 370 | if (!empty($cc2)) { $mymail->addCc($cc2); } |
da419622 | 371 | $files =& PlUpload::listFiles(S::v('forlife'), 'emails.send'); |
372 | foreach ($files as $name=>&$upload) { | |
373 | $mymail->addUploadAttachment($upload, $name); | |
91a14f73 | 374 | } |
5b21237d | 375 | if (Env::v('nowiki')) { |
376 | $mymail->setTxtBody(wordwrap($txt, 78, "\n")); | |
377 | } else { | |
378 | $mymail->setWikiBody($txt); | |
379 | } | |
81b5b746 | 380 | if ($mymail->send()) { |
a7de4ef7 | 381 | $page->trig("Ton mail a bien été envoyé."); |
cab08090 | 382 | $_REQUEST = array('bcc' => S::v('bestalias').'@'.$globals->mail->domain); |
da419622 | 383 | PlUpload::clear(S::v('forlife'), 'emails.send'); |
81b5b746 | 384 | } else { |
a7de4ef7 | 385 | $page->trig("Erreur lors de l'envoi du courriel, réessaye."); |
da419622 | 386 | $page->assign('uploaded_f', PlUpload::listFilenames(S::v('forlife'), 'emails.send')); |
81b5b746 | 387 | } |
388 | } | |
389 | } else { | |
3360c04f FB |
390 | $res = XDB::query("SELECT data |
391 | FROM email_send_save | |
392 | WHERE uid = {?}", S::i('uid')); | |
393 | if ($res->numRows() == 0) { | |
394 | PlUpload::clear(S::v('forlife'), 'emails.send'); | |
395 | $_REQUEST['bcc'] = S::v('bestalias').'@'.$globals->mail->domain; | |
396 | } else { | |
397 | $data = unserialize($res->fetchOneCell()); | |
398 | $_REQUEST = array_merge($_REQUEST, $data); | |
399 | } | |
81b5b746 | 400 | } |
401 | ||
08cce2ff | 402 | $res = XDB::query( |
81b5b746 | 403 | "SELECT u.prenom, u.nom, u.promo, a.alias as forlife |
404 | FROM auth_user_md5 AS u | |
405 | INNER JOIN contacts AS c ON (u.user_id = c.contact) | |
406 | INNER JOIN aliases AS a ON (u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags)) | |
407 | WHERE c.uid = {?} | |
cab08090 | 408 | ORDER BY u.nom, u.prenom", S::v('uid')); |
81b5b746 | 409 | $page->assign('contacts', $res->fetchAllAssoc()); |
f3fb8eda | 410 | $page->assign('maxsize', ini_get('post_max_size') . 'o'); |
81b5b746 | 411 | } |
412 | ||
5ff3f06b FB |
413 | function handler_test(&$page, $forlife = null) |
414 | { | |
415 | global $globals; | |
416 | if (!S::has_perms() || !$forlife) { | |
417 | $forlife = S::v('bestalias'); | |
418 | } | |
419 | $mailer = new PlMailer('emails/mail.test.tpl'); | |
420 | $mailer->assign('email', $forlife . '@' . $globals->mail->domain); | |
421 | $iterator = XDB::iterator("SELECT email | |
422 | FROM emails AS e | |
423 | INNER JOIN aliases AS a ON (e.uid = a.id) | |
424 | WHERE FIND_IN_SET('active', e.flags) AND a.alias = {?}", | |
425 | $forlife); | |
426 | $mailer->assign('redirects', $iterator); | |
427 | $res = XDB::query("SELECT FIND_IN_SET('femme', u.flags), prenom | |
428 | FROM auth_user_md5 AS u | |
429 | INNER JOIN aliases AS a ON (a.id = u.user_id) | |
430 | WHERE a.alias = {?}", $forlife); | |
431 | list($sexe, $prenom) = $res->fetchOneRow(); | |
432 | $mailer->assign('sexe', $sexe); | |
433 | $mailer->assign('prenom', $prenom); | |
434 | $mailer->send(); | |
435 | exit; | |
436 | } | |
437 | ||
81b5b746 | 438 | function handler_broken(&$page, $warn = null, $email = null) |
439 | { | |
440 | require_once 'emails.inc.php'; | |
4b9ba601 | 441 | require_once('wiki.inc.php'); |
a7de4ef7 | 442 | wiki_require_page('Xorg.PatteCassée'); |
81b5b746 | 443 | |
444 | global $globals; | |
445 | ||
446 | $page->changeTpl('emails/broken.tpl'); | |
447 | ||
448 | if ($warn == 'warn' && $email) { | |
449 | $email = valide_email($email); | |
a7de4ef7 | 450 | // vérifications d'usage |
08cce2ff | 451 | $sel = XDB::query( |
81b5b746 | 452 | "SELECT e.uid, a.alias |
453 | FROM emails AS e | |
454 | INNER JOIN auth_user_md5 AS u ON e.uid = u.user_id | |
455 | INNER JOIN aliases AS a ON (e.uid = a.id AND type!='homonyme' | |
456 | AND FIND_IN_SET('bestalias',a.flags)) | |
457 | WHERE e.email={?}", $email); | |
458 | ||
459 | if (list($uid, $dest) = $sel->fetchOneRow()) { | |
460 | // envoi du mail | |
461 | $message = "Bonjour ! | |
462 | ||
a7de4ef7 | 463 | Ce mail a été généré automatiquement par le service de patte cassée de |
cab08090 | 464 | Polytechnique.org car un autre utilisateur, ".S::v('prenom').' '.S::v('nom').", |
a7de4ef7 | 465 | nous a signalé qu'en t'envoyant un mail, il avait reçu un message d'erreur |
81b5b746 | 466 | indiquant que ton adresse de redirection $email |
467 | ne fonctionnait plus ! | |
468 | ||
a7de4ef7 | 469 | Nous te suggérons de vérifier cette adresse, et le cas échéant de mettre |
470 | à jour sur le site <{$globals->baseurl}/emails> tes adresses | |
81b5b746 | 471 | de redirection... |
472 | ||
a7de4ef7 | 473 | Pour plus de rensignements sur le service de patte cassée, n'hésites pas à |
2c388954 | 474 | consulter la page <{$globals->baseurl}/emails/broken>. |
81b5b746 | 475 | |
476 | ||
a7de4ef7 | 477 | A bientôt sur Polytechnique.org ! |
1d55fe45 | 478 | L'équipe d'administration <support@" . $globals->mail->domain . '>'; |
81b5b746 | 479 | |
1e33266a | 480 | $mail = new PlMailer(); |
1d55fe45 | 481 | $mail->setFrom('"Polytechnique.org" <support@' . $globals->mail->domain . '>'); |
482 | $mail->addTo("$dest@" . $globals->mail->domain); | |
81b5b746 | 483 | $mail->setSubject("Une de tes adresse de redirection Polytechnique.org ne marche plus !!"); |
484 | $mail->setTxtBody($message); | |
485 | $mail->send(); | |
a7de4ef7 | 486 | $page->trig("Mail envoyé ! :o)"); |
81b5b746 | 487 | } |
488 | } elseif (Post::has('email')) { | |
5e2307dc | 489 | $email = valide_email(Post::v('email')); |
81b5b746 | 490 | |
491 | list(,$fqdn) = explode('@', $email); | |
492 | $fqdn = strtolower($fqdn); | |
493 | if ($fqdn == 'polytechnique.org' || $fqdn == 'melix.org' | |
494 | || $fqdn == 'm4x.org' || $fqdn == 'melix.net') | |
495 | { | |
496 | $page->assign('neuneu', true); | |
497 | } else { | |
498 | $page->assign('email',$email); | |
08cce2ff | 499 | $sel = XDB::query( |
81b5b746 | 500 | "SELECT e1.uid, e1.panne != 0 AS panne, count(e2.uid) AS nb_mails, |
4b9ba601 | 501 | u.nom, u.prenom, u.promo, a.alias AS forlife |
81b5b746 | 502 | FROM emails as e1 |
eaf30d86 | 503 | LEFT JOIN emails as e2 ON(e1.uid = e2.uid |
81b5b746 | 504 | AND FIND_IN_SET('active', e2.flags) |
505 | AND e1.email != e2.email) | |
506 | INNER JOIN auth_user_md5 as u ON(e1.uid = u.user_id) | |
4b9ba601 | 507 | INNER JOIN aliases AS a ON (a.id = e1.uid AND a.type = 'a_vie') |
81b5b746 | 508 | WHERE e1.email = {?} |
509 | GROUP BY e1.uid", $email); | |
510 | if ($x = $sel->fetchOneAssoc()) { | |
a7de4ef7 | 511 | // on écrit dans la base que l'adresse est cassée |
81b5b746 | 512 | if (!$x['panne']) { |
74938c82 | 513 | XDB::execute("UPDATE emails |
514 | SET panne=NOW(), | |
515 | last=NOW(), | |
516 | panne_level = 1 | |
517 | WHERE email = {?}", $email); | |
518 | } else { | |
519 | XDB::execute("UPDATE emails | |
520 | SET panne_level = 1 | |
4b9ba601 | 521 | WHERE email = {?} AND panne_level = 0", $email); |
81b5b746 | 522 | } |
523 | $page->assign_by_ref('x', $x); | |
524 | } | |
525 | } | |
526 | } | |
527 | } | |
9e570fe0 | 528 | |
529 | function handler_duplicated(&$page, $action = 'list', $email = null) | |
530 | { | |
531 | $page->changeTpl('emails/duplicated.tpl'); | |
532 | ||
533 | $states = array('pending' => 'En attente...', | |
a7de4ef7 | 534 | 'safe' => 'Pas d\'inquiétude', |
9e570fe0 | 535 | 'unsafe' => 'Recherches en cours', |
536 | 'dangerous' => 'Usurpations par cette adresse'); | |
537 | $page->assign('states', $states); | |
538 | ||
539 | switch (Post::v('action')) { | |
540 | case 'create': | |
541 | if (trim(Post::v('emailN')) != '') { | |
542 | Xdb::execute('INSERT IGNORE INTO emails_watch (email, state, detection, last, uid, description) | |
543 | VALUES ({?}, {?}, CURDATE(), NOW(), {?}, {?})', | |
544 | trim(Post::v('emailN')), Post::v('stateN'), S::i('uid'), Post::v('descriptionN')); | |
545 | }; | |
546 | break; | |
547 | ||
548 | case 'edit': | |
549 | Xdb::execute('UPDATE emails_watch | |
550 | SET state = {?}, last = NOW(), uid = {?}, description = {?} | |
551 | WHERE email = {?}', Post::v('stateN'), S::i('uid'), Post::v('descriptionN'), Post::v('emailN')); | |
552 | break; | |
553 | ||
554 | default: | |
555 | if ($action == 'delete' && !is_null($email)) { | |
556 | Xdb::execute('DELETE FROM emails_watch WHERE email = {?}', $email); | |
557 | } | |
558 | } | |
559 | if ($action != 'create' && $action != 'edit') { | |
560 | $action = 'list'; | |
561 | } | |
562 | $page->assign('action', $action); | |
563 | ||
564 | if ($action == 'list') { | |
565 | $sql = "SELECT w.email, w.detection, w.state, a.alias AS forlife | |
566 | FROM emails_watch AS w | |
ca6d07f4 | 567 | LEFT JOIN emails AS e USING(email) |
568 | LEFT JOIN aliases AS a ON (a.id = e.uid AND a.type = 'a_vie') | |
9e570fe0 | 569 | ORDER BY w.state, w.email, a.alias"; |
570 | $it = Xdb::iterRow($sql); | |
571 | ||
572 | $table = array(); | |
573 | $props = array(); | |
574 | while (list($email, $date, $state, $forlife) = $it->next()) { | |
575 | if (count($props) == 0 || $props['mail'] != $email) { | |
576 | if (count($props) > 0) { | |
577 | $table[] = $props; | |
578 | } | |
579 | $props = array('mail' => $email, | |
580 | 'detection' => $date, | |
581 | 'state' => $state, | |
582 | 'users' => array($forlife)); | |
583 | } else { | |
584 | $props['users'][] = $forlife; | |
585 | } | |
586 | } | |
587 | if (count($props) > 0) { | |
588 | $table[] = $props; | |
589 | } | |
590 | $page->assign('table', $table); | |
591 | } elseif ($action == 'edit') { | |
592 | $sql = "SELECT w.detection, w.state, w.last, w.description, | |
593 | a1.alias AS edit, a2.alias AS forlife | |
594 | FROM emails_watch AS w | |
eaf30d86 | 595 | LEFT JOIN aliases AS a1 ON (a1.id = w.uid AND a1.type = 'a_vie') |
9615c895 | 596 | LEFT JOIN emails AS e ON (w.email = e.email) |
ca6d07f4 | 597 | LEFT JOIN aliases AS a2 ON (a2.id = e.uid AND a2.type = 'a_vie') |
9e570fe0 | 598 | WHERE w.email = {?} |
599 | ORDER BY a2.alias"; | |
600 | $it = Xdb::iterRow($sql, $email); | |
601 | ||
602 | $props = array(); | |
603 | while (list($detection, $state, $last, $description, $edit, $forlife) = $it->next()) { | |
604 | if (count($props) == 0) { | |
605 | $props = array('mail' => $email, | |
606 | 'detection' => $detection, | |
607 | 'state' => $state, | |
608 | 'last' => $last, | |
609 | 'description' => $description, | |
610 | 'edit' => $edit, | |
611 | 'users' => array($forlife)); | |
612 | } else { | |
613 | $props['users'][] = $forlife; | |
614 | } | |
615 | } | |
616 | $page->assign('doublon', $props); | |
617 | } | |
618 | } | |
7727ffc7 | 619 | function handler_lost(&$page, $action = 'list', $email = null) |
620 | { | |
621 | $page->changeTpl('emails/lost.tpl'); | |
eaf30d86 | 622 | |
7727ffc7 | 623 | $page->assign('lost_emails', XDB::iterator(' |
624 | SELECT u.user_id, a.alias | |
625 | FROM auth_user_md5 AS u | |
626 | INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = "a_vie") | |
627 | LEFT JOIN emails AS e ON (u.user_id=e.uid AND FIND_IN_SET("active",e.flags)) | |
628 | WHERE e.uid IS NULL AND u.deces = 0 | |
629 | ORDER BY u.promo DESC, u.nom, u.prenom')); | |
630 | } | |
81b5b746 | 631 | } |
632 | ||
a7de4ef7 | 633 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
81b5b746 | 634 | ?> |