Add by-account monitoring
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 24 Feb 2007 13:25:48 +0000 (13:25 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Sat, 24 Feb 2007 13:25:48 +0000 (13:25 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1514 839d8a87-29fc-0310-9880-83ba4fa771e5

include/webservices/manageurs.server.inc.php
include/xorg.misc.inc.php
include/xorg/session.inc.php
modules/admin.php
modules/register.php
modules/register/register.inc.php
templates/admin/utilisateurs.tpl
upgrade/0.9.14/01_auth_user_md5.sql [new file with mode: 0644]

index 54d8570..445f8a7 100644 (file)
@@ -151,7 +151,7 @@ function get_nouveau_infos($method, $params) {
     if( !empty($params[1]) ){ // on verifie qu'on a bien un matricule
 
         $res = XDB::query(
-            "SELECT  a.nom, a.nom_usage,a.prenom,a.flags='femme' as femme ,a.deces!= 0 as decede ,
+            "SELECT  a.nom, a.nom_usage,a.prenom, FIND_IN_SET('femme', a.flags) as femme ,a.deces!= 0 as decede ,
             a.naissance, a.promo, concat(al.alias, '@m4x.org') as mail 
             FROM  auth_user_md5 AS a
             INNER JOIN aliases as al ON a.user_id=al.id
index ba3e281..e98250e 100644 (file)
@@ -215,6 +215,11 @@ function check_email($email, $message)
     return false;
 }
 
+function check_account()
+{
+    return S::v('watch');
+}
+
 function check_redirect($red = null)
 {
     require_once 'emails.inc.php';
@@ -222,8 +227,7 @@ function check_redirect($red = null)
         $red = new Redirect(S::v('uid'));
     }    
     $_SESSION['no_redirect'] = !$red->other_active('');
-    $_SESSION['mx_failures'] = $red->get_broken_mx();
-    
+    $_SESSION['mx_failures'] = $red->get_broken_mx();    
 }
 
 function send_warning_mail($title)
index b2e6d17..9669564 100644 (file)
@@ -31,7 +31,7 @@ class XorgSession
         if (!S::has('uid')) {
             try_cookie();
         }
-        if (check_ip('dangerous') && S::has('uid')) {
+        if ((check_ip('dangerous') && S::has('uid')) || check_account()) {
             $_SESSION['log']->log("view_page", $_SERVER['REQUEST_URI']);
         }
     }
@@ -224,7 +224,8 @@ function start_connexion ($uid, $identified)
     $res  = XDB::query("
     SELECT  u.user_id AS uid, prenom, nom, perms, promo, matricule, password, FIND_IN_SET('femme', u.flags) AS femme,
                 UNIX_TIMESTAMP(s.start) AS lastlogin, s.host, a.alias AS forlife, a2.alias AS bestalias,
-                q.core_mail_fmt AS mail_fmt, UNIX_TIMESTAMP(q.banana_last) AS banana_last, q.watch_last, q.core_rss_hash
+                q.core_mail_fmt AS mail_fmt, UNIX_TIMESTAMP(q.banana_last) AS banana_last, q.watch_last, q.core_rss_hash,
+                FIND_IN_SET('watch', u.flags) AS watch_account
           FROM  auth_user_md5   AS u
     INNER JOIN  auth_user_quick AS q  USING(user_id)
     INNER JOIN  aliases         AS a  ON (u.user_id = a.id AND a.type='a_vie')
@@ -250,8 +251,16 @@ function start_connexion ($uid, $identified)
     $_SESSION         = array_merge($_SESSION, $sess);
     $_SESSION['log']  = $logger;
     $_SESSION['auth'] = ($identified ? AUTH_MDP : AUTH_COOKIE);
+    $mail_subject = null;
+    if (check_account()) {
+        $mail_subject = "Connexion d'un utilisateur surveillé";
+    }
     if (check_ip('unsafe')) {
-        send_warning_mail("Une IP surveillee a tente de se connecter");
+        if ($mail_subject) {
+            $mail_subject .= ' - ';
+        }
+        $mail_subject .= "Une IP surveillee a tente de se connecter";
+        send_warning_mail($mail_subject);
         if (check_ip('ban')) {
             $_SESSION = array();
             global $page;
@@ -261,6 +270,9 @@ function start_connexion ($uid, $identified)
             return false;
         }
     }
+    if ($mail_subject) {
+        send_warning_mail($mail_subject);
+    }
     set_skin();
     check_redirect();
     return true;
index ac905f5..dab5924 100644 (file)
@@ -388,13 +388,15 @@ class AdminModule extends PLModule
 
         if ($login) {
             if (is_numeric($login)) {
-                $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe,
+                $r = XDB::query("SELECT *, a.alias AS forlife,
+                                        FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe,
                                         (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err
                                    FROM auth_user_md5 AS u
                               LEFT JOIN aliases       AS a ON (a.id = u.user_id AND type= 'a_vie')
                                   WHERE u.user_id = {?}", $login);
             } else {
-                $r  = XDB::query("SELECT  *, a.alias AS forlife, u.flags AS sexe,
+                $r  = XDB::query("SELECT  *, a.alias AS forlife, 
+                                          FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe,
                                           (year(naissance) > promo - 15 or year(naissance) < promo - 25) AS naiss_err
                                     FROM  auth_user_md5 AS u
                               INNER JOIN  aliases       AS a ON ( a.id = u.user_id AND a.alias={?} AND type!='homonyme' )", $login);
@@ -473,7 +475,23 @@ class AdminModule extends PLModule
                     $nom   = Env::v('nomN');
                     $promo = Env::i('promoN');
                     $sexe  = Env::v('sexeN');
-                    $comm  = Env::v('commentN');
+                    $comm  = trim(Env::v('commentN'));
+                    $watch = Env::v('watchN');
+                    $flags = '';
+                    if ($sexe) {
+                        $flags = 'femme';
+                    }
+                    if ($watch) {
+                        if ($flags) {
+                            $flags .= ',';
+                        }
+                        $flags .= 'watch';
+                    }
+
+                    if ($watch && !$comm) {
+                        $page->trig("Il est nécessaire de mettre un commentaire pour surveiller un compte");
+                        break;
+                    }
 
                     $query = "UPDATE auth_user_md5 SET
                             naissance = '$naiss',
@@ -482,7 +500,7 @@ class AdminModule extends PLModule
                             perms     = '$perms',
                             prenom    = '".addslashes($prenm)."',
                             nom       = '".addslashes($nom)."',
-                            flags     = '$sexe',
+                            flags     = '$flags',
                             promo     = $promo,
                             comment   = '".addslashes($comm)."'
                         WHERE user_id = '{$mr['user_id']}'";
@@ -502,7 +520,8 @@ class AdminModule extends PLModule
                         if (Env::v('decesN') != $mr['deces']) {
                             user_clear_all_subs($mr['user_id'], false);
                         }
-                        $r = XDB::query("SELECT *, a.alias AS forlife, u.flags AS sexe
+                        $r = XDB::query("SELECT *, a.alias AS forlife,
+                                                FIND_IN_SET('watch', u.flags) AS watch, FIND_IN_SET('femme', u.flags) AS sexe
                                            FROM auth_user_md5 AS u
                                       LEFT JOIN aliases       AS a ON (a.id = u.user_id AND type= 'a_vie')
                                           WHERE u.user_id = {?}", $mr['user_id']);
index 3549145..92fc139 100644 (file)
@@ -58,17 +58,18 @@ class RegisterModule extends PLModule
 
         if ($hash) {
             $res = XDB::query(
-                    "SELECT  m.uid, u.promo, u.nom, u.prenom, u.matricule
+                    "SELECT  m.uid, u.promo, u.nom, u.prenom, u.matricule, FIND_IN_SET('watch', u.flags)
                        FROM  register_marketing AS m
                  INNER JOIN  auth_user_md5      AS u ON u.user_id = m.uid
                       WHERE  m.hash={?}", $hash);
-            if (list($uid, $promo, $nom, $prenom, $ourmat) = $res->fetchOneRow()) {
+            if (list($uid, $promo, $nom, $prenom, $ourmat, $watch) = $res->fetchOneRow()) {
                 $sub_state['uid']    = $uid;
                 $sub_state['hash']   = $hash;
                 $sub_state['promo']  = $promo;
                 $sub_state['nom']    = $nom;
                 $sub_state['prenom'] = $prenom;
                 $sub_state['ourmat'] = $ourmat;
+                $sub_state['watch']  = $watch;
 
                 XDB::execute(
                         "REPLACE INTO  register_mstats (uid,sender,success)
@@ -168,6 +169,9 @@ class RegisterModule extends PLModule
                     if (count($aliases) != 0) {
                         $alert .= "Email surveille propose a l'inscription - ";
                     }
+                    if ($sub_state['watch']) {
+                        $alter .= "Inscription d'un utilisateur surveillé - ";
+                    }
 
                     if (check_ip('unsafe')) {
                         unset($err);
index 55ae357..b9ab92f 100644 (file)
@@ -46,7 +46,7 @@ function user_cmp($prenom, $nom, $_prenom, $_nom)
 // }}}
 // {{{ function check_mat
 
-function check_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
+function check_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid, &$watch)
 {
     if (!preg_match('/^[0-9][0-9][0-9][0-9][0-9][0-9]$/', $mat)) {
         return "Le matricule doit comporter 6 chiffres.";
@@ -62,10 +62,10 @@ function check_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
     }
 
     $res = XDB::query(
-            'SELECT  user_id, promo, perms IN ("admin","user"), nom, prenom 
+            'SELECT  user_id, promo, perms IN ("admin","user"), nom, prenom, FIND_IN_SET(\'watch\', u.flags)
               FROM  auth_user_md5
              WHERE  matricule={?} and deces = 0', $ourmat);
-    list ($uid, $_promo, $_already, $_nom, $_prenom) = $res->fetchOneRow();
+    list ($uid, $_promo, $_already, $_nom, $_prenom, $watch) = $res->fetchOneRow();
     if ($_already) { return "tu es déjà inscrit ou ton matricule est incorrect !"; }
     if ($_promo != $promo) { return "erreur de matricule"; }
 
@@ -80,13 +80,13 @@ function check_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
 // }}}
 // {{{ function check_old_mat
 
-function check_old_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
+function check_old_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid, &$watch)
 {
     $res = XDB::iterRow(
-            'SELECT  user_id, nom, prenom, matricule
+            'SELECT  user_id, nom, prenom, matricule, FIND_IN_SET(\'watch\', flags)
                FROM  auth_user_md5
               WHERE  promo={?} AND deces=0 AND perms="pending"', $promo);
-    while (list($_uid, $_nom, $_prenom, $_mat) = $res->next()) {
+    while (list($_uid, $_nom, $_prenom, $_mat, $watch) = $res->next()) {
         if (user_cmp($prenom, $nom, $_prenom, $_nom)) {
             $ourid  = $_uid;
             $ourmat = $_mat;
@@ -95,11 +95,11 @@ function check_old_mat($promo, $mat, $nom, $prenom, &$ourmat, &$ourid)
     }
 
     $res = XDB::iterRow(
-            'SELECT  user_id, nom, prenom, matricule, alias
+            'SELECT  user_id, nom, prenom, matricule, alias, FIND_IN_SET(\'watch\', u.flags)
                FROM  auth_user_md5 AS u
          INNER JOIN  aliases       AS a ON (u.user_id = a.id and FIND_IN_SET("bestalias", a.flags))
               WHERE  promo={?} AND deces=0 AND perms IN ("user","admin")', $promo);
-    while (list($_uid, $_nom, $_prenom, $_mat, $alias) = $res->next()) {
+    while (list($_uid, $_nom, $_prenom, $_mat, $alias, $watch) = $res->next()) {
         if (user_cmp($prenom, $nom, $_prenom, $_nom)) {
             $ourid  = $_uid;
             $ourmat = $_mat;
@@ -127,9 +127,9 @@ function check_new_user(&$sub)
     $nom     = strtoupper(replace_accent($nom));
 
     if ($promo >= 1996) {
-        $res = check_mat($promo, $mat, $nom, $prenom, $ourmat, $ourid);
+        $res = check_mat($promo, $mat, $nom, $prenom, $ourmat, $ourid, $watch);
     } else {
-        $res = check_old_mat($promo, $mat, $nom, $prenom, $ourmat, $ourid);
+        $res = check_old_mat($promo, $mat, $nom, $prenom, $ourmat, $ourid, $watch);
     }
     if ($res !== true) { return $res; }
 
@@ -137,6 +137,7 @@ function check_new_user(&$sub)
     $sub['prenom'] = $prenom;
     $sub['ourmat'] = $ourmat;
     $sub['uid']    = $ourid;
+    $sub['watch']  = $watch;
 
     return true;
 }
index ba7d0cb..b577e38 100644 (file)
@@ -163,8 +163,8 @@ function act_fwd(fwd, activate) {
         Sexe
       </td>
       <td>
-        femme <input type="radio" name="sexeN" {if $mr.sexe eq 'femme'}checked="checked"{/if} value='femme'/>
-        <input type="radio" name="sexeN" {if $mr.sexe neq 'femme'}checked="checked"{/if} value=''/> homme
+        femme <input type="radio" name="sexeN" {if $mr.sexe}checked="checked"{/if} value='1'/>
+        <input type="radio" name="sexeN" {if !$mr.sexe}checked="checked"{/if} value='0'/> homme
       </td>
     </tr>
     <tr class="pair">
@@ -209,6 +209,17 @@ function act_fwd(fwd, activate) {
         <input type="text" name="promoN" size="4" maxlength="4" value="{$mr.promo}" />
       </td>
     </tr>
+    <tr class "impair">
+      <td class="titre">
+        Surveillance
+      </td>
+      <td>
+        <input type="checkbox" name="watchN" {if $mr.watch}checked="checked"{/if} />
+        Surveiller l'activité de ce compte<br />
+        <span class="smaller">Cette option permet d'avoir des logs complets de l'activité
+        du compte via le logger, et d'être alerté lors des connexions de l'utilisateur</span>
+      </td>
+    </tr>
     <tr class="impair">
       <td class="titre">
         Commentaire
diff --git a/upgrade/0.9.14/01_auth_user_md5.sql b/upgrade/0.9.14/01_auth_user_md5.sql
new file mode 100644 (file)
index 0000000..41f068b
--- /dev/null
@@ -0,0 +1,3 @@
+alter table auth_user_md5 change flags flags set('femme', 'watch') not null;
+
+# vim:set syntax=mysql: