#603: Show QoS informations
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Tue, 23 Jan 2007 22:20:15 +0000 (22:20 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Tue, 23 Jan 2007 22:20:15 +0000 (22:20 +0000)
-> new page "admin/mx/broken" to register the MXs to which mail can't be delivered
-> show information to users who has no valid redirection or who has a redirection which use a 'broken mx'
-> add 'broken mx' stats on 'stats/coupures'

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

ChangeLog
include/emails.inc.php
include/xorg.misc.inc.php
include/xorg/session.inc.php
modules/admin.php
modules/stats.php
templates/admin/index.tpl
templates/events/index.tpl
templates/stats/coupure.tpl
upgrade/0.9.13/06_mx_watch.sql [new file with mode: 0644]

index b6bdb99..6716bca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -67,6 +67,9 @@ Bug/Wish:
     * Register:
         - #277: Improve ergonomy.                                          -FRU
 
+    * Stats:
+        - #603: Add informations on mail delivery                          -FRU
+
     * Xnet:
         - #570: Fix geoloc skin.                                           -FRU
         - #589: Can attach a file when sending an email                    -FRU
index 1e01343..f954b23 100644 (file)
@@ -235,6 +235,7 @@ class Redirect
                 unset($this->emails[$i]);
             }
         }
+        check_redirect($this);
         return SUCCESS;
     }
 
@@ -263,6 +264,7 @@ class Redirect
 
         // security stuff
         check_email($email, "Ajout d'une adresse surveillée aux redirections de " . $this->uid);
+        check_redirect($this);
         return SUCCESS;
     }
 
@@ -279,9 +281,11 @@ class Redirect
             }
             $this->emails[$i]->rewrite($emails_rewrite[$mail->email], $this->uid);
         }
+        check_redirect($this);
     }
 
-    function modify_one_email($email, $activate) {
+    function modify_one_email($email, $activate) 
+    {
         $allinactive = true;
         $thisone = false;
         foreach ($this->emails as $i=>$mail) {
@@ -293,10 +297,12 @@ class Redirect
         if ($thisone === false) {
             return ERROR_INVALID_EMAIL;
         }
-        if ($allinactive || $activate)
+        if ($allinactive || $activate) {
             $this->emails[$thisone]->activate($this->uid);
-        else
+        } else {
             $this->emails[$thisone]->deactivate($this->uid);
+        }
+        check_redirect($this);
         if ($allinactive && !$activate) {
             return ERROR_INACTIVE_REDIRECTION;
         } else {
@@ -308,11 +314,55 @@ class Redirect
                foreach ($this->emails as $i=>$mail) {
                        if ($mail->email == $email) {
                                $this->emails[$i]->rewrite($redirect, $this->uid);
-                               return;
+                check_redirect($this);
+                return;
                        }
                }
        }
     // }}}
+    // {{{ function get_broken_mx()
+
+    function get_broken_mx()
+    {
+        $res = XDB::iterRow("SELECT  host, text
+                               FROM  mx_watch
+                              WHERE  state != 'ok'");
+        if (!$res->total()) {
+            return array();
+        }
+        $mxs = array();
+        while (list($host, $text) = $res->next()) {
+            $host = preg_quote($host, '/');
+            $host = str_replace('\*', '.*', $host);
+            $host = str_replace('\?', '.', $host);
+            $mxs[] = array('host' => "/^$host\\.?$/", 'text' => $text);
+        }
+        $mails = array();
+        foreach ($this->emails as &$mail) {
+            if ($mail->active) {
+                list(,$domain) = explode('@', $mail->email);
+                getmxrr($domain, $lcl_mxs);
+                if (empty($lcl_mxs)) {
+                    $lcl_mxs = array($domain);
+                }
+                $broken = false;
+                foreach ($mxs as &$mx) {
+                    foreach ($lcl_mxs as $lcl) {
+                        if (preg_match($mx['host'], $lcl)) {
+                            $broken = $mx['text'];
+                            break;
+                        }
+                    }
+                    if ($broken) {
+                        $mails[] = array('mail' => $mail->email, 'text' => $broken);
+                    }
+                }
+            }
+        }
+        return $mails;
+    }
+
+    // }}}
 }
 
 // }}}
index 5473e7e..18722fc 100644 (file)
@@ -139,6 +139,17 @@ function check_email($email, $message)
     return false;
 }
 
+function check_redirect($red = null)
+{
+    require_once 'emails.inc.php';
+    if (is_null($red)) {
+        $red = new Redirect(S::v('uid'));
+    }    
+    $_SESSION['no_redirect'] = !$red->other_active('');
+    $_SESSION['mx_failures'] = $red->get_broken_mx();
+    
+}
+
 function send_warning_mail($title)
 {
     $mailer = new PlMailer();
index 71fe324..515a8fe 100644 (file)
@@ -262,6 +262,7 @@ function start_connexion ($uid, $identified)
         }
     }
     set_skin();
+    check_redirect();
     return true;
 }
 
index 54ef3b1..a635f00 100644 (file)
@@ -36,6 +36,7 @@ class AdminModule extends PLModule
             'admin/postfix/delayed'        => $this->make_hook('postfix_delayed', AUTH_MDP, 'admin'),
             'admin/postfix/regexp_bounces' => $this->make_hook('postfix_regexpsbounces', AUTH_MDP, 'admin'),
             'admin/postfix/whitelist'      => $this->make_hook('postfix_whitelist', AUTH_MDP, 'admin'),
