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'); |
4f970ab0 SJ |
28 | require("Console/Getopt.php"); |
29 | ||
30 | /* | |
31 | * Parse the command-line options. | |
32 | */ | |
33 | $opts = Console_GetOpt::getopt($argv, 'v'); | |
34 | $opt_verbose = false; | |
35 | ||
36 | if (PEAR::isError($opts)) { | |
37 | echo $opts->getMessage(); | |
38 | } else { | |
39 | $opts = $opts[0]; | |
40 | foreach ($opts as $opt) { | |
41 | if ($opt[0] == 'v') { | |
42 | $opt_verbose = true; | |
43 | } | |
44 | } | |
45 | } | |
866f1333 | 46 | |
eaf30d86 | 47 | /* |
dc557110 | 48 | * Check duplicated addresses |
49 | */ | |
4f970ab0 SJ |
50 | $sql = "SELECT a1.alias, a2.alias, e1.email |
51 | FROM emails AS e1 | |
52 | INNER JOIN emails AS e2 ON (e1.email = e2.email AND e1.uid != e2.uid | |
010268b2 | 53 | AND (e1.uid < e2.uid OR NOT FIND_IN_SET('active', e2.flags))) |
4f970ab0 SJ |
54 | LEFT JOIN emails_watch AS w ON (e1.email = w.email) |
55 | INNER JOIN aliases AS a1 ON (a1.id = e1.uid AND a1.type = 'a_vie') | |
56 | INNER JOIN aliases AS a2 ON (a2.id = e2.uid AND a2.type = 'a_vie') | |
57 | INNER JOIN auth_user_md5 AS u1 ON (a1.id = u1.user_id) | |
58 | INNER JOIN auth_user_md5 AS u2 ON (a2.id = u2.user_id) | |
59 | WHERE FIND_IN_SET('active', e1.flags) AND u1.nom != u2.nom_usage AND u2.nom != u1.nom_usage AND w.email IS NULL | |
60 | ORDER BY a1.alias"; | |
866f1333 | 61 | |
62 | $it = Xdb::iterRow($sql); | |
63 | ||
64 | $insert = array(); | |
65 | $conflits = array(); | |
66 | while (list($alias1, $alias2, $mail) = $it->next()) { | |
67 | $insert[] = "('$mail', 'pending', CURDATE(), NOW())"; | |
68 | $conflits[] = "* $mail sur $alias1 et $alias2"; | |
69 | } | |
70 | ||
71 | if (count($conflits) > 0) { | |
1707967a SJ |
72 | echo "Nouvelles adresses en doublon détectées :\n" . join("\n", $conflits) |
73 | . "\n\nVous pouvez entrer les informations collectées à ce sujet sur la page :\n" | |
74 | . "https://www.polytechnique.org/admin/emails/duplicated"; | |
866f1333 | 75 | |
76 | echo "\n\n"; | |
4f970ab0 SJ |
77 | $sql = "INSERT IGNORE INTO emails_watch (email, state, detection, last) |
78 | VALUES " . join(", ", $insert); | |
0380bf85 | 79 | XDB::execute($sql); |
80 | if (XDB::errno() != 0) { | |
81 | echo 'Error : ' . XDB::error() . "\n$sql"; | |
866f1333 | 82 | } |
83 | } | |
84 | ||
dc557110 | 85 | /* |
86 | * Check dead emails | |
87 | */ | |
88 | if ($panne_level > 0) { | |
d293e17c | 89 | $sql = "SELECT e.email, u.hruid |
4f970ab0 | 90 | FROM emails AS e |
d293e17c | 91 | INNER JOIN auth_user_md5 AS u ON u.user_id = e.uid |
dc557110 | 92 | WHERE e.panne_level = $panne_level AND e.flags = 'active' |
d293e17c | 93 | ORDER BY u.hruid"; |
dc557110 | 94 | $res = Xdb::query($sql); |
95 | ||
96 | if ($res->numRows()) { | |
97 | $result = $res->fetchAllAssoc(); | |
d20d604f | 98 | echo "Nouvelles adresses en panne detectees :\n"; |
dc557110 | 99 | foreach ($result as $assoc) { |
d293e17c | 100 | echo '* ' . $assoc['email'] . ' pour ' . $assoc['hruid'] . "\n"; |
dc557110 | 101 | } |
102 | echo "\n\n"; | |
866f1333 | 103 | |
dc557110 | 104 | Xdb::execute("UPDATE emails |
105 | SET flags = 'panne' | |
106 | WHERE panne_level = 3 AND flags = 'active'"); | |
107 | } | |
108 | ||
109 | Xdb::execute("UPDATE emails | |
110 | SET panne_level = $panne_level | |
111 | WHERE panne_level > $panne_level"); | |
112 | } | |
866f1333 | 113 | |
4f970ab0 SJ |
114 | /* |
115 | * Retrieve the users with no active redirection, but still one working | |
116 | * inactive redirection. | |
117 | */ | |
118 | if ($opt_verbose) { | |
119 | $res = XDB::query("SELECT u.hruid, ei.email | |
120 | FROM auth_user_md5 AS u | |
121 | LEFT JOIN emails AS ea ON (ea.uid = u.user_id AND ea.flags='active') | |
122 | INNER JOIN emails AS ei ON (ei.uid = u.user_id AND ei.flags='') | |
123 | WHERE FIND_IN_SET('googleapps', u.mail_storage) = 0 AND ea.email IS NULL | |
124 | GROUP BY u.user_id"); | |
125 | ||
126 | if ($res->numRows()) { | |
127 | $result = $res->fetchAllAssoc(); | |
128 | echo "Camarades n'ayant plus d'adresses actives, mais ayant une adresse inactive :\n"; | |
129 | foreach ($result as $user) { | |
130 | echo '* ' . $user['email'] . ' pour ' . $user['hruid'] . "\n"; | |
131 | } | |
132 | echo "\n"; | |
133 | } | |
134 | ||
a7de4ef7 | 135 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
866f1333 | 136 | ?> |