Commit | Line | Data |
---|---|---|
ee68ddc1 | 1 | #!/usr/bin/php5 -q |
866f1333 | 2 | <?php |
3 | /*************************************************************************** | |
9f5bd98e | 4 | * Copyright (C) 2003-2010 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 | ||
5ecaa68e SJ |
27 | require './connect.db.inc.php'; |
28 | require 'Console/Getopt.php'; | |
4f970ab0 SJ |
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 | */ | |
fe2a133d SJ |
50 | $it = Xdb::iterRow("SELECT al1.alias, al2.alias, e1.email |
51 | FROM emails AS e1 | |
52 | INNER JOIN emails AS e2 ON (e1.email = e2.email AND e1.uid != e2.uid | |
53 | AND (e1.uid < e2.uid OR NOT FIND_IN_SET('active', e2.flags))) | |
54 | INNER JOIN aliases AS al1 ON (al1.uid = e1.uid AND al1.type = 'a_vie') | |
55 | INNER JOIN aliases AS al2 ON (al2.uid = e2.uid AND al2.type = 'a_vie') | |
56 | INNER JOIN accounts AS a1 ON (al1.uid = a1.uid) | |
57 | INNER JOIN accounts AS a2 ON (al2.uid = a2.uid) | |
58 | LEFT JOIN email_watch AS w ON (e1.email = w.email) | |
59 | WHERE FIND_IN_SET('active', e1.flags) AND w.email IS NULL | |
60 | ORDER BY al1.alias"); | |
866f1333 | 61 | |
62 | $insert = array(); | |
63 | $conflits = array(); | |
64 | while (list($alias1, $alias2, $mail) = $it->next()) { | |
65 | $insert[] = "('$mail', 'pending', CURDATE(), NOW())"; | |
66 | $conflits[] = "* $mail sur $alias1 et $alias2"; | |
67 | } | |
68 | ||
69 | if (count($conflits) > 0) { | |
1707967a SJ |
70 | echo "Nouvelles adresses en doublon détectées :\n" . join("\n", $conflits) |
71 | . "\n\nVous pouvez entrer les informations collectées à ce sujet sur la page :\n" | |
72 | . "https://www.polytechnique.org/admin/emails/duplicated"; | |
866f1333 | 73 | |
74 | echo "\n\n"; | |
06f4daf9 | 75 | $sql = "INSERT IGNORE INTO email_watch (email, state, detection, last) |
4f970ab0 | 76 | VALUES " . join(", ", $insert); |
0380bf85 | 77 | XDB::execute($sql); |
78 | if (XDB::errno() != 0) { | |
79 | echo 'Error : ' . XDB::error() . "\n$sql"; | |
866f1333 | 80 | } |
81 | } | |
82 | ||
dc557110 | 83 | /* |
84 | * Check dead emails | |
85 | */ | |
86 | if ($panne_level > 0) { | |
fe2a133d SJ |
87 | $res = Xdb::query("SELECT e.email, a.hruid |
88 | FROM emails AS e | |
89 | INNER JOIN accounts AS a ON (a.uid = e.uid) | |
90 | WHERE e.panne_level = {?} AND e.flags = 'active' | |
91 | ORDER BY a.hruid", | |
92 | $panne_level); | |
dc557110 | 93 | |
94 | if ($res->numRows()) { | |
95 | $result = $res->fetchAllAssoc(); | |
d20d604f | 96 | echo "Nouvelles adresses en panne detectees :\n"; |
dc557110 | 97 | foreach ($result as $assoc) { |
d293e17c | 98 | echo '* ' . $assoc['email'] . ' pour ' . $assoc['hruid'] . "\n"; |
dc557110 | 99 | } |
100 | echo "\n\n"; | |
866f1333 | 101 | |
dc557110 | 102 | Xdb::execute("UPDATE emails |
103 | SET flags = 'panne' | |
104 | WHERE panne_level = 3 AND flags = 'active'"); | |
105 | } | |
106 | ||
fe2a133d SJ |
107 | Xdb::execute('UPDATE emails |
108 | SET panne_level = {?} | |
109 | WHERE panne_level > {?}', | |
110 | $panne_level, $panne_level); | |
dc557110 | 111 | } |
866f1333 | 112 | |
4f970ab0 SJ |
113 | /* |
114 | * Retrieve the users with no active redirection, but still one working | |
115 | * inactive redirection. | |
116 | */ | |
117 | if ($opt_verbose) { | |
fe2a133d SJ |
118 | $res = XDB::query("SELECT a.hruid, ei.email |
119 | FROM accounts AS a | |
120 | LEFT JOIN emails AS ea ON (ea.uid = a.uid AND ea.flags = 'active') | |
121 | INNER JOIN emails AS ei ON (ei.uid = a.uid AND ei.flags = '') | |
122 | INNER JOIN email_options AS eo ON (eo.uid = a.uid) | |
123 | WHERE NOT FIND_IN_SET('googleapps', eo.storage) AND ea.email IS NULL | |
124 | GROUP BY a.uid"); | |
4f970ab0 SJ |
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 | } | |
c952e3ea SJ |
132 | } |
133 | echo "\n"; | |
4f970ab0 SJ |
134 | } |
135 | ||
a7de4ef7 | 136 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
866f1333 | 137 | ?> |