+            'admin/mx/broken'              => $this->make_hook('mx_broken', AUTH_MDP, 'admin'),
             'admin/skins'                  => $this->make_hook('skins', AUTH_MDP, 'admin'),
             'admin/synchro_ax'             => $this->make_hook('synchro_ax', AUTH_MDP, 'admin'),
             'admin/user'                   => $this->make_hook('user', AUTH_MDP, 'admin'),
@@ -842,6 +843,15 @@ class AdminModule extends PLModule
         $table_editor->describe('email','email',true);
         $table_editor->apply($page, $action, $id);
     }
+    function handler_mx_broken(&$page, $action = 'list', $id = null) {
+        $page->assign('xorg_title', 'Polytechnique.org - Administration - MX Défaillants');
+        $page->assign('title', 'MX Défaillant');
+        $table_editor = new PLTableEditor('admin/mx/broken', 'mx_watch', 'host', true);
+        $table_editor->describe('host', 'Masque', true);
+        $table_editor->describe('state', 'Niveau', true);
+        $table_editor->describe('text', 'Description du problème', false);
+        $table_editor->apply($page, $action, $id);
+    }
     function handler_logger_actions(&$page, $action = 'list', $id = null) {
         $page->assign('xorg_title','Polytechnique.org - Administration - Actions');
         $page->assign('title', 'Gestion des actions de logger');
index 5dff251..c6f12e7 100644 (file)
@@ -281,7 +281,7 @@ EOF2;
             $cp  = $res->fetchOneAssoc();
         }
 
-        if($cp) {
+        if(@$cp) {
             $cp['lg_services'] = serv_to_str($cp['services']);
             $page->assign_by_ref('cp',$cp);
         } else {
@@ -289,6 +289,10 @@ EOF2;
             $sql = "SELECT  id, debut, resume, services
                       FROM  coupures where debut > '$beginning_date' order by debut desc";
             $page->assign('coupures', XDB::iterator($sql));
+            $res = XDB::iterator("SELECT  host, text
+                                    FROM  mx_watch
+                                   WHERE  state != 'ok'");
+            $page->assign('mxs', $res);
         }
     }
 }
index 95e26e2..5ce73d1 100644 (file)
@@ -75,6 +75,8 @@
       <strong>Infos dynamiques :</strong>&nbsp;&nbsp;
       <a href="admin/downtime">Coupures</a>
       &nbsp;&nbsp;|&nbsp;&nbsp;
+      <a href="admin/mx/broken">MX défaillants</a>
+      &nbsp;&nbsp;|&nbsp;&nbsp;
       <a href="admin/tips">Astuces</a>
     </td>
   </tr>
index 58628f1..a0222d9 100644 (file)
@@ -35,11 +35,34 @@ Bienvenue {$smarty.session.prenom}
 {/if}
 </h1>
 
+{if $smarty.session.host}
 <div class="smaller">
   Ta connexion précédente date du
   <strong>{$smarty.session.lastlogin|date_format:"%x, %X"}</strong>
   depuis la machine <strong>{$smarty.session.host}</strong>
 </div>
+{/if}
+
+{if $smarty.session.no_redirect}
+<p class="erreur">
+  Tu n'as plus de redirection valide ce qui rend ton adresse Polytechnique.org
+  inutilisable. Rend-toi au plus vite sur <a href="emails/redirect">la page de 
+  gestion des emails</a> pour corriger ce problème.
+</p>
+{/if}
+
+{if $smarty.session.mx_failures|@count}
+<fieldset>
+  <legend>{icon name=error}Des problèmes sont actuellement recontrés sur tes redirections suivantes</legend>
+  {foreach from=$smarty.session.mx_failures item=mail}
+  <div>
+    <span class="erreur">{$mail.mail}</span>
+    <div class="explication">{$mail.text}</div>
+  </div>
+{/foreach}
+</fieldset>
+{/if}
+
   
 {if $fiche_incitation}
   <p>La dernière mise à jour de ta
index 96c02f2..d8025be 100644 (file)
@@ -20,6 +20,8 @@
 {*                                                                        *}
 {**************************************************************************}
 
+<h1>Coupures de Polytechnique.org</h1>
+
 {if $cp}
 <table class="bicol" summary="Ruptures de service">
   <tr>
@@ -73,7 +75,7 @@
     <th>services affectés</th>
   </tr>
 {iterate item=cp from=$coupures}
-  <tr class="{cycle values="pair,impair"}">
+  <tr class="{cycle values="impair,pair"}">
     <td>
       <span class="smaller">
         {$cp.debut|date_format}
   </tr>
 {/iterate}
 </table>
+
+<h1>Problèmes avec les autres fournisseurs de services</h1>
+
+<p>
+  La liste ci-dessous indique quels sont les fournisseurs de mails vers lesquels nous avons
+  actuellement des problèmes de tranmission.
+</p>
+
+<table class="bicol">
+  <tr><th>Liste des disfonctionnements</th></tr>
+  {iterate from=$mxs item=mx}
+  <tr class="{cycle values="impair,pair"}">
+    <td><strong>{$mx.host}</strong><div class="explication">{$mx.text}</div></td>
+  </tr>
+  {/iterate}
+</table>
+
 {/if}
 
 {* vim:set et sw=2 sts=2 sws=2: *}
diff --git a/upgrade/0.9.13/06_mx_watch.sql b/upgrade/0.9.13/06_mx_watch.sql
new file mode 100644 (file)
index 0000000..8799cc4
--- /dev/null
@@ -0,0 +1,8 @@
+CREATE TABLE `mx_watch` (
+    `host` VARCHAR(64) NOT NULL,
+    `state` ENUM('ok', 'warning', 'broken') DEFAULT 'ok',
+    `text` MEDIUMTEXT NOT NULL,
+    PRIMARY KEY(`host`)
+);
+
+# vim:set syntax=mysql: