Better duplicated email check
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 27 Jul 2006 10:01:25 +0000 (10:01 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Thu, 27 Jul 2006 10:01:25 +0000 (10:01 +0000)
Still have to make the associated admin page

git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@675 839d8a87-29fc-0310-9880-83ba4fa771e5

bin/cron/checkdb.php
bin/cron/emails.check.php [new file with mode: 0755]
configs/platal.cron
upgrade/0.9.11/05_email_watch.sql [new file with mode: 0644]

index 66bca29..c804224 100755 (executable)
@@ -122,11 +122,12 @@ check("SELECT a.uid, a.country, a.region FROM adresses AS a LEFT JOIN geoloc_reg
 info("select e.matricule,e.nom,e.prenom,e.promo from envoidirect as e inner join auth_user_md5 as a on (e.matricule = a.matricule and a.perms = 'user') order by promo,nom;");
 
 /* donne la liste des emails qui apparaissent 2 fois dans la table emails pour des personnes différentes */
-info("SELECT  a1.alias, a2.alias, e1.email, e2.flags
+info("SELECT  a1.alias, a2.alias, e1.email, e2.flags, w.state, w.description
         FROM  emails        AS e1
         INNER JOIN  emails        AS e2 ON(e1.email = e2.email AND e1.uid!=e2.uid AND 
             (e1.uid<e2.uid  OR  NOT FIND_IN_SET(e2.flags,'active'))
             )
+        INNER JOIN  emails_watch  AS w  ON(w.email = e1.email AND w.state != 'safe')
         INNER JOIN  aliases       AS a1 ON(a1.id=e1.uid AND a1.type='a_vie')
         INNER JOIN  aliases       AS a2 ON(a2.id=e2.uid AND a2.type='a_vie')
         INNER JOIN  auth_user_md5 AS u1 ON(a1.id=u1.user_id)
diff --git a/bin/cron/emails.check.php b/bin/cron/emails.check.php
new file mode 100755 (executable)
index 0000000..fc9322c
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/php4 -q
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2006 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+require('./connect.db.inc.php');
+
+$sql = "SELECT a1.alias, a2.alias, e1.email
+          FROM emails        AS e1
+    INNER JOIN emails        AS e2 ON (e1.email = e2.email AND e1.uid != e2.uid 
+                                       AND (e1.uid < e2.uid OR NOT FIND_IN_SET(e2.flags, 'active')))
+     LEFT JOIN emails_watch  AS w  ON (e1.email = w.email)
+    INNER JOIN aliases       AS a1 ON (a1.id = e1.uid AND a1.type = 'a_vie')
+    INNER JOIN aliases       AS a2 ON (a2.id = e2.uid AND a2.type = 'a_vie')
+    INNER JOIN auth_user_md5 AS u1 ON (a1.id = u1.user_id)
+    INNER JOIN auth_user_md5 AS u2 ON (a2.id = u2.user_id)
+         WHERE FIND_IN_SET(e1.flags, 'active') AND u1.nom != u2.nom_usage AND u2.nom != u1.nom_usage AND w.email IS NULL
+      ORDER BY a1.alias";
+
+$it = Xdb::iterRow($sql);
+
+$insert   = array();
+$conflits = array();
+while (list($alias1, $alias2, $mail) = $it->next()) {
+    $insert[]   = "('$mail', 'pending', CURDATE(), NOW())";
+    $conflits[] = "* $mail sur $alias1 et $alias2";
+}
+
+if (count($conflits) > 0) {
+    echo "Nouvelles adresses en doublon détectées :\n" . join("\n", $conflits)
+        . "\n\nVous pouvez entrer les informations collectées à ce sujet sur la page :\n"
+        . "http://www.polytechnique.org/admin/doublons";
+
+    echo "\n\n";
+    $sql = "INSERT IGNORE INTO emails_watch (email, state, detection, last)
+                        VALUES " . join(", ", $insert);
+    Xdb::execute($sql);
+    if (mysql_errno() != 0) {
+        echo 'Error : ' . mysql_error() . "\n$sql";
+    }
+}
+
+
+
+?>
index cae5cb4..6bcf68c 100644 (file)
@@ -6,6 +6,7 @@ WD=/home/web/prod/platal/bin/cron
 0  5 * * *     web     cd $WD; ./clean.php
 0 21 * * 1-6   web     cd $WD; ./checkdb.php    | mail -e -s "verifications sur la BDD de plat/al"         br@m4x.org
 0 21 * * 0     web     cd $WD; ./checkdb.php -v | mail -e -s "verifications verbose sur la BDD de plat/al" br@m4x.org
+0 20 * * *      web     cd $WD; ./emails.check.php | mail -e -s "recherche d'usurpateurs"                   br@m4x.org
 
 # inscription report
 0  6 * * 1     web     cd $WD; ./rapports_inscription.php
diff --git a/upgrade/0.9.11/05_email_watch.sql b/upgrade/0.9.11/05_email_watch.sql
new file mode 100644 (file)
index 0000000..e24f906
--- /dev/null
@@ -0,0 +1,9 @@
+CREATE TABLE `emails_watch` (
+    `email` CHAR(60) NOT NULL,
+    `state` ENUM('pending', 'safe', 'unsafe', 'dangerous') NOT NULL DEFAULT 'pending',
+    `detection` DATE DEFAULT 0,
+    `last` TIMESTAMP DEFAULT 0,
+    `uid`  SMALLINT(5) DEFAULT NULL,
+    `description` TEXT NOT NULL,
+    PRIMARY KEY(`email`)
+);