Commit | Line | Data |
---|---|---|
ee68ddc1 | 1 | #!/usr/bin/php5 -q |
866f1333 | 2 | <?php |
3 | /*************************************************************************** | |
8d84c630 | 4 | * Copyright (C) 2003-2009 Polytechnique.org * |
866f1333 | 5 | * http://opensource.polytechnique.org/ * |
6 | * * | |
7 | * This program is free software; you can redistribute it and/or modify * | |
8 | * it under the terms of the GNU General Public License as published by * | |
9 | * the Free Software Foundation; either version 2 of the License, or * | |
10 | * (at your option) any later version. * | |
11 | * * | |
12 | * This program is distributed in the hope that it will be useful, * | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
15 | * GNU General Public License for more details. * | |
16 | * * | |
17 | * You should have received a copy of the GNU General Public License * | |
18 | * along with this program; if not, write to the Free Software * | |
19 | * Foundation, Inc., * | |
20 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
21 | ***************************************************************************/ | |
22 | ||
dc557110 | 23 | /* Number of consecutive month of bounce before deactivating a redirection |
24 | */ | |
25 | $panne_level = 3; | |
26 | ||
866f1333 | 27 | require('./connect.db.inc.php'); |
28 | ||
eaf30d86 | 29 | /* |
dc557110 | 30 | * Check duplicated addresses |
31 | */ | |
866f1333 | 32 | $sql = "SELECT a1.alias, a2.alias, e1.email |
33 | FROM emails AS e1 | |
eaf30d86 | 34 | INNER JOIN emails AS e2 ON (e1.email = e2.email AND e1.uid != e2.uid |
010268b2 | 35 | AND (e1.uid < e2.uid OR NOT FIND_IN_SET('active', e2.flags))) |
866f1333 | 36 | LEFT JOIN emails_watch AS w ON (e1.email = w.email) |
37 | INNER JOIN aliases AS a1 ON (a1.id = e1.uid AND a1.type = 'a_vie') | |
38 | INNER JOIN aliases AS a2 ON (a2.id = e2.uid AND a2.type = 'a_vie') | |
39 | INNER JOIN auth_user_md5 AS u1 ON (a1.id = u1.user_id) | |
40 | INNER JOIN auth_user_md5 AS u2 ON (a2.id = u2.user_id) | |
010268b2 | 41 | WHERE FIND_IN_SET('active', e1.flags) AND u1.nom != u2.nom_usage AND u2.nom != u1.nom_usage AND w.email IS NULL |
866f1333 | 42 | ORDER BY a1.alias"; |
43 | ||
44 | $it = Xdb::iterRow($sql); | |
45 | ||
46 | $insert = array(); | |
47 | $conflits = array(); | |
48 | while (list($alias1, $alias2, $mail) = $it->next()) { | |
49 | $insert[] = "('$mail', 'pending', CURDATE(), NOW())"; | |
50 | $conflits[] = "* $mail sur $alias1 et $alias2"; | |
51 | } | |
52 | ||
53 | if (count($conflits) > 0) { | |
1707967a SJ |
54 | echo "Nouvelles adresses en doublon détectées :\n" . join("\n", $conflits) |
55 | . "\n\nVous pouvez entrer les informations collectées à ce sujet sur la page :\n" | |
56 | . "https://www.polytechnique.org/admin/emails/duplicated"; | |
866f1333 | 57 | |
58 | echo "\n\n"; | |
59 | $sql = "INSERT IGNORE INTO emails_watch (email, state, detection, last) | |
60 | VALUES " . join(", ", $insert); | |
0380bf85 | 61 | XDB::execute($sql); |
62 | if (XDB::errno() != 0) { | |
63 | echo 'Error : ' . XDB::error() . "\n$sql"; | |
866f1333 | 64 | } |
65 | } | |
66 | ||
dc557110 | 67 | /* |
68 | * Check dead emails | |
69 | */ | |
70 | if ($panne_level > 0) { | |
d293e17c | 71 | $sql = "SELECT e.email, u.hruid |
dc557110 | 72 | FROM emails AS e |
d293e17c | 73 | INNER JOIN auth_user_md5 AS u ON u.user_id = e.uid |
dc557110 | 74 | WHERE e.panne_level = $panne_level AND e.flags = 'active' |
d293e17c | 75 | ORDER BY u.hruid"; |
dc557110 | 76 | $res = Xdb::query($sql); |
77 | ||
78 | if ($res->numRows()) { | |
79 | $result = $res->fetchAllAssoc(); | |
d20d604f | 80 | echo "Nouvelles adresses en panne detectees :\n"; |
dc557110 | 81 | foreach ($result as $assoc) { |
d293e17c | 82 | echo '* ' . $assoc['email'] . ' pour ' . $assoc['hruid'] . "\n"; |
dc557110 | 83 | } |
84 | echo "\n\n"; | |
866f1333 | 85 | |
dc557110 | 86 | Xdb::execute("UPDATE emails |
87 | SET flags = 'panne' | |
88 | WHERE panne_level = 3 AND flags = 'active'"); | |
89 | } | |
90 | ||
91 | Xdb::execute("UPDATE emails | |
92 | SET panne_level = $panne_level | |
93 | WHERE panne_level > $panne_level"); | |
94 | } | |
866f1333 | 95 | |
a7de4ef7 | 96 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
866f1333 | 97 | ?> |