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